]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
ProgressBarTextureMod
authorPerttu Ahola <celeron55@gmail.com>
Fri, 24 Dec 2010 09:44:26 +0000 (11:44 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 24 Dec 2010 09:44:26 +0000 (11:44 +0200)
data/tool_stpick.png
data/tool_wpick.png
src/inventory.h
src/irrlichtwrapper.cpp
src/irrlichtwrapper.h
src/main.cpp
src/map.cpp
src/mapblockobject.h
src/server.cpp

index 531599f44965e8600a807f3777cdf0124f841aa3..9ca3a5e03524a653dfebbb28e6ba63d25443fc07 100644 (file)
Binary files a/data/tool_stpick.png and b/data/tool_stpick.png differ
index ee7b8222e0d143a3f430cc7c54c33bd79626390b..3592495154f62365e3adf6b6941dec31c793772d 100644 (file)
Binary files a/data/tool_wpick.png and b/data/tool_wpick.png differ
index e97db8ffbb20d0b6bb200e93f0e54f7cff7f1953..fd2cd87787751bd1edaf8efb894e77279d8986d4 100644 (file)
@@ -226,17 +226,39 @@ class ToolItem : public InventoryItem
 #ifndef SERVER
        video::ITexture * getImage()
        {
+               std::string basename;
                if(m_toolname == "WPick")
-                       return g_irrlicht->getTexture("../data/tool_wpick.png");
-               if(m_toolname == "STPick")
-                       return g_irrlicht->getTexture("../data/tool_stpick.png");
+                       basename = "../data/tool_wpick.png";
+               else if(m_toolname == "STPick")
+                       basename = "../data/tool_stpick.png";
                // Default to cloud texture
-               return g_irrlicht->getTexture(tile_texture_path_get(TILE_CLOUD));
+               else
+                       basename = tile_texture_path_get(TILE_CLOUD);
+               
+               /*
+                       Calculate some progress value with sane amount of
+                       maximum states
+               */
+               u32 maxprogress = 30;
+               u32 toolprogress = (65535-m_wear)/(65535/maxprogress);
+               
+               // Make texture name for the new texture with a progress bar
+               std::ostringstream os;
+               os<<basename<<"-toolprogress-"<<toolprogress;
+               std::string finalname = os.str();
+
+               float value_f = (float)toolprogress / (float)maxprogress;
+               
+               // Get such a texture
+               TextureMod *mod = new ProgressBarTextureMod(value_f);
+               return g_irrlicht->getTexture(TextureSpec(finalname, basename, mod));
        }
 #endif
        std::string getText()
        {
-               std::ostringstream os;
+               return "";
+               
+               /*std::ostringstream os;
                u16 f = 4;
                u16 d = 65535/f;
                u16 i;
@@ -244,7 +266,7 @@ class ToolItem : public InventoryItem
                        os<<'X';
                for(; i<f; i++)
                        os<<'-';
-               return os.str();
+               return os.str();*/
                
                /*std::ostringstream os;
                os<<m_toolname;
index c012b136e80df098746ff8c1b6c95d50a31fb131..fc9f96b18320522c54e2f27bc5d000df453de164 100644 (file)
@@ -146,39 +146,45 @@ video::ITexture * CrackTextureMod::make(video::ITexture *original,
        return newtexture;
 }
 
-#if 0
-video::ITexture * createAlphaBlitTexture(const char *name, video::ITexture *base,
-               video::ITexture *other, v2u32 size, v2s32 pos_base, v2s32 pos_other)
+video::ITexture * ProgressBarTextureMod::make(video::ITexture *original,
+               const char *newname, video::IVideoDriver* driver)
 {
-       if(g_device == NULL)
-               return NULL;
-       video::IVideoDriver* driver = g_device->getVideoDriver();
-
-       core::dimension2d<u32> dim(size.X, size.Y);
+       core::position2d<s32> pos_base(0, 0);
+       core::dimension2d<u32> dim = original->getOriginalSize();
 
-       video::IImage *baseimage = driver->createImage(
-                       base,
-                       core::position2d<s32>(pos_base.X, pos_base.Y),
-                       dim);
+       video::IImage *baseimage = driver->createImage(original, pos_base, dim);
        assert(baseimage);
-
-       video::IImage *otherimage = driver->createImage(
-                       other,
-                       core::position2d<s32>(pos_other.X, pos_other.Y),
-                       dim);
-       assert(sourceimage);
        
-       otherimage->copyToWithAlpha(baseimage, v2s32(0,0),
-                       core::rect<s32>(v2s32(0,0), dim),
-                       video::SColor(255,255,255,255),
-                       core::rect<s32>(v2s32(0,0), dim));
-       otherimage->drop();
+       core::dimension2d<u32> size = baseimage->getDimension();
 
-       video::ITexture *newtexture = driver->addTexture(name, baseimage);
+       u32 barheight = 1;
+       u32 barpad_x = 1;
+       u32 barpad_y = 1;
+       u32 barwidth = size.Width - barpad_x*2;
+       v2u32 barpos(barpad_x, size.Height - barheight - barpad_y);
+
+       u32 barvalue_i = round((float)barwidth * value);
+
+       video::SColor active(255,255,0,0);
+       video::SColor inactive(255,0,0,0);
+       for(u32 x0=0; x0<barwidth; x0++)
+       {
+               video::SColor *c;
+               if(x0 < barvalue_i)
+                       c = &active;
+               else
+                       c = &inactive;
+               u32 x = x0 + barpos.X;
+               for(u32 y=barpos.Y; y<barpos.Y+barheight; y++)
+               {
+                       baseimage->setPixel(x,y, *c);
+               }
+       }
+       
+       video::ITexture *newtexture = driver->addTexture(newname, baseimage);
 
        baseimage->drop();
 
        return newtexture;
 }
-#endif
 
index 981e3377fe5d761d55298b36919716297684a3d8..ce54b70c0c86bb235ced5b35e2e52d20f7a55b55 100644 (file)
@@ -97,6 +97,20 @@ struct CrackTextureMod: public TextureMod
        u16 progression;
 };
 
+struct ProgressBarTextureMod: public TextureMod
+{
+       // value is from 0.0 to 1.0
+       ProgressBarTextureMod(float a_value)
+       {
+               value = a_value;
+       }
+       
+       virtual video::ITexture * make(video::ITexture *original,
+                       const char *newname, video::IVideoDriver* driver);
+       
+       float value;
+};
+
 /*
        A class for specifying a requested texture
 */
index ac91b9d3dd44630c4418eccf420f845cb53e9151..df335ad39868a8215104850641262c0a658c375f 100644 (file)
@@ -177,7 +177,8 @@ TODO: Check if the usage of Client::isFetchingBlocks() in
 Doing now:\r
 ======================================================================\r
 \r
-TODO: Tool capability table\r
+TODO: Tool capability table: Which materials, at what speed, how much\r
+      wearing\r
 TODO: Transferring of the table from server to client\r
 \r
 ======================================================================\r
@@ -2122,9 +2123,21 @@ int main(int argc, char *argv[])
                                                        }\r
                                                }\r
                                        }\r
