Skip to content

Commit

Permalink
hud image of transport items
Browse files Browse the repository at this point in the history
  • Loading branch information
naturefreshmilk committed May 9, 2018
1 parent 8ff6ab6 commit a21d6e2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ missions.load_missions = function()
-- TODO
end


missions.start_mission = function(player, mission)

-- print(dump(mission)) --XXX

local playername = player:get_player_name()

if has_xp_redo_mod and mission.entryxp then
Expand Down
78 changes: 78 additions & 0 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@ local HUD_ALIGNMENT = {x = 1, y = 0}

local hud = {} -- playerName -> {}


-- returns the image (itam, node, tool) or ""
local get_image = function(name)
-- minetest.registered_items[name].inventory_image
-- minetest.registered_tools[name].inventory_image
-- minetest.registered_nodes["default:stone"].tiles[1]


if name == nil then
return ""
end

local node = minetest.registered_nodes[name]
if node ~= nil and node.tiles ~= nil and table.getn(node.tiles) == 1 then
return minetest.inventorycube(node.tiles[1],node.tiles[1],node.tiles[1])
end

local item = minetest.registered_items[name]
if item ~= nil and item.inventory_image ~= nil then
return item.inventory_image
end

local tool = minetest.registered_tools[name]
if tool ~= nil and tool.inventory_image ~= nil then
return tool.inventory_image
end

-- none found
return ""
end

minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()

Expand Down Expand Up @@ -39,6 +70,33 @@ minetest.register_on_joinplayer(function(player)
number = 0x00FF00
})

data.transport1 = player:hud_add({
hud_elem_type = "image",
position = HUD_POSITION,
offset = {x = 0, y = 110},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 1, y = 1},
})

data.transport2 = player:hud_add({
hud_elem_type = "image",
position = HUD_POSITION,
offset = {x = 40, y = 110},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 1, y = 1},
})

data.transport3 = player:hud_add({
hud_elem_type = "image",
position = HUD_POSITION,
offset = {x = 80, y = 110},
text = "",
alignment = HUD_ALIGNMENT,
scale = {x = 1, y = 1},
})

hud[playername] = data
end)

Expand Down Expand Up @@ -111,6 +169,7 @@ missions.hud_update = function(player, playermissions)
topMission = mission
end
end

end
end

Expand All @@ -127,11 +186,30 @@ missions.hud_update = function(player, playermissions)
player:hud_change(data.time, "number", 0xFF0000)
player:hud_change(data.mission, "number", 0xFF0000)
end

if topMission.transport.list[1] ~= nil then
local img = get_image(ItemStack(topMission.transport.list[1]):get_name());
player:hud_change(data.transport1, "text", img)
end

if topMission.transport.list[2] ~= nil then
local img = get_image(ItemStack(topMission.transport.list[2]):get_name());
player:hud_change(data.transport2, "text", img)
end

if topMission.transport.list[3] ~= nil then
local img = get_image(ItemStack(topMission.transport.list[3]):get_name());
player:hud_change(data.transport3, "text", img)
end

else
-- no missions running
player:hud_change(data.title, "text", "")
player:hud_change(data.mission, "text", "")
player:hud_change(data.time, "text", "")
player:hud_change(data.transport1, "text", "")
player:hud_change(data.transport2, "text", "")
player:hud_change(data.transport3, "text", "")
end

end
Expand Down

0 comments on commit a21d6e2

Please sign in to comment.