Skip to content

Commit 9c819c6

Browse files
committed
refine toolbar icon behavior
1 parent eb6ac8f commit 9c819c6

2 files changed

Lines changed: 72 additions & 55 deletions

File tree

plugins/dig.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ static int registerWarmDampBox(lua_State *L) {
19431943
}
19441944

19451945
static void paintScreenWarmDamp(bool show_hidden = false) {
1946-
//TRACE(log).print("entering paintScreenDampWarm\n");
1946+
TRACE(log).print("entering paintScreenDampWarm\n");
19471947

19481948
if (Screen::inGraphicsMode())
19491949
return;
@@ -1977,7 +1977,10 @@ static void paintScreenWarmDamp(bool show_hidden = false) {
19771977
}
19781978

19791979
// this will also change the color of the cursor or any selection box that overlaps
1980-
// the tile. this is intentional since it makes the UI more readable
1980+
// the tile. this is intentional since it makes the UI more readable. it will also change
1981+
// the color of any UI elements (e.g. info sheets) that happen to overlap the map
1982+
// on that tile. this is undesirable, but unavoidable, since we can't know which tiles
1983+
// the UI is overwriting.
19811984
if (cur_tile.fg && cur_tile.ch != ' ') {
19821985
cur_tile.fg = color;
19831986
cur_tile.bg = 0;

plugins/lua/dig.lua

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,82 @@ end
2525

2626
WarmDampDigConfig = defclass(WarmDampDigConfig, widgets.Panel)
2727
WarmDampDigConfig.ATTRS {
28-
frame={w=25, h=20, b=7},
29-
frame_style=gui.FRAME_MEDIUM,
30-
frame_background=gui.CLEAR_PEN,
31-
autoarrange_subviews=true,
32-
autoarrange_gap=1,
28+
frame={w=25, h=18, b=7},
3329
}
3430

3531
function WarmDampDigConfig:init()
36-
self:addviews{
37-
widgets.Label{
38-
text={
39-
'Mark newly designated', NEWLINE,
40-
'tiles for:'
32+
local panel = widgets.Panel{
33+
frame_style=gui.FRAME_MEDIUM,
34+
frame_background=gui.CLEAR_PEN,
35+
autoarrange_subviews=true,
36+
autoarrange_gap=1,
37+
subviews={
38+
widgets.Label{
39+
text={
40+
'Mark newly designated', NEWLINE,
41+
'tiles for:'
42+
},
4143
},
42-
},
43-
widgets.ToggleHotkeyLabel{
44-
view_id='damp',
45-
key='CUSTOM_CTRL_D',
46-
label='Damp dig:',
47-
initial_option=false,
48-
on_change=setDampPaintEnabled,
49-
},
50-
widgets.ToggleHotkeyLabel{
51-
view_id='warm',
52-
key='CUSTOM_CTRL_W',
53-
label='Warm dig:',
54-
initial_option=false,
55-
on_change=setWarmPaintEnabled,
56-
},
57-
widgets.Divider{
58-
frame={h=1},
59-
frame_style=gui.FRAME_INTERIOR,
60-
frame_style_l=false,
61-
frame_style_r=false,
62-
},
63-
widgets.Label{
64-
text={
65-
'Mark/unmark currently', NEWLINE,
66-
'designated tiles on', NEWLINE,
67-
'this level for:'
44+
widgets.ToggleHotkeyLabel{
45+
view_id='damp',
46+
key='CUSTOM_CTRL_D',
47+
label='Damp dig:',
48+
initial_option=false,
49+
on_change=setDampPaintEnabled,
50+
},
51+
widgets.ToggleHotkeyLabel{
52+
view_id='warm',
53+
key='CUSTOM_CTRL_W',
54+
label='Warm dig:',
55+
initial_option=false,
56+
on_change=setWarmPaintEnabled,
57+
},
58+
widgets.Divider{
59+
frame={h=1},
60+
frame_style=gui.FRAME_INTERIOR,
61+
frame_style_l=false,
62+
frame_style_r=false,
63+
},
64+
widgets.Label{
65+
text={
66+
'Mark/unmark currently', NEWLINE,
67+
'designated tiles on', NEWLINE,
68+
'this level for:'
69+
},
70+
},
71+
widgets.HotkeyLabel{
72+
key='CUSTOM_CTRL_N',
73+
label='Damp dig',
74+
on_activate=markCurLevelDampDig,
75+
},
76+
widgets.HotkeyLabel{
77+
key='CUSTOM_CTRL_M',
78+
label='Warm dig',
79+
on_activate=markCurLevelWarmDig,
6880
},
6981
},
70-
widgets.HotkeyLabel{
71-
key='CUSTOM_CTRL_N',
72-
label='Damp dig',
73-
on_activate=markCurLevelDampDig,
74-
},
75-
widgets.HotkeyLabel{
76-
key='CUSTOM_CTRL_M',
77-
label='Warm dig',
78-
on_activate=markCurLevelWarmDig,
79-
},
82+
}
83+
self:addviews{
84+
panel,
85+
widgets.HelpButton{command='dig'},
8086
}
8187
end
8288

8389
function WarmDampDigConfig:render(dc)
84-
-- TODO: dismiss if icon no longer shown
8590
self.subviews.damp:setOption(getDampPaintEnabled())
8691
self.subviews.warm:setOption(getWarmPaintEnabled())
8792
WarmDampDigConfig.super.render(self, dc)
8893
end
8994

95+
function WarmDampDigConfig:onInput(keys)
96+
if keys._MOUSE_L and not self:getMouseFramePos() then
97+
self.parent_view:dismiss()
98+
return
99+
end
100+
return WarmDampDigConfig.super.onInput(self, keys) or
101+
keys._MOUSE_L and self:getMouseFramePos()
102+
end
103+
90104
function WarmDampDigConfig:preUpdateLayout(parent_rect)
91105
self.frame.l = get_l_offset(parent_rect) - 1
92106
end
@@ -155,8 +169,8 @@ function WarmDampDigOverlay:init()
155169
{tile=tp(4+offset, 191, border_color)},
156170
NEWLINE,
157171
{tile=tp(9+offset, 179, border_color)},
158-
{tile=tp(10+offset, '~', heat_color)},
159-
{tile=tp(11+offset, '~', damp_color)},
172+
{tile=tp(10+offset, '~', damp_color)},
173+
{tile=tp(11+offset, '~', heat_color)},
160174
{tile=tp(12+offset, 179, border_color)},
161175
NEWLINE,
162176
{tile=tp(17+offset, 192, border_color)},
@@ -173,22 +187,22 @@ function WarmDampDigOverlay:init()
173187
widgets.Label{
174188
text=get_tile_tokens(24, COLOR_GREY, COLOR_GREY, COLOR_GREY),
175189
on_click=launch_warm_damp_dig_config,
176-
visible=true,
190+
visible=function() return not getWarmPaintEnabled() and not getDampPaintEnabled() end,
177191
},
178192
widgets.Label{
179193
text=get_tile_tokens(28, COLOR_RED, COLOR_GREY, COLOR_WHITE),
180194
on_click=launch_warm_damp_dig_config,
181-
visible=false,
195+
visible=function() return getWarmPaintEnabled() and not getDampPaintEnabled() end,
182196
},
183197
widgets.Label{
184198
text=get_tile_tokens(28, COLOR_GREY, COLOR_BLUE, COLOR_WHITE),
185199
on_click=launch_warm_damp_dig_config,
186-
visible=false,
200+
visible=function() return not getWarmPaintEnabled() and getDampPaintEnabled() end,
187201
},
188202
widgets.Label{
189203
text=get_tile_tokens(28, COLOR_RED, COLOR_BLUE, COLOR_WHITE),
190204
on_click=launch_warm_damp_dig_config,
191-
visible=false,
205+
visible=function() return getWarmPaintEnabled() and getDampPaintEnabled() end,
192206
},
193207
},
194208
},

0 commit comments

Comments
 (0)