Browse Source

townselector

Laserlicht 1 year ago
parent
commit
7c96ffa8ff
2 changed files with 53 additions and 3 deletions
  1. 37 3
      client/lobby/CSelectionBase.cpp
  2. 16 0
      client/lobby/CSelectionBase.h

+ 37 - 3
client/lobby/CSelectionBase.cpp

@@ -44,6 +44,7 @@
 
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CHeroHandler.h"
+#include "../../lib/CTownHandler.h"
 #include "../../lib/CRandomGenerator.h"
 #include "../../lib/CThreadHelper.h"
 #include "../../lib/MetaString.h"
@@ -402,21 +403,23 @@ PvPBox::PvPBox(const Rect & rect)
 	backgroundTexture->playerColored(PlayerColor(1));
 	backgroundBorder = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, rect.w, rect.h), ColorRGBA(0, 0, 0, 64), ColorRGBA(96, 96, 96, 255), 1);
 
-	buttonFlipCoin = std::make_shared<CButton>(Point(17, 10), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("flip coin"), [](){
+	factionselector = std::make_shared<FactionSelector>(Point(5, 3));
+
+	buttonFlipCoin = std::make_shared<CButton>(Point(203, 6), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("flip coin"), [](){
 		LobbyPvPAction lpa;
 		lpa.action = LobbyPvPAction::COIN;
 		CSH->sendLobbyPack(lpa);
 	}, EShortcut::NONE);
 	buttonFlipCoin->setTextOverlay("Flip coin2", EFonts::FONT_SMALL, Colors::WHITE);
 
-	buttonRandomTown = std::make_shared<CButton>(Point(17, 30), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("random town"), [](){
+	buttonRandomTown = std::make_shared<CButton>(Point(203, 31), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("random town"), [](){
 		LobbyPvPAction lpa;
 		lpa.action = LobbyPvPAction::RANDOM_TOWN;
 		CSH->sendLobbyPack(lpa);
 	}, EShortcut::NONE);
 	buttonRandomTown->setTextOverlay("random town", EFonts::FONT_SMALL, Colors::WHITE);
 
-	buttonRandomTownVs = std::make_shared<CButton>(Point(17, 50), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("random town vs"), [](){
+	buttonRandomTownVs = std::make_shared<CButton>(Point(203, 56), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("random town vs"), [](){
 		LobbyPvPAction lpa;
 		lpa.action = LobbyPvPAction::RANDOM_TOWN_VS;
 		CSH->sendLobbyPack(lpa);
@@ -424,6 +427,37 @@ PvPBox::PvPBox(const Rect & rect)
 	buttonRandomTownVs->setTextOverlay("random town vs", EFonts::FONT_SMALL, Colors::WHITE);
 }
 
+FactionSelector::FactionSelector(const Point & loc)
+{
+	OBJ_CONSTRUCTION;
+	pos += loc;
+	setRedrawParent(true);
+
+	int x = 0, y = 0;
+	CGI->factions()->forEach([this, &x, &y](const Faction *entity, bool &stop){
+		if(!entity->hasTown())
+			return;
+
+		FactionID factionID = entity->getFaction();
+		auto getImageIndex = [](FactionID factionID, bool enabled){ return (*CGI->townh)[factionID]->town->clientInfo.icons[true][!enabled] + 2; }; 
+		towns[factionID] = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPA"), getImageIndex(factionID, true), 0, 48 * x, 32 * y);
+		townsArea[factionID] = std::make_shared<LRClickableArea>(Rect(48 * x, 32 * y, 48, 32), [this, getImageIndex, factionID](){
+			townsEnabled[factionID] = !townsEnabled[factionID];
+			towns[factionID]->setFrame(getImageIndex(factionID, townsEnabled[factionID]));
+			redraw();
+		});
+		townsEnabled[factionID] = true;
+
+		if (x < 2)
+			x++;
+		else
+		{
+			x = 0;
+			y++;
+		}
+	});
+}
+
 CFlagBox::CFlagBox(const Rect & rect)
 	: CIntObject(SHOW_POPUP)
 {

+ 16 - 0
client/lobby/CSelectionBase.h

@@ -32,11 +32,14 @@ class SelectionTab;
 class InfoCard;
 class CChatBox;
 class PvPBox;
+class FactionSelector;
 class CLabel;
+class CSlider;
 class CFlagBox;
 class CLabelGroup;
 class TransparentFilledRectangle;
 class FilledTexturePlayerColored;
+class LRClickableArea;
 
 class ISelectionScreenInfo
 {
@@ -145,6 +148,8 @@ class PvPBox : public CIntObject
 	std::shared_ptr<FilledTexturePlayerColored> backgroundTexture;
 	std::shared_ptr<TransparentFilledRectangle> backgroundBorder;
 	
+	std::shared_ptr<FactionSelector> factionselector;
+
 	std::shared_ptr<CButton> buttonFlipCoin;
 	std::shared_ptr<CButton> buttonRandomTown;
 	std::shared_ptr<CButton> buttonRandomTownVs;
@@ -152,6 +157,17 @@ public:
 	PvPBox(const Rect & rect);
 };
 
+class FactionSelector : public CIntObject
+{
+	std::map<FactionID, std::shared_ptr<CAnimImage>> towns;
+	std::map<FactionID, std::shared_ptr<LRClickableArea>> townsArea;
+	std::map<FactionID, bool> townsEnabled;
+	std::shared_ptr<CSlider> slider;
+
+public:
+	FactionSelector(const Point & loc);
+};
+
 class CFlagBox : public CIntObject
 {
 	std::shared_ptr<CAnimation> iconsTeamFlags;