@@ -66,6 +66,10 @@ if RELOAD then config = nil end
6666config = config or {
6767 follow_units = true ,
6868 follow_mouse = false ,
69+ show_unit_jobs = true ,
70+ job_shortenings = {
71+ [" Store item in stockpile" ] = " Store item" ,
72+ },
6973 show_happiness = true ,
7074 happiness_levels = {
7175 -- keep in mind, the text will look differently with game's font
@@ -79,10 +83,6 @@ config = config or {
7983 {text = " :D" , pen = COLOR_LIGHTGREEN , visible = true , name = " Happy" },
8084 {text = " =D" , pen = COLOR_LIGHTCYAN , visible = true , name = " Ecstatic" },
8185 },
82- show_unit_jobs = true ,
83- job_shortenings = {
84- [" Store item in stockpile" ] = " Store item" ,
85- }
8686}
8787
8888---- ----------------------------------------------------------------------------
@@ -123,69 +123,65 @@ TooltipControlWindow.ATTRS {
123123 },
124124}
125125
126- -- right pad string `s` to `n` symbols with spaces
127- local function rpad (s , n )
128- local formatStr = " %-" .. n .. " s" -- `"%-10s"`
129- return string.format (formatStr , s )
126+ local function make_enabled_text (indent , text , cfg , key )
127+ local function get_enabled_button_token (enabled_tile , disabled_tile , cfg , key )
128+ return {
129+ tile = function () return cfg [key ] and enabled_tile or disabled_tile end ,
130+ }
131+ end
132+
133+ local tokens = {
134+ string.format (" %" .. indent .. " s" , ' ' ),
135+ get_enabled_button_token (ENABLED_PEN_LEFT , DISABLED_PEN_LEFT , cfg , key ),
136+ get_enabled_button_token (ENABLED_PEN_CENTER , DISABLED_PEN_CENTER , cfg , key ),
137+ get_enabled_button_token (ENABLED_PEN_RIGHT , DISABLED_PEN_RIGHT , cfg , key ),
138+ ' ' ,
139+ }
140+ if type (text ) == ' string' then
141+ tokens [# tokens + 1 ] = text
142+ else -- must be a table
143+ -- append it
144+ for _ , v in ipairs (text ) do
145+ tokens [# tokens + 1 ] = v
146+ end
147+ end
148+
149+ return tokens
150+ end
151+
152+ local function make_choice (indent , text , cfg , key )
153+ return {
154+ text = make_enabled_text (indent , text , cfg , key ),
155+ data = {cfg = cfg , key = key },
156+ }
130157end
131158
132159function TooltipControlWindow :init ()
133- local w = self .frame .w - 2 - 3 -- 2 is border, 3 is active indicator width
134- local keyW = 7 -- Length of "Alt+u: "
160+ local choices = {}
161+ table.insert (choices , make_choice (0 , " unit banners" , config , " follow_units" ))
162+ table.insert (choices , make_choice (0 , " mouse tooltips" , config , " follow_mouse" ))
163+ table.insert (choices , make_choice (0 , " include jobs" , config , " show_unit_jobs" ))
164+ table.insert (choices , make_choice (0 , " include stress levels" , config , " show_happiness" ))
165+ for i = 0 , # config .happiness_levels do
166+ local cfg = config .happiness_levels [i ]
167+ table.insert (choices , make_choice (3 , {{text = cfg .text , pen = cfg .pen }, ' ' , cfg .name }, cfg , " visible" ))
168+ end
135169
136170 self :addviews {
137- ToggleLabel {
138- view_id = ' btn_follow_units' ,
139- frame = {t = 0 , h = 1 },
140- label = rpad (" Unit banners" , w - keyW ),
141- key = ' CUSTOM_ALT_U' ,
142- initial_option = config .follow_units ,
143- on_change = function (new ) config .follow_units = new end ,
144- },
145- ToggleLabel {
146- view_id = ' btn_follow_mouse' ,
147- frame = {t = 1 , h = 1 },
148- label = rpad (" Mouse tooltip" , w - keyW ),
149- key = ' CUSTOM_ALT_M' ,
150- initial_option = config .follow_mouse ,
151- on_change = function (new ) config .follow_mouse = new end ,
152- },
153- ToggleLabel {
154- frame = {t = 2 , h = 1 },
155- label = rpad (" Show jobs" , w ),
156- initial_option = config .show_unit_jobs ,
157- on_change = function (new ) config .show_unit_jobs = new end ,
158- },
159- ToggleLabel {
160- frame = {t = 3 , h = 1 },
161- label = rpad (" Show stress levels" , w ),
162- initial_option = config .show_happiness ,
163- on_change = function (new ) config .show_happiness = new end ,
171+ widgets .List {
172+ frame = {t = 0 },
173+ view_id = ' list' ,
174+ on_submit = self :callback (' on_submit' ),
175+ row_height = 1 ,
176+ choices = choices ,
164177 },
165178 }
179+ end
166180
167- local happinessLabels = {}
168-
169- -- align the emoticons
170- local maxNameLength = 1
171- for _ , v in pairs (config .happiness_levels ) do
172- local l = # v .name
173- if l > maxNameLength then
174- maxNameLength = l
175- end
176- end
177-
178- local indent = 3
179- for lvl , cfg in pairs (config .happiness_levels ) do
180- happinessLabels [# happinessLabels + 1 ] = ToggleLabel {
181- frame = {t = 4 + lvl , h = 1 , l = indent },
182- initial_option = cfg .visible ,
183- text_pen = cfg .pen ,
184- label = rpad (rpad (cfg .name , maxNameLength ) .. " " .. cfg .text , w - indent ),
185- on_change = function (new ) cfg .visible = new end
186- }
187- end
188- self :addviews (happinessLabels )
181+ function TooltipControlWindow :on_submit (index , choice )
182+ local cfg = choice .data .cfg
183+ local key = choice .data .key
184+ cfg [key ] = not cfg [key ]
189185end
190186
191187local function GetUnitHappiness (unit )
0 commit comments