-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathpetitions.lua
More file actions
107 lines (94 loc) · 3.22 KB
/
Copy pathpetitions.lua
File metadata and controls
107 lines (94 loc) · 3.22 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
99
100
101
102
103
104
105
106
107
-- Show fort's petitions, pending and fulfilled.
local gui = require 'gui'
local list_agreements = reqscript('list-agreements')
local widgets = require 'gui.widgets'
Petitions = defclass(Petitions, widgets.Window)
Petitions.ATTRS {
frame_title='Petitions',
frame={w=110, h=30},
resizable=true,
resize_min={w=70, h=15},
}
function Petitions:init()
self:addviews{
widgets.List{
view_id='list',
frame={t=0, l=0, r=0, b=2},
row_height=3,
},
widgets.ToggleHotkeyLabel{
view_id='show_fulfilled',
frame={b=0, l=0, w=33},
key='CUSTOM_CTRL_A',
label='Show past agreements:',
initial_option=false,
on_change=function() self:refresh() end,
},
}
self:refresh()
local list = self.subviews.list
self.frame.w = math.max(list:getContentWidth() + 6, self.resize_min.w)
self.frame.h = math.max(list:getContentHeight() + 6, self.resize_min.h)
end
local function get_choice_text(agr)
local loctype = list_agreements.get_location_type(agr)
local loc_name = list_agreements.get_location_name(agr.details[0].data.Location.tier, loctype)
local agr_age = list_agreements.get_petition_age(agr)
local resolved, resolution_string = list_agreements.is_resolved(agr)
local details_pre, details_target, details_post
if loctype == df.abstract_building_type.TEMPLE then
details_pre = 'worshiping '
details_target = list_agreements.get_deity_name(agr)
details_post = ''
else
details_pre = 'a '
details_target = list_agreements.get_guildhall_profession(agr)
details_post = ' guild'
end
return {
'Establish a ',
{text=loc_name, pen=COLOR_WHITE},
' for ',
{text=list_agreements.get_agr_party_name(agr), pen=COLOR_BROWN},
', ',
details_pre,
{text=details_target, pen=COLOR_MAGENTA},
details_post,
',',
NEWLINE,
{gap=4, text='as agreed on '},
list_agreements.get_petition_date(agr),
', ',
('%dy, %dm, %dd ago '):format(agr_age[1], agr_age[2], agr_age[3]),
{text=('(%s)'):format(resolution_string), pen=resolved and COLOR_GREEN or COLOR_YELLOW},
}
end
function Petitions:refresh()
local cull_resolved = not self.subviews.show_fulfilled:getOptionValue()
local t_agr, g_agr = list_agreements.get_fort_agreements(cull_resolved)
local choices = {}
for _, agr in ipairs(t_agr) do
table.insert(choices, {text=get_choice_text(agr)})
end
for _, agr in ipairs(g_agr) do
table.insert(choices, {text=get_choice_text(agr)})
end
if #choices == 0 then
table.insert(choices, {text='No outstanding agreements'})
end
self.subviews.list:setChoices(choices)
end
PetitionsScreen = defclass(PetitionsScreen, gui.ZScreen)
PetitionsScreen.ATTRS {
focus_path='petitions',
}
function PetitionsScreen:init()
self:addviews{Petitions{}}
end
function PetitionsScreen:onDismiss()
view = nil
end
if not dfhack.world.isFortressMode() or not dfhack.isMapLoaded() then
qerror('gui/petitions requires a fortress map to be loaded')
end
view = view and view:raise() or PetitionsScreen{}:show()