2014-07-05 12:58:42 +03:00
|
|
|
/*
|
|
|
|
* CComponent.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../gui/CIntObject.h"
|
2014-07-05 12:58:42 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-07-14 17:19:44 +03:00
|
|
|
struct Component;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2014-07-15 10:14:49 +03:00
|
|
|
class CAnimImage;
|
2018-04-07 13:34:11 +02:00
|
|
|
class CLabel;
|
2014-07-14 17:19:44 +03:00
|
|
|
|
2014-07-05 12:58:42 +03:00
|
|
|
/// common popup window component
|
|
|
|
class CComponent : public virtual CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Etype
|
|
|
|
{
|
|
|
|
primskill, secskill, resource, creature, artifact, experience, spell, morale, luck, building, hero, flag, typeInvalid
|
|
|
|
};
|
|
|
|
|
|
|
|
//NOTE: not all types have exact these sizes or have less than 4 of them. In such cases closest one will be used
|
|
|
|
enum ESize
|
|
|
|
{
|
|
|
|
tiny, // ~22-24px
|
|
|
|
small, // ~30px
|
|
|
|
medium,// ~42px
|
|
|
|
large, // ~82px
|
|
|
|
sizeInvalid
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CLabel>> lines;
|
|
|
|
|
2014-07-05 12:58:42 +03:00
|
|
|
size_t getIndex();
|
|
|
|
const std::vector<std::string> getFileName();
|
|
|
|
void setSurface(std::string defName, int imgPos);
|
|
|
|
std::string getSubtitleInternal();
|
|
|
|
|
2023-03-10 00:26:44 +02:00
|
|
|
void init(Etype Type, int Subtype, int Val, ESize imageSize, EFonts font = FONT_SMALL);
|
2014-07-05 12:58:42 +03:00
|
|
|
|
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> image;
|
2014-07-05 12:58:42 +03:00
|
|
|
|
|
|
|
Etype compType; //component type
|
|
|
|
ESize size; //component size.
|
2023-03-10 00:26:44 +02:00
|
|
|
EFonts font; //Font size of label
|
2014-07-05 12:58:42 +03:00
|
|
|
int subtype; //type-dependant subtype. See getSomething methods for details
|
|
|
|
int val; // value \ strength \ amount of component. See getSomething methods for details
|
|
|
|
bool perDay; // add "per day" text to subtitle
|
|
|
|
|
|
|
|
std::string getDescription();
|
|
|
|
std::string getSubtitle();
|
|
|
|
|
2023-03-10 00:26:44 +02:00
|
|
|
CComponent(Etype Type, int Subtype, int Val = 0, ESize imageSize=large, EFonts font = FONT_SMALL);
|
|
|
|
CComponent(const Component &c, ESize imageSize=large, EFonts font = FONT_SMALL);
|
2014-07-05 12:58:42 +03:00
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void showPopupWindow(const Point & cursorPosition) override; //call-in
|
2014-07-05 12:58:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// component that can be selected or deselected
|
|
|
|
class CSelectableComponent : public CComponent, public CKeyShortcut
|
|
|
|
{
|
|
|
|
void init();
|
|
|
|
public:
|
|
|
|
bool selected; //if true, this component is selected
|
|
|
|
std::function<void()> onSelect; //function called on selection change
|
|
|
|
|
2023-06-02 15:42:18 +02:00
|
|
|
void showAll(Canvas & to) override;
|
2014-07-05 12:58:42 +03:00
|
|
|
void select(bool on);
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void clickPressed(const Point & cursorPosition) override; //call-in
|
2017-07-17 23:04:00 +02:00
|
|
|
CSelectableComponent(Etype Type, int Sub, int Val, ESize imageSize=large, std::function<void()> OnSelect = nullptr);
|
2018-04-07 13:34:11 +02:00
|
|
|
CSelectableComponent(const Component & c, std::function<void()> OnSelect = nullptr);
|
2014-07-05 12:58:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// box with multiple components (up to 8?)
|
|
|
|
/// will take ownership on components and delete them afterwards
|
|
|
|
class CComponentBox : public CIntObject
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CComponent>> components;
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<CLabel>> orLabels;
|
2014-07-05 12:58:42 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CSelectableComponent> selected;
|
2014-07-05 12:58:42 +03:00
|
|
|
std::function<void(int newID)> onSelect;
|
|
|
|
|
2023-03-06 01:30:21 +02:00
|
|
|
static constexpr int defaultBetweenImagesMin = 20;
|
|
|
|
static constexpr int defaultBetweenSubtitlesMin = 10;
|
|
|
|
static constexpr int defaultBetweenRows = 22;
|
2023-03-10 17:54:37 +02:00
|
|
|
static constexpr int defaultComponentsInRow = 4;
|
2023-03-06 01:30:21 +02:00
|
|
|
|
|
|
|
int betweenImagesMin;
|
|
|
|
int betweenSubtitlesMin;
|
|
|
|
int betweenRows;
|
2023-03-10 17:54:37 +02:00
|
|
|
int componentsInRow;
|
2023-03-06 01:30:21 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void selectionChanged(std::shared_ptr<CSelectableComponent> newSelection);
|
2014-07-05 12:58:42 +03:00
|
|
|
|
|
|
|
//get position of "or" text between these comps
|
|
|
|
//it will place "or" equidistant to both images
|
|
|
|
Point getOrTextPos(CComponent *left, CComponent * right);
|
|
|
|
|
|
|
|
//get distance between these copmonents
|
|
|
|
int getDistance(CComponent *left, CComponent * right);
|
|
|
|
void placeComponents(bool selectable);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// return index of selected item
|
|
|
|
int selectedIndex();
|
|
|
|
|
2023-03-06 01:30:21 +02:00
|
|
|
/// constructors for non-selectable components
|
2018-04-07 13:34:11 +02:00
|
|
|
CComponentBox(std::vector<std::shared_ptr<CComponent>> components, Rect position);
|
2023-03-10 17:54:37 +02:00
|
|
|
CComponentBox(std::vector<std::shared_ptr<CComponent>> components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow);
|
2014-07-05 12:58:42 +03:00
|
|
|
|
|
|
|
/// constructor for selectable components
|
|
|
|
/// will also create "or" labels between components
|
|
|
|
/// onSelect - optional function that will be called every time on selection change
|
2018-04-07 13:34:11 +02:00
|
|
|
CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> components, Rect position, std::function<void(int newID)> onSelect = nullptr);
|
2023-03-10 17:54:37 +02:00
|
|
|
CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> components, Rect position, std::function<void(int newID)> onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow);
|
2014-07-05 12:58:42 +03:00
|
|
|
};
|