From 07a4da65736df10b07b36d7f8c70eec7a7b42969 Mon Sep 17 00:00:00 2001 From: Taxi Service Date: Mon, 3 Apr 2023 22:23:32 +0200 Subject: [PATCH 1/6] reworked itemselection ui & added vertical divider pens --- docs/changelog.txt | 1 + plugins/lua/buildingplan/itemselection.lua | 81 ++++++++++++---------- plugins/lua/buildingplan/pens.lua | 6 ++ 3 files changed, 52 insertions(+), 36 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index b0b86c4cd..dd1a29e28 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -42,6 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - `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 diff --git a/plugins/lua/buildingplan/itemselection.lua b/plugins/lua/buildingplan/itemselection.lua index 9cfe0f843..dfb77d1fd 100644 --- a/plugins/lua/buildingplan/itemselection.lua +++ b/plugins/lua/buildingplan/itemselection.lua @@ -55,7 +55,7 @@ end ItemSelection = defclass(ItemSelection, widgets.Window) ItemSelection.ATTRS{ frame_title='Choose items', - frame={w=56, h=20, l=4, t=8}, + frame={w=56, h=24, l=4, t=7}, resizable=true, index=DEFAULT_NIL, desc=DEFAULT_NIL, @@ -114,17 +114,8 @@ function ItemSelection:init() on_click=self:callback('submit'), 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{ - frame={l=0, b=2}, + frame={l=1, t=3}, key='CUSTOM_SHIFT_R', label='Sort by:', options={ @@ -134,53 +125,71 @@ function ItemSelection:init() }, on_change=self:callback('on_sort'), }, - widgets.HotkeyLabel{ - frame={l=0, b=1}, - key='SELECT', - label='Use all/none', - auto_width=true, - on_activate=function() self:toggle_group(self.subviews.flist.list:getSelected()) end, + 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.HotkeyLabel{ - frame={l=22, b=1}, - key='CUSTOM_SHIFT_C', - label='Continue', - auto_width=true, - on_activate=self:callback('submit'), + widgets.Label{ + frame={l=1, t=5}, + text_pen=COLOR_LIGHTCYAN, + text={">"}, }, - widgets.HotkeyLabel{ - frame={l=38, b=1}, - key='LEAVESCREEN', - label='Go back', - auto_width=true, - on_activate=self:callback('on_cancel'), + widgets.Panel{ + frame={l=0, t=6, r=0, b=4}, + frame_style=gui.INTERIOR_FRAME, }, widgets.HotkeyLabel{ - frame={l=0, b=0}, + frame={l=0, b=2}, key='KEYBOARD_CURSOR_RIGHT_FAST', - key_sep=' : ', + 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=0, w=5}, + frame={l=6, b=2, w=5}, text_pen=COLOR_LIGHTGREEN, text='Right', }, widgets.HotkeyLabel{ - frame={l=23, b=0}, + frame={l=1, b=1}, key='KEYBOARD_CURSOR_LEFT_FAST', - key_sep=' : ', + 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=29, b=0, w=4}, + 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'), + }, } end @@ -234,7 +243,7 @@ function ItemSelection:get_choices(sort_fn) for desc,choice in pairs(buckets) do local data = choice.data 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}, } table.insert(choices, choice) diff --git a/plugins/lua/buildingplan/pens.lua b/plugins/lua/buildingplan/pens.lua index 973bb7bc6..288aea0db 100644 --- a/plugins/lua/buildingplan/pens.lua +++ b/plugins/lua/buildingplan/pens.lua @@ -2,6 +2,7 @@ local _ENV = mkmodule('plugins.buildingplan.pens') GOOD_TILE_PEN, BAD_TILE_PEN = 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 SELECTED_ITEM_PEN = 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_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() 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} From ea9f3ef9d1a743945b29c4d70fcbb628cb579cfb Mon Sep 17 00:00:00 2001 From: Taxi Service Date: Mon, 3 Apr 2023 22:27:50 +0200 Subject: [PATCH 2/6] restored pens.lua (has nothing to do with itemselection) --- plugins/lua/buildingplan/pens.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/lua/buildingplan/pens.lua b/plugins/lua/buildingplan/pens.lua index 288aea0db..973bb7bc6 100644 --- a/plugins/lua/buildingplan/pens.lua +++ b/plugins/lua/buildingplan/pens.lua @@ -2,7 +2,6 @@ local _ENV = mkmodule('plugins.buildingplan.pens') GOOD_TILE_PEN, BAD_TILE_PEN = 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 SELECTED_ITEM_PEN = nil MINIMIZED_LEFT_PEN, MINIMIZED_RIGHT_PEN = nil, nil @@ -23,11 +22,6 @@ function reload_pens() 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} - 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() 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} From e8fb2c5a4671e613dcb3c6b58a4c76f786e0c11c Mon Sep 17 00:00:00 2001 From: TaxiService Date: Tue, 4 Apr 2023 01:37:03 +0200 Subject: [PATCH 3/6] Update docs/changelog.txt Co-authored-by: Myk --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index dd1a29e28..cbc7b284d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -42,7 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - `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 +-@ `buildingplan`: rearranged elements of ``itemselection`` interface ## Documentation From aa8870fcad5dc3811ffe21157508ca616fba79bd Mon Sep 17 00:00:00 2001 From: Taxi Service Date: Tue, 4 Apr 2023 17:38:38 +0200 Subject: [PATCH 4/6] 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 From 59b79472301f88ba94775608afb3684478cce31e Mon Sep 17 00:00:00 2001 From: TaxiService Date: Tue, 4 Apr 2023 18:31:04 +0200 Subject: [PATCH 5/6] removed trailing whitespace... --- plugins/lua/buildingplan/itemselection.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lua/buildingplan/itemselection.lua b/plugins/lua/buildingplan/itemselection.lua index e8687c01d..782ac915b 100644 --- a/plugins/lua/buildingplan/itemselection.lua +++ b/plugins/lua/buildingplan/itemselection.lua @@ -164,7 +164,7 @@ function ItemSelection:init() view_id='footer', frame={l=1, r=1, b=0, h=3}, subviews={ - --[[ + --[[ add an explanation for this terribleness --]] widgets.HotkeyLabel{ From c490a9ebc2fb92ebcd018b9c0d5192ba01152d81 Mon Sep 17 00:00:00 2001 From: TaxiService Date: Wed, 5 Apr 2023 15:55:47 +0200 Subject: [PATCH 6/6] updated comments in the footer area --- plugins/lua/buildingplan/itemselection.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/lua/buildingplan/itemselection.lua b/plugins/lua/buildingplan/itemselection.lua index 782ac915b..84e866502 100644 --- a/plugins/lua/buildingplan/itemselection.lua +++ b/plugins/lua/buildingplan/itemselection.lua @@ -164,13 +164,10 @@ function ItemSelection:init() 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 + key_sep='----: ', -- these hypens function as "padding" to be overwritten by the next Label label='Use one', auto_width=true, on_activate=function() self:increment_group(self.subviews.flist.list:getSelected()) end, @@ -178,12 +175,12 @@ function ItemSelection:init() widgets.Label{ frame={l=6, w=5, t=0}, text_pen=COLOR_LIGHTGREEN, - text='Right', + text='Right', -- this overrides the "6----" characters from the previous HotkeyLabel }, widgets.HotkeyLabel{ frame={l=1, h=1, t=1}, key='KEYBOARD_CURSOR_LEFT_FAST', - key_sep='---: ', --these hypens are overwritten by the next Label + key_sep='---: ', -- these hypens function as "padding" to be overwritten by the next Label label='Use one fewer', auto_width=true, on_activate=function() self:decrement_group(self.subviews.flist.list:getSelected()) end, @@ -191,7 +188,7 @@ function ItemSelection:init() widgets.Label{ frame={l=7, w=4, t=1}, 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},