summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlockMen <nmuelll@web.de>2015-04-12 18:58:08 +0200
committerBlockMen <nmuelll@web.de>2015-04-12 18:58:08 +0200
commit20ef67cf5bb5a469efc1e1f278525e316a0c364f (patch)
treea3cf2b1ed342c9282b061da4cb24cc7ad670f8f8
parent2deb4f5b012a942e66e6593b7847fa8ee570d01c (diff)
Add experimental ItemWheel (replaces hotbar)
-rw-r--r--builtin.lua28
-rw-r--r--init.lua3
-rw-r--r--itemwheel.lua149
-rw-r--r--textures/hud_new.pngbin0 -> 3456 bytes
-rw-r--r--textures/hud_wielded.pngbin0 -> 143 bytes
5 files changed, 175 insertions, 5 deletions
diff --git a/builtin.lua b/builtin.lua
index ea64992..057189c 100644
--- a/builtin.lua
+++ b/builtin.lua
@@ -1,3 +1,9 @@
+HUD_IW_MAX = 8
+HUD_IW_TICK = 0.4
+if minetest.is_singleplayer() == true then
+ HUD_IW_TICK = 0.2
+end
+
HUD_SB_SIZE = {x = 24, y = 24}
HUD_HEALTH_POS = {x = 0.5,y = 1}
@@ -9,6 +15,19 @@ HUD_HUNGER_OFFSET = {x = 15, y = -110}
HUD_ARMOR_POS = {x = 0.5, y = 1}
HUD_ARMOR_OFFSET = {x = -262, y = -110}
+-- Reorder everything when using ItemWeel
+hud.item_wheel = minetest.setting_getbool("hud_item_wheel")
+if hud.item_wheel then
+ HUD_HEALTH_POS = {x = 0.5,y = 1}
+ HUD_HEALTH_OFFSET = {x = -385, y = -77}
+ HUD_AIR_POS = {x = 0.5, y = 1}
+ HUD_AIR_OFFSET = {x = 150, y = -77}
+ HUD_HUNGER_POS = {x = 0.5, y = 1}
+ HUD_HUNGER_OFFSET = {x = 180, y = -44}
+ HUD_ARMOR_POS = {x = 0.5, y = 1}
+ HUD_ARMOR_OFFSET = {x = -415, y = -44}
+end
+
-- read hud.conf settings
hud.read_conf()
@@ -30,7 +49,7 @@ if damage_enabled then
size = HUD_SB_SIZE,
text = "hud_heart_fg.png",
number = 20,
- alignment = {x=-1,y=-1},
+ alignment = {x = -1, y = -1},
offset = HUD_HEALTH_OFFSET,
background = "hud_heart_bg.png",
events = {
@@ -49,7 +68,7 @@ if damage_enabled then
size = HUD_SB_SIZE,
text = "hud_air_fg.png",
number = 0,
- alignment = {x=-1,y=-1},
+ alignment = {x = -1, y = -1},
offset = HUD_AIR_OFFSET,
background = nil,
events = {
@@ -72,7 +91,7 @@ if damage_enabled then
size = HUD_SB_SIZE,
text = "hud_armor_fg.png",
number = 0,
- alignment = {x=-1,y=-1},
+ alignment = {x = -1, y = -1},
offset = HUD_ARMOR_OFFSET,
background = "hud_armor_bg.png",
autohide_bg = true,
@@ -85,10 +104,9 @@ if damage_enabled then
size = HUD_SB_SIZE,
text = "hud_hunger_fg.png",
number = 0,
- alignment = {x=-1,y=-1},
+ alignment = {x = -1, y = -1},
offset = HUD_HUNGER_OFFSET,
background = "hud_hunger_bg.png",
- --autohide_bg = true,
max = 0,
})
else
diff --git a/init.lua b/init.lua
index c011f67..fe0f41f 100644
--- a/init.lua
+++ b/init.lua
@@ -5,4 +5,7 @@ dofile(modpath .. "/api.lua")
dofile(modpath .. "/functions.lua")
dofile(modpath .. "/builtin.lua")
dofile(modpath .. "/legacy.lua")
+if hud.item_wheel then
+ dofile(modpath .. "/itemwheel.lua")
+end
diff --git a/itemwheel.lua b/itemwheel.lua
new file mode 100644
index 0000000..66c4305
--- /dev/null
+++ b/itemwheel.lua
@@ -0,0 +1,149 @@
+local hb = {}
+
+local function update_wheel(player)
+ local name = player:get_player_name()
+ if not player or not name then
+ return
+ end
+
+ local i = player:get_wield_index()
+ local i1 = i - 1
+ local i3 = i + 1
+
+ -- it's a wheel
+ if i1 < 1 then
+ i1 = HUD_IW_MAX
+ end
+ if i3 > HUD_IW_MAX then
+ i3 = 1
+ end
+
+ -- get the displayed items
+ local inv = player:get_inventory()
+ local item = hb[name].item
+ local item2 = player:get_wielded_item():get_name()
+
+ -- update all items when wielded has changed
+ if item and item2 and item ~= item2 or item == "wheel_init" then
+ local items = {}
+ items[1] = inv:get_stack("main", i1):get_name() or nil
+ items[2] = item2
+ items[3] = inv:get_stack("main", i3):get_name() or nil
+
+ for n, m in pairs(items) do
+ -- some default values
+ local image = "hud_wielded.png"
+ local scale = false
+ local s1 = {x = 1, y = 1}
+ local s2 = {x = 3, y = 3}
+ if n ~= 2 then
+ s1 = {x = 0.6, y = 0.6}
+ s2 = {x = 2, y = 2}
+ end
+
+ -- get the images
+ local def = minetest.registered_items[m]
+ if def then
+ if def.tiles then
+ image = minetest.inventorycube(def.tiles[1], def.tiles[6] or def.tiles[3] or def.tiles[1], def.tiles[3] or def.tiles[1])
+ scale = true
+ end
+ if def.inventory_image and def.inventory_image ~= "" then
+ image = def.inventory_image
+ scale = false
+ end
+ if def.wielded_image and def.wielded_image ~= "" then
+ image = def.wielded_image
+ scale = false
+ end
+ end
+
+ -- get the id and update hud elements
+ local id = hb[name].id[n]
+ if id and image then
+ if scale then
+ player:hud_change(id, "scale", s1)
+ else
+ player:hud_change(id, "scale", s2)
+ end
+ -- make previous and next item darker
+ --if n ~= 2 then
+ --image = image .. "^[colorize:#0005"
+ --end
+ player:hud_change(id, "text", image)
+ end
+ end
+ end
+
+ -- update wielded buffer
+ if hb[name].id[2] ~= nil then
+ hb[name].item = item
+ end
+end
+
+minetest.register_on_joinplayer(function(player)
+ local name = player:get_player_name()
+ hb[name]= {}
+ hb[name].id = {}
+ hb[name].item = "wheel_init"
+
+ minetest.after(0.1, function()
+
+ -- hide builtin hotbar
+ local hud_flags = player:hud_get_flags()
+ hud_flags.hotbar = false
+ player:hud_set_flags(hud_flags)
+
+ player:hud_add({
+ hud_elem_type = "image",
+ text = "hud_new.png",
+ position = {x=0.5, y=1},
+ scale = {x=1, y=1},
+ alignment = {x=0, y=-1},
+ offset = {x = 0, y = 0}
+ })
+
+ hb[name].id[1] = player:hud_add({
+ hud_elem_type = "image",
+ text = "hud_wielded.png",
+ position = {x = 0.5, y = 1},
+ scale = {x = 1, y = 1},
+ alignment = {x = 0, y = -1},
+ offset = {x = -75, y = -8}
+ })
+
+ hb[name].id[2] = player:hud_add({
+ hud_elem_type = "image",
+ text = "hud_wielded.png",
+ position = {x = 0.5, y = 1},
+ scale = {x = 3, y = 3},
+ alignment = {x = 0, y = -1},
+ offset = {x = 0, y = -20}
+ })
+
+ hb[name].id[3] = player:hud_add({
+ hud_elem_type = "image",
+ text = "hud_wielded.png",
+ position = {x = 0.5, y = 1},
+ scale = {x = 1, y = 1},
+ alignment = {x = 0, y = -1},
+ offset = {x = 75, y = -8}
+ })
+
+ -- init item wheel
+ hb[name].item = "wheel_init"
+ update_wheel(player)
+ end)
+end)
+
+
+local timer = 0
+minetest.register_globalstep(function(dtime)
+ timer = timer + dtime
+ if timer >= HUD_IW_TICK then
+ timer = 0
+ for _, player in ipairs(minetest.get_connected_players()) do
+ update_wheel(player)
+ end
+ end--timer
+end) \ No newline at end of file
diff --git a/textures/hud_new.png b/textures/hud_new.png
new file mode 100644
index 0000000..17fa8d2
--- /dev/null
+++ b/textures/hud_new.png
Binary files differ
diff --git a/textures/hud_wielded.png b/textures/hud_wielded.png
new file mode 100644
index 0000000..2dc0e3d
--- /dev/null
+++ b/textures/hud_wielded.png
Binary files differ