From 3c44e22760b6cead3b42194097c24700b314683a Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 18 May 2012 17:54:05 +0400 Subject: [PATCH] Support trade viewscreens in Items::getSelectedItem. --- library/include/PluginManager.h | 2 ++ library/modules/Gui.cpp | 30 ++++++++++++++++++++++++++++++ library/xml | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 02974f36b..31633dfe2 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -31,6 +31,8 @@ distribution. #include #include +#include "Core.h" + #include "RemoteClient.h" typedef struct lua_State lua_State; diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 2d9402fca..461921391 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -54,7 +54,9 @@ using namespace DFHack; #include "df/viewscreen_layer_workshop_profilest.h" #include "df/viewscreen_layer_noblelistst.h" #include "df/viewscreen_layer_overall_healthst.h" +#include "df/viewscreen_layer_assigntradest.h" #include "df/viewscreen_petst.h" +#include "df/viewscreen_tradegoodsst.h" #include "df/ui_unit_view_mode.h" #include "df/ui_sidebar_menus.h" #include "df/ui_look_list.h" @@ -69,6 +71,7 @@ using namespace DFHack; #include "df/interfacest.h" #include "df/graphic.h" #include "df/layer_object_listst.h" +#include "df/assign_trade_status.h" using namespace df::enums; using df::global::gview; @@ -420,6 +423,33 @@ static df::item *getAnyItem(df::viewscreen *top) return ref ? ref->getItem() : NULL; } + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_layer_assigntradest, top)) + { + auto list1 = getLayerList(screen, 0); + auto list2 = getLayerList(screen, 1); + if (!list1 || !list2 || !list2->bright) + return NULL; + + int list_idx = vector_get(screen->visible_lists, list1->cursor, (int16_t)-1); + unsigned num_lists = sizeof(screen->lists)/sizeof(std::vector); + if (unsigned(list_idx) >= num_lists) + return NULL; + + int idx = vector_get(screen->lists[list_idx], list2->cursor, -1); + if (auto info = vector_get(screen->info, idx)) + return info->item; + + return NULL; + } + + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_tradegoodsst, top)) + { + if (screen->in_right_pane) + return vector_get(screen->broker_items, screen->broker_cursor); + else + return vector_get(screen->trader_items, screen->trader_cursor); + } + if (!Gui::dwarfmode_hotkey(top)) return NULL; diff --git a/library/xml b/library/xml index 3c8269225..f004804fd 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 3c8269225b1a68fd8803b7b7160d547247449789 +Subproject commit f004804fd655efcb4bf9ea31bd95ae4f759937b4