-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.gui_script
More file actions
76 lines (69 loc) · 2.7 KB
/
stats.gui_script
File metadata and controls
76 lines (69 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local lazy = {"state", "todo", "target_type", "health", "meele_weapon", "ranged_weapon", "damage", "harvest", "build", "accuracy", "inventory",
"meele_weapon_durability", "ranged_weapon_durability"}
local lazy2 = {"Task", "To do", "Target", "Health", "Meele Weapon", "Ranged Weapon", "Damage", "Harvest Amount", "Build Amount", "Accuracy", "Inventory",
"Meele Weapon Durability", "Ranged Weapon Durability"}
local images = {"Target", "Meele Weapon", "Ranged Weapon"}
local bars = {"Health", "Inventory"}
local global = require "main.global" -- Import the module
local bars_no_text = {"Meele Weapon Durability", "Ranged Weapon Durability"}
function init(self)
self.container_node = gui.get_node("container")
gui.set_enabled(self.container_node, false)
self.health_bar_pos = vmath.vector3(0, 120, 0)
self.inventory_bar_pos = vmath.vector3(0, 85, 0)
self.meele_weapon_durability_bar_pos = vmath.vector3(0, -45, 0)
self.ranged_weapon_durability_bar_pos = vmath.vector3(0, -85, 0)
end
local function bar(self, node, value, max)
local pos = self[tostring(node) .. "_bar_pos"]
local node = gui.get_node(node .. "_bar")
local size = gui.get_size(node)
size = vmath.vector3(0 + value*(100/max), size.y, 0)
gui.set_size(node, size)
gui.set_position(node, vmath.vector3(pos.x, pos.y, 0))
end
local function image(self, node, image)
local node = gui.get_node(node .. "_image")
if image then
gui.set_enabled(node, true)
if image == "Barrack" then
gui.play_flipbook(node, string.lower(image) .. "s")
else
gui.play_flipbook(node, string.lower(image))
end
else
gui.set_enabled(node, false)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("person_info") then
gui.set_enabled(self.container_node, true)
for _, l in ipairs(lazy) do
local text = lazy2[global.remove_by_value(lazy, l)]
local info = message.info[l] or "None"
if not global.contains(images, text) and not global.contains(bars_no_text, text) then
gui.set_text(gui.get_node(l), text .. " " .. info)
end
if text == "Health" then
bar(self,l , message.info[l], 100)
elseif text == "Inventory" then
bar(self,l , message.info[l], 50)
elseif text == "Meele Weapon Durability" then
bar(self,l , message.info[l], message.info["max_meele"])
elseif text == "Ranged Weapon Durability" then
bar(self,l , message.info[l], message.info["max_ranged"])
end
if text == "Target" or text == "Meele Weapon" or text == "Ranged Weapon" then
image(self, l, message.info[l])
end
end
end
if message_id == hash("hide_info") then
gui.set_enabled(self.container_node, false)
end
end
function on_input(self, action_id, action)
--if action_id == hash("click") then
--print(action.x, action.y)
--end
end