瀏覽代碼

Merge remote-tracking branch 'upstream/develop' into interface-builder

nordsoft 2 年之前
父節點
當前提交
7e7071fc95

+ 2 - 2
AI/Nullkiller/Goals/ExecuteHeroChain.cpp

@@ -127,7 +127,7 @@ void ExecuteHeroChain::accept(AIGateway * ai)
 							continue;
 						}
 					}
-					catch(cannotFulfillGoalException)
+					catch(cannotFulfillGoalException &)
 					{
 						if(!heroPtr.validAndSet())
 						{
@@ -173,7 +173,7 @@ void ExecuteHeroChain::accept(AIGateway * ai)
 			ai->nullkiller->lockHero(hero, HeroLockedReason::HERO_CHAIN);
 			blockedIndexes.insert(node.parentIndex);
 		}
-		catch(goalFulfilledException)
+		catch(goalFulfilledException &)
 		{
 			if(!heroPtr.validAndSet())
 			{

+ 5 - 2
client/battle/BattleInterfaceClasses.cpp

@@ -27,6 +27,7 @@
 #include "../gui/Canvas.h"
 #include "../gui/CCursorHandler.h"
 #include "../gui/CGuiHandler.h"
+#include "../widgets/AdventureMapClasses.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/Images.h"
 #include "../widgets/TextControls.h"
@@ -113,10 +114,12 @@ BattleConsole::BattleConsole(const Rect & position)
 	pos.h = position.h;
 }
 
-BattleConsole::~BattleConsole()
+void BattleConsole::deactivate()
 {
 	if (enteringText)
-		setEnteringMode(false);
+		LOCPLINT->cingconsole->endEnteringText(false);
+
+	CIntObject::deactivate();
 }
 
 void BattleConsole::setEnteringMode(bool on)

+ 2 - 1
client/battle/BattleInterfaceClasses.h

@@ -59,8 +59,9 @@ private:
 	bool enteringText;
 public:
 	BattleConsole(const Rect & position);
-	~BattleConsole();
+
 	void showAll(SDL_Surface * to) override;
+	void deactivate() override;
 
 	bool addText(const std::string &text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
 	void scrollUp(ui32 by = 1); //scrolls console up by 'by' positions

+ 4 - 7
client/gui/SDL_Extensions.cpp

@@ -526,13 +526,10 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y )
 
 	SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.a);
 
-	// color is considered transparent here if
-	// a) image has aplha: less than 50% transparency
-	// b) no alpha: color is cyan
-	if (srf->format->Amask)
-		return color.a < 128; // almost transparent
-	else
-		return (color.r == 0 && color.g == 255 && color.b == 255);
+	bool pixelTransparent = color.a < 128;
+	bool pixelCyan = (color.r == 0 && color.g == 255 && color.b == 255);
+
+	return pixelTransparent || pixelCyan;
 }
 
 void CSDL_Ext::VflipSurf(SDL_Surface * surf)

+ 3 - 3
client/lobby/CSavingScreen.cpp

