From 2ebc318daa91553355c4b67c6940b5901e9c99ec Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 21:47:14 -0700 Subject: [PATCH 1/8] Removing autotrade's obsolete Mark All --- NEWS | 2 + plugins/autotrade.cpp | 86 +------------------------------------------ 2 files changed, 4 insertions(+), 84 deletions(-) diff --git a/NEWS b/NEWS index 42559f069..b31d30197 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ DFHack Future + Fixes: + - autotrade: Removed the newly obsolete "Mark all" functionality. DFHack 0.40.14-r1 Internals: diff --git a/plugins/autotrade.cpp b/plugins/autotrade.cpp index eff1b5d64..26c51c348 100644 --- a/plugins/autotrade.cpp +++ b/plugins/autotrade.cpp @@ -25,7 +25,7 @@ using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("autotrade"); -#define PLUGIN_VERSION 0.4 +#define PLUGIN_VERSION 0.5 static const string PERSISTENCE_KEY = "autotrade/stockpiles"; @@ -445,86 +445,6 @@ struct trade_hook : public df::viewscreen_dwarfmodest IMPLEMENT_VMETHOD_INTERPOSE(trade_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(trade_hook, render); -struct tradeview_hook : public df::viewscreen_tradegoodsst -{ - typedef df::viewscreen_tradegoodsst interpose_base; - - bool handleInput(set *input) - { - if (input->count(interface_key::CUSTOM_M)) - { - for (int i = 0; i < trader_selected.size(); i++) - { - // Only mark containers, not their contents. - // Granted, this behaves poorly with the search plugin... - trader_selected[i] = !trader_items[i]->flags.bits.in_inventory; - } - } - else if (input->count(interface_key::CUSTOM_U)) - { - for (int i = 0; i < trader_selected.size(); i++) - { - trader_selected[i] = 0; - } - } - else if (input->count(interface_key::CUSTOM_SHIFT_M)) - { - for (int i = 0; i < broker_selected.size(); i++) - { - // Only mark containers, not their contents. - broker_selected[i] = !broker_items[i]->flags.bits.in_inventory; - } - } - else if (input->count(interface_key::CUSTOM_SHIFT_U)) - { - for (int i = 0; i < broker_selected.size(); i++) - { - broker_selected[i] = 0; - } - } - else - { - return false; - } - - return true; - } - - DEFINE_VMETHOD_INTERPOSE(void, feed, (set *input)) - { - if (!handleInput(input)) - INTERPOSE_NEXT(feed)(input); - } - - DEFINE_VMETHOD_INTERPOSE(void, render, ()) - { - INTERPOSE_NEXT(render)(); - - if (counteroffer.size() > 0) - { - // The merchant is proposing a counteroffer, - // so there is nothing to mark. - return; - } - - // Insert into the blank line between trade items and standard keys. - // The blank line at the bottom is taken by the search plugin. - auto dim = Screen::getWindowSize(); - int y = dim.y - 5; - - int x = 2; - OutputHotkeyString(x, y, "Mark all, ", "m", false, x, COLOR_WHITE, COLOR_LIGHTRED); - OutputHotkeyString(x, y, "Unmark all", "u", false, x, COLOR_WHITE, COLOR_LIGHTRED); - - x = 42; - OutputHotkeyString(x, y, "Mark all, ", "M", false, x, COLOR_WHITE, COLOR_LIGHTRED); - OutputHotkeyString(x, y, "Unmark all", "U", false, x, COLOR_WHITE, COLOR_LIGHTRED); - } -}; - -IMPLEMENT_VMETHOD_INTERPOSE(tradeview_hook, feed); -IMPLEMENT_VMETHOD_INTERPOSE(tradeview_hook, render); - static command_result autotrade_cmd(color_ostream &out, vector & parameters) { @@ -568,9 +488,7 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) monitor.reset(); if (!INTERPOSE_HOOK(trade_hook, feed).apply(enable) || - !INTERPOSE_HOOK(trade_hook, render).apply(enable) || - !INTERPOSE_HOOK(tradeview_hook, feed).apply(enable) || - !INTERPOSE_HOOK(tradeview_hook, render).apply(enable)) + !INTERPOSE_HOOK(trade_hook, render).apply(enable)) return CR_FAILURE; is_enabled = enable; From db7bc8c5c87f610a66797a9221eae1b47b13c093 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 21:53:00 -0700 Subject: [PATCH 2/8] Removing autotrade's version reporting. It's built with DFHack itself now, so the global version is more accurate than the plugin-specific version, which hasn't been consistently getting incremented. --- plugins/autotrade.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/plugins/autotrade.cpp b/plugins/autotrade.cpp index 26c51c348..f3922b96a 100644 --- a/plugins/autotrade.cpp +++ b/plugins/autotrade.cpp @@ -25,7 +25,6 @@ using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("autotrade"); -#define PLUGIN_VERSION 0.5 static const string PERSISTENCE_KEY = "autotrade/stockpiles"; @@ -446,19 +445,6 @@ IMPLEMENT_VMETHOD_INTERPOSE(trade_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(trade_hook, render); -static command_result autotrade_cmd(color_ostream &out, vector & parameters) -{ - if (!parameters.empty()) - { - if (parameters.size() == 1 && toLower(parameters[0])[0] == 'v') - { - out << "Autotrade" << endl << "Version: " << PLUGIN_VERSION << endl; - } - } - - return CR_OK; -} - DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { switch (event) @@ -499,11 +485,6 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.push_back( - PluginCommand( - "autotrade", "Automatically send items in marked stockpiles to trade depot, when trading is possible.", - autotrade_cmd, false, "Run 'autotrade version' to query the plugin version.\n")); - return CR_OK; } From 777b2f6416906e3c6626adcfd79cd4beadc3bd2b Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 22:05:05 -0700 Subject: [PATCH 3/8] Moving trade screen search options to match the new column size --- plugins/search.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/search.cpp b/plugins/search.cpp index 90a146c32..e25b36fe1 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -1093,8 +1093,7 @@ public: { int32_t x = 2; int32_t y = gps->dimy - 3; - make_text_dim(2, 37, y); - make_text_dim(42, gps->dimx-2, y); + make_text_dim(2, gps->dimx-2, y); OutputString(COLOR_LIGHTRED, x, y, string(1, select_key + 'A' - 'a')); OutputString(COLOR_WHITE, x, y, ": Clear search to trade "); } @@ -1138,14 +1137,13 @@ public: return; } - print_search_option(42, -1); + int32_t x = gps->dimx / 2 + 2; + print_search_option(x, -1); if (!search_string.empty()) { - int32_t x = 42; int32_t y = gps->dimy - 3; - make_text_dim(2, 37, y); - make_text_dim(42, gps->dimx-2, y); + make_text_dim(2, gps->dimx-2, y); OutputString(COLOR_LIGHTRED, x, y, string(1, select_key + 'A' - 'a')); OutputString(COLOR_WHITE, x, y, ": Clear search to trade "); } From 7fb82131c797cd30864eed9f803f446955a6a73c Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 22:14:00 -0700 Subject: [PATCH 4/8] Switching fast-trade from Shift-Enter to Shift-Down Technically, from SELECT_ALL to CURSOR_DOWN_FAST, to avoid blocking the new native Select All functionality. As a bonus, the new key repeats as you hold it down. --- Readme.html | 2 +- Readme.rst | 2 +- plugins/tweak/tweaks/fast-trade.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.html b/Readme.html index 51a8e8ecf..3255a3bad 100644 --- a/Readme.html +++ b/Readme.html @@ -1969,7 +1969,7 @@ the contents separately from the container. This forcefully skips child reagents.

