浏览代码

Changing other enums to enum classes and adding comments with reasons for why some enums stay as enum-in-namespace.

Warzyw647 2 年之前
父节点
当前提交
5363fd5db3
共有 5 个文件被更改,包括 34 次插入40 次删除
  1. 3 3
      lib/rmg/CMapGenOptions.cpp
  2. 9 12
      lib/rmg/CMapGenOptions.h
  3. 1 1
      lib/rmg/CMapGenerator.cpp
  4. 8 8
      lib/rmg/CRmgTemplate.cpp
  5. 13 16
      lib/rmg/CRmgTemplate.h

+ 3 - 3
lib/rmg/CMapGenOptions.cpp

@@ -191,7 +191,7 @@ void CMapGenOptions::setStartingTownForPlayer(const PlayerColor & color, si32 to
 	it->second.setStartingTown(town);
 }
 
-void CMapGenOptions::setPlayerTypeForStandardPlayer(const PlayerColor & color, EPlayerType::EPlayerType playerType)
+void CMapGenOptions::setPlayerTypeForStandardPlayer(const PlayerColor & color, EPlayerType playerType)
 {
 	assert(playerType != EPlayerType::COMP_ONLY);
 	auto it = players.find(color);
@@ -526,12 +526,12 @@ void CMapGenOptions::CPlayerSettings::setStartingTown(si32 value)
 	startingTown = value;
 }
 
-EPlayerType::EPlayerType CMapGenOptions::CPlayerSettings::getPlayerType() const
+EPlayerType CMapGenOptions::CPlayerSettings::getPlayerType() const
 {
 	return playerType;
 }
 
-void CMapGenOptions::CPlayerSettings::setPlayerType(EPlayerType::EPlayerType value)
+void CMapGenOptions::CPlayerSettings::setPlayerType(EPlayerType value)
 {
 	playerType = value;
 }

+ 9 - 12
lib/rmg/CMapGenOptions.h

@@ -17,15 +17,12 @@ VCMI_LIB_NAMESPACE_BEGIN
 
 class CRandomGenerator;
 
-namespace EPlayerType
+enum class EPlayerType
 {
-	enum EPlayerType
-	{
-		HUMAN,
-		AI,
-		COMP_ONLY
-	};
-}
+	HUMAN,
+	AI,
+	COMP_ONLY
+};
 
 /// The map gen options class holds values about general map generation settings
 /// e.g. the size of the map, the count of players,...
@@ -49,8 +46,8 @@ public:
 		void setStartingTown(si32 value);
 
 		/// The default value is EPlayerType::AI.
-		EPlayerType::EPlayerType getPlayerType() const;
-		void setPlayerType(EPlayerType::EPlayerType value);
+		EPlayerType getPlayerType() const;
+		void setPlayerType(EPlayerType value);
 		
 		/// Team id for this player. TeamID::NO_TEAM by default - team will be randomly assigned
 		TeamID getTeam() const;
@@ -62,7 +59,7 @@ public:
 	private:
 		PlayerColor color;
 		si32 startingTown;
-		EPlayerType::EPlayerType playerType;
+		EPlayerType playerType;
 		TeamID team;
 
 	public:
@@ -122,7 +119,7 @@ public:
 	void setStartingTownForPlayer(const PlayerColor & color, si32 town);
 	/// Sets a player type for a standard player. A standard player is the opposite of a computer only player. The
 	/// values which can be chosen for the player type are EPlayerType::AI or EPlayerType::HUMAN.
-	void setPlayerTypeForStandardPlayer(const PlayerColor & color, EPlayerType::EPlayerType playerType);
+	void setPlayerTypeForStandardPlayer(const PlayerColor & color, EPlayerType playerType);
 
 	void setPlayerTeam(const PlayerColor & color, const TeamID & team = TeamID::NO_TEAM);
 

+ 1 - 1
lib/rmg/CMapGenerator.cpp

