1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
vcmi/client/lobby/OptionsTab.h

192 lines
5.1 KiB
C
Raw Normal View History

/*
* 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 "../windows/CWindowObject.h"
VCMI_LIB_NAMESPACE_BEGIN
struct PlayerSettings;
struct PlayerInfo;
VCMI_LIB_NAMESPACE_END
#include "../widgets/Scrollable.h"
2023-08-12 02:41:48 +02:00
#include "../../lib/mapping/CMapHeader.h"
class CSlider;
class CLabel;
class CMultiLineLabel;
class CFilledTexture;
class CAnimImage;
class CComponentBox;
class CTextBox;
class CButton;
/// The options tab which is shown at the map selection phase.
class OptionsTab : public CIntObject
{
std::shared_ptr<CPicture> background;
std::shared_ptr<CLabel> labelTitle;
std::shared_ptr<CMultiLineLabel> labelSubTitle;
std::shared_ptr<CMultiLineLabel> labelPlayerNameAndHandicap;
std::shared_ptr<CMultiLineLabel> labelStartingTown;
std::shared_ptr<CMultiLineLabel> labelStartingHero;
std::shared_ptr<CMultiLineLabel> labelStartingBonus;
std::shared_ptr<CLabel> labelPlayerTurnDuration;
std::shared_ptr<CLabel> labelTurnDurationValue;
2021-11-08 18:49:04 +02:00
ui8 humanPlayers;
public:
enum SelType
{
TOWN,
HERO,
BONUS
};
struct CPlayerSettingsHelper
{
const PlayerSettings & settings;
const SelType type;
CPlayerSettingsHelper(const PlayerSettings & settings, SelType type)
: settings(settings), type(type)
{}
/// visible image settings
2023-08-12 13:19:58 +02:00
size_t getImageIndex(bool big = false);
std::string 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<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);
};
2023-08-12 02:41:48 +02:00
class SelectionWindow : public CWindowObject
{
2023-08-12 15:05:26 +02:00
const int ELEMENTS_PER_LINE = 4;
2023-08-12 13:19:58 +02:00
2023-08-12 17:46:35 +02:00
PlayerColor color;
2023-08-12 16:49:42 +02:00
2023-08-12 02:41:48 +02:00
std::shared_ptr<CFilledTexture> backgroundTexture;
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-12 02:41:48 +02:00
2023-08-12 17:46:35 +02:00
FactionID initialFraction;
HeroTypeID initialHero;
int initialBonus;
FactionID selectedFraction;
HeroTypeID selectedHero;
int selectedBonus;
std::set<FactionID> allowedFactions;
2023-08-12 21:50:40 +02:00
std::set<HeroTypeID> allowedHeroes;
2023-08-12 19:33:25 +02:00
std::vector<bool> allowedBonus;
2023-08-12 17:46:35 +02:00
2023-08-12 22:59:45 +02:00
int amountLines;
2023-08-12 15:19:40 +02:00
void genContentTitle();
2023-08-12 22:59:45 +02:00
void genContentGrid();
2023-08-12 16:49:42 +02:00
void genContentCastles();
void genContentHeroes();
void genContentBonus();
2023-08-12 02:41:48 +02:00
2023-08-12 22:59:45 +02:00
int calcLines();
2023-08-12 02:41:48 +02:00
void apply();
2023-08-12 20:02:36 +02:00
void recreate();
2023-08-12 18:20:44 +02:00
void setSelection();
2023-08-12 02:41:48 +02:00
FactionID getElementCastle(const Point & cursorPosition);
2023-08-12 15:05:26 +02:00
HeroTypeID getElementHero(const Point & cursorPosition);
2023-08-12 02:41:48 +02:00
int getElementBonus(const Point & cursorPosition);
2023-08-12 15:05:26 +02:00
Point getElement(const Point & cursorPosition, int area);
2023-08-12 02:41:48 +02:00
void clickReleased(const Point & cursorPosition) override;
void showPopupWindow(const Point & cursorPosition) override;
public:
2023-08-12 17:46:35 +02:00
SelectionWindow(PlayerColor _color);
2023-08-12 02:41:48 +02:00
};
/// Image with current town/hero/bonus
struct SelectedBox : public Scrollable, public CPlayerSettingsHelper
{
std::shared_ptr<CAnimImage> image;
std::shared_ptr<CLabel> subtitle;
2023-08-12 16:49:42 +02:00
SelectedBox(Point position, PlayerSettings & settings, SelType type);
void showPopupWindow(const Point & cursorPosition) override;
2023-08-12 02:41:48 +02:00
void clickReleased(const Point & cursorPosition) override;
void scrollBy(int distance) override;
void update();
};
struct PlayerOptionsEntry : public CIntObject
{
std::unique_ptr<PlayerInfo> pi;
std::unique_ptr<PlayerSettings> s;
std::shared_ptr<CLabel> labelPlayerName;
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;
enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
2021-11-08 18:49:04 +02:00
PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);
void hideUnavailableButtons();
2021-11-08 18:49:04 +02:00
private:
const OptionsTab & parentTab;
};
std::shared_ptr<CSlider> sliderTurnDuration;
std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
OptionsTab();
void recreate();
2021-11-08 18:49:04 +02:00
void onSetPlayerClicked(const PlayerSettings & ps) const;
};