-fast-trade:

Makes Shift-Enter in the Move Goods to Depot and Trade screens select +fast-trade:

Makes Shift-Down in the Move Goods to Depot and Trade screens select the current item (fully, in case of a stack), and scroll down one line.

diff --git a/Readme.rst b/Readme.rst index 378b32667..fac12afe9 100644 --- a/Readme.rst +++ b/Readme.rst @@ -1266,7 +1266,7 @@ Subcommands that persist until disabled or DF quit: in advmode. The issue is that the screen tries to force you to select the contents separately from the container. This forcefully skips child reagents. -:fast-trade: Makes Shift-Enter in the Move Goods to Depot and Trade screens select +:fast-trade: Makes Shift-Down in the Move Goods to Depot and Trade screens select the current item (fully, in case of a stack), and scroll down one line. :military-stable-assign: Preserve list order and cursor position when assigning to squad, i.e. stop the rightmost list of the Positions page of the military diff --git a/plugins/tweak/tweaks/fast-trade.h b/plugins/tweak/tweaks/fast-trade.h index 66e1c9637..a74b7ac81 100644 --- a/plugins/tweak/tweaks/fast-trade.h +++ b/plugins/tweak/tweaks/fast-trade.h @@ -5,7 +5,7 @@ struct fast_trade_assign_hook : df::viewscreen_layer_assigntradest { DEFINE_VMETHOD_INTERPOSE(void, feed, (set *input)) { - if (layer_objects[1]->active && input->count(interface_key::SELECT_ALL)) + if (layer_objects[1]->active && input->count(interface_key::CURSOR_DOWN_FAST)) { set tmp; tmp.insert(interface_key::SELECT); INTERPOSE_NEXT(feed)(&tmp); @@ -25,7 +25,7 @@ struct fast_trade_select_hook : df::viewscreen_tradegoodsst { DEFINE_VMETHOD_INTERPOSE(void, feed, (set *input)) { if (!(is_unloading || !has_traders || in_edit_count) - && input->count(interface_key::SELECT_ALL)) + && input->count(interface_key::CURSOR_DOWN_FAST)) { set tmp; tmp.insert(interface_key::SELECT); INTERPOSE_NEXT(feed)(&tmp); From 46ebeaa7223c615fb7127e9435592cb794812f8c Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 22:22:02 -0700 Subject: [PATCH 5/8] Adding Shift-Up to the fast-trade tweak. --- plugins/tweak/tweaks/fast-trade.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/tweak/tweaks/fast-trade.h b/plugins/tweak/tweaks/fast-trade.h index a74b7ac81..85d99c8a8 100644 --- a/plugins/tweak/tweaks/fast-trade.h +++ b/plugins/tweak/tweaks/fast-trade.h @@ -12,6 +12,13 @@ struct fast_trade_assign_hook : df::viewscreen_layer_assigntradest { tmp.clear(); tmp.insert(interface_key::STANDARDSCROLL_DOWN); INTERPOSE_NEXT(feed)(&tmp); } + else if (layer_objects[1]->active && input->count(interface_key::CURSOR_UP_FAST)) + { + set tmp; tmp.insert(interface_key::SELECT); + INTERPOSE_NEXT(feed)(&tmp); + tmp.clear(); tmp.insert(interface_key::STANDARDSCROLL_UP); + INTERPOSE_NEXT(feed)(&tmp); + } else INTERPOSE_NEXT(feed)(input); } @@ -25,13 +32,18 @@ struct fast_trade_select_hook : df::viewscreen_tradegoodsst { DEFINE_VMETHOD_INTERPOSE(void, feed, (set *input)) { if (!(is_unloading || !has_traders || in_edit_count) - && input->count(interface_key::CURSOR_DOWN_FAST)) + && (input->count(interface_key::CURSOR_DOWN_FAST) || input->count(interface_key::CURSOR_UP_FAST))) { set tmp; tmp.insert(interface_key::SELECT); INTERPOSE_NEXT(feed)(&tmp); if (in_edit_count) INTERPOSE_NEXT(feed)(&tmp); - tmp.clear(); tmp.insert(interface_key::STANDARDSCROLL_DOWN); + tmp.clear(); + if (input->count(interface_key::CURSOR_DOWN_FAST)) { + tmp.insert(interface_key::STANDARDSCROLL_DOWN); + } else if (input->count(interface_key::CURSOR_UP_FAST)) { + tmp.insert(interface_key::STANDARDSCROLL_UP); + } INTERPOSE_NEXT(feed)(&tmp); } else From ea5fff79036e9faa3dc8015d2eec518e7f05a223 Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 22:28:13 -0700 Subject: [PATCH 6/8] NEWS reports for trade screen issues --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index b31d30197..57edb0f1e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ DFHack Future Fixes: - autotrade: Removed the newly obsolete "Mark all" functionality. + - search: Adapts to the new trade screen column width + - tweak fast-trade: Switching the fast-trade keybinding to Shift-Up/Shift-Down, due to Select All conflict DFHack 0.40.14-r1 Internals: From 308e95defeec97df5a25688d129029900e83ba2b Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 22:41:16 -0700 Subject: [PATCH 7/8] Documenting autotrade It's similar enough to automelt to share a section, right? --- Readme.html | 8 +++++--- Readme.rst | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Readme.html b/Readme.html index 3255a3bad..1e068ff29 100644 --- a/Readme.html +++ b/Readme.html @@ -3344,12 +3344,14 @@ enabled materials, you should be able to place complex constructions more conven

Stockpile Automation

-

Enable the automelt plugin in your dfhack.init with:

+

Enable the automelt or autotrade plugins in your dfhack.init with:

 enable automelt
+enable autotrade
 
-

When querying a stockpile an option will appear to toggle automelt for this stockpile. -Any items placed in this stockpile will be designated to be melted.

+

When querying a stockpile, options will appear to toggle automelt and/or autotrade for this stockpile. +When automelt is enabled for a stockpile, any meltable items placed in it will be designated to be melted. +When autotrade is enabled for a stockpile, any items placed in it will be designated to be taken to the Trade Depot whenever merchants are on the map.

Track Stop Menu

diff --git a/Readme.rst b/Readme.rst index fac12afe9..9b119c968 100644 --- a/Readme.rst +++ b/Readme.rst @@ -2669,12 +2669,14 @@ enabled materials, you should be able to place complex constructions more conven Stockpile Automation ==================== -Enable the automelt plugin in your dfhack.init with:: +Enable the automelt or autotrade plugins in your dfhack.init with:: enable automelt + enable autotrade -When querying a stockpile an option will appear to toggle automelt for this stockpile. -Any items placed in this stockpile will be designated to be melted. +When querying a stockpile, options will appear to toggle automelt and/or autotrade for this stockpile. +When automelt is enabled for a stockpile, any meltable items placed in it will be designated to be melted. +When autotrade is enabled for a stockpile, any items placed in it will be designated to be taken to the Trade Depot whenever merchants are on the map. Track Stop Menu =============== From 8ac974870020b458100420ee911555cd6bd6e8fe Mon Sep 17 00:00:00 2001 From: Eric Wald Date: Thu, 6 Nov 2014 23:06:17 -0700 Subject: [PATCH 8/8] Switching fast-trade Shift-Up to move before marking This makes it undo Shift-Down, instead of mirroring it, which works much better when you've gone too far down the list. --- plugins/tweak/tweaks/fast-trade.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/tweak/tweaks/fast-trade.h b/plugins/tweak/tweaks/fast-trade.h index 85d99c8a8..d0bcc9812 100644 --- a/plugins/tweak/tweaks/fast-trade.h +++ b/plugins/tweak/tweaks/fast-trade.h @@ -14,9 +14,9 @@ struct fast_trade_assign_hook : df::viewscreen_layer_assigntradest { } else if (layer_objects[1]->active && input->count(interface_key::CURSOR_UP_FAST)) { - set tmp; tmp.insert(interface_key::SELECT); + set tmp; tmp.insert(interface_key::STANDARDSCROLL_UP); INTERPOSE_NEXT(feed)(&tmp); - tmp.clear(); tmp.insert(interface_key::STANDARDSCROLL_UP); + tmp.clear(); tmp.insert(interface_key::SELECT); INTERPOSE_NEXT(feed)(&tmp); } else @@ -32,19 +32,24 @@ struct fast_trade_select_hook : df::viewscreen_tradegoodsst { DEFINE_VMETHOD_INTERPOSE(void, feed, (set *input)) { if (!(is_unloading || !has_traders || in_edit_count) - && (input->count(interface_key::CURSOR_DOWN_FAST) || input->count(interface_key::CURSOR_UP_FAST))) + && input->count(interface_key::CURSOR_DOWN_FAST)) { set tmp; tmp.insert(interface_key::SELECT); INTERPOSE_NEXT(feed)(&tmp); if (in_edit_count) INTERPOSE_NEXT(feed)(&tmp); - tmp.clear(); - if (input->count(interface_key::CURSOR_DOWN_FAST)) { - tmp.insert(interface_key::STANDARDSCROLL_DOWN); - } else if (input->count(interface_key::CURSOR_UP_FAST)) { - tmp.insert(interface_key::STANDARDSCROLL_UP); - } + tmp.clear(); tmp.insert(interface_key::STANDARDSCROLL_DOWN); + INTERPOSE_NEXT(feed)(&tmp); + } + else if (!(is_unloading || !has_traders || in_edit_count) + && input->count(interface_key::CURSOR_UP_FAST)) + { + set tmp; tmp.insert(interface_key::STANDARDSCROLL_UP); + INTERPOSE_NEXT(feed)(&tmp); + tmp.clear(); tmp.insert(interface_key::SELECT); INTERPOSE_NEXT(feed)(&tmp); + if (in_edit_count) + INTERPOSE_NEXT(feed)(&tmp); } else INTERPOSE_NEXT(feed)(input);