1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

battle log expansion

This commit is contained in:
Laserlicht 2024-05-14 02:50:57 +02:00 committed by GitHub
parent 58d1c93c1b
commit e06c09d709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 6 deletions

View File

@ -127,7 +127,7 @@ void BattleInterface::playIntroSoundAndUnlockInterface()
}
}
bool BattleInterface::openingPlaying()
bool BattleInterface::openingPlaying() const
{
return battleOpeningDelayActive;
}

View File

@ -149,7 +149,7 @@ public:
std::shared_ptr<BattleHero> attackingHero;
std::shared_ptr<BattleHero> defendingHero;
bool openingPlaying();
bool openingPlaying() const;
void openingEnd();
bool makingTurn() const;

View File

@ -33,6 +33,7 @@
#include "../render/Graphics.h"
#include "../widgets/Buttons.h"
#include "../widgets/Images.h"
#include "../widgets/Slider.h"
#include "../widgets/TextControls.h"
#include "../widgets/GraphicalPrimitiveCanvas.h"
#include "../windows/CMessage.h"
@ -141,8 +142,10 @@ void BattleConsole::scrollDown(ui32 by)
redraw();
}
BattleConsole::BattleConsole(std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size)
: scrollPosition(-1)
BattleConsole::BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size)
: CIntObject(LCLICK)
, owner(owner)
, scrollPosition(-1)
, enteringText(false)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
@ -161,6 +164,14 @@ void BattleConsole::deactivate()
CIntObject::deactivate();
}
void BattleConsole::clickPressed(const Point & cursorPosition)
{
if(owner.makingTurn() && !owner.openingPlaying())
{
GH.windows().createAndPushWindow<BattleConsoleWindow>(boost::algorithm::join(logEntries, "\n"));
}
}
void BattleConsole::setEnteringMode(bool on)
{
consoleText.clear();
@ -203,6 +214,28 @@ void BattleConsole::clear()
write({});
}
BattleConsoleWindow::BattleConsoleWindow(std::string text)
: CWindowObject(BORDERED)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
pos.w = 429;
pos.h = 434;
updateShadow();
center();
addUsedEvents(LCLICK);
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
buttonOk = std::make_shared<CButton>(Point(183, 388), AnimationPath::builtin("IOKAY"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT);
Rect textArea(18, 17, 393, 354);
textBoxBackgroundBorder = std::make_shared<TransparentFilledRectangle>(textArea, ColorRGBA(0, 0, 0, 75), ColorRGBA(128, 100, 75));
textBox = std::make_shared<CTextBox>(text, textArea.resize(-5), CSlider::BROWN);
if(textBox->slider)
textBox->slider->scrollToMax();
}
const CGHeroInstance * BattleHero::instance()
{
return hero;

View File

@ -47,6 +47,8 @@ class BattleRenderer;
class BattleConsole : public CIntObject, public IStatusBar
{
private:
const BattleInterface & owner;
std::shared_ptr<CPicture> background;
/// List of all texts added during battle, essentially - log of entire battle
@ -70,11 +72,13 @@ private:
/// select line(s) that will be visible in UI
std::vector<std::string> getVisibleText();
public:
BattleConsole(std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);
void showAll(Canvas & to) override;
void deactivate() override;
void clickPressed(const Point & cursorPosition) 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
void scrollDown(ui32 by = 1); //scrolls console up by 'by' positions
@ -87,6 +91,17 @@ public:
void setEnteredText(const std::string & text) override;
};
class BattleConsoleWindow : public CWindowObject
{
private:
std::shared_ptr<CFilledTexture> backgroundTexture;
std::shared_ptr<CButton> buttonOk;
std::shared_ptr<TransparentFilledRectangle> textBoxBackgroundBorder;
std::shared_ptr<CTextBox> textBox;
public:
BattleConsoleWindow(std::string text);
};
/// Hero battle animation
class BattleHero : public CIntObject
{

View File

@ -199,7 +199,7 @@ std::shared_ptr<BattleConsole> BattleWindow::buildBattleConsole(const JsonNode &
auto rect = readRect(config["rect"]);
auto offset = readPosition(config["imagePosition"]);
auto background = widget<CPicture>("menuBattle");
return std::make_shared<BattleConsole>(background, rect.topLeft(), offset, rect.dimensions() );
return std::make_shared<BattleConsole>(owner, background, rect.topLeft(), offset, rect.dimensions() );
}
void BattleWindow::toggleQueueVisibility()