2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* OptionsTab.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-11-09 13:45:46 +02:00
|
|
|
#include "OptionsTabBase.h"
|
2023-05-20 17:28:35 +02:00
|
|
|
#include "../windows/CWindowObject.h"
|
2023-08-23 17:29:50 +02:00
|
|
|
#include "../widgets/Scrollable.h"
|
2023-05-20 17:28:35 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
struct PlayerSettings;
|
|
|
|
struct PlayerInfo;
|
2023-09-28 18:43:04 +02:00
|
|
|
enum class PlayerStartingBonus : int8_t;
|
2023-05-20 17:28:35 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
class CLabel;
|
|
|
|
class CMultiLineLabel;
|
|
|
|
class CFilledTexture;
|
|
|
|
class CAnimImage;
|
|
|
|
class CComponentBox;
|
2023-05-20 17:28:35 +02:00
|
|
|
class CTextBox;
|
|
|
|
class CButton;
|
2024-06-29 16:14:16 +02:00
|
|
|
class CSlider;
|
2024-07-16 02:01:55 +02:00
|
|
|
class LRClickableArea;
|
2023-05-20 17:28:35 +02:00
|
|
|
|
2023-08-17 17:29:31 +02:00
|
|
|
class FilledTexturePlayerColored;
|
2024-07-24 22:26:44 +02:00
|
|
|
class TransparentFilledRectangle;
|
2023-08-17 17:29:31 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
/// The options tab which is shown at the map selection phase.
|
2023-11-09 13:45:46 +02:00
|
|
|
class OptionsTab : public OptionsTabBase
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-23 17:29:50 +02:00
|
|
|
struct PlayerOptionsEntry;
|
|
|
|
|
2021-11-08 18:49:04 +02:00
|
|
|
ui8 humanPlayers;
|
2023-08-23 17:29:50 +02:00
|
|
|
std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
public:
|
2023-08-23 17:29:50 +02:00
|
|
|
|
|
|
|
OptionsTab();
|
|
|
|
void recreate();
|
|
|
|
void onSetPlayerClicked(const PlayerSettings & ps) const;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
enum SelType
|
|
|
|
{
|
|
|
|
TOWN,
|
|
|
|
HERO,
|
|
|
|
BONUS
|
|
|
|
};
|
|
|
|
|
2024-07-25 23:32:45 +02:00
|
|
|
class HandicapWindow : public CWindowObject
|
|
|
|
{
|
|
|
|
std::shared_ptr<FilledTexturePlayerColored> backgroundTexture;
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<CLabel>> labels;
|
|
|
|
std::vector<std::shared_ptr<CAnimImage>> anim;
|
|
|
|
std::vector<std::shared_ptr<TransparentFilledRectangle>> textinputbackgrounds;
|
|
|
|
std::map<PlayerColor, std::map<EGameResID, std::shared_ptr<CTextInput>>> textinputs;
|
|
|
|
std::vector<std::shared_ptr<CButton>> buttons;
|
|
|
|
|
2024-11-03 02:13:14 +02:00
|
|
|
void notFocusedClick() override;
|
2024-07-25 23:32:45 +02:00
|
|
|
public:
|
|
|
|
HandicapWindow();
|
|
|
|
};
|
|
|
|
|
2023-08-23 17:29:50 +02:00
|
|
|
private:
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
struct CPlayerSettingsHelper
|
|
|
|
{
|
2023-09-17 00:32:10 +02:00
|
|
|
const PlayerSettings & playerSettings;
|
2023-09-28 18:43:04 +02:00
|
|
|
const SelType selectionType;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-17 00:32:10 +02:00
|
|
|
CPlayerSettingsHelper(const PlayerSettings & playerSettings, SelType type)
|
2023-09-28 18:43:04 +02:00
|
|
|
: playerSettings(playerSettings), selectionType(type)
|
2018-01-05 19:21:07 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
/// visible image settings
|
2023-08-12 13:19:58 +02:00
|
|
|
size_t getImageIndex(bool big = false);
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath getImageName(bool big = false);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
std::string getName(); /// name visible in options dialog
|
|
|
|
std::string getTitle(); /// title in popup box
|
|
|
|
std::string getSubtitle(); /// popup box subtitle
|
|
|
|
std::string getDescription(); /// popup box description, not always present
|
|
|
|
};
|
|
|
|
|
|
|
|
class CPlayerOptionTooltipBox : public CWindowObject, public CPlayerSettingsHelper
|
|
|
|
{
|
|
|
|
std::shared_ptr<CFilledTexture> backgroundTexture;
|
|
|
|
std::shared_ptr<CLabel> labelTitle;
|
|
|
|
std::shared_ptr<CLabel> labelSubTitle;
|
|
|
|
std::shared_ptr<CAnimImage> image;
|
|
|
|
|
|
|
|
std::shared_ptr<CLabel> labelAssociatedCreatures;
|
|
|
|
std::shared_ptr<CComponentBox> boxAssociatedCreatures;
|
|
|
|
|
|
|
|
std::shared_ptr<CLabel> labelHeroSpeciality;
|
|
|
|
std::shared_ptr<CAnimImage> imageSpeciality;
|
|
|
|
std::shared_ptr<CLabel> labelSpecialityName;
|
|
|
|
|
|
|
|
std::shared_ptr<CTextBox> textBonusDescription;
|
|
|
|
|
|
|
|
void genHeader();
|
|
|
|
void genTownWindow();
|
|
|
|
void genHeroWindow();
|
|
|
|
void genBonusWindow();
|
|
|
|
|
|
|
|
public:
|
|
|
|
CPlayerOptionTooltipBox(CPlayerSettingsHelper & helper);
|
|
|
|
};
|
|
|
|
|
2024-01-13 22:51:56 +02:00
|
|
|
class SelectionWindow : public CWindowObject
|
2023-08-12 02:41:48 +02:00
|
|
|
{
|
2023-08-17 20:34:31 +02:00
|
|
|
//const int ICON_SMALL_WIDTH = 48;
|
2023-08-17 17:54:53 +02:00
|
|
|
const int ICON_SMALL_HEIGHT = 32;
|
|
|
|
const int ICON_BIG_WIDTH = 58;
|
|
|
|
const int ICON_BIG_HEIGHT = 64;
|
|
|
|
const int TEXT_POS_X = 29;
|
|
|
|
const int TEXT_POS_Y = 56;
|
|
|
|
|
2024-07-06 22:55:56 +02:00
|
|
|
const int MAX_LINES = 5;
|
|
|
|
const int MAX_ELEM_PER_LINES = 5;
|
2024-06-29 16:14:16 +02:00
|
|
|
|
2023-08-13 22:58:49 +02:00
|
|
|
int elementsPerLine;
|
2023-08-12 13:19:58 +02:00
|
|
|
|
2024-06-29 16:14:16 +02:00
|
|
|
std::shared_ptr<CSlider> slider;
|
|
|
|
|
2023-08-12 17:46:35 +02:00
|
|
|
PlayerColor color;
|
2023-08-13 19:23:27 +02:00
|
|
|
SelType type;
|
2023-08-12 16:49:42 +02:00
|
|
|
|
2023-08-14 22:22:43 +02:00
|
|
|
std::shared_ptr<FilledTexturePlayerColored> backgroundTexture;
|
2023-08-12 02:41:48 +02:00
|
|
|
std::vector<std::shared_ptr<CIntObject>> components;
|
|
|
|
|
|
|
|
std::vector<FactionID> factions;
|
2023-08-12 13:19:58 +02:00
|
|
|
std::vector<HeroTypeID> heroes;
|
2023-08-29 21:08:18 +02:00
|
|
|
std::set<HeroTypeID> unusableHeroes;
|
|
|
|
|
2023-08-14 00:40:12 +02:00
|
|
|
FactionID initialFaction;
|
2023-08-12 17:46:35 +02:00
|
|
|
HeroTypeID initialHero;
|
2023-09-28 18:43:04 +02:00
|
|
|
PlayerStartingBonus initialBonus;
|
2023-08-14 00:40:12 +02:00
|
|
|
FactionID selectedFaction;
|
2023-08-12 17:46:35 +02:00
|
|
|
HeroTypeID selectedHero;
|
2023-09-28 18:43:04 +02:00
|
|
|
PlayerStartingBonus selectedBonus;
|
2023-08-12 17:46:35 +02:00
|
|
|
|
|
|
|
std::set<FactionID> allowedFactions;
|
2023-08-12 21:50:40 +02:00
|
|
|
std::set<HeroTypeID> allowedHeroes;
|
2023-09-28 18:43:04 +02:00
|
|
|
std::vector<PlayerStartingBonus> allowedBonus;
|
2023-08-12 17:46:35 +02:00
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
void genContentGrid(int lines);
|
2023-08-14 00:40:12 +02:00
|
|
|
void genContentFactions();
|
2023-08-12 16:49:42 +02:00
|
|
|
void genContentHeroes();
|
|
|
|
void genContentBonus();
|
2023-08-12 02:41:48 +02:00
|
|
|
|
2023-08-13 22:58:49 +02:00
|
|
|
void drawOutlinedText(int x, int y, ColorRGBA color, std::string text);
|
2024-07-06 23:22:40 +02:00
|
|
|
std::tuple<int, int> calcLines(FactionID faction);
|
2023-08-12 02:41:48 +02:00
|
|
|
void apply();
|
2024-07-06 22:55:56 +02:00
|
|
|
void recreate(int sliderPos = 0);
|
2023-08-12 18:20:44 +02:00
|
|
|
void setSelection();
|
2023-08-13 19:23:27 +02:00
|
|
|
int getElement(const Point & cursorPosition);
|
2023-08-17 20:34:31 +02:00
|
|
|
void setElement(int element, bool doApply);
|
2023-08-12 02:41:48 +02:00
|
|
|
|
2024-06-29 16:14:16 +02:00
|
|
|
void sliderMove(int slidPos);
|
|
|
|
|
2024-11-03 02:13:14 +02:00
|
|
|
void notFocusedClick() override;
|
2023-08-12 02:41:48 +02:00
|
|
|
void clickReleased(const Point & cursorPosition) override;
|
|
|
|
void showPopupWindow(const Point & cursorPosition) override;
|
|
|
|
|
|
|
|
public:
|
2023-08-29 02:04:32 +02:00
|
|
|
void reopen();
|
|
|
|
|
2024-07-06 22:55:56 +02:00
|
|
|
SelectionWindow(const PlayerColor & color, SelType _type, int sliderPos = 0);
|
2023-08-12 02:41:48 +02:00
|
|
|
};
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
/// Image with current town/hero/bonus
|
2023-05-30 17:53:51 +02:00
|
|
|
struct SelectedBox : public Scrollable, public CPlayerSettingsHelper
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<CAnimImage> image;
|
|
|
|
std::shared_ptr<CLabel> subtitle;
|
|
|
|
|
2023-09-17 00:32:10 +02:00
|
|
|
SelectedBox(Point position, PlayerSettings & playerSettings, SelType type);
|
2023-07-08 13:33:04 +02:00
|
|
|
void showPopupWindow(const Point & cursorPosition) override;
|
2023-08-12 02:41:48 +02:00
|
|
|
void clickReleased(const Point & cursorPosition) override;
|
2023-05-30 17:53:51 +02:00
|
|
|
void scrollBy(int distance) override;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
void update();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PlayerOptionsEntry : public CIntObject
|
|
|
|
{
|
2023-10-14 13:34:39 +02:00
|
|
|
std::string name;
|
2023-05-20 17:28:35 +02:00
|
|
|
std::unique_ptr<PlayerInfo> pi;
|
|
|
|
std::unique_ptr<PlayerSettings> s;
|
2018-01-05 19:21:07 +02:00
|
|
|
std::shared_ptr<CLabel> labelPlayerName;
|
2023-10-13 23:04:35 +02:00
|
|
|
std::shared_ptr<CTextInput> labelPlayerNameEdit;
|
2018-01-05 19:21:07 +02:00
|
|
|
std::shared_ptr<CMultiLineLabel> labelWhoCanPlay;
|
|
|
|
std::shared_ptr<CPicture> background;
|
|
|
|
std::shared_ptr<CButton> buttonTownLeft;
|
|
|
|
std::shared_ptr<CButton> buttonTownRight;
|
|
|
|
std::shared_ptr<CButton> buttonHeroLeft;
|
|
|
|
std::shared_ptr<CButton> buttonHeroRight;
|
|
|
|
std::shared_ptr<CButton> buttonBonusLeft;
|
|
|
|
std::shared_ptr<CButton> buttonBonusRight;
|
|
|
|
std::shared_ptr<CButton> flag;
|
|
|
|
std::shared_ptr<SelectedBox> town;
|
|
|
|
std::shared_ptr<SelectedBox> hero;
|
|
|
|
std::shared_ptr<SelectedBox> bonus;
|
2024-07-16 02:01:55 +02:00
|
|
|
std::shared_ptr<LRClickableArea> handicap;
|
|
|
|
std::shared_ptr<CMultiLineLabel> labelHandicap;
|
2018-01-05 19:21:07 +02:00
|
|
|
enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
|
|
|
|
|
2021-11-08 18:49:04 +02:00
|
|
|
PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);
|
2018-01-05 19:21:07 +02:00
|
|
|
void hideUnavailableButtons();
|
2023-10-13 23:04:35 +02:00
|
|
|
bool captureThisKey(EShortcut key) override;
|
|
|
|
void keyPressed(EShortcut key) override;
|
2023-10-14 12:08:38 +02:00
|
|
|
void clickReleased(const Point & cursorPosition) override;
|
|
|
|
bool receiveEvent(const Point & position, int eventType) const override;
|
2021-11-08 18:49:04 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const OptionsTab & parentTab;
|
2023-10-14 12:08:38 +02:00
|
|
|
|
2023-10-16 21:24:59 +02:00
|
|
|
void updateName();
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
};
|