From aa8870fcad5dc3811ffe21157508ca616fba79bd Mon Sep 17 00:00:00 2001 From: Taxi Service Date: Tue, 4 Apr 2023 17:38:38 +0200 Subject: [PATCH] custom EditField & reorganized panels --- plugins/lua/buildingplan/itemselection.lua | 237 ++++++++++++--------- 1 file changed, 134 insertions(+), 103 deletions(-) diff --git a/plugins/lua/buildingplan/itemselection.lua b/plugins/lua/buildingplan/itemselection.lua index dfb77d1fd..e8687c01d 100644 --- a/plugins/lua/buildingplan/itemselection.lua +++ b/plugins/lua/buildingplan/itemselection.lua @@ -81,116 +81,147 @@ function ItemSelection:init() end self:addviews{ - widgets.Label{ - frame={t=0, l=0, r=16}, - text={ - self.desc, plural, NEWLINE, - ('Select up to %d item%s ('):format(self.quantity, plural), - {text=function() return self.num_selected end}, - ' selected)', - }, - }, - widgets.Label{ - frame={r=0, w=15, t=0, h=3}, - text_pen=BUILD_TEXT_PEN, - text_hpen=BUILD_TEXT_HPEN, - text={ - ' Use filter ', NEWLINE, - ' for remaining ', NEWLINE, - ' items ', - }, - on_click=self:callback('submit'), - visible=function() return self.num_selected < self.quantity end, - }, - widgets.Label{ - frame={r=0, w=15, t=0, h=3}, - text_pen=BUILD_TEXT_PEN, - text_hpen=BUILD_TEXT_HPEN, - text={ - ' ', NEWLINE, - ' Continue ', NEWLINE, - ' ', + widgets.Panel{ + view_id='header', + frame={t=0, h=3}, + subviews={ + widgets.Label{ + frame={t=0, l=0, r=16}, + text={ + self.desc, plural, NEWLINE, + ('Select up to %d item%s ('):format(self.quantity, plural), + {text=function() return self.num_selected end}, + ' selected)', + }, + }, + widgets.Label{ + frame={r=0, w=15, t=0, h=3}, + text_pen=BUILD_TEXT_PEN, + text_hpen=BUILD_TEXT_HPEN, + text={ + ' Use filter ', NEWLINE, + ' for remaining ', NEWLINE, + ' items ', + }, + on_click=self:callback('submit'), + visible=function() return self.num_selected < self.quantity end, + }, + widgets.Label{ + frame={r=0, w=15, t=0, h=3}, + text_pen=BUILD_TEXT_PEN, + text_hpen=BUILD_TEXT_HPEN, + text={ + ' ', NEWLINE, + ' Continue ', NEWLINE, + ' ', + }, + on_click=self:callback('submit'), + visible=function() return self.num_selected >= self.quantity end, + }, }, - on_click=self:callback('submit'), - visible=function() return self.num_selected >= self.quantity end, }, - widgets.CycleHotkeyLabel{ - frame={l=1, t=3}, - key='CUSTOM_SHIFT_R', - label='Sort by:', - options={ - {label='Recently used', value=sort_by_recency}, - {label='Name', value=sort_by_name}, - {label='Amount', value=sort_by_quantity}, + } + + self:addviews{ + widgets.Panel{ + view_id='body', + 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{ + frame={l=1, t=2}, + key='CUSTOM_SHIFT_R', + label='Sort by:', + options={ + {label='Recently used', value=sort_by_recency}, + {label='Name', value=sort_by_name}, + {label='Amount', value=sort_by_quantity}, + }, + on_change=self:callback('on_sort'), + }, + widgets.Panel{ + frame={l=0, t=3, r=0, b=0}, + frame_style=gui.INTERIOR_FRAME, + subviews={ + widgets.FilteredList{ + view_id='flist', + frame={t=0, b=0}, + case_sensitive=false, + choices=choices, + icon_width=2, + on_submit=self:callback('toggle_group'), + }, + }, + }, }, - on_change=self:callback('on_sort'), - }, - widgets.FilteredList{ - view_id='flist', - frame={t=5, l=1, r=1, b=5}, - 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.Label{ - frame={l=1, t=5}, - text_pen=COLOR_LIGHTCYAN, - text={">"}, }, widgets.Panel{ - frame={l=0, t=6, r=0, b=4}, - frame_style=gui.INTERIOR_FRAME, - }, - widgets.HotkeyLabel{ - frame={l=0, b=2}, - key='KEYBOARD_CURSOR_RIGHT_FAST', - key_sep='ight: ', - label='Use one', - auto_width=true, - on_activate=function() self:increment_group(self.subviews.flist.list:getSelected()) end, - }, - widgets.Label{ - frame={l=6, b=2, w=5}, - text_pen=COLOR_LIGHTGREEN, - text='Right', - }, - widgets.HotkeyLabel{ - frame={l=1, b=1}, - key='KEYBOARD_CURSOR_LEFT_FAST', - key_sep='eft: ', - label='Use one fewer', - auto_width=true, - on_activate=function() self:decrement_group(self.subviews.flist.list:getSelected()) end, - }, - widgets.Label{ - frame={l=7, b=1, w=4}, - text_pen=COLOR_LIGHTGREEN, - 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'), + view_id='footer', + frame={l=1, r=1, b=0, h=3}, + subviews={ + --[[ + add an explanation for this terribleness + --]] + widgets.HotkeyLabel{ + frame={l=0, h=1, t=0}, + key='KEYBOARD_CURSOR_RIGHT_FAST', + key_sep='----: ', --these hypens are overwritten by the next Label + label='Use one', + auto_width=true, + on_activate=function() self:increment_group(self.subviews.flist.list:getSelected()) end, + }, + widgets.Label{ + frame={l=6, w=5, t=0}, + text_pen=COLOR_LIGHTGREEN, + text='Right', + }, + widgets.HotkeyLabel{ + frame={l=1, h=1, t=1}, + key='KEYBOARD_CURSOR_LEFT_FAST', + key_sep='---: ', --these hypens are overwritten by the next Label + label='Use one fewer', + auto_width=true, + on_activate=function() self:decrement_group(self.subviews.flist.list:getSelected()) end, + }, + widgets.Label{ + frame={l=7, w=4, t=1}, + text_pen=COLOR_LIGHTGREEN, + text='Left', + }, + 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 -- resort and restore selection