2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* CList.h, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2012-06-13 16:04:06 +03:00
|
|
|
#pragma once
|
|
|
|
|
2023-05-30 17:53:51 +02:00
|
|
|
#include "../widgets/Scrollable.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../../lib/FunctionList.h"
|
2012-06-13 16:04:06 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2012-06-13 16:04:06 +03:00
|
|
|
class CGHeroInstance;
|
|
|
|
class CGTownInstance;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2023-05-08 23:04:44 +02:00
|
|
|
class CListBox;
|
2022-07-26 15:07:42 +02:00
|
|
|
class CButton;
|
2023-05-08 23:04:44 +02:00
|
|
|
class CAnimImage;
|
2012-06-13 16:04:06 +03:00
|
|
|
|
|
|
|
/// Base UI Element for hero\town lists
|
2023-05-30 17:53:51 +02:00
|
|
|
class CList : public Scrollable
|
2012-06-13 16:04:06 +03:00
|
|
|
{
|
|
|
|
protected:
|
2018-04-07 13:34:11 +02:00
|
|
|
class CListItem : public CIntObject, public std::enable_shared_from_this<CListItem>
|
2012-06-13 16:04:06 +03:00
|
|
|
{
|
|
|
|
CList * parent;
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> selection;
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
|
|
|
CListItem(CList * parent);
|
|
|
|
~CListItem();
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void showPopupWindow(const Point & cursorPosition) override;
|
|
|
|
void clickPressed(const Point & cursorPosition) override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void hover(bool on) override;
|
2012-06-13 16:04:06 +03:00
|
|
|
void onSelect(bool on);
|
|
|
|
|
|
|
|
/// create object with selection rectangle
|
2018-04-07 13:34:11 +02:00
|
|
|
virtual std::shared_ptr<CIntObject> genSelection()=0;
|
2012-06-13 16:04:06 +03:00
|
|
|
/// reaction on item selection (e.g. enable selection border)
|
|
|
|
/// NOTE: item may be deleted in selected state
|
|
|
|
virtual void select(bool on)=0;
|
|
|
|
/// open item (town or hero screen)
|
|
|
|
virtual void open()=0;
|
|
|
|
/// show right-click tooltip
|
|
|
|
virtual void showTooltip()=0;
|
|
|
|
/// get hover text for status bar
|
|
|
|
virtual std::string getHoverText()=0;
|
|
|
|
};
|
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
private:
|
2012-06-13 16:04:06 +03:00
|
|
|
const size_t size;
|
|
|
|
|
|
|
|
//for selection\deselection
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CListItem> selected;
|
|
|
|
void select(std::shared_ptr<CListItem> which);
|
2012-06-13 16:04:06 +03:00
|
|
|
friend class CListItem;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CButton> scrollUp;
|
|
|
|
std::shared_ptr<CButton> scrollDown;
|
|
|
|
|
2023-05-30 17:53:51 +02:00
|
|
|
void scrollBy(int distance) override;
|
|
|
|
void scrollPrev() override;
|
|
|
|
void scrollNext() override;
|
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
protected:
|
|
|
|
std::shared_ptr<CListBox> listBox;
|
|
|
|
|
2023-05-06 15:52:43 +02:00
|
|
|
CList(int size, Rect widgetDimensions);
|
2023-04-26 14:44:10 +02:00
|
|
|
|
2023-05-06 15:52:43 +02:00
|
|
|
void createList(Point firstItemPosition, Point itemPositionDelta, size_t listAmount);
|
2023-04-26 14:44:10 +02:00
|
|
|
|
|
|
|
virtual std::shared_ptr<CIntObject> createItem(size_t index) = 0;
|
2012-06-13 16:04:06 +03:00
|
|
|
|
2023-07-13 13:35:24 +02:00
|
|
|
/// should be called when list is invalidated
|
|
|
|
void update();
|
|
|
|
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
|
|
|
/// functions that will be called when selection changes
|
|
|
|
CFunctionList<void()> onSelect;
|
|
|
|
|
|
|
|
/// return index of currently selected element
|
|
|
|
int getSelectedIndex();
|
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
void setScrollUpButton(std::shared_ptr<CButton> button);
|
|
|
|
void setScrollDownButton(std::shared_ptr<CButton> button);
|
|
|
|
|
|
|
|
|
2012-06-13 16:04:06 +03:00
|
|
|
/// set of methods to switch selection
|
|
|
|
void selectIndex(int which);
|
|
|
|
void selectNext();
|
|
|
|
void selectPrev();
|
2023-05-06 15:52:43 +02:00
|
|
|
|
2023-06-02 15:42:18 +02:00
|
|
|
void showAll(Canvas & to) override;
|
2012-06-13 16:04:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// List of heroes which is shown at the right of the adventure map screen
|
|
|
|
class CHeroList : public CList
|
|
|
|
{
|
|
|
|
/// Empty hero item used as placeholder for unused entries in list
|
|
|
|
class CEmptyHeroItem : public CIntObject
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> movement;
|
|
|
|
std::shared_ptr<CAnimImage> mana;
|
|
|
|
std::shared_ptr<CPicture> portrait;
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
|
|
|
CEmptyHeroItem();
|
|
|
|
};
|
|
|
|
|
|
|
|
class CHeroItem : public CListItem
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> movement;
|
|
|
|
std::shared_ptr<CAnimImage> mana;
|
|
|
|
std::shared_ptr<CAnimImage> portrait;
|
2023-10-17 21:13:08 +02:00
|
|
|
CHeroList *parentList;
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
|
|
|
const CGHeroInstance * const hero;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CHeroItem(CHeroList * parent, const CGHeroInstance * hero);
|
2012-06-13 16:04:06 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> genSelection() override;
|
2012-06-13 16:04:06 +03:00
|
|
|
void update();
|
2015-10-12 15:47:10 +02:00
|
|
|
void select(bool on) override;
|
|
|
|
void open() override;
|
|
|
|
void showTooltip() override;
|
2023-10-17 21:13:08 +02:00
|
|
|
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
|
2015-10-12 15:47:10 +02:00
|
|
|
std::string getHoverText() override;
|
2012-06-13 16:04:06 +03:00
|
|
|
};
|
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
std::shared_ptr<CIntObject> createItem(size_t index);
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
2023-05-06 15:52:43 +02:00
|
|
|
CHeroList(int visibleItemsCount, Rect widgetPosition, Point firstItemOffset, Point itemOffsetDelta, size_t initialItemsCount);
|
2012-06-13 16:04:06 +03:00
|
|
|
|
|
|
|
/// Select specific hero and scroll if needed
|
|
|
|
void select(const CGHeroInstance * hero = nullptr);
|
|
|
|
|
|
|
|
/// Update hero. Will add or remove it from the list if needed
|
2023-07-13 13:35:24 +02:00
|
|
|
void updateElement(const CGHeroInstance * hero);
|
|
|
|
|
|
|
|
/// Update all heroes
|
|
|
|
void updateWidget();
|
2012-06-13 16:04:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// List of towns which is shown at the right of the adventure map screen or in the town screen
|
|
|
|
class CTownList : public CList
|
|
|
|
{
|
|
|
|
class CTownItem : public CListItem
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> picture;
|
2023-10-15 14:31:33 +02:00
|
|
|
CTownList *parentList;
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
2023-10-17 21:17:57 +02:00
|
|
|
int townIndex;
|
2012-06-13 16:04:06 +03:00
|
|
|
|
|
|
|
CTownItem(CTownList *parent, const CGTownInstance * town);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> genSelection() override;
|
2012-06-13 16:04:06 +03:00
|
|
|
void update();
|
2015-10-12 15:47:10 +02:00
|
|
|
void select(bool on) override;
|
|
|
|
void open() override;
|
|
|
|
void showTooltip() override;
|
2023-10-15 14:31:33 +02:00
|
|
|
void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
|
2015-10-12 15:47:10 +02:00
|
|
|
std::string getHoverText() override;
|
2012-06-13 16:04:06 +03:00
|
|
|
};
|
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
std::shared_ptr<CIntObject> createItem(size_t index) override;
|
2012-06-13 16:04:06 +03:00
|
|
|
public:
|
2023-05-06 15:52:43 +02:00
|
|
|
CTownList(int visibleItemsCount, Rect widgetPosition, Point firstItemOffset, Point itemOffsetDelta, size_t initialItemsCount);
|
2012-06-13 16:04:06 +03:00
|
|
|
|
|
|
|
/// Select specific town and scroll if needed
|
|
|
|
void select(const CGTownInstance * town = nullptr);
|
|
|
|
|
|
|
|
/// Update town. Will add or remove it from the list if needed
|
2023-07-13 13:35:24 +02:00
|
|
|
void updateElement(const CGTownInstance * town);
|
|
|
|
|
|
|
|
/// Update all towns
|
|
|
|
void updateWidget();
|
2012-06-13 16:04:06 +03:00
|
|
|
};
|
|
|
|
|