@@ -185,7 +185,7 @@ void CMapGenerator::addPlayerInfo()
 {
 	// Calculate which team numbers exist
 
-	enum ETeams {CPHUMAN = 0, CPUONLY = 1, AFTER_LAST = 2};
+	enum ETeams {CPHUMAN = 0, CPUONLY = 1, AFTER_LAST = 2}; // Used as a kind of a local named array index, so left as enum, not enum class
 	std::array<std::list<int>, 2> teamNumbers;
 	std::set<int> teamsTotal;
 

+ 8 - 8
lib/rmg/CRmgTemplate.cpp

@@ -162,12 +162,12 @@ void ZoneOptions::setId(TRmgTemplateZoneId value)
 	id = value;
 }
 
-ETemplateZoneType::ETemplateZoneType ZoneOptions::getType() const
+ETemplateZoneType ZoneOptions::getType() const
 {
 	return type;
 }
 	
-void ZoneOptions::setType(ETemplateZoneType::ETemplateZoneType value)
+void ZoneOptions::setType(ETemplateZoneType value)
 {
 	type = value;
 }
@@ -466,7 +466,7 @@ bool CRmgTemplate::matchesSize(const int3 & value) const
 
 bool CRmgTemplate::isWaterContentAllowed(EWaterContent::EWaterContent waterContent) const
 {
-	return waterContent == EWaterContent::EWaterContent::RANDOM || allowedWaterContent.count(waterContent);
+	return waterContent == EWaterContent::RANDOM || allowedWaterContent.count(waterContent);
 }
 
 const std::set<EWaterContent::EWaterContent> & CRmgTemplate::getWaterContentAllowed() const
@@ -754,13 +754,13 @@ void CRmgTemplate::afterLoad()
 		zone2->addConnection(id1);
 	}
 	
-	if(allowedWaterContent.empty() || allowedWaterContent.count(EWaterContent::EWaterContent::RANDOM))
+	if(allowedWaterContent.empty() || allowedWaterContent.count(EWaterContent::RANDOM))
 	{
-		allowedWaterContent.insert(EWaterContent::EWaterContent::NONE);
-		allowedWaterContent.insert(EWaterContent::EWaterContent::NORMAL);
-		allowedWaterContent.insert(EWaterContent::EWaterContent::ISLANDS);
+		allowedWaterContent.insert(EWaterContent::NONE);
+		allowedWaterContent.insert(EWaterContent::NORMAL);
+		allowedWaterContent.insert(EWaterContent::ISLANDS);
 	}
-	allowedWaterContent.erase(EWaterContent::EWaterContent::RANDOM);
+	allowedWaterContent.erase(EWaterContent::RANDOM);
 }
 
 void CRmgTemplate::serializeSize(JsonSerializeFormat & handler, int3 & value, const std::string & fieldName)

+ 13 - 16
lib/rmg/CRmgTemplate.h

@@ -18,21 +18,18 @@ VCMI_LIB_NAMESPACE_BEGIN
 
 class JsonSerializeFormat;
 
-namespace ETemplateZoneType
+enum class ETemplateZoneType
 {
-	enum ETemplateZoneType
-	{
-		PLAYER_START,
-		CPU_START,
-		TREASURE,
-		JUNCTION,
-		WATER
-	};
-}
+	PLAYER_START,
+	CPU_START,
+	TREASURE,
+	JUNCTION,
+	WATER
+};
 
-namespace EWaterContent
-{
-	enum EWaterContent
+namespace EWaterContent // Not enum class, because it's used in method RandomMapTab::setMapGenOptions
+{ // defined in client\lobby\RandomMapTab.cpp and probably in other similar places
+	enum EWaterContent // as an argument of CToggleGroup::setSelected(int id) from \client\widgets\Buttons.cpp 
 	{
 		RANDOM = -1,
 		NONE,
@@ -126,8 +123,8 @@ public:
 	TRmgTemplateZoneId getId() const;
 	void setId(TRmgTemplateZoneId value);
 
-	ETemplateZoneType::ETemplateZoneType getType() const;
-	void setType(ETemplateZoneType::ETemplateZoneType value);
+	ETemplateZoneType getType() const;
+	void setType(ETemplateZoneType value);
 	
 	int getSize() const;
 	void setSize(int value);
@@ -170,7 +167,7 @@ public:
 
 protected:
 	TRmgTemplateZoneId id;
-	ETemplateZoneType::ETemplateZoneType type;
+	ETemplateZoneType type;
 	int size;
 	ui32 maxTreasureValue;
 	std::optional<int> owner;