فهرست منبع

reuse begin button

Laserlicht 4 هفته پیش
والد
کامیت
a5cbf878bd
4فایلهای تغییر یافته به همراه21 افزوده شده و 12 حذف شده
  1. 4 5
      client/lobby/BattleOnlyModeTab.cpp
  2. 2 3
      client/lobby/BattleOnlyModeTab.h
  3. 14 4
      client/lobby/CLobbyScreen.cpp
  4. 1 0
      client/lobby/CLobbyScreen.h

+ 4 - 5
client/lobby/BattleOnlyModeTab.cpp

@@ -10,6 +10,7 @@
 
 #include "StdInc.h"
 #include "BattleOnlyModeTab.h"
+#include "CLobbyScreen.h"
 
 #include "../CServerHandler.h"
 #include "../GameEngine.h"
@@ -65,8 +66,6 @@ BattleOnlyModeTab::BattleOnlyModeTab()
 	init();
 
 	backgroundImage = std::make_shared<CPicture>(ImagePath::builtin("AdventureOptionsBackgroundClear"), 0, 6);
-	buttonOk = std::make_shared<CButton>(Point(148, 430), AnimationPath::builtin("CBBEGIB"), CButton::tooltip(), [this](){ startBattle(); }, EShortcut::GLOBAL_ACCEPT);
-	buttonOk->block(true);
 	title = std::make_shared<CLabel>(220, 35, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyMode"));
 	subTitle = std::make_shared<CMultiLineLabel>(Rect(55, 40, 333, 40), FONT_SMALL, ETextAlignment::BOTTOMCENTER, Colors::WHITE, LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeSubTitle"));
 
@@ -167,7 +166,7 @@ void BattleOnlyModeTab::onChange()
 void BattleOnlyModeTab::update()
 {
 	setTerrainButtonText();
-	setOkButtonEnabled();
+	setStartButtonEnabled();
 	
 	heroSelector1->setHeroIcon();
 	heroSelector1->setCreatureIcons();
@@ -187,13 +186,13 @@ void BattleOnlyModeTab::setTerrainButtonText()
 	battlefieldSelector->setTextOverlay(LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattlefield") + ":   " + (startInfo->selectedTerrain ? (*startInfo->selectedTerrain).toEntity(LIBRARY)->getNameTranslated() : (*startInfo->selectedTown).toEntity(LIBRARY)->getNameTranslated()), EFonts::FONT_SMALL, disabledColor);
 }
 
-void BattleOnlyModeTab::setOkButtonEnabled()
+void BattleOnlyModeTab::setStartButtonEnabled()
 {
 	bool army2Empty = std::all_of(startInfo->selectedArmy[1].begin(), startInfo->selectedArmy[1].end(), [](const auto x) { return x.getId() == CreatureID::NONE; });
 
 	bool canStart = (startInfo->selectedTerrain || startInfo->selectedTown);
 	canStart &= (startInfo->selectedHero[0] && ((startInfo->selectedHero[1]) || (startInfo->selectedTown && !army2Empty)));
-	buttonOk->block(!canStart || GAME->server().isGuest());
+	(static_cast<CLobbyScreen *>(parent))->buttonStart->block(!canStart || GAME->server().isGuest());
 }
 
 std::shared_ptr<IImage> drawBlackBox(Point size, std::string text, ColorRGBA color)

+ 2 - 3
client/lobby/BattleOnlyModeTab.h

@@ -65,7 +65,6 @@ private:
 	std::shared_ptr<EditorCallback> cb;
 
 	std::shared_ptr<CPicture> backgroundImage;
-	std::shared_ptr<CButton> buttonOk;
 	std::shared_ptr<CLabel> title;
 	std::shared_ptr<CMultiLineLabel> subTitle;
 
@@ -80,9 +79,9 @@ private:
 	void onChange();
 	void update();
 	void setTerrainButtonText();
-	void setOkButtonEnabled();
-	void startBattle();
 public:
 	BattleOnlyModeTab();
 	void applyStartInfo(std::shared_ptr<BattleOnlyModeStartInfo> si);
+	void startBattle();
+	void setStartButtonEnabled();
 };

+ 14 - 4
client/lobby/CLobbyScreen.cpp

@@ -88,7 +88,7 @@ CLobbyScreen::CLobbyScreen(ESelectionScreen screenType, bool hideScreen)
 
 		card->iconDifficulty->addCallback(std::bind(&IServerAPI::setDifficulty, &GAME->server(), _1));
 
-		buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRBEG.DEF"), LIBRARY->generaltexth->zelp[103], std::bind(&CLobbyScreen::startScenario, this, false), EShortcut::LOBBY_BEGIN_STANDARD_GAME);
+		buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRBEG.DEF"), LIBRARY->generaltexth->zelp[103], std::bind(&CLobbyScreen::start, this, false), EShortcut::LOBBY_BEGIN_STANDARD_GAME);
 		initLobby();
 		break;
 	}
@@ -97,13 +97,13 @@ CLobbyScreen::CLobbyScreen(ESelectionScreen screenType, bool hideScreen)
 		tabOpt = std::make_shared<OptionsTab>();
 		tabTurnOptions = std::make_shared<TurnOptionsTab>();
 		tabExtraOptions = std::make_shared<ExtraOptionsTab>();
-		buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRLOD.DEF"), LIBRARY->generaltexth->zelp[103], std::bind(&CLobbyScreen::startScenario, this, false), EShortcut::LOBBY_LOAD_GAME);
+		buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRLOD.DEF"), LIBRARY->generaltexth->zelp[103], std::bind(&CLobbyScreen::start, this, false), EShortcut::LOBBY_LOAD_GAME);
 		initLobby();
 		break;
 	}
 	case ESelectionScreen::campaignList:
 		tabSel->callOnSelect = std::bind(&IServerAPI::setMapInfo, &GAME->server(), _1, nullptr);
-		buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRLOD.DEF"), CButton::tooltip(), std::bind(&CLobbyScreen::startCampaign, this), EShortcut::LOBBY_BEGIN_CAMPAIGN);
+		buttonStart = std::make_shared<CButton>(Point(411, 535), AnimationPath::builtin("SCNRLOD.DEF"), CButton::tooltip(), std::bind(&CLobbyScreen::start, this, true), EShortcut::LOBBY_BEGIN_CAMPAIGN);
 		break;
 	}
 
@@ -152,7 +152,7 @@ void CLobbyScreen::toggleTab(std::shared_ptr<CIntObject> tab)
 
 	if(tab == tabBattleOnlyMode)
 	{
-		buttonStart->block(true);
+		tabBattleOnlyMode->setStartButtonEnabled();
 		card->clearSelection();
 	}
 	else
@@ -164,6 +164,16 @@ void CLobbyScreen::toggleTab(std::shared_ptr<CIntObject> tab)
 	CSelectionBase::toggleTab(tab);
 }
 
+void CLobbyScreen::start(bool campaign)
+{
+	if(curTab == tabBattleOnlyMode)
+		tabBattleOnlyMode->startBattle();
+	else if(campaign)
+		startCampaign();
+	else
+		startScenario(false);
+}
+
 void CLobbyScreen::startCampaign()
 {
 	if(!GAME->server().mi)

+ 1 - 0
client/lobby/CLobbyScreen.h

@@ -23,6 +23,7 @@ public:
 	CLobbyScreen(ESelectionScreen type, bool hideScreen = false);
 	~CLobbyScreen();
 	void toggleTab(std::shared_ptr<CIntObject> tab) final;
+	void start(bool campaign);
 	void startCampaign();
 	void startScenario(bool allowOnlyAI = false);
 	void toggleMode(bool host);