Skip to content

Commit

Permalink
Merge pull request #3895 from myk002/myk_stocks
Browse files Browse the repository at this point in the history
[stocks] overlay hotkey for collapsing all categories
  • Loading branch information
myk002 authored Oct 16, 2023
2 parents 6a1f3a8 + d141182 commit 5045482
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Template for new versions:
- `sort`: new search widgets for burrow assignment screen and other unit assignment dialogs
- `sort`: new search widgets for artifacts on the world/raid screen
- `sort`: new search widgets for slab engraving menu; can filter for only units that need a slab to prevent rising as a ghost
- `stocks`: hotkey for collapsing all categories on stocks screen

## Fixes
- `buildingplan`: remove bars of ash, coal, and soap as valid building materials to match v50 rules
Expand Down
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ if(BUILD_SUPPORTED)
add_subdirectory(spectate)
#dfhack_plugin(stockflow stockflow.cpp LINK_LIBRARIES lua)
add_subdirectory(stockpiles)
#dfhack_plugin(stocks stocks.cpp)
dfhack_plugin(stocks stocks.cpp LINK_LIBRARIES lua)
dfhack_plugin(strangemood strangemood.cpp)
dfhack_plugin(tailor tailor.cpp LINK_LIBRARIES lua)
dfhack_plugin(tiletypes tiletypes.cpp Brushes.h LINK_LIBRARIES lua)
Expand Down
55 changes: 55 additions & 0 deletions plugins/lua/stocks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
local _ENV = mkmodule('plugins.stocks')

local gui = require('gui')
local overlay = require('plugins.overlay')
local widgets = require('gui.widgets')

local stocks = df.global.game.main_interface.stocks

local function collapse_all()
local num_sections = #stocks.current_type_a_expanded
for idx=0,num_sections-1 do
stocks.current_type_a_expanded[idx] = false
end
stocks.i_height = num_sections * 3
end

-- -------------------
-- StocksOverlay
--

StocksOverlay = defclass(StocksOverlay, overlay.OverlayWidget)
StocksOverlay.ATTRS{
default_pos={x=-3,y=-20},
default_enabled=true,
viewscreens='dwarfmode/Stocks',
frame={w=27, h=5},
frame_style=gui.MEDIUM_FRAME,
frame_background=gui.CLEAR_PEN,
}

function StocksOverlay:init()
self:addviews{
widgets.HotkeyLabel{
frame={t=0, l=0},
label='collapse all',
key='CUSTOM_CTRL_X',
on_activate=collapse_all,
},
widgets.Label{
frame={t=2, l=0},
text = 'Shift+Scroll',
text_pen=COLOR_LIGHTGREEN,
},
widgets.Label{
frame={t=2, l=12},
text = ': fast scroll',
},
}
end

OVERLAY_WIDGETS = {
overlay=StocksOverlay,
}

return _ENV
32 changes: 23 additions & 9 deletions plugins/stocks.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#include "PluginManager.h"

using std::vector;
using std::string;

using namespace DFHack;

DFHACK_PLUGIN("stocks");

/*
#include "uicommon.h"
#include "listcolumn.h"
Expand Down Expand Up @@ -41,12 +51,12 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
#define MAX_NAME 30
#define SIDEBAR_WIDTH 30

*/

/*
* Utility
*/

/*
static string get_quality_name(const df::item_quality quality)
{
if (gps->dimx - SIDEBAR_WIDTH < 60)
Expand All @@ -66,12 +76,12 @@ static df::item *get_container_of(df::unit *unit)
auto ref = Units::getGeneralRef(unit, general_ref_type::CONTAINED_IN_ITEM);
return (ref) ? ref->getItem() : nullptr;
}

*/

/*
* Trade Info
*/

/*
class TradeDepotInfo
{
public:
Expand Down Expand Up @@ -168,12 +178,12 @@ class TradeDepotInfo
};
static TradeDepotInfo depot_info;

*/

/*
* Item manipulation
*/

/*
static map<df::item *, bool> items_in_cages;
static df::job *get_item_job(df::item *item)
Expand Down Expand Up @@ -950,7 +960,7 @@ class ViewscreenStocks : public dfhack_viewscreen
OutputHotkeyString(x, y, "Min Qual: ", "-+");
OutputString(COLOR_BROWN, x, y, get_quality_name(min_quality), true, left_margin);
OutputHotkeyString(x, y, "Max Qual: ", "/*");
OutputHotkeyString(x, y, "Max Qual: ", "/ *");
OutputString(COLOR_BROWN, x, y, get_quality_name(max_quality), true, left_margin);
OutputHotkeyString(x, y, "Min Wear: ", "Shift-W");
OutputString(COLOR_BROWN, x, y, int_to_string(min_wear), true, left_margin);
Expand Down Expand Up @@ -1466,19 +1476,22 @@ static command_result stocks_cmd(color_ostream &out, vector <string> & parameter
return CR_WRONG_USAGE;
}
*/

DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
DFhackCExport command_result plugin_init (color_ostream &out, vector <PluginCommand> &commands)
{
/*
commands.push_back(PluginCommand(
"stocks",
"An improved stocks management screen.",
stocks_cmd));
ViewscreenStocks::reset();

*/
return CR_OK;
}

/*
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
switch (event) {
Expand All @@ -1491,3 +1504,4 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK;
}
*/

0 comments on commit 5045482

Please sign in to comment.