@@ -66,10 +66,10 @@ void CSavingScreen::changeSelection(std::shared_ptr<CMapInfo> to)
 
 void CSavingScreen::saveGame()
 {
-	if(!(tabSel && tabSel->inputName && tabSel->inputName->text.size()))
+	if(!(tabSel && tabSel->inputName && tabSel->inputName->getText().size()))
 		return;
 
-	std::string path = "Saves/" + tabSel->inputName->text;
+	std::string path = "Saves/" + tabSel->inputName->getText();
 
 	auto overWrite = [this, path]() -> void
 	{
@@ -82,7 +82,7 @@ void CSavingScreen::saveGame()
 	if(CResourceHandler::get("local")->existsResource(ResourceID(path, EResType::CLIENT_SAVEGAME)))
 	{
 		std::string hlp = CGI->generaltexth->allTexts[493]; //%s exists. Overwrite?
-		boost::algorithm::replace_first(hlp, "%s", tabSel->inputName->text);
+		boost::algorithm::replace_first(hlp, "%s", tabSel->inputName->getText());
 		LOCPLINT->showYesNoDialog(hlp, overWrite, nullptr);
 	}
 	else

+ 3 - 3
client/lobby/CSelectionBase.cpp

@@ -321,9 +321,9 @@ CChatBox::CChatBox(const Rect & rect)
 
 void CChatBox::keyPressed(const SDL_KeyboardEvent & key)
 {
-	if(key.keysym.sym == SDLK_RETURN && key.state == SDL_PRESSED && inputBox->text.size())
+	if(key.keysym.sym == SDLK_RETURN && key.state == SDL_PRESSED && inputBox->getText().size())
 	{
-		CSH->sendMessage(inputBox->text);
+		CSH->sendMessage(inputBox->getText());
 		inputBox->setText("");
 	}
 	else
@@ -333,7 +333,7 @@ void CChatBox::keyPressed(const SDL_KeyboardEvent & key)
 void CChatBox::addNewMessage(const std::string & text)
 {
 	CCS->soundh->playSound("CHAT");
-	chatHistory->setText(chatHistory->label->text + text + "\n");
+	chatHistory->setText(chatHistory->label->getText() + text + "\n");
 	if(chatHistory->slider)
 		chatHistory->slider->moveToMax();
 }

+ 5 - 5
client/mainmenu/CMainMenu.cpp

@@ -438,7 +438,7 @@ void CMultiPlayers::onChange(std::string newText)
 	size_t namesCount = 0;
 
 	for(auto & elem : inputNames)
-		if(!elem->text.empty())
+		if(!elem->getText().empty())
 			namesCount++;
 }
 
@@ -447,8 +447,8 @@ void CMultiPlayers::enterSelectionScreen()
 	std::vector<std::string> names;
 	for(auto name : inputNames)
 	{
-		if(name->text.length())
-			names.push_back(name->text);
+		if(name->getText().length())
+			names.push_back(name->getText());
 	}
 
 	Settings name = settings.write["general"]["playerName"];
@@ -494,7 +494,7 @@ void CSimpleJoinScreen::connectToServer()
 	buttonOk->block(true);
 	CSDL_Ext::stopTextInput();
 
-	boost::thread(&CSimpleJoinScreen::connectThread, this, inputAddress->text, boost::lexical_cast<ui16>(inputPort->text));
+	boost::thread(&CSimpleJoinScreen::connectThread, this, inputAddress->getText(), boost::lexical_cast<ui16>(inputPort->getText()));
 }
 
 void CSimpleJoinScreen::leaveScreen()
@@ -512,7 +512,7 @@ void CSimpleJoinScreen::leaveScreen()
 
 void CSimpleJoinScreen::onChange(const std::string & newText)
 {
-	buttonOk->block(inputAddress->text.empty() || inputPort->text.empty());
+	buttonOk->block(inputAddress->getText().empty() || inputPort->getText().empty());
 }
 
 void CSimpleJoinScreen::connectThread(const std::string addr, const ui16 port)

+ 23 - 2
client/widgets/AdventureMapClasses.cpp

@@ -1126,7 +1126,17 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event)
 
 void CInGameConsole::startEnteringText()
 {
+	if (!active)
+		return;
+
+	if (captureAllKeys)
+		return;
+
 	assert(GH.statusbar);
+	assert(currentStatusBar.expired());//effectively, nullptr check
+
+	currentStatusBar = GH.statusbar;
+
 	captureAllKeys = true;
 	enteredText = "_";
 
@@ -1145,12 +1155,23 @@ void CInGameConsole::endEnteringText(bool printEnteredText)
 		previouslyEntered.push_back(txt);
 	}
 	enteredText.clear();
-	GH.statusbar->setEnteringMode(false);
+
+	auto statusbar = currentStatusBar.lock();
+	assert(statusbar);
+
+	if (statusbar)
+		statusbar->setEnteringMode(false);
+
+	currentStatusBar.reset();
 }
 
 void CInGameConsole::refreshEnteredText()
 {
-	GH.statusbar->setEnteredText(enteredText);
+	auto statusbar = currentStatusBar.lock();
+	assert(statusbar);
+
+	if (statusbar)
+		statusbar->setEnteredText(enteredText);
 }
 
 CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position)

+ 2 - 0
client/widgets/AdventureMapClasses.h

@@ -412,6 +412,8 @@ private:
 	int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
 	int defaultTimeout; //timeout for new texts (in ms)
 	int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
+
+	std::weak_ptr<IStatusBar> currentStatusBar;
 public:
 	std::string enteredText;
 	void show(SDL_Surface * to) override;

+ 9 - 4
client/widgets/TextControls.cpp

@@ -14,7 +14,9 @@
 #include "Images.h"
 
 #include "../CMessage.h"
+#include "../CPlayerInterface.h"
 #include "../gui/CGuiHandler.h"
+#include "../widgets/AdventureMapClasses.h"
 
 #include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff
 
@@ -428,14 +430,17 @@ void CGStatusBar::clickLeft(tribool down, bool previousState)
 {
 	if(!down && onClick)
 	{
-		onClick();
+		if(LOCPLINT && LOCPLINT->cingconsole->active)
+			LOCPLINT->cingconsole->startEnteringText();
 	}
 }
 
-void CGStatusBar::setOnClick(std::function<void()> handler)
+void CGStatusBar::deactivate()
 {
-	onClick = handler;
-	addUsedEvents(LCLICK);
+	if (enteringText)
+		LOCPLINT->cingconsole->endEnteringText(false);
+
+	CIntObject::deactivate();
 }
 
 Point CGStatusBar::getBorderSize()

+ 11 - 4
client/widgets/TextControls.h

@@ -41,11 +41,11 @@ protected:
 	virtual std::string visibleText();
 
 	std::shared_ptr<CPicture> background;
-public:
-
 	std::string text;
 	bool autoRedraw;  //whether control will redraw itself on setTxt
 
+public:
+
 	std::string getText();
 	virtual void setAutoRedraw(bool option);
 	virtual void setText(const std::string & Txt);
@@ -124,6 +124,14 @@ class CGStatusBar : public CLabel, public std::enable_shared_from_this<CGStatusB
 
 	CGStatusBar(std::shared_ptr<CPicture> background_, EFonts Font = FONT_SMALL, ETextAlignment Align = ETextAlignment::CENTER, const SDL_Color & Color = Colors::WHITE);
 	CGStatusBar(int x, int y, std::string name, int maxw = -1);
+
+	//make CLabel API private
+	using CLabel::getText;
+	using CLabel::setAutoRedraw;
+	using CLabel::setText;
+	using CLabel::setColor;
+	using CLabel::getWidth;
+
 protected:
 	Point getBorderSize() override;
 
@@ -141,9 +149,8 @@ public:
 		return ret;
 	}
 
-	void setOnClick(std::function<void()> handler);
-
 	void show(SDL_Surface * to) override;
+	void deactivate() override;
 
 	// IStatusBar interface
 	void write(const std::string & Text) override;

+ 3 - 7
client/windows/CAdvmapInterface.cpp

@@ -716,11 +716,6 @@ CAdvMapInt::CAdvMapInt():
 	worldViewUnderground->block(!CGI->mh->map->twoLevel);
 
 	addUsedEvents(MOVE);
-
-	statusbar->setOnClick([&]
-		{
-			if(LOCPLINT) LOCPLINT->cingconsole->startEnteringText();
-		});
 }
 
 CAdvMapInt::~CAdvMapInt()
@@ -978,6 +973,7 @@ void CAdvMapInt::deactivate()
 		}
 		minimap.deactivate();
 		terrain.deactivate();
+		statusbar->deactivate();
 	}
 }
 
@@ -1667,13 +1663,13 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
 		objRelations = LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner);
 		std::string text = curHero() ? objAtTile->getHoverText(curHero()) : objAtTile->getHoverText(LOCPLINT->playerID);
 		boost::replace_all(text,"\n"," ");
-		statusbar->setText(text);
+		statusbar->write(text);
 	}
 	else
 	{
 		std::string hlp;
 		CGI->mh->getTerrainDescr(mapPos, hlp, false);
-		statusbar->setText(hlp);
+		statusbar->write(hlp);
 	}
 
 	if(spellBeingCasted)

+ 1 - 1
client/windows/CCastleInterface.cpp

@@ -1019,7 +1019,7 @@ void CCreaInfo::update()
 		else
 			value = boost::lexical_cast<std::string>(town->creatureGrowth(level));
 
-		if(value != label->text)
+		if(value != label->getText())
 			label->setText(value);
 	}
 }

+ 1 - 1
client/windows/CKingdomInterface.cpp

@@ -799,7 +799,7 @@ void CTownItem::updateGarrisons()
 void CTownItem::update()
 {
 	std::string incomeVal = boost::lexical_cast<std::string>(town->dailyIncome()[Res::GOLD]);
-	if (incomeVal != income->text)
+	if (incomeVal != income->getText())
 		income->setText(incomeVal);
 
 	heroes->update();

+ 3 - 3
client/windows/CSpellWindow.cpp

@@ -66,7 +66,7 @@ void CSpellWindow::InteractiveArea::clickRight(tribool down, bool previousState)
 void CSpellWindow::InteractiveArea::hover(bool on)
 {
 	if(on)
-		owner->statusBar->setText(hoverText);
+		owner->statusBar->write(hoverText);
 	else
 		owner->statusBar->clear();
 }
@@ -513,7 +513,7 @@ CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
 	cost = std::make_shared<CLabel>(39, 94, FONT_TINY, ETextAlignment::CENTER);
 
 	for(auto l : {name, level, cost})
-		l->autoRedraw = false;
+		l->setAutoRedraw(false);
 }
 
 CSpellWindow::SpellArea::~SpellArea() = default;
@@ -609,7 +609,7 @@ void CSpellWindow::SpellArea::hover(bool on)
 	if(mySpell)
 	{
 		if(on)
-			owner->statusBar->setText(boost::to_string(boost::format("%s (%s)") % mySpell->name % CGI->generaltexth->allTexts[171+mySpell->level]));
+			owner->statusBar->write(boost::to_string(boost::format("%s (%s)") % mySpell->name % CGI->generaltexth->allTexts[171+mySpell->level]));
 		else
 			owner->statusBar->clear();
 	}

+ 1 - 1
client/windows/GUIClasses.cpp

@@ -579,7 +579,7 @@ void CSystemOptionsWindow::selectGameRes()
 #endif
 
 		auto resolutionStr = resolutionToString(resolution.first, resolution.second);
-		if(gameResLabel->text == resolutionStr)
+		if(gameResLabel->getText() == resolutionStr)
 			currentResolutionIndex = i;
 		items.push_back(std::move(resolutionStr));
 		++i;

+ 6 - 1
lib/NetPacksLib.cpp

@@ -1171,7 +1171,12 @@ DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
 	const CArtifactInstance *transformedArt = al.getArt();
 	assert(transformedArt);
 	bool combineEquipped = !ArtifactUtils::isSlotBackpack(al.slot);
-	assert(vstd::contains(transformedArt->assemblyPossibilities(artSet, combineEquipped), builtArt));
+
+	assert(vstd::contains_if(transformedArt->assemblyPossibilities(artSet, combineEquipped), [=](const CArtifact * art)->bool
+		{
+			return art->id == builtArt->id;
+		}));
+
 	UNUSED(transformedArt);
 
 	auto combinedArt = new CCombinedArtifactInstance(builtArt);

+ 25 - 36
lib/VCMIDirs.cpp

@@ -15,26 +15,6 @@
 #include "iOS_utils.h"
 #endif
 
-#ifdef VCMI_ANDROID
-#include "CAndroidVMHelper.h"
-#endif
-
-#ifdef VCMI_WINDOWS
-
-#ifdef __MINGW32__
-	#define _WIN32_IE 0x0500
-
-	#ifndef CSIDL_MYDOCUMENTS
-	#define CSIDL_MYDOCUMENTS CSIDL_PERSONAL
-	#endif
-#endif // __MINGW32__
-
-#include <windows.h>
-#include <shlobj.h>
-#include <shellapi.h>
-
-#endif
-
 VCMI_LIB_NAMESPACE_BEGIN
 
 namespace bfs = boost::filesystem;
