reworked itemselection ui & added vertical divider pens

develop
Taxi Service 2023-04-03 22:23:32 +02:00
parent 7d293c89a2
commit 07a4da6573
3 changed files with 52 additions and 36 deletions

@ -42,6 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Misc Improvements ## Misc Improvements
- `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base game - `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base game
- `buildingplan`: rearranged elements of ``itemselection`` interface
## Documentation ## Documentation

@ -55,7 +55,7 @@ end
ItemSelection = defclass(ItemSelection, widgets.Window) ItemSelection = defclass(ItemSelection, widgets.Window)
ItemSelection.ATTRS{ ItemSelection.ATTRS{
frame_title='Choose items', frame_title='Choose items',
frame={w=56, h=20, l=4, t=8}, frame={w=56, h=24, l=4, t=7},
resizable=true, resizable=true,
index=DEFAULT_NIL, index=DEFAULT_NIL,
desc=DEFAULT_NIL, desc=DEFAULT_NIL,
@ -114,17 +114,8 @@ function ItemSelection:init()
on_click=self:callback('submit'), on_click=self:callback('submit'),
visible=function() return self.num_selected >= self.quantity end, visible=function() return self.num_selected >= self.quantity end,
}, },
widgets.FilteredList{
view_id='flist',
frame={t=3, l=0, r=0, b=4},
case_sensitive=false,
choices=choices,
icon_width=2,
on_submit=self:callback('toggle_group'),
edit_on_char=function(ch) return ch:match('[%l -]') end,
},
widgets.CycleHotkeyLabel{ widgets.CycleHotkeyLabel{
frame={l=0, b=2}, frame={l=1, t=3},
key='CUSTOM_SHIFT_R', key='CUSTOM_SHIFT_R',
label='Sort by:', label='Sort by:',
options={ options={
@ -134,53 +125,71 @@ function ItemSelection:init()
}, },
on_change=self:callback('on_sort'), on_change=self:callback('on_sort'),
}, },
widgets.HotkeyLabel{ widgets.FilteredList{
frame={l=0, b=1}, view_id='flist',
key='SELECT', frame={t=5, l=1, r=1, b=5},
label='Use all/none', case_sensitive=false,
auto_width=true, choices=choices,
on_activate=function() self:toggle_group(self.subviews.flist.list:getSelected()) end, icon_width=2,
on_submit=self:callback('toggle_group'),
edit_on_char=function(ch) return ch:match('[%l -]') end,
}, },
widgets.HotkeyLabel{ widgets.Label{
frame={l=22, b=1}, frame={l=1, t=5},
key='CUSTOM_SHIFT_C', text_pen=COLOR_LIGHTCYAN,
label='Continue', text={">"},
auto_width=true,
on_activate=self:callback('submit'),
}, },
widgets.HotkeyLabel{ widgets.Panel{
frame={l=38, b=1}, frame={l=0, t=6, r=0, b=4},
key='LEAVESCREEN', frame_style=gui.INTERIOR_FRAME,
label='Go back',
auto_width=true,
on_activate=self:callback('on_cancel'),
}, },
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={l=0, b=0}, frame={l=0, b=2},
key='KEYBOARD_CURSOR_RIGHT_FAST', key='KEYBOARD_CURSOR_RIGHT_FAST',
key_sep=' : ', key_sep='ight: ',
label='Use one', label='Use one',
auto_width=true, auto_width=true,
on_activate=function() self:increment_group(self.subviews.flist.list:getSelected()) end, on_activate=function() self:increment_group(self.subviews.flist.list:getSelected()) end,
}, },
widgets.Label{ widgets.Label{
frame={l=6, b=0, w=5}, frame={l=6, b=2, w=5},
text_pen=COLOR_LIGHTGREEN, text_pen=COLOR_LIGHTGREEN,
text='Right', text='Right',
}, },
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={l=23, b=0}, frame={l=1, b=1},
key='KEYBOARD_CURSOR_LEFT_FAST', key='KEYBOARD_CURSOR_LEFT_FAST',
key_sep=' : ', key_sep='eft: ',
label='Use one fewer', label='Use one fewer',
auto_width=true, auto_width=true,
on_activate=function() self:decrement_group(self.subviews.flist.list:getSelected()) end, on_activate=function() self:decrement_group(self.subviews.flist.list:getSelected()) end,
}, },
widgets.Label{ widgets.Label{
frame={l=29, b=0, w=4}, frame={l=7, b=1, w=4},
text_pen=COLOR_LIGHTGREEN, text_pen=COLOR_LIGHTGREEN,
text='Left', text='Left',
}, },
widgets.HotkeyLabel{
frame={l=6, b=0},
key='SELECT',
label='Use all/none',
auto_width=true,
on_activate=function() self:toggle_group(self.subviews.flist.list:getSelected()) end,
},
widgets.HotkeyLabel{
frame={r=5, b=2},
key='LEAVESCREEN',
label='Go back',
auto_width=true,
on_activate=self:callback('on_cancel'),
},
widgets.HotkeyLabel{
frame={r=4, b=0},
key='CUSTOM_SHIFT_C',
label='Continue',
auto_width=true,
on_activate=self:callback('submit'),
},
} }
end end
@ -234,7 +243,7 @@ function ItemSelection:get_choices(sort_fn)
for desc,choice in pairs(buckets) do for desc,choice in pairs(buckets) do
local data = choice.data local data = choice.data
choice.text = { choice.text = {
{width=10, text=function() return ('[%d/%d]'):format(data.selected, data.quantity) end}, {width=10, text=function() return ('%d/%d'):format(data.selected, data.quantity) end},
{gap=2, text=desc}, {gap=2, text=desc},
} }
table.insert(choices, choice) table.insert(choices, choice)

