diff --git a/README.md b/README.md index e350e04..168f9c6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ HUD Compass [hud_compass] ------------------------- -A Minetest mod to optionally place a HUD compass on the screen. +A Minetest mod to optionally place a HUD compass and 24-hour clock on the screen. By David G (kestral246) @@ -10,13 +10,13 @@ By David G (kestral246) How to enable ------------- -This mod defaults to not displaying compass. To enable, use the chat command: +This mod defaults to not displaying compass and clock. To enable, use the chat command: - "/compass" -> By default this places a compass in the bottom right corner of the screen. + "/compass" -> By default this places a compass and clock in the bottom right corner of the screen. -Repeated use of this command will toggle the compass display off and on. +Repeated use of this command will toggle the display of the compass and clock off and on. -**New:** When given with an argument, the position of the compass can be changed. This is particularly useful with Android clients, where the bottom right corner of the screen has the jump button. +**New:** When given with an argument, the position of the compass and clock can be changed. This is particularly useful with Android clients, where the bottom right corner of the screen has the jump button. "/compass 1" -> top right corner "/compass 2" -> bottom right corner diff --git a/init.lua b/init.lua index 93148b9..ee28b28 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,8 @@ -- hud_compass --- Optionally place a compass on the screen. +-- Optionally place a compass and 24-hour clock on the screen. -- A HUD version of my realcompass mod. -- By David_G (kestral246@gmail.com) --- 2019-12-24 +-- 2019-12-29 local hud_compass = {} local storage = minetest.get_mod_storage() @@ -13,7 +13,13 @@ local storage = minetest.get_mod_storage() local default_corner = -2 -- SE corner, off by default -local lookup = { +local lookup_compass = { + {hud_elem_type="image", text="", position={x=1,y=0}, scale={x=4,y=4}, alignment={x=-1,y=1}, offset={x=-76,y=4}}, + {hud_elem_type="image", text="", position={x=1,y=1}, scale={x=4,y=4}, alignment={x=-1,y=-1}, offset={x=-76,y=-4}}, + {hud_elem_type="image", text="", position={x=0,y=1}, scale={x=4,y=4}, alignment={x=1,y=-1}, offset={x=76,y=-4}}, + {hud_elem_type="image", text="", position={x=0,y=0}, scale={x=4,y=4}, alignment={x=1,y=1}, offset={x=76,y=4}} +} +local lookup_clock = { {hud_elem_type="image", text="", position={x=1,y=0}, scale={x=4,y=4}, alignment={x=-1,y=1}, offset={x=-8,y=4}}, {hud_elem_type="image", text="", position={x=1,y=1}, scale={x=4,y=4}, alignment={x=-1,y=-1}, offset={x=-8,y=-4}}, {hud_elem_type="image", text="", position={x=0,y=1}, scale={x=4,y=4}, alignment={x=1,y=-1}, offset={x=8,y=-4}}, @@ -30,8 +36,10 @@ minetest.register_on_joinplayer(function(player) end end hud_compass[pname] = { - id = player:hud_add(lookup[math.abs(corner)]), - last_image = -1, + id_compass = player:hud_add(lookup_compass[math.abs(corner)]), + last_image_compass = -1, + id_clock = player:hud_add(lookup_clock[math.abs(corner)]), + last_image_clock = -1, state = corner, } end) @@ -44,23 +52,30 @@ minetest.register_chatcommand("compass", { local player = minetest.get_player_by_name(pname) if params and string.len(params) > 0 then -- includes corner parameter local corner = tonumber(string.match(params, "^%d$")) - if corner and corner == 0 then -- disable compass - player:hud_change(hud_compass[pname].id, "text", "") -- blank hud - hud_compass[pname].last_image = -1 + if corner and corner == 0 then -- disable compass and clock + player:hud_change(hud_compass[pname].id_compass, "text", "") -- blank hud compass + hud_compass[pname].last_image_compass = -1 + player:hud_change(hud_compass[pname].id_clock, "text", "") -- blank hud clock + hud_compass[pname].last_image_clock = -1 hud_compass[pname].state = -1 * math.abs(hud_compass[pname].state) storage:set_string(pname, hud_compass[pname].state) - elseif corner and corner > 0 and corner <= 4 then -- enable compass to given corner - player:hud_remove(hud_compass[pname].id) -- remove old hud - hud_compass[pname].id = player:hud_add(lookup[corner]) -- place new hud at requested corner - hud_compass[pname].last_image = -1 + elseif corner and corner > 0 and corner <= 4 then -- enable compass and clock to given corner + player:hud_remove(hud_compass[pname].id_compass) -- remove old hud compass + player:hud_remove(hud_compass[pname].id_clock) -- remove old hud clock + hud_compass[pname].id_compass = player:hud_add(lookup_compass[corner]) -- place new hud compass at requested corner + hud_compass[pname].last_image_compass = -1 + hud_compass[pname].id_clock = player:hud_add(lookup_clock[corner]) -- place new hud clock at requested corner + hud_compass[pname].last_image_clock = -1 hud_compass[pname].state = corner storage:set_string(pname, corner) end else -- just toggle hud if hud_compass[pname].state > 0 then -- is enabled + player:hud_change(hud_compass[pname].id_compass, "text", "") -- blank hud compass + hud_compass[pname].last_image_compass = -1 + player:hud_change(hud_compass[pname].id_clock, "text", "") -- blank hud clock + hud_compass[pname].last_image_clock = -1 hud_compass[pname].state = -1 * hud_compass[pname].state -- toggle to disabled - hud_compass[pname].last_image = -1 -- reset initial direction - player:hud_change(hud_compass[pname].id, "text", "") -- blank hud storage:set_string(pname, hud_compass[pname].state) else -- is disabled hud_compass[pname].state = -1 * hud_compass[pname].state -- toggle to enabled @@ -83,13 +98,21 @@ minetest.register_globalstep(function(dtime) local pname = player:get_player_name() local dir = player:get_look_horizontal() local angle_relative = math.deg(dir) - local image = math.floor((angle_relative/22.5) + 0.5)%16 + local image_compass = math.floor((angle_relative/22.5) + 0.5)%16 + local image_clock = math.floor(24 * minetest.get_timeofday()) - if hud_compass[pname].state > 0 and image ~= hud_compass[pname].last_image then - local rc = player:hud_change(hud_compass[pname].id, "text", "realcompass_"..image..".png") + if hud_compass[pname].state > 0 and image_compass ~= hud_compass[pname].last_image_compass then + local rc = player:hud_change(hud_compass[pname].id_compass, "text", "realcompass_"..image_compass..".png") -- Check return code, seems to fix occasional startup glitch. if rc == 1 then - hud_compass[pname].last_image = image + hud_compass[pname].last_image_compass = image_compass + end + end + if hud_compass[pname].state > 0 and image_clock ~= hud_compass[pname].last_image_clock then + local rc = player:hud_change(hud_compass[pname].id_clock, "text", "hud_24hr_clock_"..image_clock..".png") + -- Check return code, seems to fix occasional startup glitch. + if rc == 1 then + hud_compass[pname].last_image_clock = image_clock end end end diff --git a/mod.conf b/mod.conf index c10228d..c9c29d1 100644 --- a/mod.conf +++ b/mod.conf @@ -1,2 +1,2 @@ name = hud_compass -description = Optionally place a HUD compass on the screen. +description = Optionally place a HUD compass and 24-hour clock on the screen. diff --git a/screenshot.png b/screenshot.png index b9309dd..3271283 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/textures/hud_24hr_clock_0.png b/textures/hud_24hr_clock_0.png new file mode 100644 index 0000000..53a184a Binary files /dev/null and b/textures/hud_24hr_clock_0.png differ diff --git a/textures/hud_24hr_clock_1.png b/textures/hud_24hr_clock_1.png new file mode 100644 index 0000000..f3c34db Binary files /dev/null and b/textures/hud_24hr_clock_1.png differ diff --git a/textures/hud_24hr_clock_10.png b/textures/hud_24hr_clock_10.png new file mode 100644 index 0000000..d5945e8 Binary files /dev/null and b/textures/hud_24hr_clock_10.png differ diff --git a/textures/hud_24hr_clock_11.png b/textures/hud_24hr_clock_11.png new file mode 100644 index 0000000..2b6cef8 Binary files /dev/null and b/textures/hud_24hr_clock_11.png differ diff --git a/textures/hud_24hr_clock_12.png b/textures/hud_24hr_clock_12.png new file mode 100644 index 0000000..34b447c Binary files /dev/null and b/textures/hud_24hr_clock_12.png differ diff --git a/textures/hud_24hr_clock_13.png b/textures/hud_24hr_clock_13.png new file mode 100644 index 0000000..ea72d6e Binary files /dev/null and b/textures/hud_24hr_clock_13.png differ diff --git a/textures/hud_24hr_clock_14.png b/textures/hud_24hr_clock_14.png new file mode 100644 index 0000000..a7fa12a Binary files /dev/null and b/textures/hud_24hr_clock_14.png differ diff --git a/textures/hud_24hr_clock_15.png b/textures/hud_24hr_clock_15.png new file mode 100644 index 0000000..f3a6b44 Binary files /dev/null and b/textures/hud_24hr_clock_15.png differ diff --git a/textures/hud_24hr_clock_16.png b/textures/hud_24hr_clock_16.png new file mode 100644 index 0000000..a00d54e Binary files /dev/null and b/textures/hud_24hr_clock_16.png differ diff --git a/textures/hud_24hr_clock_17.png b/textures/hud_24hr_clock_17.png new file mode 100644 index 0000000..c66d49a Binary files /dev/null and b/textures/hud_24hr_clock_17.png differ diff --git a/textures/hud_24hr_clock_18.png b/textures/hud_24hr_clock_18.png new file mode 100644 index 0000000..72f9b69 Binary files /dev/null and b/textures/hud_24hr_clock_18.png differ diff --git a/textures/hud_24hr_clock_19.png b/textures/hud_24hr_clock_19.png new file mode 100644 index 0000000..c49d7c5 Binary files /dev/null and b/textures/hud_24hr_clock_19.png differ diff --git a/textures/hud_24hr_clock_2.png b/textures/hud_24hr_clock_2.png new file mode 100644 index 0000000..632252f Binary files /dev/null and b/textures/hud_24hr_clock_2.png differ diff --git a/textures/hud_24hr_clock_20.png b/textures/hud_24hr_clock_20.png new file mode 100644 index 0000000..cb361eb Binary files /dev/null and b/textures/hud_24hr_clock_20.png differ diff --git a/textures/hud_24hr_clock_21.png b/textures/hud_24hr_clock_21.png new file mode 100644 index 0000000..f6d5a8a Binary files /dev/null and b/textures/hud_24hr_clock_21.png differ diff --git a/textures/hud_24hr_clock_22.png b/textures/hud_24hr_clock_22.png new file mode 100644 index 0000000..4b31775 Binary files /dev/null and b/textures/hud_24hr_clock_22.png differ diff --git a/textures/hud_24hr_clock_23.png b/textures/hud_24hr_clock_23.png new file mode 100644 index 0000000..fbc85f4 Binary files /dev/null and b/textures/hud_24hr_clock_23.png differ diff --git a/textures/hud_24hr_clock_3.png b/textures/hud_24hr_clock_3.png new file mode 100644 index 0000000..1a63502 Binary files /dev/null and b/textures/hud_24hr_clock_3.png differ diff --git a/textures/hud_24hr_clock_4.png b/textures/hud_24hr_clock_4.png new file mode 100644 index 0000000..30e0318 Binary files /dev/null and b/textures/hud_24hr_clock_4.png differ diff --git a/textures/hud_24hr_clock_5.png b/textures/hud_24hr_clock_5.png new file mode 100644 index 0000000..7679a23 Binary files /dev/null and b/textures/hud_24hr_clock_5.png differ diff --git a/textures/hud_24hr_clock_6.png b/textures/hud_24hr_clock_6.png new file mode 100644 index 0000000..cfbb93e Binary files /dev/null and b/textures/hud_24hr_clock_6.png differ diff --git a/textures/hud_24hr_clock_7.png b/textures/hud_24hr_clock_7.png new file mode 100644 index 0000000..84048bd Binary files /dev/null and b/textures/hud_24hr_clock_7.png differ diff --git a/textures/hud_24hr_clock_8.png b/textures/hud_24hr_clock_8.png new file mode 100644 index 0000000..a5ae896 Binary files /dev/null and b/textures/hud_24hr_clock_8.png differ diff --git a/textures/hud_24hr_clock_9.png b/textures/hud_24hr_clock_9.png new file mode 100644 index 0000000..04b1352 Binary files /dev/null and b/textures/hud_24hr_clock_9.png differ