Compare commits
5 Commits
602acc0dfb
...
648c7448c1
Author | SHA1 | Date |
---|---|---|
David G | 648c7448c1 | |
David G | ac0867f570 | |
David G | b4fb496c68 | |
David G | d32a75a014 | |
David G | cbc71c0d94 |
37
README.md
|
@ -1,7 +1,7 @@
|
|||
HUD Compass [hud_compass]
|
||||
-------------------------
|
||||
|
||||
A Minetest mod to optionally place a HUD compass and 24-hour clock on the screen.
|
||||
A Minetest mod to optionally place a HUD compass and a 24-hour clock on the screen.
|
||||
|
||||
By David G (kestral246)
|
||||
|
||||
|
@ -10,26 +10,40 @@ By David G (kestral246)
|
|||
How to enable
|
||||
-------------
|
||||
|
||||
This mod defaults to not displaying compass and clock. To enable, use the chat command:
|
||||
This mod defaults to not displaying a compass or a clock. To enable, use the chat command:
|
||||
|
||||
"/compass" -> By default this places a compass and clock in the bottom right corner of the screen.
|
||||
"/compass" -> By default this places just a compass in the bottom right corner of the screen.
|
||||
|
||||
Repeated use of this command will toggle the display of the compass and clock off and on.
|
||||
Repeated use of this command will toggle the display of the compass off and on.
|
||||
|
||||
**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.
|
||||
When given with an argument, the user can select whether to display just a compass, or a compass and a clock, and which corner of the screen to place them in. 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
|
||||
"/compass 3" -> bottom left corner
|
||||
"/compass 4" -> top left corner
|
||||
"/compass 1" -> compass only, top right corner
|
||||
"/compass 2" -> compass only, bottom right corner
|
||||
"/compass 3" -> compass only, bottom left corner
|
||||
"/compass 4" -> compass only, top left corner
|
||||
|
||||
"/compass 5" -> compass and clock, top right corner
|
||||
"/compass 6" -> compass and clock, bottom right corner
|
||||
"/compass 7" -> compass and clock, bottom left corner
|
||||
"/compass 8" -> compass and clock, top left corner
|
||||
|
||||
In addition:
|
||||
|
||||
"/compass 0" -> forces compass off.
|
||||
"/compass 0" -> forces compass and clock off.
|
||||
|
||||
**Note:** The clock is a 24-hour clock, with only one hand that displays the hours. Noon is at the top and midnight is at the bottom.
|
||||
|
||||
**New:** The default initial state can now be set in minetest.conf using "compass\_default\_corner = n", where "n" can be one of the eight corner numbers above. If it's positive, the compass (or compass and clock) will be enabled at start, while if it's negative, they will start disabled.
|
||||
|
||||
Local mod storage is used to maintain the state and position of hud_compass display between sessions, per user.
|
||||
|
||||
|
||||
Special Thanks
|
||||
--------------
|
||||
Special thanks go out to MoNTE48, for pointing out that the image files could be significantly reduced with zopflipng (much better than with optipng), in this mod's first Pull Request.
|
||||
|
||||
|
||||
Licenses
|
||||
--------
|
||||
Source code
|
||||
|
@ -40,8 +54,7 @@ Media (textures)
|
|||
|
||||
> Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
|
||||
> (Textures were copied from my realcompass mod, which were originally based on the textures created by tacotexmex for the ccompass mod.)
|
||||
|
||||
> (Compass textures were copied from my realcompass mod, which were originally based on the textures created by tacotexmex for the ccompass mod. Clock textures were derived from these same textures.)
|
||||
|
||||
|
||||
|
||||
|
|
46
init.lua
|
@ -2,24 +2,34 @@
|
|||
-- 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-29
|
||||
-- 2019-12-31
|
||||
|
||||
local hud_compass = {}
|
||||
local storage = minetest.get_mod_storage()
|
||||
|
||||
-- State of hud_compass
|
||||
-- 1 == NE, 2 == SE, 3 == SW, 4 == NW
|
||||
-- 1 = NE, 2 = SE, 3 = SW, 4 = NW (just compass)
|
||||
-- 5 = NE, 6 = SE, 7 = SW, 8 = NW (both compass and clock)
|
||||
-- positive == enabled, negative == disabled
|
||||
|
||||
local default_corner = -2 -- SE corner, off by default
|
||||
-- Define default (if not overridden): SE corner, compass only, off by default
|
||||
local default_corner = tonumber(minetest.settings:get("compass_default_corner") or -2)
|
||||
|
||||
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=-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}},
|
||||
{hud_elem_type="image", text="", position={x=0,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=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}},
|
||||
{hud_elem_type="image", text="", position={x=0,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=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}},
|
||||
|
@ -31,7 +41,7 @@ minetest.register_on_joinplayer(function(player)
|
|||
local corner = default_corner
|
||||
if storage:get(pname) and tonumber(storage:get(pname)) then -- validate mod storage value
|
||||
local temp = math.floor(tonumber(storage:get(pname)))
|
||||
if temp ~= nil and temp ~= 0 and temp >= -4 and temp <= 4 then
|
||||
if temp ~= nil and temp ~= 0 and temp >= -8 and temp <= 8 then
|
||||
corner = temp
|
||||
end
|
||||
end
|
||||
|
@ -46,7 +56,7 @@ end)
|
|||
|
||||
minetest.register_chatcommand("compass", {
|
||||
params = "[<corner>]",
|
||||
description = "Change display of hud compass.",
|
||||
description = "Change display of HUD Compass.",
|
||||
privs = {},
|
||||
func = function(pname, params)
|
||||
local player = minetest.get_player_by_name(pname)
|
||||
|
@ -59,13 +69,21 @@ minetest.register_chatcommand("compass", {
|
|||
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 and clock to given corner
|
||||
elseif corner and corner > 0 and corner <= 4 then -- enable compass only 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
|
||||
player:hud_remove(hud_compass[pname].id_clock) -- remove old hud clock
|
||||
hud_compass[pname].last_image_clock = -1
|
||||
hud_compass[pname].id_compass = player:hud_add(lookup_compass[corner]) -- place new hud compass at requested corner
|
||||
hud_compass[pname].state = corner
|
||||
storage:set_string(pname, corner)
|
||||
elseif corner and corner >= 5 and corner <= 8 then -- enable compass and clock to given corner
|
||||
player:hud_remove(hud_compass[pname].id_compass) -- remove old hud compass
|
||||
hud_compass[pname].last_image_compass = -1
|
||||
player:hud_remove(hud_compass[pname].id_clock) -- remove old hud clock
|
||||
hud_compass[pname].last_image_clock = -1
|
||||
hud_compass[pname].id_compass = player:hud_add(lookup_compass[corner]) -- place new hud compass at requested corner
|
||||
hud_compass[pname].id_clock = player:hud_add(lookup_clock[corner]) -- place new hud clock at requested corner
|
||||
hud_compass[pname].state = corner
|
||||
storage:set_string(pname, corner)
|
||||
end
|
||||
|
@ -75,12 +93,9 @@ minetest.register_chatcommand("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
|
||||
storage:set_string(pname, hud_compass[pname].state)
|
||||
else -- is disabled
|
||||
hud_compass[pname].state = -1 * hud_compass[pname].state -- toggle to enabled
|
||||
storage:set_string(pname, hud_compass[pname].state)
|
||||
end
|
||||
hud_compass[pname].state = -1 * hud_compass[pname].state -- toggle state
|
||||
storage:set_string(pname, hud_compass[pname].state)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -97,6 +112,7 @@ minetest.register_globalstep(function(dtime)
|
|||
for i,player in ipairs(players) do
|
||||
local pname = player:get_player_name()
|
||||
local dir = player:get_look_horizontal()
|
||||
-- Calculate image indexes for compass and clock.
|
||||
local angle_relative = math.deg(dir)
|
||||
local image_compass = math.floor((angle_relative/22.5) + 0.5)%16
|
||||
local image_clock = math.floor(24 * minetest.get_timeofday())
|
||||
|
@ -108,7 +124,7 @@ minetest.register_globalstep(function(dtime)
|
|||
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
|
||||
if hud_compass[pname].state >= 5 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
|
||||
|
|
BIN
screenshot.png
Before Width: | Height: | Size: 371 KiB After Width: | Height: | Size: 150 KiB |
|
@ -0,0 +1,8 @@
|
|||
# This file contains settings for wand_of_illumination that can be changed in
|
||||
# minetest.conf
|
||||
|
||||
# Define default to place compass and whether to use clock.
|
||||
# -1 to -4 = compass only (disabled), -5 to -8 = compass + clock (disabled)
|
||||
# 1 to 4 = compass only (enabled), 5 to 8 = compass + clock (enabled)
|
||||
# (default = -2)
|
||||
compass_default_corner (Default corner to place compass) enum -2 -8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 397 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 401 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 395 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 400 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 395 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 396 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 396 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 394 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 395 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 392 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 388 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 390 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 396 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 392 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 391 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 396 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 402 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 395 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 392 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 390 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 388 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 390 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 395 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 394 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 483 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 487 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 491 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 489 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 488 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 491 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 486 B |