mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
CampaignRegions class encapsulation
This commit is contained in:
@@ -64,7 +64,7 @@ CBonusSelection::CBonusSelection()
|
|||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
|
|
||||||
std::string bgName = getCampaign()->getRegions().campPrefix + "_BG.BMP";
|
std::string bgName = getCampaign()->getRegions().getBackgroundName();
|
||||||
setBackground(bgName);
|
setBackground(bgName);
|
||||||
|
|
||||||
panelBackground = std::make_shared<CPicture>("CAMPBRF.BMP", 456, 6);
|
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)
|
: CIntObject(LCLICK | SHOW_POPUP), idOfMapAndRegion(id), accessible(accessible), selectable(selectable)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION;
|
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 += campDsc.getPosition(id);
|
||||||
pos.x += desc.xpos;
|
|
||||||
pos.y += desc.ypos;
|
|
||||||
|
|
||||||
std::string prefix = campDsc.campPrefix + desc.infix + "_";
|
auto color = CSH->si->campState->scenario(idOfMapAndRegion).regionColor;
|
||||||
std::string suffix = colors[campDsc.colorSuffixLength - 1][CSH->si->campState->scenario(idOfMapAndRegion).regionColor];
|
|
||||||
graphicsNotSelected = std::make_shared<CPicture>(prefix + "En" + suffix + ".BMP");
|
graphicsNotSelected = std::make_shared<CPicture>(campDsc.getAvailableName(id, color));
|
||||||
graphicsNotSelected->disable();
|
graphicsNotSelected->disable();
|
||||||
graphicsSelected = std::make_shared<CPicture>(prefix + "Se" + suffix + ".BMP");
|
graphicsSelected = std::make_shared<CPicture>(campDsc.getSelectedName(id, color));
|
||||||
graphicsSelected->disable();
|
graphicsSelected->disable();
|
||||||
graphicsStriped = std::make_shared<CPicture>(prefix + "Co" + suffix + ".BMP");
|
graphicsStriped = std::make_shared<CPicture>(campDsc.getConqueredName(id, color));
|
||||||
graphicsStriped->disable();
|
graphicsStriped->disable();
|
||||||
pos.w = graphicsNotSelected->pos.w;
|
pos.w = graphicsNotSelected->pos.w;
|
||||||
pos.h = graphicsNotSelected->pos.h;
|
pos.h = graphicsNotSelected->pos.h;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBonusSelection::CRegion::updateState()
|
void CBonusSelection::CRegion::updateState()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class CampaignState;
|
class CampaignState;
|
||||||
struct CampaignRegions;
|
class CampaignRegions;
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,47 @@ CampaignRegions CampaignRegions::getLegacy(int campId)
|
|||||||
return campDescriptions.at(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
|
bool CampaignBonus::isBonusForHero() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ class CMap;
|
|||||||
class CMapHeader;
|
class CMapHeader;
|
||||||
class CMapInfo;
|
class CMapInfo;
|
||||||
class JsonNode;
|
class JsonNode;
|
||||||
|
class Point;
|
||||||
|
|
||||||
struct DLL_LINKAGE CampaignRegions
|
class DLL_LINKAGE CampaignRegions
|
||||||
{
|
{
|
||||||
std::string campPrefix;
|
std::string campPrefix;
|
||||||
int colorSuffixLength;
|
int colorSuffixLength;
|
||||||
@@ -46,6 +47,15 @@ struct DLL_LINKAGE CampaignRegions
|
|||||||
|
|
||||||
std::vector<RegionDescription> regions;
|
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)
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
||||||
{
|
{
|
||||||
h & campPrefix;
|
h & campPrefix;
|
||||||
@@ -101,7 +111,7 @@ public:
|
|||||||
|
|
||||||
struct DLL_LINKAGE CampaignBonus
|
struct DLL_LINKAGE CampaignBonus
|
||||||
{
|
{
|
||||||
CampaignBonusType type = CampaignBonusType::NONE; //uses EBonusType
|
CampaignBonusType type = CampaignBonusType::NONE;
|
||||||
|
|
||||||
//purpose depends on type
|
//purpose depends on type
|
||||||
int32_t info1 = 0;
|
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
|
struct DLL_LINKAGE WhatHeroKeeps
|
||||||
{
|
{
|
||||||
bool experience = false;
|
bool experience = false;
|
||||||
@@ -160,9 +168,8 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLL_LINKAGE CampaignScenario
|
struct DLL_LINKAGE CampaignScenario
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
std::string mapName; //*.h3m
|
std::string mapName; //*.h3m
|
||||||
std::string scenarioName; //from header. human-readble
|
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)
|
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;
|
CampaignHeroes crossover;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// Returns last completed scenario, if any
|
||||||
std::optional<CampaignScenarioID> lastScenario() const;
|
std::optional<CampaignScenarioID> lastScenario() const;
|
||||||
|
|
||||||
std::optional<CampaignScenarioID> currentScenario() const;
|
std::optional<CampaignScenarioID> currentScenario() const;
|
||||||
std::set<CampaignScenarioID> conqueredScenarios() const;
|
std::set<CampaignScenarioID> conqueredScenarios() const;
|
||||||
|
|
||||||
|
/// Returns bonus selected for specific scenario
|
||||||
std::optional<CampaignBonus> getBonus(CampaignScenarioID which) const;
|
std::optional<CampaignBonus> getBonus(CampaignScenarioID which) const;
|
||||||
|
|
||||||
|
/// Returns index of selected bonus for specified scenario
|
||||||
std::optional<ui8> getBonusID(CampaignScenarioID which) const;
|
std::optional<ui8> getBonusID(CampaignScenarioID which) const;
|
||||||
|
|
||||||
/// Returns true if selected scenario can be selected and started by player
|
/// Returns true if selected scenario can be selected and started by player
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class CMap;
|
|||||||
struct CPack;
|
struct CPack;
|
||||||
class CHeroClass;
|
class CHeroClass;
|
||||||
struct EventCondition;
|
struct EventCondition;
|
||||||
class CampaignTravel;
|
struct CampaignTravel;
|
||||||
class CStackInstance;
|
class CStackInstance;
|
||||||
class CGameStateCampaign;
|
class CGameStateCampaign;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
struct CampaignBonus;
|
struct CampaignBonus;
|
||||||
class CampaignTravel;
|
struct CampaignTravel;
|
||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
class CGameState;
|
class CGameState;
|
||||||
class CMap;
|
class CMap;
|
||||||
|
|||||||
Reference in New Issue
Block a user