Просмотр исходного кода

Progress update on client side

nordsoft 2 лет назад
Родитель
Сommit
45f13c7964

+ 4 - 1
client/Client.cpp

@@ -181,7 +181,10 @@ void CClient::newGame(CGameState * initializedGameState)
 	gs->preInit(VLC);
 	logNetwork->trace("\tCreating gamestate: %i", CSH->th->getDiff());
 	if(!initializedGameState)
-		gs->init(&mapService, CSH->si.get(), settings["general"]["saveRandomMaps"].Bool());
+	{
+		Load::Progress * progressTrackingPointer = nullptr;
+		gs->init(&mapService, CSH->si.get(), progressTrackingPointer, settings["general"]["saveRandomMaps"].Bool());
+	}
 	logNetwork->trace("Initializing GameState (together): %d ms", CSH->th->getDiff());
 
 	initMapHandler();

+ 3 - 0
client/NetPacksLobbyClient.cpp

@@ -131,7 +131,10 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pac
 void ApplyOnLobbyScreenNetPackVisitor::visitLobbyLoadProgress(LobbyLoadProgress & pack)
 {
 	if(auto w = GH.windows().topWindow<CLoadingScreen>())
+	{
 		w->set(pack.progress);
+		w->redraw();
+	}
 	else
 		GH.windows().createAndPushWindow<CLoadingScreen>();
 }

+ 27 - 2
client/mainmenu/CMainMenu.cpp

@@ -585,7 +585,22 @@ void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
 CLoadingScreen::CLoadingScreen()
 	: CWindowObject(BORDERED, getBackground())
 {
+	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
+	
 	CCS->musich->stopMusic(5000);
+	
+	const auto & conf = CMainMenuConfig::get().getConfig()["loading"];
+	
+	const int posx = conf["x"].Integer(), posy = conf["y"].Integer();
+	const int blockSize = conf["size"].Integer();
+	const int blocksAmount = conf["amount"].Integer();
+			
+	for(int i = 0; i < blocksAmount; ++i)
+	{
+		progressBlocks.push_back(std::make_shared<CAnimImage>(conf["name"].String(), i, 0, posx + i * blockSize, posy));
+		progressBlocks.back()->deactivate();
+		progressBlocks.back()->visible = false;
+	}
 }
 
 CLoadingScreen::~CLoadingScreen()
@@ -597,13 +612,23 @@ void CLoadingScreen::showAll(Canvas & to)
 	//FIXME: filling screen with transparency? BLACK intended?
 	//Rect rect(0, 0, to->w, to->h);
 	//CSDL_Ext::fillRect(to, rect, Colors::TRANSPARENCY);
-
+	if(!progressBlocks.empty())
+	{
+		int status = float(get()) / (2.55f * progressBlocks.size());
+		
+		for(int i = 0; i < status; ++i)
+		{
+			progressBlocks.at(i)->activate();
+			progressBlocks.at(i)->visible = true;
+		}
+	}
+	
 	CWindowObject::showAll(to);
 }
 
 std::string CLoadingScreen::getBackground()
 {
-	const auto & conf = CMainMenuConfig::get().getConfig()["loading"].Vector();
+	const auto & conf = CMainMenuConfig::get().getConfig()["loading"]["background"].Vector();
 
 	if(conf.empty())
 	{

+ 4 - 0
client/mainmenu/CMainMenu.h

@@ -9,6 +9,7 @@
  */
 #pragma once
 
+#include "../widgets/Images.h"
 #include "../windows/CWindowObject.h"
 #include "../../lib/JsonNode.h"
 #include "../../lib/LoadProgress.h"
@@ -26,6 +27,7 @@ class CTabbedInt;
 class CAnimation;
 class CButton;
 class CFilledTexture;
+class CLabel;
 
 
 // TODO: Find new location for these enums
@@ -181,6 +183,8 @@ public:
 
 class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
 {
+	std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
+	
 	std::string getBackground();
 
 public:	

+ 5 - 1
config/mainmenu.json

@@ -2,7 +2,11 @@
 	//images used in game selection screen
 	"game-select" : ["gamselb0", "gamselb1"],
 
-	"loading" : ["loadbar"],
+	"loading" :
+	{
+		"background" : ["loadbar"],
+		"x": 395, "y": 548, "size": 18, "amount": 20, "name": "loadprog"
+	},
 
 	//Main menu window, consists of several sub-menus aka items
 	"window":

+ 2 - 2
lib/gameState/CGameState.cpp

@@ -404,7 +404,7 @@ void CGameState::preInit(Services * services)
 	this->services = services;
 }
 
-void CGameState::init(const IMapService * mapService, StartInfo * si, bool allowSavingRandomMap, Load::Progress * progressTracking)
+void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Progress *& progressTracking, bool allowSavingRandomMap)
 {
 	preInitAuto();
 	logGlobal->info("\tUsing random seed: %d", si->seedToBeUsed);
@@ -535,7 +535,7 @@ void CGameState::preInitAuto()
 	}
 }
 
-void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress * progressTracking)
+void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress *& progressTracking)
 {
 	if(scenarioOps->createRandomMap())
 	{

+ 2 - 2
lib/gameState/CGameState.h

@@ -90,7 +90,7 @@ public:
 
 	void preInit(Services * services);
 
-	void init(const IMapService * mapService, StartInfo * si, bool allowSavingRandomMap = false, Load::Progress * progressTracking = nullptr);
+	void init(const IMapService * mapService, StartInfo * si, Load::Progress *&, bool allowSavingRandomMap = false);
 	void updateOnLoad(StartInfo * si);
 
 	ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
@@ -167,7 +167,7 @@ public:
 private:
 	// ----- initialization -----
 	void preInitAuto();
-	void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress * progressTracking = nullptr);
+	void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::Progress *& progressTracking);
 	void checkMapChecksum();
 	void initGlobalBonuses();
 	void initGrailPosition();

+ 2 - 2
server/CGameHandler.cpp

@@ -1599,7 +1599,7 @@ void CGameHandler::reinitScripting()
 #endif
 }
 
-void CGameHandler::init(StartInfo *si, Load::Progress * progressTracking)
+void CGameHandler::init(StartInfo *si, Load::Progress *& progressTracking)
 {
 	if (si->seedToBeUsed == 0)
 	{
@@ -1609,7 +1609,7 @@ void CGameHandler::init(StartInfo *si, Load::Progress * progressTracking)
 	gs = new CGameState();
 	gs->preInit(VLC);
 	logGlobal->info("Gamestate created!");
-	gs->init(&mapService, si, false, progressTracking);
+	gs->init(&mapService, si, progressTracking);
 	logGlobal->info("Gamestate initialized!");
 
 	// reset seed, so that clients can't predict any following random values

+ 1 - 1
server/CGameHandler.h

@@ -237,7 +237,7 @@ public:
 	void expGiven(const CGHeroInstance *hero); //triggers needed level-ups, handles also commander of this hero
 	//////////////////////////////////////////////////////////////////////////
 
-	void init(StartInfo *si, Load::Progress * progressTracking = nullptr);
+	void init(StartInfo *si, Load::Progress *& progressTracking);
 	void handleClientDisconnection(std::shared_ptr<CConnection> c);
 	void handleReceivedPack(CPackForServer * pack);
 	PlayerColor getPlayerAt(std::shared_ptr<CConnection> c) const;

+ 1 - 1
server/CVCMIServer.cpp

@@ -291,7 +291,7 @@ bool CVCMIServer::prepareToStartGame()
 				loadProgress->progress = progressTracking->get();
 				addToAnnounceQueue(std::move(loadProgress));
 			}
-			std::this_thread::sleep_for(std::chrono::milliseconds(100));
+			std::this_thread::sleep_for(std::chrono::milliseconds(200));
 		}
 		progressTrackingFinished = false;
 	});