@ -2,6 +2,7 @@ local _ENV = mkmodule('plugins.buildingplan.pens')
GOOD_TILE_PEN, BAD_TILE_PEN = nil, nil GOOD_TILE_PEN, BAD_TILE_PEN = nil, nil
VERT_TOP_PEN, VERT_MID_PEN, VERT_BOT_PEN = nil, nil, nil VERT_TOP_PEN, VERT_MID_PEN, VERT_BOT_PEN = nil, nil, nil
HORI_LEFT_PEN, HORI_MID_PEN, HORI_RIGHT_PEN = nil, nil, nil
BUTTON_START_PEN, BUTTON_END_PEN = nil, nil BUTTON_START_PEN, BUTTON_END_PEN = nil, nil
SELECTED_ITEM_PEN = nil SELECTED_ITEM_PEN = nil
MINIMIZED_LEFT_PEN, MINIMIZED_RIGHT_PEN = nil, nil MINIMIZED_LEFT_PEN, MINIMIZED_RIGHT_PEN = nil, nil
@ -22,6 +23,11 @@ function reload_pens()
VERT_MID_PEN = to_pen{tile=tp(tb_texpos, 4), ch=192, fg=COLOR_GREY, bg=COLOR_BLACK} VERT_MID_PEN = to_pen{tile=tp(tb_texpos, 4), ch=192, fg=COLOR_GREY, bg=COLOR_BLACK}
VERT_BOT_PEN = to_pen{tile=tp(tb_texpos, 11), ch=179, fg=COLOR_GREY, bg=COLOR_BLACK} VERT_BOT_PEN = to_pen{tile=tp(tb_texpos, 11), ch=179, fg=COLOR_GREY, bg=COLOR_BLACK}
local mb_texpos = dfhack.textures.getMediumBordersTexposStart()
HORI_LEFT_PEN = to_pen{tile=tp(mb_texpos, 12), ch=195, fg=COLOR_GREY, bg=COLOR_BLACK}
HORI_MID_PEN = to_pen{tile=tp(mb_texpos, 5), ch=196, fg=COLOR_GREY, bg=COLOR_BLACK}
HORI_RIGHT_PEN = to_pen{tile=tp(mb_texpos, 13), ch=180, fg=COLOR_GREY, bg=COLOR_BLACK}
local cp_texpos = dfhack.textures.getControlPanelTexposStart() local cp_texpos = dfhack.textures.getControlPanelTexposStart()
BUTTON_START_PEN = to_pen{tile=tp(cp_texpos, 13), ch='[', fg=COLOR_YELLOW} BUTTON_START_PEN = to_pen{tile=tp(cp_texpos, 13), ch='[', fg=COLOR_YELLOW}
BUTTON_END_PEN = to_pen{tile=tp(cp_texpos, 15), ch=']', fg=COLOR_YELLOW} BUTTON_END_PEN = to_pen{tile=tp(cp_texpos, 15), ch=']', fg=COLOR_YELLOW}