]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix precision not working in hud_change (#10186)
authorLars Müller <34514239+appgurueu@users.noreply.github.com>
Wed, 12 Aug 2020 09:51:50 +0000 (11:51 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Aug 2020 09:51:50 +0000 (11:51 +0200)
games/devtest/mods/util_commands/init.lua
src/hud.cpp
src/script/common/c_content.cpp

index 3a0e91a410a1575574ba62d0530882b647270829..f2a155fb2c345fd57ff95410760057c6248afa6f 100644 (file)
@@ -112,6 +112,62 @@ minetest.register_chatcommand("detach", {
        end,
 })
 
+-- Use this to test waypoint capabilities
+minetest.register_chatcommand("test_waypoints", {
+       params = "[change_immediate]",
+       description = "tests waypoint capabilities",
+       func = function(name, params)
+               local player = minetest.get_player_by_name(name)
+               local regular = player:hud_add {
+                       hud_elem_type = "waypoint",
+                       name = "regular waypoint",
+                       text = "m",
+                       number = 0xFF0000,
+                       world_pos = vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0})
+               }
+               local reduced_precision = player:hud_add {
+                       hud_elem_type = "waypoint",
+                       name = "better waypoint",
+                       text = "m (0.5 steps, precision = 2)",
+                       precision = 10,
+                       number = 0xFFFF00,
+                       world_pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0})
+               }
+               local function change()
+                       if regular then
+                               player:hud_change(regular, "world_pos", vector.add(player:get_pos(), {x = 0, y = 3, z = 0}))
+                       end
+                       if reduced_precision then
+                               player:hud_change(reduced_precision, "precision", 2)
+                       end
+               end
+               if params ~= "" then
+                       -- change immediate
+                       change()
+               else
+                       minetest.after(0.5, change)
+               end
+               regular = regular or "error"
+               reduced_precision = reduced_precision or "error"
+               local hidden_distance = player:hud_add {
+                       hud_elem_type = "waypoint",
+                       name = "waypoint with hidden distance",
+                       text = "this text is hidden as well (precision = 0)",
+                       precision = 0,
+                       number = 0x0000FF,
+                       world_pos = vector.add(player:get_pos(), {x = 0, y = 0.5, z = 0})
+               } or "error"
+               local image_waypoint = player:hud_add {
+                       hud_elem_type = "image_waypoint",
+                       text = "wieldhand.png",
+                       world_pos = player:get_pos(),
+                       scale = {x = 10, y = 10},
+                       offset = {x = 0, y = -32}
+               } or "error"
+               minetest.chat_send_player(name, "Waypoint IDs: regular: " .. regular .. ", reduced precision: " .. reduced_precision ..
+                       ", hidden distance: " .. hidden_distance .. ", image waypoint: " .. image_waypoint)
+       end
+})
 
 -- Unlimited node placement
 minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
index 3079b5cd81bfb2b6a435697be7be11048353b850..4830c56a4d074c540f08fdf136c3d24850e7b3ca 100644 (file)
@@ -40,6 +40,7 @@ const struct EnumString es_HudElementStat[] =
        {HUD_STAT_TEXT,   "text"},
        {HUD_STAT_NUMBER, "number"},
        {HUD_STAT_ITEM,   "item"},
+       {HUD_STAT_ITEM,   "precision"},
        {HUD_STAT_DIR,    "direction"},
        {HUD_STAT_ALIGN,  "alignment"},
        {HUD_STAT_OFFSET, "offset"},
index 3dfd7ce61f250531bd9ed81e00e85dd7ae85c75e..774b6a3266d5dc476e5a65a65746fa366a10d7be 100644 (file)
@@ -1959,9 +1959,10 @@ void push_hud_element(lua_State *L, HudElement *elem)
 HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
 {
        HudElementStat stat = HUD_STAT_NUMBER;
+       std::string statstr;
        if (lua_isstring(L, 3)) {
                int statint;
-               std::string statstr = lua_tostring(L, 3);
+               statstr = lua_tostring(L, 3);
                stat = string_to_enum(es_HudElementStat, statint, statstr) ?
                                (HudElementStat)statint : stat;
        }
@@ -1989,6 +1990,8 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
                        break;
                case HUD_STAT_ITEM:
                        elem->item = luaL_checknumber(L, 4);
+                       if (elem->type == HUD_ELEM_WAYPOINT && statstr == "precision")
+                               elem->item++;
                        *value = &elem->item;
                        break;
                case HUD_STAT_DIR: