-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy patheditor_counters.lua
More file actions
98 lines (93 loc) · 2.67 KB
/
Copy patheditor_counters.lua
File metadata and controls
98 lines (93 loc) · 2.67 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- Counters editor module for gui/gm-unit.
--@ module = true
local dialog = require 'gui.dialogs'
local widgets = require 'gui.widgets'
local base_editor = reqscript("internal/gm-unit/base_editor")
Editor_Counters=defclass(Editor_Counters, base_editor.Editor)
Editor_Counters.ATTRS{
frame_title = "Counters editor",
counters1={
"job_counter",
"swap_counter",
"winded",
"stunned",
"unconscious",
"suffocation",
"webbed",
"soldier_mood_countdown",
"soldier_mood", --todo enum,
"pain",
"nausea",
"dizziness",
},
counters2={
"paralysis",
"numbness",
"fever",
"exhaustion",
"hunger_timer",
"thirst_timer",
"sleepiness_timer",
"stomach_content",
"stomach_food",
"vomit_timeout",
"stored_fat" --TODO what to reset to?
}
}
function Editor_Counters:fill_counters()
local ret = {}
local u = self.target_unit
for i, v in ipairs(self.counters1) do
table.insert(ret, {f=u.counters:_field(v),name=v})
end
for i, v in ipairs(self.counters2) do
table.insert(ret, {f=u.counters2:_field(v),name=v})
end
return ret
end
function Editor_Counters:update_counters()
for i, v in ipairs(self.counter_list) do
v.text=string.format("%s: %d", v.name, v.f.value)
end
self.subviews.counters:setChoices(self.counter_list)
end
function Editor_Counters:set_cur_counter(value,_,choice)
choice.f.value = value
self:update_counters()
end
function Editor_Counters:choose_cur_counter(index,choice)
dialog.showInputPrompt(choice.name,"Enter new value:",COLOR_WHITE,
tostring(choice.f.value),function(new_value)
self:set_cur_counter(new_value,index,choice)
end)
end
function Editor_Counters:init( args )
if self.target_unit==nil then
qerror("invalid unit")
end
self.counter_list=self:fill_counters()
self:addviews{
widgets.FilteredList{
choices=self.counter_list,
frame = {t=0, b=2,l=0},
view_id="counters",
edit_ignore_keys={"STRING_A047"},
on_submit=self:callback("choose_cur_counter"),
},
widgets.Label{
frame = {b=0,l=0},
text = {
{text=": set counter ", key = "SELECT"},
--TODO some things need to be set to different defaults
{text=": reset counter ", key = "STRING_A047",
on_activate=function()
self:set_cur_counter(0, self.subviews.counters:getSelected())
end},
}
},
}
self:update_counters()
end
function Editor_Counters:onOpen()
self.subviews[1].edit:setFocus(true)
end