@@ -66,8 +46,8 @@ std::string IVCMIDirs::genHelpString() const
 		"  user cache:		" + userCachePath().string() + "\n"
 		"  user config:		" + userConfigPath().string() + "\n"
 		"  user logs:		" + userLogsPath().string() + "\n"
-		"  user saves:		" + userSavePath().string() + "\n"
-		"  user extracted:	" + userExtractedPath().string() + "\n";
+		"  user saves:		" + userSavePath().string() + "\n";
+		"  user extracted:	" + userExtractedPath().string() + "\n"; // Should end without new-line?
 }
 
 void IVCMIDirs::init()
@@ -80,9 +60,25 @@ void IVCMIDirs::init()
 	bfs::create_directories(userSavePath());
 }
 
+#ifdef VCMI_ANDROID
+#include "CAndroidVMHelper.h"
+
+#endif
 
 #ifdef VCMI_WINDOWS
 
+#ifdef __MINGW32__
+    #define _WIN32_IE 0x0500
+
+	#ifndef CSIDL_MYDOCUMENTS
+	#define CSIDL_MYDOCUMENTS CSIDL_PERSONAL
+	#endif
+#endif // __MINGW32__
+
+#include <windows.h>
+#include <shlobj.h>
+#include <shellapi.h>
+
 // Generates script file named _temp.bat in 'to' directory and runs it
 // Script will:
 // - Wait util 'exeName' ends.
@@ -365,20 +361,13 @@ class IVCMIDirsUNIX : public IVCMIDirs
 		bfs::path clientPath() const override;
 		bfs::path serverPath() const override;
 
-		virtual bool developmentModeData() const;
-		virtual bool developmentModeBinaries() const;
+		virtual bool developmentMode() const;
 };
 
-bool IVCMIDirsUNIX::developmentModeData() const
-{
-	// We want to be able to run VCMI from single directory. E.g to run from build output directory
-	return bfs::exists("config") && bfs::exists("Mods") && bfs::exists("../CMakeCache.txt");
-}
-
-bool IVCMIDirsUNIX::developmentModeBinaries() const
+bool IVCMIDirsUNIX::developmentMode() const
 {
 	// We want to be able to run VCMI from single directory. E.g to run from build output directory
-	return bfs::exists("AI") && bfs::exists("../CMakeCache.txt");
+	return bfs::exists("AI") && bfs::exists("config") && bfs::exists("Mods") && bfs::exists("vcmiserver") && bfs::exists("vcmiclient");
 }
 
 bfs::path IVCMIDirsUNIX::clientPath() const { return binaryPath() / "vcmiclient"; }
@@ -522,7 +511,7 @@ std::vector<bfs::path> VCMIDirsOSX::dataPaths() const
 {
 	std::vector<bfs::path> ret;
 	//FIXME: need some proper codepath for detecting running from build output directory
-	if(developmentModeData())
+	if(developmentMode())
 	{
 		ret.push_back(".");
 	}
@@ -595,7 +584,7 @@ std::vector<bfs::path> VCMIDirsXDG::dataPaths() const
 	// in vcmi fs last directory has highest priority
 	std::vector<bfs::path> ret;
 
-	if(developmentModeData())
+	if(developmentMode())
 	{
 		//For now we'll disable usage of system directories when VCMI running from bin directory
 		ret.push_back(".");
@@ -627,7 +616,7 @@ std::vector<bfs::path> VCMIDirsXDG::dataPaths() const
 
 bfs::path VCMIDirsXDG::libraryPath() const
 {
-	if(developmentModeBinaries())
+	if(developmentMode())
 		return ".";
 	else
 		return M_LIB_DIR;
@@ -635,7 +624,7 @@ bfs::path VCMIDirsXDG::libraryPath() const
 
 bfs::path VCMIDirsXDG::binaryPath() const
 {
-	if(developmentModeBinaries())
+	if(developmentMode())
 		return ".";
 	else
 		return M_BIN_DIR;