Merge pull request #1250 from IvanSavenko/battle_regressions_fix
Battle regressions fix
This commit is contained in:
15 files changed
+76
-44
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user