1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

CampaignRegions class encapsulation

This commit is contained in:
Ivan Savenko 2023-06-26 01:42:53 +03:00
parent f6b2f58da9
commit e2bd98e21e
6 changed files with 69 additions and 25 deletions

View File

@ -64,7 +64,7 @@ CBonusSelection::CBonusSelection()
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
std::string bgName = getCampaign()->getRegions().campPrefix + "_BG.BMP";
std::string bgName = getCampaign()->getRegions().getBackgroundName();
setBackground(bgName);
panelBackground = std::make_shared<CPicture>("CAMPBRF.BMP", 456, 6);
@ -449,27 +449,19 @@ CBonusSelection::CRegion::CRegion(CampaignScenarioID id, bool accessible, bool s
: CIntObject(LCLICK | SHOW_POPUP), idOfMapAndRegion(id), accessible(accessible), selectable(selectable)
{
OBJ_CONSTRUCTION;
static const std::string colors[2][8] =
{
{"R", "B", "N", "G", "O", "V", "T", "P"},
{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}
};
const CampaignRegions::RegionDescription & desc = campDsc.regions[static_cast<int>(idOfMapAndRegion)];
pos.x += desc.xpos;
pos.y += desc.ypos;
pos += campDsc.getPosition(id);
std::string prefix = campDsc.campPrefix + desc.infix + "_";
std::string suffix = colors[campDsc.colorSuffixLength - 1][CSH->si->campState->scenario(idOfMapAndRegion).regionColor];
graphicsNotSelected = std::make_shared<CPicture>(prefix + "En" + suffix + ".BMP");
auto color = CSH->si->campState->scenario(idOfMapAndRegion).regionColor;
graphicsNotSelected = std::make_shared<CPicture>(campDsc.getAvailableName(id, color));
graphicsNotSelected->disable();
graphicsSelected = std::make_shared<CPicture>(prefix + "Se" + suffix + ".BMP");
graphicsSelected = std::make_shared<CPicture>(campDsc.getSelectedName(id, color));
graphicsSelected->disable();
graphicsStriped = std::make_shared<CPicture>(prefix + "Co" + suffix + ".BMP");
graphicsStriped = std::make_shared<CPicture>(campDsc.getConqueredName(id, color));
graphicsStriped->disable();
pos.w = graphicsNotSelected->pos.w;
pos.h = graphicsNotSelected->pos.h;
}
void CBonusSelection::CRegion::updateState()

View File

@ -16,7 +16,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class CampaignState;
struct CampaignRegions;
class CampaignRegions;
VCMI_LIB_NAMESPACE_END

View File

@ -66,6 +66,47 @@ CampaignRegions CampaignRegions::getLegacy(int campId)
return campDescriptions.at(campId);
}
std::string CampaignRegions::getBackgroundName() const
{
return campPrefix + "_BG.BMP";
}
Point CampaignRegions::getPosition(CampaignScenarioID which) const
{
auto const & region = regions[static_cast<int>(which)];
return Point(region.xpos, region.ypos);
}
std::string CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, std::string type) const
{
auto const & region = regions[static_cast<int>(which)];
static const std::string colors[2][8] =
{
{"R", "B", "N", "G", "O", "V", "T", "P"},
{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}
};
std::string color = colors[colorSuffixLength - 1][colorIndex];
return campPrefix + region.infix + "_" + type + color + ".BMP";
}
std::string CampaignRegions::getAvailableName(CampaignScenarioID which, int color) const
{
return getNameFor(which, color, "En");
}
std::string CampaignRegions::getSelectedName(CampaignScenarioID which, int color) const
{
return getNameFor(which, color, "Se");
}
std::string CampaignRegions::getConqueredName(CampaignScenarioID which, int color) const
{
return getNameFor(which, color, "Co");
}
bool CampaignBonus::isBonusForHero() const
{

View File

@ -23,8 +23,9 @@ class CMap;
class CMapHeader;
class CMapInfo;
class JsonNode;
class Point;
struct DLL_LINKAGE CampaignRegions
class DLL_LINKAGE CampaignRegions
{
std::string campPrefix;
int colorSuffixLength;
@ -46,6 +47,15 @@ struct DLL_LINKAGE CampaignRegions
std::vector<RegionDescription> regions;
std::string getNameFor(CampaignScenarioID which, int color, std::string type) const;
public:
std::string getBackgroundName() const;
Point getPosition(CampaignScenarioID which) const;
std::string getAvailableName(CampaignScenarioID which, int color) const;
std::string getSelectedName(CampaignScenarioID which, int color) const;
std::string getConqueredName(CampaignScenarioID which, int color) const;
template <typename Handler> void serialize(Handler &h, const int formatVersion)
{
h & campPrefix;
@ -101,7 +111,7 @@ public:
struct DLL_LINKAGE CampaignBonus
{
CampaignBonusType type = CampaignBonusType::NONE; //uses EBonusType
CampaignBonusType type = CampaignBonusType::NONE;
//purpose depends on type
int32_t info1 = 0;
@ -119,10 +129,8 @@ struct DLL_LINKAGE CampaignBonus
}
};
class DLL_LINKAGE CampaignTravel
struct DLL_LINKAGE CampaignTravel
{
public:
struct DLL_LINKAGE WhatHeroKeeps
{
bool experience = false;
@ -160,9 +168,8 @@ public:
}
};
class DLL_LINKAGE CampaignScenario
struct DLL_LINKAGE CampaignScenario
{
public:
std::string mapName; //*.h3m
std::string scenarioName; //from header. human-readble
std::set<CampaignScenarioID> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
@ -242,12 +249,16 @@ class DLL_LINKAGE CampaignState : public Campaign
CampaignHeroes crossover;
public:
/// Returns last completed scenario, if any
std::optional<CampaignScenarioID> lastScenario() const;
std::optional<CampaignScenarioID> currentScenario() const;
std::set<CampaignScenarioID> conqueredScenarios() const;
/// Returns bonus selected for specific scenario
std::optional<CampaignBonus> getBonus(CampaignScenarioID which) const;
/// Returns index of selected bonus for specified scenario
std::optional<ui8> getBonusID(CampaignScenarioID which) const;
/// Returns true if selected scenario can be selected and started by player

View File

@ -26,7 +26,7 @@ class CMap;
struct CPack;
class CHeroClass;
struct EventCondition;
class CampaignTravel;
struct CampaignTravel;
class CStackInstance;
class CGameStateCampaign;

View File

@ -14,7 +14,7 @@
VCMI_LIB_NAMESPACE_BEGIN
struct CampaignBonus;
class CampaignTravel;
struct CampaignTravel;
class CGHeroInstance;
class CGameState;
class CMap;