mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-25 12:14:46 +02:00
rework town portal
This commit is contained in:
parent
5d8b65befd
commit
ebb2cce8b8
@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
#include "render/CAnimation.h"
|
#include "render/CAnimation.h"
|
||||||
#include "render/IImage.h"
|
#include "render/IImage.h"
|
||||||
|
#include "render/IRenderHandler.h"
|
||||||
|
|
||||||
#include "widgets/Buttons.h"
|
#include "widgets/Buttons.h"
|
||||||
#include "widgets/CComponent.h"
|
#include "widgets/CComponent.h"
|
||||||
@ -1092,8 +1093,24 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
|
|||||||
std::shared_ptr<CIntObject> localIcon = localIconC.image;
|
std::shared_ptr<CIntObject> localIcon = localIconC.image;
|
||||||
localIconC.removeChild(localIcon.get(), false);
|
localIconC.removeChild(localIcon.get(), false);
|
||||||
|
|
||||||
auto wnd = std::make_shared<CObjectListWindow>(tempList, localIcon, localTitle, localDescription, selectCallback);
|
std::vector<std::shared_ptr<IImage>> images;
|
||||||
|
for(auto & obj : objects)
|
||||||
|
{
|
||||||
|
if(!settings["general"]["enableUiEnhancements"].Bool())
|
||||||
|
break;
|
||||||
|
const CGTownInstance * t = dynamic_cast<const CGTownInstance *>(cb->getObj(obj));
|
||||||
|
if(t)
|
||||||
|
{
|
||||||
|
std::shared_ptr<CAnimation> 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<CObjectListWindow>(tempList, localIcon, localTitle, localDescription, selectCallback, 0, images);
|
||||||
wnd->onExit = cancelCallback;
|
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);
|
GH.windows().pushWindow(wnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "../render/Canvas.h"
|
#include "../render/Canvas.h"
|
||||||
#include "../render/IImage.h"
|
#include "../render/IImage.h"
|
||||||
#include "../render/IRenderHandler.h"
|
#include "../render/IRenderHandler.h"
|
||||||
|
#include "../render/CAnimation.h"
|
||||||
#include "../render/ColorFilter.h"
|
#include "../render/ColorFilter.h"
|
||||||
#include "../adventureMap/AdventureMapInterface.h"
|
#include "../adventureMap/AdventureMapInterface.h"
|
||||||
#include "../adventureMap/CList.h"
|
#include "../adventureMap/CList.h"
|
||||||
@ -883,9 +884,22 @@ void CCastleBuildings::enterCastleGate()
|
|||||||
availableTowns.push_back(t->id.getNum());//add to the list
|
availableTowns.push_back(t->id.getNum());//add to the list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<IImage>> images;
|
||||||
|
for(auto & t : Towns)
|
||||||
|
{
|
||||||
|
if(!settings["general"]["enableUiEnhancements"].Bool())
|
||||||
|
break;
|
||||||
|
std::shared_ptr<CAnimation> 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<CAnimImage>(town->town->clientInfo.buildingsIcons, BuildingID::CASTLE_GATE);//will be deleted by selection window
|
auto gateIcon = std::make_shared<CAnimImage>(town->town->clientInfo.buildingsIcons, BuildingID::CASTLE_GATE);//will be deleted by selection window
|
||||||
GH.windows().createAndPushWindow<CObjectListWindow>(availableTowns, gateIcon, CGI->generaltexth->jktexts[40],
|
auto wnd = std::make_shared<CObjectListWindow>(availableTowns, gateIcon, CGI->generaltexth->jktexts[40],
|
||||||
CGI->generaltexth->jktexts[41], std::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1));
|
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)
|
void CCastleBuildings::enterDwelling(int level)
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "../render/Canvas.h"
|
#include "../render/Canvas.h"
|
||||||
#include "../render/CAnimation.h"
|
#include "../render/CAnimation.h"
|
||||||
#include "../render/IRenderHandler.h"
|
#include "../render/IRenderHandler.h"
|
||||||
|
#include "../render/IImage.h"
|
||||||
|
|
||||||
#include "../../CCallback.h"
|
#include "../../CCallback.h"
|
||||||
|
|
||||||
@ -1674,11 +1675,13 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
|
|||||||
}
|
}
|
||||||
|
|
||||||
CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::string _text)
|
CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::string _text)
|
||||||
: CIntObject(LCLICK | DOUBLECLICK),
|
: CIntObject(LCLICK | DOUBLECLICK | RCLICK_POPUP),
|
||||||
parent(_parent),
|
parent(_parent),
|
||||||
index(_id)
|
index(_id)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||||
|
if(parent->images.size() > index)
|
||||||
|
icon = std::make_shared<CPicture>(parent->images[index], Point(1, 1));
|
||||||
border = std::make_shared<CPicture>(ImagePath::builtin("TPGATES"));
|
border = std::make_shared<CPicture>(ImagePath::builtin("TPGATES"));
|
||||||
pos = border->pos;
|
pos = border->pos;
|
||||||
|
|
||||||
@ -1701,6 +1704,9 @@ void CObjectListWindow::CItem::select(bool on)
|
|||||||
void CObjectListWindow::CItem::clickPressed(const Point & cursorPosition)
|
void CObjectListWindow::CItem::clickPressed(const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
parent->changeSelection(index);
|
parent->changeSelection(index);
|
||||||
|
|
||||||
|
if(parent->onClicked)
|
||||||
|
parent->onClicked(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectListWindow::CItem::clickDouble(const Point & cursorPosition)
|
void CObjectListWindow::CItem::clickDouble(const Point & cursorPosition)
|
||||||
@ -1708,10 +1714,20 @@ void CObjectListWindow::CItem::clickDouble(const Point & cursorPosition)
|
|||||||
parent->elementSelected();
|
parent->elementSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection)
|
void CObjectListWindow::CItem::showPopupWindow(const Point & cursorPosition)
|
||||||
|
{
|
||||||
|
if(parent->onPopup)
|
||||||
|
parent->onPopup(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection, std::vector<std::shared_ptr<IImage>> images)
|
||||||
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("TPGATE")),
|
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("TPGATE")),
|
||||||
onSelect(Callback),
|
onSelect(Callback),
|
||||||
selected(initialSelection)
|
onExit(nullptr),
|
||||||
|
onPopup(nullptr),
|
||||||
|
onClicked(nullptr),
|
||||||
|
selected(initialSelection),
|
||||||
|
images(images)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||||
items.reserve(_items.size());
|
items.reserve(_items.size());
|
||||||
@ -1724,10 +1740,14 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::share
|
|||||||
init(titleWidget_, _title, _descr);
|
init(titleWidget_, _title, _descr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection)
|
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection, std::vector<std::shared_ptr<IImage>> images)
|
||||||
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("TPGATE")),
|
: CWindowObject(PLAYER_COLORED, ImagePath::builtin("TPGATE")),
|
||||||
onSelect(Callback),
|
onSelect(Callback),
|
||||||
selected(initialSelection)
|
onExit(nullptr),
|
||||||
|
onPopup(nullptr),
|
||||||
|
onClicked(nullptr),
|
||||||
|
selected(initialSelection),
|
||||||
|
images(images)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||||
items.reserve(_items.size());
|
items.reserve(_items.size());
|
||||||
@ -1805,7 +1825,7 @@ void CObjectListWindow::changeSelection(size_t which)
|
|||||||
selected = which;
|
selected = which;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectListWindow::keyPressed (EShortcut key)
|
void CObjectListWindow::keyPressed(EShortcut key)
|
||||||
{
|
{
|
||||||
int sel = static_cast<int>(selected);
|
int sel = static_cast<int>(selected);
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ class CGarrisonSlot;
|
|||||||
class CHeroArea;
|
class CHeroArea;
|
||||||
class CAnimImage;
|
class CAnimImage;
|
||||||
class CFilledTexture;
|
class CFilledTexture;
|
||||||
|
class IImage;
|
||||||
|
|
||||||
enum class EUserEvent;
|
enum class EUserEvent;
|
||||||
|
|
||||||
@ -157,6 +158,7 @@ class CObjectListWindow : public CWindowObject
|
|||||||
CObjectListWindow * parent;
|
CObjectListWindow * parent;
|
||||||
std::shared_ptr<CLabel> text;
|
std::shared_ptr<CLabel> text;
|
||||||
std::shared_ptr<CPicture> border;
|
std::shared_ptr<CPicture> border;
|
||||||
|
std::shared_ptr<CPicture> icon;
|
||||||
public:
|
public:
|
||||||
const size_t index;
|
const size_t index;
|
||||||
CItem(CObjectListWindow * parent, size_t id, std::string text);
|
CItem(CObjectListWindow * parent, size_t id, std::string text);
|
||||||
@ -164,12 +166,14 @@ class CObjectListWindow : public CWindowObject
|
|||||||
void select(bool on);
|
void select(bool on);
|
||||||
void clickPressed(const Point & cursorPosition) override;
|
void clickPressed(const Point & cursorPosition) override;
|
||||||
void clickDouble(const Point & cursorPosition) override;
|
void clickDouble(const Point & cursorPosition) override;
|
||||||
|
void showPopupWindow(const Point & cursorPosition) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
|
std::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
|
||||||
std::shared_ptr<CIntObject> titleWidget;
|
std::shared_ptr<CIntObject> titleWidget;
|
||||||
std::shared_ptr<CLabel> title;
|
std::shared_ptr<CLabel> title;
|
||||||
std::shared_ptr<CLabel> descr;
|
std::shared_ptr<CLabel> descr;
|
||||||
|
std::vector<std::shared_ptr<IImage>> images;
|
||||||
|
|
||||||
std::shared_ptr<CListBox> list;
|
std::shared_ptr<CListBox> list;
|
||||||
std::shared_ptr<CButton> ok;
|
std::shared_ptr<CButton> ok;
|
||||||
@ -183,12 +187,14 @@ public:
|
|||||||
size_t selected;//index of currently selected item
|
size_t selected;//index of currently selected item
|
||||||
|
|
||||||
std::function<void()> onExit;//optional exit callback
|
std::function<void()> onExit;//optional exit callback
|
||||||
|
std::function<void(int)> onPopup;//optional popup callback
|
||||||
|
std::function<void(int)> 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
|
/// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
|
||||||
/// Image can be nullptr
|
/// Image can be nullptr
|
||||||
///item names will be taken from map objects
|
///item names will be taken from map objects
|
||||||
CObjectListWindow(const std::vector<int> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0);
|
CObjectListWindow(const std::vector<int> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0, std::vector<std::shared_ptr<IImage>> images = {});
|
||||||
CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0);
|
CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0, std::vector<std::shared_ptr<IImage>> images = {});
|
||||||
|
|
||||||
std::shared_ptr<CIntObject> genItem(size_t index);
|
std::shared_ptr<CIntObject> genItem(size_t index);
|
||||||
void elementSelected();//call callback and close this window
|
void elementSelected();//call callback and close this window
|
||||||
|
Loading…
x
Reference in New Issue
Block a user