+                                       else if(n.d == CONTENT_TORCH)\r
+                                       {\r
+                                               dig_time_complete = 0.0;\r
+                                       }\r
                                        \r
-                                       dig_index = (u16)((float)CRACK_ANIMATION_LENGTH\r
-                                                       * dig_time/dig_time_complete);\r
+                                       if(dig_time_complete >= 0.001)\r
+                                       {\r
+                                               dig_index = (u16)((float)CRACK_ANIMATION_LENGTH\r
+                                                               * dig_time/dig_time_complete);\r
+                                       }\r
+                                       // This is for torches\r
+                                       else\r
+                                       {\r
+                                               dig_index = CRACK_ANIMATION_LENGTH;\r
+                                       }\r
 \r
                                        if(dig_index < CRACK_ANIMATION_LENGTH)\r
                                        {\r
@@ -2142,6 +2155,19 @@ int main(int argc, char *argv[])
 \r
                                                nodig_delay_counter = dig_time_complete\r
                                                                / (float)CRACK_ANIMATION_LENGTH;\r
+\r
+                                               // We don't want a corresponding delay to\r
+                                               // very time consuming nodes\r
+                                               if(nodig_delay_counter > 0.5)\r
+                                               {\r
+                                                       nodig_delay_counter = 0.5;\r
+                                               }\r
+                                               // We want a slight delay to very little\r
+                                               // time consuming nodes\r
+                                               if(nodig_delay_counter < 0.15)\r
+                                               {\r
+                                                       nodig_delay_counter = 0.15;\r
+                                               }\r
                                        }\r
 \r
                                        dig_time += dtime;\r
index acaf8436a3deea78edf8aea16ab4366aac606577..fe94d6e971222b866084f2f4621a325d7d1ab444 100644 (file)
@@ -1991,7 +1991,9 @@ MapBlock * ServerMap::emergeBlock(
                        coal_rareness = 1;
                if(rand()%coal_rareness == 0)
                {
-                       for(s16 i=0; i<coal_amount; i++)
+                       u16 a = rand() % 16;
+                       u16 amount = coal_amount * a*a*a / 1000;
+                       for(s16 i=0; i<amount; i++)
                        {
                                v3s16 cp(
                                        (rand()%(MAP_BLOCKSIZE-2))+1,
index 05d5229019486b01108853712d84ccf752e0bd9f..08f535514f7ca94c7fde155533d056dd7120b265 100644 (file)
@@ -809,7 +809,7 @@ class ItemObject : public MapBlockObject
 #ifndef SERVER
        virtual void clientStep(float dtime)
        {
-               m_yaw += dtime * 90;
+               m_yaw += dtime * 60;
                if(m_yaw >= 360.)
                        m_yaw -= 360.;
 
index db4e0422880c3e918b6d6fed79aa493b1ed416d3..35f1f8a2754932d562c1733828c352f1d640d255 100644 (file)
@@ -1785,7 +1785,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                /*
                        3: Digging completed
                */
-               if(action == 3)
+               else if(action == 3)
                {
                        // Mandatory parameter; actually used for nothing
                        core::map<v3s16, MapBlock*> modified_blocks;