diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 14a9d9c44..767091a64 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -43,6 +43,7 @@ #include "render/CAnimation.h" #include "render/IImage.h" +#include "render/IRenderHandler.h" #include "widgets/Buttons.h" #include "widgets/CComponent.h" @@ -1092,8 +1093,24 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component std::shared_ptr localIcon = localIconC.image; localIconC.removeChild(localIcon.get(), false); - auto wnd = std::make_shared(tempList, localIcon, localTitle, localDescription, selectCallback); + std::vector> images; + for(auto & obj : objects) + { + if(!settings["general"]["enableUiEnhancements"].Bool()) + break; + const CGTownInstance * t = dynamic_cast(cb->getObj(obj)); + if(t) + { + std::shared_ptr a = GH.renderHandler().loadAnimation(AnimationPath::builtin("ITPA")); + a->preload(); + images.push_back(a->getImage(t->town->clientInfo.icons[t->hasFort()][false] + 2)->scaleFast(Point(35, 23))); + } + } + + auto wnd = std::make_shared(tempList, localIcon, localTitle, localDescription, selectCallback, 0, images); wnd->onExit = cancelCallback; + wnd->onPopup = [this, objects](int index) { CRClickPopup::createAndPush(cb->getObj(objects[index]), GH.getCursorPosition()); }; + wnd->onClicked = [this, objects](int index) { adventureInt->centerOnObject(cb->getObj(objects[index])); GH.windows().totalRedraw(); }; GH.windows().pushWindow(wnd); } diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index f9f7fce24..9fcc1f8e2 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -34,6 +34,7 @@ #include "../render/Canvas.h" #include "../render/IImage.h" #include "../render/IRenderHandler.h" +#include "../render/CAnimation.h" #include "../render/ColorFilter.h" #include "../adventureMap/AdventureMapInterface.h" #include "../adventureMap/CList.h" @@ -883,9 +884,22 @@ void CCastleBuildings::enterCastleGate() availableTowns.push_back(t->id.getNum());//add to the list } } + + std::vector> images; + for(auto & t : Towns) + { + if(!settings["general"]["enableUiEnhancements"].Bool()) + break; + std::shared_ptr a = GH.renderHandler().loadAnimation(AnimationPath::builtin("ITPA")); + a->preload(); + images.push_back(a->getImage(t->town->clientInfo.icons[t->hasFort()][false] + 2)->scaleFast(Point(35, 23))); + } + auto gateIcon = std::make_shared(town->town->clientInfo.buildingsIcons, BuildingID::CASTLE_GATE);//will be deleted by selection window - GH.windows().createAndPushWindow(availableTowns, gateIcon, CGI->generaltexth->jktexts[40], - CGI->generaltexth->jktexts[41], std::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1)); + auto wnd = std::make_shared(availableTowns, gateIcon, CGI->generaltexth->jktexts[40], + CGI->generaltexth->jktexts[41], std::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1), 0, images); + wnd->onPopup = [this, Towns](int index) { CRClickPopup::createAndPush(Towns[index], GH.getCursorPosition()); }; + GH.windows().pushWindow(wnd); } void CCastleBuildings::enterDwelling(int level) diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index e77d1dcc7..0adb62bd9 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -39,6 +39,7 @@ #include "../render/Canvas.h" #include "../render/CAnimation.h" #include "../render/IRenderHandler.h" +#include "../render/IImage.h" #include "../../CCallback.h" @@ -1674,11 +1675,13 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner): } CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::string _text) - : CIntObject(LCLICK | DOUBLECLICK), + : CIntObject(LCLICK | DOUBLECLICK | RCLICK_POPUP), parent(_parent), index(_id) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); + if(parent->images.size() > index) + icon = std::make_shared(parent->images[index], Point(1, 1)); border = std::make_shared(ImagePath::builtin("TPGATES")); pos = border->pos; @@ -1701,6 +1704,9 @@ void CObjectListWindow::CItem::select(bool on) void CObjectListWindow::CItem::clickPressed(const Point & cursorPosition) { parent->changeSelection(index); + + if(parent->onClicked) + parent->onClicked(index); } void CObjectListWindow::CItem::clickDouble(const Point & cursorPosition) @@ -1708,10 +1714,20 @@ void CObjectListWindow::CItem::clickDouble(const Point & cursorPosition) parent->elementSelected(); } -CObjectListWindow::CObjectListWindow(const std::vector & _items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection) +void CObjectListWindow::CItem::showPopupWindow(const Point & cursorPosition) +{ + if(parent->onPopup) + parent->onPopup(index); +} + +CObjectListWindow::CObjectListWindow(const std::vector & _items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection, std::vector> images) : CWindowObject(PLAYER_COLORED, ImagePath::builtin("TPGATE")), onSelect(Callback), - selected(initialSelection) + onExit(nullptr), + onPopup(nullptr), + onClicked(nullptr), + selected(initialSelection), + images(images) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); items.reserve(_items.size()); @@ -1724,10 +1740,14 @@ CObjectListWindow::CObjectListWindow(const std::vector & _items, std::share init(titleWidget_, _title, _descr); } -CObjectListWindow::CObjectListWindow(const std::vector & _items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection) +CObjectListWindow::CObjectListWindow(const std::vector & _items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection, std::vector> images) : CWindowObject(PLAYER_COLORED, ImagePath::builtin("TPGATE")), onSelect(Callback), - selected(initialSelection) + onExit(nullptr), + onPopup(nullptr), + onClicked(nullptr), + selected(initialSelection), + images(images) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); items.reserve(_items.size()); @@ -1805,7 +1825,7 @@ void CObjectListWindow::changeSelection(size_t which) selected = which; } -void CObjectListWindow::keyPressed (EShortcut key) +void CObjectListWindow::keyPressed(EShortcut key) { int sel = static_cast(selected); diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index e37c510ee..d118e8203 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -38,6 +38,7 @@ class CGarrisonSlot; class CHeroArea; class CAnimImage; class CFilledTexture; +class IImage; enum class EUserEvent; @@ -157,6 +158,7 @@ class CObjectListWindow : public CWindowObject CObjectListWindow * parent; std::shared_ptr text; std::shared_ptr border; + std::shared_ptr icon; public: const size_t index; CItem(CObjectListWindow * parent, size_t id, std::string text); @@ -164,12 +166,14 @@ class CObjectListWindow : public CWindowObject void select(bool on); void clickPressed(const Point & cursorPosition) override; void clickDouble(const Point & cursorPosition) override; + void showPopupWindow(const Point & cursorPosition) override; }; std::function onSelect;//called when OK button is pressed, returns id of selected item. std::shared_ptr titleWidget; std::shared_ptr title; std::shared_ptr descr; + std::vector> images; std::shared_ptr list; std::shared_ptr ok; @@ -183,12 +187,14 @@ public: size_t selected;//index of currently selected item std::function onExit;//optional exit callback + std::function onPopup;//optional popup callback + std::function onClicked;//optional if clicked on item callback /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item /// Image can be nullptr ///item names will be taken from map objects - CObjectListWindow(const std::vector &_items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection = 0); - CObjectListWindow(const std::vector &_items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection = 0); + CObjectListWindow(const std::vector &_items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection = 0, std::vector> images = {}); + CObjectListWindow(const std::vector &_items, std::shared_ptr titleWidget_, std::string _title, std::string _descr, std::function Callback, size_t initialSelection = 0, std::vector> images = {}); std::shared_ptr genItem(size_t index); void elementSelected();//call callback and close this window