From 07a4da65736df10b07b36d7f8c70eec7a7b42969 Mon Sep 17 00:00:00 2001 From: Taxi Service Date: Mon, 3 Apr 2023 22:23:32 +0200 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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}, From 8d40ca8be68725c11dcaadbc95cb20084bd93649 Mon Sep 17 00:00:00 2001 From: Quietust Date: Sat, 1 Apr 2023 12:37:36 -0600 Subject: [PATCH 07/13] Add "faststart" plugin to make DF start faster In particular, it makes the game's "Loading..." screen animate as quickly as possible, shortening it from around 10 seconds to slightly more than 1 second. A conditional build setting makes it skip the animation as well, making it slightly faster yet. Ideally, this should become part of the Tweak plugin, but we're not building that right now. --- docs/changelog.txt | 1 + docs/plugins/faststart.rst | 18 ++++++++++ plugins/CMakeLists.txt | 1 + plugins/faststart.cpp | 69 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 docs/plugins/faststart.rst create mode 100644 plugins/faststart.cpp diff --git a/docs/changelog.txt b/docs/changelog.txt index 4be3e6a64..59c0dc2b1 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -34,6 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future ## New Plugins +- `faststart`: speeds up the "Loading..." screen so the Main Menu appears sooner ## Fixes - `hotkeys`: hotkey hints on menu popup will no longer get their last character cut off by the scrollbar diff --git a/docs/plugins/faststart.rst b/docs/plugins/faststart.rst new file mode 100644 index 000000000..3dc734183 --- /dev/null +++ b/docs/plugins/faststart.rst @@ -0,0 +1,18 @@ +faststart +========= + +.. dfhack-tool:: + :summary: Makes the main menu appear sooner. + :tags: interface + :no-command: + +This plugin accelerates the initial "Loading..." screen that appears when the +game first starts, so you don't have to wait as long before the Main Menu +appears and you can start playing. + +Usage +----- + +:: + + enable faststart diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index dc7fa9276..53d0296c7 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -112,6 +112,7 @@ dfhack_plugin(dig-now dig-now.cpp LINK_LIBRARIES lua) #dfhack_plugin(embark-tools embark-tools.cpp) dfhack_plugin(eventful eventful.cpp LINK_LIBRARIES lua) dfhack_plugin(fastdwarf fastdwarf.cpp) +dfhack_plugin(faststart faststart.cpp) dfhack_plugin(filltraffic filltraffic.cpp) #dfhack_plugin(fix-unit-occupancy fix-unit-occupancy.cpp) #dfhack_plugin(fixveins fixveins.cpp) diff --git a/plugins/faststart.cpp b/plugins/faststart.cpp new file mode 100644 index 000000000..d885726c0 --- /dev/null +++ b/plugins/faststart.cpp @@ -0,0 +1,69 @@ +// Fast Startup tweak + +#include "Core.h" +#include +#include +#include +#include +#include + +#include "df/viewscreen_initial_prepst.h" +#include + +using namespace DFHack; +using namespace df::enums; +using std::vector; + +// Uncomment this to make the Loading screen as fast as possible +// This has the side effect of removing the dwarf face animation +// (and briefly making the game become unresponsive) + +//#define REALLY_FAST + +DFHACK_PLUGIN("faststart"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); + +struct prep_hook : df::viewscreen_initial_prepst +{ + typedef df::viewscreen_initial_prepst interpose_base; + + DEFINE_VMETHOD_INTERPOSE(void, logic, ()) + { +#ifdef REALLY_FAST + while (breakdown_level != interface_breakdown_types::STOPSCREEN) + { + render_count++; + INTERPOSE_NEXT(logic)(); + } +#else + render_count = 4; + INTERPOSE_NEXT(logic)(); +#endif + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(prep_hook, logic); + +DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) +{ + if (enable != is_enabled) + { + if (!INTERPOSE_HOOK(prep_hook, logic).apply(enable)) + return CR_FAILURE; + + is_enabled = enable; + } + + return CR_OK; +} + +DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) +{ + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + INTERPOSE_HOOK(prep_hook, logic).remove(); + return CR_OK; +} From 93962df3de15db1193438b520c52ef2af00aa93d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Apr 2023 01:57:11 +0000 Subject: [PATCH 08/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/faststart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/faststart.cpp b/plugins/faststart.cpp index d885726c0..de014801c 100644 --- a/plugins/faststart.cpp +++ b/plugins/faststart.cpp @@ -18,7 +18,7 @@ using std::vector; // This has the side effect of removing the dwarf face animation // (and briefly making the game become unresponsive) -//#define REALLY_FAST +//#define REALLY_FAST DFHACK_PLUGIN("faststart"); DFHACK_PLUGIN_IS_ENABLED(is_enabled); From 75bdc8904c920a5542c0ee2d28a67339f9b44c19 Mon Sep 17 00:00:00 2001 From: Myk Date: Thu, 6 Apr 2023 18:59:57 -0700 Subject: [PATCH 09/13] add dfhack tag to faststart --- docs/plugins/faststart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/faststart.rst b/docs/plugins/faststart.rst index 3dc734183..b39269e01 100644 --- a/docs/plugins/faststart.rst +++ b/docs/plugins/faststart.rst @@ -3,7 +3,7 @@ faststart .. dfhack-tool:: :summary: Makes the main menu appear sooner. - :tags: interface + :tags: dfhack interface :no-command: This plugin accelerates the initial "Loading..." screen that appears when the From 2ac2817987ae2e8b9d426550c50406c2e1576b3f Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 6 Apr 2023 23:19:04 -0700 Subject: [PATCH 10/13] enable bugfix services by default --- data/dfhack-config/init/dfhack.control-panel-system.init | 4 ++++ .../dfhack-config/init/onMapLoad.control-panel-new-fort.init | 4 ++++ data/dfhack-config/init/onMapLoad.control-panel-repeats.init | 5 +++++ docs/changelog.txt | 1 + 4 files changed, 14 insertions(+) create mode 100644 data/dfhack-config/init/dfhack.control-panel-system.init create mode 100644 data/dfhack-config/init/onMapLoad.control-panel-new-fort.init create mode 100644 data/dfhack-config/init/onMapLoad.control-panel-repeats.init diff --git a/data/dfhack-config/init/dfhack.control-panel-system.init b/data/dfhack-config/init/dfhack.control-panel-system.init new file mode 100644 index 000000000..c13565c28 --- /dev/null +++ b/data/dfhack-config/init/dfhack.control-panel-system.init @@ -0,0 +1,4 @@ +# DO NOT EDIT THIS FILE +# Please use gui/control-panel to edit this file + +enable faststart diff --git a/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init b/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init new file mode 100644 index 000000000..8a159b0de --- /dev/null +++ b/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init @@ -0,0 +1,4 @@ +# DO NOT EDIT THIS FILE +# Please use gui/control-panel to edit this file + +on-new-fortress enable fix/protect-nicks diff --git a/data/dfhack-config/init/onMapLoad.control-panel-repeats.init b/data/dfhack-config/init/onMapLoad.control-panel-repeats.init new file mode 100644 index 000000000..1463230aa --- /dev/null +++ b/data/dfhack-config/init/onMapLoad.control-panel-repeats.init @@ -0,0 +1,5 @@ +# DO NOT EDIT THIS FILE +# Please use gui/control-panel to edit this file + +repeat --name general-strike --time 1 --timeUnits days --command [ fix/general-strike -q ] +repeat --name warn-starving --time 10 --timeUnits days --command [ warn-starving ] diff --git a/docs/changelog.txt b/docs/changelog.txt index 59c0dc2b1..2ae96aa86 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -46,6 +46,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base 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 +- `gui/control-panel`: bugfix services are now enabled by default ## Documentation From 2923cf7d2114df2578227202a36746df7d9bff3a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Apr 2023 06:22:02 +0000 Subject: [PATCH 11/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../init/dfhack.control-panel-system.init | 8 ++++---- .../init/onMapLoad.control-panel-new-fort.init | 8 ++++---- .../init/onMapLoad.control-panel-repeats.init | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/data/dfhack-config/init/dfhack.control-panel-system.init b/data/dfhack-config/init/dfhack.control-panel-system.init index c13565c28..8b1431373 100644 --- a/data/dfhack-config/init/dfhack.control-panel-system.init +++ b/data/dfhack-config/init/dfhack.control-panel-system.init @@ -1,4 +1,4 @@ -# DO NOT EDIT THIS FILE -# Please use gui/control-panel to edit this file - -enable faststart +# DO NOT EDIT THIS FILE +# Please use gui/control-panel to edit this file + +enable faststart diff --git a/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init b/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init index 8a159b0de..66a07d14f 100644 --- a/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init +++ b/data/dfhack-config/init/onMapLoad.control-panel-new-fort.init @@ -1,4 +1,4 @@ -# DO NOT EDIT THIS FILE -# Please use gui/control-panel to edit this file - -on-new-fortress enable fix/protect-nicks +# DO NOT EDIT THIS FILE +# Please use gui/control-panel to edit this file + +on-new-fortress enable fix/protect-nicks diff --git a/data/dfhack-config/init/onMapLoad.control-panel-repeats.init b/data/dfhack-config/init/onMapLoad.control-panel-repeats.init index 1463230aa..cbed00b67 100644 --- a/data/dfhack-config/init/onMapLoad.control-panel-repeats.init +++ b/data/dfhack-config/init/onMapLoad.control-panel-repeats.init @@ -1,5 +1,5 @@ -# DO NOT EDIT THIS FILE -# Please use gui/control-panel to edit this file - -repeat --name general-strike --time 1 --timeUnits days --command [ fix/general-strike -q ] -repeat --name warn-starving --time 10 --timeUnits days --command [ warn-starving ] +# DO NOT EDIT THIS FILE +# Please use gui/control-panel to edit this file + +repeat --name general-strike --time 1 --timeUnits days --command [ fix/general-strike -q ] +repeat --name warn-starving --time 10 --timeUnits days --command [ warn-starving ] From 00445767c74eb21600971ffd0699921e2b43300d Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Fri, 7 Apr 2023 06:27:56 +0000 Subject: [PATCH 12/13] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index e6216cc28..a4e5d4514 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit e6216cc28e4315df5fb128411d0ca57fe78ccb2b +Subproject commit a4e5d4514ec33462ee0c0bd25e02d4a9c3e2ce01 From 83017e8b8f7fffb935fd72bee5e356f972c1e6dd Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 7 Apr 2023 00:48:04 -0700 Subject: [PATCH 13/13] give active mods a chance to reattach their hooks --- docs/changelog.txt | 1 + docs/guides/modding-guide.rst | 5 +++++ library/Core.cpp | 5 ++++- library/LuaApi.cpp | 2 +- library/lua/script-manager.lua | 41 ++++++++++++++++++++++------------ 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 2ae96aa86..a0919c602 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -46,6 +46,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base 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: give active mods a chance to reattach their load hooks when a world is reloaded - `gui/control-panel`: bugfix services are now enabled by default ## Documentation diff --git a/docs/guides/modding-guide.rst b/docs/guides/modding-guide.rst index 0c9513fef..38117503c 100644 --- a/docs/guides/modding-guide.rst +++ b/docs/guides/modding-guide.rst @@ -461,6 +461,11 @@ Ok, you're all set up! Now, let's take a look at an example dfhack.onStateChange[GLOBAL_KEY] = function(sc) if sc == SC_MAP_UNLOADED then dfhack.run_command('disable', 'example-mod') + + -- ensure our mod doesn't try to enable itself when a different + -- world is loaded where we are *not* active + dfhack.onStateChange[GLOBAL_KEY] = nil + return end diff --git a/library/Core.cpp b/library/Core.cpp index d13c82fa5..97c69946e 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2148,7 +2148,10 @@ void Core::onStateChange(color_ostream &out, state_change_event event) loadModScriptPaths(out); auto L = Lua::Core::State; Lua::StackUnwinder top(L); - Lua::CallLuaModuleFunction(con, L, "script-manager", "reload"); + Lua::CallLuaModuleFunction(con, L, "script-manager", "reload", 1, 0, + [](lua_State* L) { + Lua::Push(L, true); + }); // fallthrough } case SC_WORLD_UNLOADED: diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index d30dc7f77..08903c7bd 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -2729,7 +2729,7 @@ static int filesystem_listdir_recursive(lua_State *L) include_prefix = lua_toboolean(L, 3); std::map files; int err = DFHack::Filesystem::listdir_recursive(dir, files, depth, include_prefix); - if (err != -1) { + if (err != 0 && err != -1) { lua_pushnil(L); lua_pushstring(L, strerror(err)); lua_pushinteger(L, err); diff --git a/library/lua/script-manager.lua b/library/lua/script-manager.lua index 1a7161a10..450012357 100644 --- a/library/lua/script-manager.lua +++ b/library/lua/script-manager.lua @@ -6,22 +6,27 @@ local utils = require('utils') -- enabled API -- for each script that can be loaded as a module, calls cb(script_name, env) -function foreach_module_script(cb) +function foreach_module_script(cb, preprocess_script_file_fn) for _,script_path in ipairs(dfhack.internal.getScriptPaths()) do local files = dfhack.filesystem.listdir_recursive( script_path, nil, false) if not files then goto skip_path end for _,f in ipairs(files) do - if not f.isdir and - f.path:endswith('.lua') and - not f.path:startswith('test/') and - not f.path:startswith('internal/') then - local script_name = f.path:sub(1, #f.path - 4) -- remove '.lua' - local ok, script_env = pcall(reqscript, script_name) - if ok then - cb(script_name, script_env) - end + if f.isdir or not f.path:endswith('.lua') or + f.path:startswith('.git') or + f.path:startswith('test/') or + f.path:startswith('internal/') then + goto continue end + if preprocess_script_file_fn then + preprocess_script_file_fn(script_path, f.path) + end + local script_name = f.path:sub(1, #f.path - 4) -- remove '.lua' + local ok, script_env = pcall(reqscript, script_name) + if ok then + cb(script_name, script_env) + end + ::continue:: end ::skip_path:: end @@ -42,9 +47,17 @@ local function process_script(env_name, env) enabled_map[env_name] = fn end -function reload() +function reload(refresh_active_mod_scripts) enabled_map = utils.OrderedTable() - foreach_module_script(process_script) + local force_refresh_fn = refresh_active_mod_scripts and function(script_path, script_name) + if script_path:find('scripts_modactive') then + internal_script = dfhack.internal.scripts[script_path..'/'..script_name] + if internal_script then + internal_script.env = nil + end + end + end or nil + foreach_module_script(process_script, force_refresh_fn) end local function ensure_loaded() @@ -97,7 +110,7 @@ end local function add_script_path(mod_script_paths, path) if dfhack.filesystem.isdir(path) then - print('indexing scripts from mod script path: ' .. path) + print('indexing mod scripts: ' .. path) table.insert(mod_script_paths, path) end end @@ -120,7 +133,7 @@ function get_mod_script_paths() -- if a world is loaded, process active mods first, and lock to active version if dfhack.isWorldLoaded() then for _,path in ipairs(df.global.world.object_loader.object_load_order_src_dir) do - path = tostring(path) + path = tostring(path.value) if not path:startswith(INSTALLED_MODS_PATH) then goto continue end local id = get_mod_id_and_version(path) if not id then goto continue end