Merge pull request #3164 from TaxiService/bplan_itemselection

buildingplan: itemselection ui rework
develop
Myk 2023-04-07 01:13:37 -07:00 committed by GitHub
commit 0cbd27d796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 134 additions and 96 deletions

@ -44,6 +44,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
- Mods: scripts in mods that are only in the steam workshop directory are now accessible. this means that a script-only mod that you never mark as "active" when generating a world will still receive automatic updates and be usable from in-game - Mods: scripts in mods that are only in the steam workshop directory are now accessible. this means that a script-only mod that you never mark as "active" when generating a world will still receive automatic updates and be usable from in-game
- Mods: scripts from only the most recent version of an installed mod are added to the script path - Mods: scripts from only the most recent version of an installed mod are added to the script path
- Mods: give active mods a chance to reattach their load hooks when a world is reloaded - Mods: give active mods a chance to reattach their load hooks when a world is reloaded

@ -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,
@ -81,6 +81,10 @@ function ItemSelection:init()
end end
self:addviews{ self:addviews{
widgets.Panel{
view_id='header',
frame={t=0, h=3},
subviews={
widgets.Label{ widgets.Label{
frame={t=0, l=0, r=16}, frame={t=0, l=0, r=16},
text={ text={
@ -114,17 +118,23 @@ 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, self:addviews{
icon_width=2, widgets.Panel{
on_submit=self:callback('toggle_group'), view_id='body',
edit_on_char=function(ch) return ch:match('[%l -]') end, frame={t=self.subviews.header.frame.h, b=4},
subviews={
widgets.EditField{
view_id='search',
frame={l=1, t=0},
label_text='Search: ',
on_char=function(ch) return ch:match('[%l -]') end,
}, },
widgets.CycleHotkeyLabel{ widgets.CycleHotkeyLabel{
frame={l=0, b=2}, frame={l=1, t=2},
key='CUSTOM_SHIFT_R', key='CUSTOM_SHIFT_R',
label='Sort by:', label='Sort by:',
options={ options={
@ -134,54 +144,81 @@ function ItemSelection:init()
}, },
on_change=self:callback('on_sort'), on_change=self:callback('on_sort'),
}, },
widgets.HotkeyLabel{ widgets.Panel{
frame={l=0, b=1}, frame={l=0, t=3, r=0, b=0},
key='SELECT', frame_style=gui.INTERIOR_FRAME,
label='Use all/none', subviews={
auto_width=true, widgets.FilteredList{
on_activate=function() self:toggle_group(self.subviews.flist.list:getSelected()) end, view_id='flist',
frame={t=0, b=0},
case_sensitive=false,
choices=choices,
icon_width=2,
on_submit=self:callback('toggle_group'),
}, },
widgets.HotkeyLabel{
frame={l=22, b=1},
key='CUSTOM_SHIFT_C',
label='Continue',
auto_width=true,
on_activate=self:callback('submit'),
}, },
widgets.HotkeyLabel{
frame={l=38, b=1},
key='LEAVESCREEN',
label='Go back',
auto_width=true,
on_activate=self:callback('on_cancel'),
}, },
},
},
widgets.Panel{
view_id='footer',
frame={l=1, r=1, b=0, h=3},
subviews={
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={l=0, b=0}, frame={l=0, h=1, t=0},
key='KEYBOARD_CURSOR_RIGHT_FAST', key='KEYBOARD_CURSOR_RIGHT_FAST',
key_sep=' : ', key_sep='----: ', -- these hypens function as "padding" to be overwritten by the next Label
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, w=5, t=0},
text_pen=COLOR_LIGHTGREEN, text_pen=COLOR_LIGHTGREEN,
text='Right', text='Right', -- this overrides the "6----" characters from the previous HotkeyLabel
}, },
widgets.HotkeyLabel{ widgets.HotkeyLabel{
frame={l=23, b=0}, frame={l=1, h=1, t=1},
key='KEYBOARD_CURSOR_LEFT_FAST', key='KEYBOARD_CURSOR_LEFT_FAST',
key_sep=' : ', key_sep='---: ', -- these hypens function as "padding" to be overwritten by the next Label
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, w=4, t=1},
text_pen=COLOR_LIGHTGREEN, text_pen=COLOR_LIGHTGREEN,
text='Left', text='Left', -- this overrides the "4---" characters from the previous HotkeyLabel
},
widgets.HotkeyLabel{
frame={l=6, t=2, h=2},
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, t=0},
key='LEAVESCREEN',
label='Go back',
auto_width=true,
on_activate=self:callback('on_cancel'),
},
widgets.HotkeyLabel{
frame={r=4, t=2},
key='CUSTOM_SHIFT_C',
label='Continue',
auto_width=true,
on_activate=self:callback('submit'),
},
},
}, },
} }
self.subviews.flist.list.frame.t = 0
self.subviews.flist.edit.visible = false
self.subviews.flist.edit = self.subviews.search
self.subviews.search.on_change = self.subviews.flist:callback('onFilterChange')
end end
-- resort and restore selection -- resort and restore selection
@ -234,7 +271,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)