/* * 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 #include "OptionsTabBase.h" #include "../windows/CWindowObject.h" #include "../widgets/Scrollable.h" VCMI_LIB_NAMESPACE_BEGIN struct PlayerSettings; struct PlayerInfo; enum class PlayerStartingBonus : int8_t; VCMI_LIB_NAMESPACE_END class CLabel; class CMultiLineLabel; class CFilledTexture; class CAnimImage; class CComponentBox; class CTextBox; class CButton; class CSlider; class LRClickableArea; class FilledTexturePlayerColored; class TransparentFilledRectangle; /// The options tab which is shown at the map selection phase. class OptionsTab : public OptionsTabBase { struct PlayerOptionsEntry; ui8 humanPlayers; std::map> entries; public: OptionsTab(); void recreate(); void onSetPlayerClicked(const PlayerSettings & ps) const; enum SelType { TOWN, HERO, BONUS }; class HandicapWindow : public CWindowObject { std::shared_ptr backgroundTexture; std::vector> labels; std::vector> anim; std::vector> textinputbackgrounds; std::map>> textinputs; std::vector> buttons; bool receiveEvent(const Point & position, int eventType) const override; void clickReleased(const Point & cursorPosition) override; public: HandicapWindow(); }; private: struct CPlayerSettingsHelper { const PlayerSettings & playerSettings; const SelType selectionType; CPlayerSettingsHelper(const PlayerSettings & playerSettings, SelType type) : playerSettings(playerSettings), selectionType(type) {} /// visible image settings size_t getImageIndex(bool big = false); AnimationPath getImageName(bool big = false); 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 backgroundTexture; std::shared_ptr labelTitle; std::shared_ptr labelSubTitle; std::shared_ptr image; std::shared_ptr labelAssociatedCreatures; std::shared_ptr boxAssociatedCreatures; std::shared_ptr labelHeroSpeciality; std::shared_ptr imageSpeciality; std::shared_ptr labelSpecialityName; std::shared_ptr textBonusDescription; void genHeader(); void genTownWindow(); void genHeroWindow(); void genBonusWindow(); public: CPlayerOptionTooltipBox(CPlayerSettingsHelper & helper); }; class SelectionWindow : public CWindowObject { //const int ICON_SMALL_WIDTH = 48; 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; const int MAX_LINES = 5; const int MAX_ELEM_PER_LINES = 5; int elementsPerLine; std::shared_ptr slider; PlayerColor color; SelType type; std::shared_ptr backgroundTexture; std::vector> components; std::vector factions; std::vector heroes; std::set unusableHeroes; FactionID initialFaction; HeroTypeID initialHero; PlayerStartingBonus initialBonus; FactionID selectedFaction; HeroTypeID selectedHero; PlayerStartingBonus selectedBonus; std::set allowedFactions; std::set allowedHeroes; std::vector allowedBonus; void genContentGrid(int lines); void genContentFactions(); void genContentHeroes(); void genContentBonus(); void drawOutlinedText(int x, int y, ColorRGBA color, std::string text); std::tuple calcLines(FactionID faction); void apply(); void recreate(int sliderPos = 0); void setSelection(); int getElement(const Point & cursorPosition); void setElement(int element, bool doApply); void sliderMove(int slidPos); bool receiveEvent(const Point & position, int eventType) const override; void clickReleased(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; public: void reopen(); SelectionWindow(const PlayerColor & color, SelType _type, int sliderPos = 0); }; /// Image with current town/hero/bonus struct SelectedBox : public Scrollable, public CPlayerSettingsHelper { std::shared_ptr image; std::shared_ptr subtitle; SelectedBox(Point position, PlayerSettings & playerSettings, SelType type); void showPopupWindow(const Point & cursorPosition) override; void clickReleased(const Point & cursorPosition) override; void scrollBy(int distance) override; void update(); }; struct PlayerOptionsEntry : public CIntObject { std::string name; std::unique_ptr pi; std::unique_ptr s; std::shared_ptr labelPlayerName; std::shared_ptr labelPlayerNameEdit; std::shared_ptr labelWhoCanPlay; std::shared_ptr background; std::shared_ptr buttonTownLeft; std::shared_ptr buttonTownRight; std::shared_ptr buttonHeroLeft; std::shared_ptr buttonHeroRight; std::shared_ptr buttonBonusLeft; std::shared_ptr buttonBonusRight; std::shared_ptr flag; std::shared_ptr town; std::shared_ptr hero; std::shared_ptr bonus; std::shared_ptr handicap; std::shared_ptr labelHandicap; enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay; PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab); void hideUnavailableButtons(); bool captureThisKey(EShortcut key) override; void keyPressed(EShortcut key) override; void clickReleased(const Point & cursorPosition) override; bool receiveEvent(const Point & position, int eventType) const override; private: const OptionsTab & parentTab; void updateName(); }; };