mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Code formatting
This commit is contained in:
@@ -11,42 +11,36 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CMessage.h"
|
#include "CMessage.h"
|
||||||
|
|
||||||
#include "../CGameInfo.h"
|
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
|
||||||
#include "../../lib/TextOperations.h"
|
#include "../../lib/TextOperations.h"
|
||||||
|
|
||||||
#include "../windows/InfoWindows.h"
|
|
||||||
#include "../widgets/Images.h"
|
|
||||||
#include "../widgets/Buttons.h"
|
|
||||||
#include "../widgets/CComponent.h"
|
|
||||||
#include "../widgets/Slider.h"
|
|
||||||
#include "../widgets/TextControls.h"
|
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../render/CAnimation.h"
|
#include "../render/CAnimation.h"
|
||||||
#include "../render/IImage.h"
|
|
||||||
#include "../render/IRenderHandler.h"
|
|
||||||
#include "../render/Canvas.h"
|
#include "../render/Canvas.h"
|
||||||
#include "../render/Graphics.h"
|
#include "../render/Graphics.h"
|
||||||
#include "../render/IFont.h"
|
#include "../render/IFont.h"
|
||||||
#include "../renderSDL/SDL_Extensions.h"
|
#include "../render/IImage.h"
|
||||||
|
#include "../render/IRenderHandler.h"
|
||||||
|
#include "../widgets/Buttons.h"
|
||||||
|
#include "../widgets/CComponent.h"
|
||||||
|
#include "../widgets/Images.h"
|
||||||
|
#include "../widgets/Slider.h"
|
||||||
|
#include "../widgets/TextControls.h"
|
||||||
|
#include "../windows/InfoWindows.h"
|
||||||
|
|
||||||
const int BEFORE_COMPONENTS = 30;
|
const int BEFORE_COMPONENTS = 30;
|
||||||
const int SIDE_MARGIN = 30;
|
const int SIDE_MARGIN = 30;
|
||||||
|
|
||||||
namespace
|
static std::array<std::shared_ptr<CAnimation>, PlayerColor::PLAYER_LIMIT_I> dialogBorders;
|
||||||
{
|
static std::array<std::vector<std::shared_ptr<IImage>>, PlayerColor::PLAYER_LIMIT_I> piecesOfBox;
|
||||||
std::array<std::shared_ptr<CAnimation>, PlayerColor::PLAYER_LIMIT_I> dialogBorders;
|
|
||||||
std::array<std::vector<std::shared_ptr<IImage>>, PlayerColor::PLAYER_LIMIT_I> piecesOfBox;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMessage::init()
|
void CMessage::init()
|
||||||
{
|
{
|
||||||
for(int i=0; i<PlayerColor::PLAYER_LIMIT_I; i++)
|
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; i++)
|
||||||
{
|
{
|
||||||
dialogBorders[i] = GH.renderHandler().loadAnimation(AnimationPath::builtin("DIALGBOX"));
|
dialogBorders[i] = GH.renderHandler().loadAnimation(AnimationPath::builtin("DIALGBOX"));
|
||||||
dialogBorders[i]->preload();
|
dialogBorders[i]->preload();
|
||||||
|
|
||||||
for(int j=0; j < dialogBorders[i]->size(0); j++)
|
for(int j = 0; j < dialogBorders[i]->size(0); j++)
|
||||||
{
|
{
|
||||||
auto image = dialogBorders[i]->getImage(j, 0);
|
auto image = dialogBorders[i]->getImage(j, 0);
|
||||||
//assume blue color initially
|
//assume blue color initially
|
||||||
@@ -63,18 +57,18 @@ void CMessage::dispose()
|
|||||||
item.reset();
|
item.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWidth, EFonts font )
|
std::vector<std::string> CMessage::breakText(std::string text, size_t maxLineWidth, EFonts font)
|
||||||
{
|
{
|
||||||
assert(maxLineWidth != 0);
|
assert(maxLineWidth != 0);
|
||||||
if (maxLineWidth == 0)
|
if(maxLineWidth == 0)
|
||||||
return { text };
|
return {text};
|
||||||
|
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
|
|
||||||
boost::algorithm::trim_right_if(text,boost::algorithm::is_any_of(std::string(" ")));
|
boost::algorithm::trim_right_if(text, boost::algorithm::is_any_of(std::string(" ")));
|
||||||
|
|
||||||
// each iteration generates one output line
|
// each iteration generates one output line
|
||||||
while (text.length())
|
while(text.length())
|
||||||
{
|
{
|
||||||
ui32 lineWidth = 0; //in characters or given char metric
|
ui32 lineWidth = 0; //in characters or given char metric
|
||||||
ui32 wordBreak = -1; //last position for line break (last space character)
|
ui32 wordBreak = -1; //last position for line break (last space character)
|
||||||
@@ -92,13 +86,13 @@ std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWi
|
|||||||
glyphWidth = graphics->fonts[font]->getGlyphWidth(text.data() + currPos);
|
glyphWidth = graphics->fonts[font]->getGlyphWidth(text.data() + currPos);
|
||||||
|
|
||||||
// candidate for line break
|
// candidate for line break
|
||||||
if (ui8(text[currPos]) <= ui8(' '))
|
if(ui8(text[currPos]) <= ui8(' '))
|
||||||
wordBreak = currPos;
|
wordBreak = currPos;
|
||||||
|
|
||||||
/* We don't count braces in string length. */
|
/* We don't count braces in string length. */
|
||||||
if (text[currPos] == '{')
|
if(text[currPos] == '{')
|
||||||
{
|
{
|
||||||
opened=true;
|
opened = true;
|
||||||
|
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
std::regex expr("^\\{(.*?)\\|");
|
std::regex expr("^\\{(.*?)\\|");
|
||||||
@@ -113,9 +107,9 @@ std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (text[currPos]=='}')
|
else if(text[currPos] == '}')
|
||||||
{
|
{
|
||||||
opened=false;
|
opened = false;
|
||||||
color = "";
|
color = "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -124,9 +118,9 @@ std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// long line, create line break
|
// long line, create line break
|
||||||
if (currPos < text.length() && (text[currPos] != 0x0a))
|
if(currPos < text.length() && (text[currPos] != 0x0a))
|
||||||
{
|
{
|
||||||
if (wordBreak != ui32(-1))
|
if(wordBreak != ui32(-1))
|
||||||
currPos = wordBreak;
|
currPos = wordBreak;
|
||||||
else
|
else
|
||||||
currPos -= (ui32)symbolSize;
|
currPos -= (ui32)symbolSize;
|
||||||
@@ -137,7 +131,7 @@ std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWi
|
|||||||
{
|
{
|
||||||
ret.push_back(text.substr(0, currPos));
|
ret.push_back(text.substr(0, currPos));
|
||||||
|
|
||||||
if (opened)
|
if(opened)
|
||||||
/* Close the brace for the current line. */
|
/* Close the brace for the current line. */
|
||||||
ret.back() += '}';
|
ret.back() += '}';
|
||||||
|
|
||||||
@@ -148,7 +142,7 @@ std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWi
|
|||||||
ret.push_back(""); //add empty string, no extra actions needed
|
ret.push_back(""); //add empty string, no extra actions needed
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text.length() != 0 && text[0] == 0x0a)
|
if(text.length() != 0 && text[0] == 0x0a)
|
||||||
{
|
{
|
||||||
/* Remove LF */
|
/* Remove LF */
|
||||||
text.erase(0, 1);
|
text.erase(0, 1);
|
||||||
@@ -157,19 +151,19 @@ std::vector<std::string> CMessage::breakText( std::string text, size_t maxLineWi
|
|||||||
{
|
{
|
||||||
// trim only if line does not starts with LF
|
// trim only if line does not starts with LF
|
||||||
// FIXME: necessary? All lines will be trimmed before returning anyway
|
// FIXME: necessary? All lines will be trimmed before returning anyway
|
||||||
boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(std::string(" ")));
|
boost::algorithm::trim_left_if(text, boost::algorithm::is_any_of(std::string(" ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opened)
|
if(opened)
|
||||||
{
|
{
|
||||||
/* Add an opening brace for the next line. */
|
/* Add an opening brace for the next line. */
|
||||||
if (text.length() != 0)
|
if(text.length() != 0)
|
||||||
text.insert(0, "{" + color);
|
text.insert(0, "{" + color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Trim whitespaces of every line. */
|
/* Trim whitespaces of every line. */
|
||||||
for (auto & elem : ret)
|
for(auto & elem : ret)
|
||||||
boost::algorithm::trim(elem);
|
boost::algorithm::trim(elem);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -196,11 +190,11 @@ int CMessage::guessHeight(const std::string & txt, int width, EFonts font)
|
|||||||
|
|
||||||
int CMessage::getEstimatedComponentHeight(int numComps)
|
int CMessage::getEstimatedComponentHeight(int numComps)
|
||||||
{
|
{
|
||||||
if (numComps > 8) //Bigger than 8 components - return invalid value
|
if(numComps > 8) //Bigger than 8 components - return invalid value
|
||||||
return std::numeric_limits<int>::max();
|
return std::numeric_limits<int>::max();
|
||||||
else if (numComps > 2)
|
else if(numComps > 2)
|
||||||
return 160; // 32px * 1 row + 20 to offset
|
return 160; // 32px * 1 row + 20 to offset
|
||||||
else if (numComps)
|
else if(numComps)
|
||||||
return 118; // 118 px to offset
|
return 118; // 118 px to offset
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -215,10 +209,10 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
|
|||||||
|
|
||||||
assert(ret && ret->text);
|
assert(ret && ret->text);
|
||||||
|
|
||||||
for (auto const & area : textAreaSizes)
|
for(const auto & area : textAreaSizes)
|
||||||
{
|
{
|
||||||
ret->text->resize(area);
|
ret->text->resize(area);
|
||||||
if (!ret->text->slider)
|
if(!ret->text->slider)
|
||||||
break; // suitable size found, use it
|
break; // suitable size found, use it
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,27 +223,27 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
|
|||||||
|
|
||||||
Point winSize(ret->text->pos.w, ret->text->pos.h); //start with text size
|
Point winSize(ret->text->pos.w, ret->text->pos.h); //start with text size
|
||||||
|
|
||||||
if (ret->components)
|
if(ret->components)
|
||||||
winSize.y += 10 + ret->components->pos.h; //space to first component
|
winSize.y += 10 + ret->components->pos.h; //space to first component
|
||||||
|
|
||||||
int bw = 0;
|
int bw = 0;
|
||||||
if (ret->buttons.size())
|
if(ret->buttons.size())
|
||||||
{
|
{
|
||||||
int bh = 0;
|
int bh = 0;
|
||||||
// Compute total width of buttons
|
// Compute total width of buttons
|
||||||
bw = 20*((int)ret->buttons.size()-1); // space between all buttons
|
bw = 20 * ((int)ret->buttons.size() - 1); // space between all buttons
|
||||||
for(auto & elem : ret->buttons) //and add buttons width
|
for(auto & elem : ret->buttons) //and add buttons width
|
||||||
{
|
{
|
||||||
bw+=elem->pos.w;
|
bw += elem->pos.w;
|
||||||
vstd::amax(bh, elem->pos.h);
|
vstd::amax(bh, elem->pos.h);
|
||||||
}
|
}
|
||||||
winSize.y += 20 + bh;//before button + button
|
winSize.y += 20 + bh; //before button + button
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clip window size
|
// Clip window size
|
||||||
vstd::amax(winSize.y, 50);
|
vstd::amax(winSize.y, 50);
|
||||||
vstd::amax(winSize.x, 80);
|
vstd::amax(winSize.x, 80);
|
||||||
if (ret->components)
|
if(ret->components)
|
||||||
vstd::amax(winSize.x, ret->components->pos.w);
|
vstd::amax(winSize.x, ret->components->pos.w);
|
||||||
vstd::amax(winSize.x, bw);
|
vstd::amax(winSize.x, bw);
|
||||||
|
|
||||||
@@ -261,19 +255,19 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
|
|||||||
ret->backgroundTexture->pos = ret->pos;
|
ret->backgroundTexture->pos = ret->pos;
|
||||||
|
|
||||||
int curh = SIDE_MARGIN;
|
int curh = SIDE_MARGIN;
|
||||||
int xOffset = (ret->pos.w - ret->text->pos.w)/2;
|
int xOffset = (ret->pos.w - ret->text->pos.w) / 2;
|
||||||
|
|
||||||
if(ret->buttons.empty() && !ret->components) //improvement for very small text only popups -> center text vertically
|
if(ret->buttons.empty() && !ret->components) //improvement for very small text only popups -> center text vertically
|
||||||
{
|
{
|
||||||
if(ret->pos.h > ret->text->pos.h + 2*SIDE_MARGIN)
|
if(ret->pos.h > ret->text->pos.h + 2 * SIDE_MARGIN)
|
||||||
curh = (ret->pos.h - ret->text->pos.h)/2;
|
curh = (ret->pos.h - ret->text->pos.h) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->text->moveBy(Point(xOffset, curh));
|
ret->text->moveBy(Point(xOffset, curh));
|
||||||
|
|
||||||
curh += ret->text->pos.h;
|
curh += ret->text->pos.h;
|
||||||
|
|
||||||
if (ret->components)
|
if(ret->components)
|
||||||
{
|
{
|
||||||
curh += BEFORE_COMPONENTS;
|
curh += BEFORE_COMPONENTS;
|
||||||
curh += ret->components->pos.h;
|
curh += ret->components->pos.h;
|
||||||
@@ -282,7 +276,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
|
|||||||
if(ret->buttons.size())
|
if(ret->buttons.size())
|
||||||
{
|
{
|
||||||
// Position the buttons at the bottom of the window
|
// Position the buttons at the bottom of the window
|
||||||
bw = (ret->pos.w/2) - (bw/2);
|
bw = (ret->pos.w / 2) - (bw / 2);
|
||||||
curh = ret->pos.h - SIDE_MARGIN - ret->buttons[0]->pos.h;
|
curh = ret->pos.h - SIDE_MARGIN - ret->buttons[0]->pos.h;
|
||||||
|
|
||||||
for(auto & elem : ret->buttons)
|
for(auto & elem : ret->buttons)
|
||||||
@@ -291,7 +285,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
|
|||||||
bw += elem->pos.w + 20;
|
bw += elem->pos.w + 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret->components)
|
if(ret->components)
|
||||||
ret->components->moveBy(Point(ret->pos.x, ret->pos.y));
|
ret->components->moveBy(Point(ret->pos.x, ret->pos.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,8 +300,9 @@ void CMessage::drawBorder(PlayerColor playerColor, Canvas & to, int w, int h, in
|
|||||||
// Horizontal borders
|
// Horizontal borders
|
||||||
int start_x = x + box[0]->width();
|
int start_x = x + box[0]->width();
|
||||||
const int stop_x = x + w - box[1]->width();
|
const int stop_x = x + w - box[1]->width();
|
||||||
const int bottom_y = y+h-box[7]->height()+1;
|
const int bottom_y = y + h - box[7]->height() + 1;
|
||||||
while (start_x < stop_x) {
|
while(start_x < stop_x)
|
||||||
|
{
|
||||||
|
|
||||||
// Top border
|
// Top border
|
||||||
to.draw(box[6], Point(start_x, y));
|
to.draw(box[6], Point(start_x, y));
|
||||||
@@ -319,9 +314,10 @@ void CMessage::drawBorder(PlayerColor playerColor, Canvas & to, int w, int h, in
|
|||||||
|
|
||||||
// Vertical borders
|
// Vertical borders
|
||||||
int start_y = y + box[0]->height();
|
int start_y = y + box[0]->height();
|
||||||
const int stop_y = y + h - box[2]->height()+1;
|
const int stop_y = y + h - box[2]->height() + 1;
|
||||||
const int right_x = x+w-box[5]->width();
|
const int right_x = x + w - box[5]->width();
|
||||||
while (start_y < stop_y) {
|
while(start_y < stop_y)
|
||||||
|
{
|
||||||
|
|
||||||
// Left border
|
// Left border
|
||||||
to.draw(box[4], Point(x, start_y));
|
to.draw(box[4], Point(x, start_y));
|
||||||
@@ -332,8 +328,8 @@ void CMessage::drawBorder(PlayerColor playerColor, Canvas & to, int w, int h, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
//corners
|
//corners
|
||||||
to.draw(box[0], Point(x,y));
|
to.draw(box[0], Point(x, y));
|
||||||
to.draw(box[1], Point(x+w-box[1]->width(), y));
|
to.draw(box[1], Point(x + w - box[1]->width(), y));
|
||||||
to.draw(box[2], Point(x, y+h-box[2]->height()+1));
|
to.draw(box[2], Point(x, y + h - box[2]->height() + 1));
|
||||||
to.draw(box[3], Point(x+w-box[3]->width(), y+h-box[3]->height()+1));
|
to.draw(box[3], Point(x + w - box[3]->width(), y + h - box[3]->height() + 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
class ColorRGBA;
|
class ColorRGBA;
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
|
|
||||||
/// Class which draws formatted text messages and generates chat windows
|
/// Class which draws formatted text messages and generates chat windows
|
||||||
class CMessage
|
class CMessage
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,19 +11,14 @@
|
|||||||
#include "InfoWindows.h"
|
#include "InfoWindows.h"
|
||||||
|
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../PlayerLocalState.h"
|
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../CMusicHandler.h"
|
#include "../PlayerLocalState.h"
|
||||||
|
|
||||||
#include "../adventureMap/AdventureMapInterface.h"
|
#include "../adventureMap/AdventureMapInterface.h"
|
||||||
#include "../battle/BattleInterface.h"
|
|
||||||
#include "../battle/BattleInterfaceClasses.h"
|
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/CursorHandler.h"
|
#include "../gui/CursorHandler.h"
|
||||||
#include "../gui/Shortcut.h"
|
#include "../gui/Shortcut.h"
|
||||||
#include "../gui/WindowHandler.h"
|
#include "../gui/WindowHandler.h"
|
||||||
#include "../render/Canvas.h"
|
|
||||||
#include "../renderSDL/SDL_Extensions.h"
|
|
||||||
#include "../widgets/Buttons.h"
|
#include "../widgets/Buttons.h"
|
||||||
#include "../widgets/CComponent.h"
|
#include "../widgets/CComponent.h"
|
||||||
#include "../widgets/Images.h"
|
#include "../widgets/Images.h"
|
||||||
@@ -35,35 +30,32 @@
|
|||||||
|
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/CondSh.h"
|
#include "../../lib/CondSh.h"
|
||||||
#include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff
|
#include "../../lib/gameState/InfoAboutArmy.h"
|
||||||
#include "../../lib/mapObjects/CGCreature.h"
|
#include "../../lib/mapObjects/CGCreature.h"
|
||||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||||
#include "../../lib/mapObjects/CGTownInstance.h"
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
||||||
#include "../../lib/mapObjects/MiscObjects.h"
|
#include "../../lib/mapObjects/MiscObjects.h"
|
||||||
#include "../../lib/gameState/InfoAboutArmy.h"
|
|
||||||
|
|
||||||
CSelWindow::CSelWindow(const std::string &Text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath, CFunctionList<void()> > > &Buttons, QueryID askID)
|
CSelWindow::CSelWindow( const std::string & Text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath, CFunctionList<void()>>> & Buttons, QueryID askID)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||||
|
|
||||||
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
|
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
|
||||||
|
|
||||||
ID = askID;
|
ID = askID;
|
||||||
for (int i = 0; i < Buttons.size(); i++)
|
for(int i = 0; i < Buttons.size(); i++)
|
||||||
{
|
{
|
||||||
buttons.push_back(std::make_shared<CButton>(Point(0, 0), Buttons[i].first, CButton::tooltip(), Buttons[i].second));
|
buttons.push_back(std::make_shared<CButton>(Point(0, 0), Buttons[i].first, CButton::tooltip(), Buttons[i].second));
|
||||||
if (!i && askID.getNum() >= 0)
|
if(!i && askID.getNum() >= 0)
|
||||||
buttons.back()->addCallback(std::bind(&CSelWindow::madeChoice, this));
|
buttons.back()->addCallback(std::bind(&CSelWindow::madeChoice, this));
|
||||||
buttons[i]->addCallback(std::bind(&CInfoWindow::close, this)); //each button will close the window apart from call-defined actions
|
buttons[i]->addCallback(std::bind(&CInfoWindow::close, this)); //each button will close the window apart from call-defined actions
|
||||||
}
|
}
|
||||||
|
|
||||||
text = std::make_shared<CTextBox>(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
|
text = std::make_shared<CTextBox>(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
|
||||||
|
|
||||||
if (buttons.size() > 1 && askID.getNum() >= 0) //cancel button functionality
|
if(buttons.size() > 1 && askID.getNum() >= 0) //cancel button functionality
|
||||||
{
|
{
|
||||||
buttons.back()->addCallback([askID]() {
|
buttons.back()->addCallback([askID](){LOCPLINT->cb.get()->selectionMade(0, askID);});
|
||||||
LOCPLINT->cb.get()->selectionMade(0, askID);
|
|
||||||
});
|
|
||||||
//buttons.back()->addCallback(std::bind(&CCallback::selectionMade, LOCPLINT->cb.get(), 0, askID));
|
//buttons.back()->addCallback(std::bind(&CCallback::selectionMade, LOCPLINT->cb.get(), 0, askID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,8 +68,8 @@ CSelWindow::CSelWindow(const std::string &Text, PlayerColor player, int charperl
|
|||||||
buttons.back()->assignedKey = EShortcut::GLOBAL_CANCEL;
|
buttons.back()->assignedKey = EShortcut::GLOBAL_CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!comps.empty())
|
if(!comps.empty())
|
||||||
components = std::make_shared<CComponentBox>(comps, Rect(0,0,600,300));
|
components = std::make_shared<CComponentBox>(comps, Rect(0, 0, 600, 300));
|
||||||
|
|
||||||
CMessage::drawIWindow(this, Text, player);
|
CMessage::drawIWindow(this, Text, player);
|
||||||
}
|
}
|
||||||
@@ -87,10 +79,10 @@ void CSelWindow::madeChoice()
|
|||||||
if(ID.getNum() < 0)
|
if(ID.getNum() < 0)
|
||||||
return;
|
return;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (components)
|
if(components)
|
||||||
ret = components->selectedIndex();
|
ret = components->selectedIndex();
|
||||||
|
|
||||||
LOCPLINT->cb->selectionMade(ret+1,ID);
|
LOCPLINT->cb->selectionMade(ret + 1, ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSelWindow::madeChoiceAndClose()
|
void CSelWindow::madeChoiceAndClose()
|
||||||
@@ -101,14 +93,14 @@ void CSelWindow::madeChoiceAndClose()
|
|||||||
|
|
||||||
CInfoWindow::CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps, const TButtonsInfo & Buttons)
|
CInfoWindow::CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps, const TButtonsInfo & Buttons)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||||
|
|
||||||
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
|
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
|
||||||
|
|
||||||
ID = QueryID(-1);
|
ID = QueryID(-1);
|
||||||
for(auto & Button : Buttons)
|
for(auto & Button : Buttons)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CButton> button = std::make_shared<CButton>(Point(0,0), Button.first, CButton::tooltip(), std::bind(&CInfoWindow::close, this));
|
std::shared_ptr<CButton> button = std::make_shared<CButton>(Point(0, 0), Button.first, CButton::tooltip(), std::bind(&CInfoWindow::close, this));
|
||||||
button->setBorderColor(Colors::METALLIC_GOLD);
|
button->setBorderColor(Colors::METALLIC_GOLD);
|
||||||
button->addCallback(Button.second); //each button will close the window apart from call-defined actions
|
button->addCallback(Button.second); //each button will close the window apart from call-defined actions
|
||||||
buttons.push_back(button);
|
buttons.push_back(button);
|
||||||
@@ -131,10 +123,10 @@ CInfoWindow::CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo
|
|||||||
buttons.back()->assignedKey = EShortcut::GLOBAL_CANCEL;
|
buttons.back()->assignedKey = EShortcut::GLOBAL_CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!comps.empty())
|
if(!comps.empty())
|
||||||
components = std::make_shared<CComponentBox>(comps, Rect(0,0,600,300));
|
components = std::make_shared<CComponentBox>(comps, Rect(0, 0, 600, 300));
|
||||||
|
|
||||||
CMessage::drawIWindow(this,Text,player);
|
CMessage::drawIWindow(this, Text, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
CInfoWindow::CInfoWindow()
|
CInfoWindow::CInfoWindow()
|
||||||
@@ -158,28 +150,28 @@ void CInfoWindow::showAll(Canvas & to)
|
|||||||
|
|
||||||
CInfoWindow::~CInfoWindow() = default;
|
CInfoWindow::~CInfoWindow() = default;
|
||||||
|
|
||||||
void CInfoWindow::showInfoDialog(const std::string &text, const TCompsInfo & components, PlayerColor player)
|
void CInfoWindow::showInfoDialog(const std::string & text, const TCompsInfo & components, PlayerColor player)
|
||||||
{
|
{
|
||||||
GH.windows().pushWindow(CInfoWindow::create(text, player, components));
|
GH.windows().pushWindow(CInfoWindow::create(text, player, components));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInfoWindow::showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, PlayerColor player)
|
void CInfoWindow::showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player)
|
||||||
{
|
{
|
||||||
assert(!LOCPLINT || LOCPLINT->showingDialog->get());
|
assert(!LOCPLINT || LOCPLINT->showingDialog->get());
|
||||||
std::vector<std::pair<AnimationPath,CFunctionList<void()> > > pom;
|
std::vector<std::pair<AnimationPath, CFunctionList<void()>>> pom;
|
||||||
pom.push_back( { AnimationPath::builtin("IOKAY.DEF"), 0 });
|
pom.push_back({AnimationPath::builtin("IOKAY.DEF"), 0});
|
||||||
pom.push_back( { AnimationPath::builtin("ICANCEL.DEF"), 0 });
|
pom.push_back({AnimationPath::builtin("ICANCEL.DEF"), 0});
|
||||||
std::shared_ptr<CInfoWindow> temp = std::make_shared<CInfoWindow>(text, player, components, pom);
|
std::shared_ptr<CInfoWindow> temp = std::make_shared<CInfoWindow>(text, player, components, pom);
|
||||||
|
|
||||||
temp->buttons[0]->addCallback( onYes );
|
temp->buttons[0]->addCallback(onYes);
|
||||||
temp->buttons[1]->addCallback( onNo );
|
temp->buttons[1]->addCallback(onNo);
|
||||||
|
|
||||||
GH.windows().pushWindow(temp);
|
GH.windows().pushWindow(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CInfoWindow> CInfoWindow::create(const std::string &text, PlayerColor playerID, const TCompsInfo & components)
|
std::shared_ptr<CInfoWindow> CInfoWindow::create(const std::string & text, PlayerColor playerID, const TCompsInfo & components)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<AnimationPath,CFunctionList<void()> > > pom;
|
std::vector<std::pair<AnimationPath, CFunctionList<void()>>> pom;
|
||||||
pom.push_back({AnimationPath::builtin("IOKAY.DEF"), 0});
|
pom.push_back({AnimationPath::builtin("IOKAY.DEF"), 0});
|
||||||
return std::make_shared<CInfoWindow>(text, playerID, components, pom);
|
return std::make_shared<CInfoWindow>(text, playerID, components, pom);
|
||||||
}
|
}
|
||||||
@@ -199,10 +191,10 @@ void CRClickPopup::close()
|
|||||||
WindowBase::close();
|
WindowBase::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCompsInfo &comps)
|
void CRClickPopup::createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo & comps)
|
||||||
{
|
{
|
||||||
PlayerColor player = LOCPLINT ? LOCPLINT->playerID : PlayerColor(1); //if no player, then use blue
|
PlayerColor player = LOCPLINT ? LOCPLINT->playerID : PlayerColor(1); //if no player, then use blue
|
||||||
if(settings["session"]["spectate"].Bool())//TODO: there must be better way to implement this
|
if(settings["session"]["spectate"].Bool()) //TODO: there must be better way to implement this
|
||||||
player = PlayerColor(1);
|
player = PlayerColor(1);
|
||||||
|
|
||||||
auto temp = std::make_shared<CInfoWindow>(txt, player, comps);
|
auto temp = std::make_shared<CInfoWindow>(txt, player, comps);
|
||||||
@@ -233,7 +225,7 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::vector<Component> components;
|
std::vector<Component> components;
|
||||||
if (settings["general"]["enableUiEnhancements"].Bool())
|
if(settings["general"]["enableUiEnhancements"].Bool())
|
||||||
{
|
{
|
||||||
if(LOCPLINT->localState->getCurrentHero())
|
if(LOCPLINT->localState->getCurrentHero())
|
||||||
components = obj->getPopupComponents(LOCPLINT->localState->getCurrentHero());
|
components = obj->getPopupComponents(LOCPLINT->localState->getCurrentHero());
|
||||||
@@ -242,7 +234,7 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<CComponent>> guiComponents;
|
std::vector<std::shared_ptr<CComponent>> guiComponents;
|
||||||
for (auto & component : components)
|
for(auto & component : components)
|
||||||
guiComponents.push_back(std::make_shared<CComponent>(component));
|
guiComponents.push_back(std::make_shared<CComponent>(component));
|
||||||
|
|
||||||
if(LOCPLINT->localState->getCurrentHero())
|
if(LOCPLINT->localState->getCurrentHero())
|
||||||
@@ -282,7 +274,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town)
|
|||||||
InfoAboutTown iah;
|
InfoAboutTown iah;
|
||||||
LOCPLINT->cb->getTownInfo(town, iah, LOCPLINT->localState->getCurrentTown()); //todo: should this be nearest hero?
|
LOCPLINT->cb->getTownInfo(town, iah, LOCPLINT->localState->getCurrentTown()); //todo: should this be nearest hero?
|
||||||
|
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||||
tooltip = std::make_shared<CTownTooltip>(Point(9, 10), iah);
|
tooltip = std::make_shared<CTownTooltip>(Point(9, 10), iah);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,9 +282,9 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero)
|
|||||||
: CWindowObject(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("HEROQVBK"), toScreen(position))
|
: CWindowObject(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("HEROQVBK"), toScreen(position))
|
||||||
{
|
{
|
||||||
InfoAboutHero iah;
|
InfoAboutHero iah;
|
||||||
LOCPLINT->cb->getHeroInfo(hero, iah, LOCPLINT->localState->getCurrentHero());//todo: should this be nearest hero?
|
LOCPLINT->cb->getHeroInfo(hero, iah, LOCPLINT->localState->getCurrentHero()); //todo: should this be nearest hero?
|
||||||
|
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||||
tooltip = std::make_shared<CHeroTooltip>(Point(9, 10), iah);
|
tooltip = std::make_shared<CHeroTooltip>(Point(9, 10), iah);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,18 +294,19 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
|
|||||||
InfoAboutTown iah;
|
InfoAboutTown iah;
|
||||||
LOCPLINT->cb->getTownInfo(garr, iah);
|
LOCPLINT->cb->getTownInfo(garr, iah);
|
||||||
|
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||||
tooltip = std::make_shared<CArmyTooltip>(Point(9, 10), iah);
|
tooltip = std::make_shared<CArmyTooltip>(Point(9, 10), iah);
|
||||||
}
|
}
|
||||||
|
|
||||||
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
|
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
|
||||||
: CWindowObject(RCLICK_POPUP | BORDERED, ImagePath::builtin("DIBOXBCK"), toScreen(position))
|
: CWindowObject(RCLICK_POPUP | BORDERED, ImagePath::builtin("DIBOXBCK"), toScreen(position))
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||||
tooltip = std::make_shared<CreatureTooltip>(Point(9, 10), creature);
|
tooltip = std::make_shared<CreatureTooltip>(Point(9, 10), creature);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<WindowBase> CRClickPopup::createCustomInfoWindow(Point position, const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
|
std::shared_ptr<WindowBase>
|
||||||
|
CRClickPopup::createCustomInfoWindow(Point position, const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
|
||||||
{
|
{
|
||||||
if(nullptr == specific)
|
if(nullptr == specific)
|
||||||
specific = LOCPLINT->localState->getCurrentArmy();
|
specific = LOCPLINT->localState->getCurrentArmy();
|
||||||
|
|||||||
@@ -20,21 +20,14 @@ class CGTownInstance;
|
|||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
class CGGarrison;
|
class CGGarrison;
|
||||||
class CGCreature;
|
class CGCreature;
|
||||||
class Rect;
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
struct SDL_Surface;
|
|
||||||
class CAnimImage;
|
|
||||||
class CLabel;
|
|
||||||
class CAnimation;
|
|
||||||
class CComponent;
|
class CComponent;
|
||||||
class CComponentBox;
|
class CComponentBox;
|
||||||
class CSelectableComponent;
|
class CSelectableComponent;
|
||||||
class CTextBox;
|
class CTextBox;
|
||||||
class CButton;
|
class CButton;
|
||||||
class CSlider;
|
|
||||||
class CArmyTooltip;
|
|
||||||
class CFilledTexture;
|
class CFilledTexture;
|
||||||
|
|
||||||
/// text + comp. + ok button
|
/// text + comp. + ok button
|
||||||
@@ -59,8 +52,8 @@ public:
|
|||||||
~CInfoWindow();
|
~CInfoWindow();
|
||||||
|
|
||||||
//use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
|
//use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
|
||||||
static void showInfoDialog( const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
|
static void showInfoDialog(const std::string & text, const TCompsInfo & components, PlayerColor player = PlayerColor(1));
|
||||||
static void showYesNoDialog( const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
|
static void showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player = PlayerColor(1));
|
||||||
static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
|
static std::shared_ptr<CInfoWindow> create(const std::string & text, PlayerColor playerID = PlayerColor(1), const TCompsInfo & components = TCompsInfo());
|
||||||
|
|
||||||
/// create text from title and description: {title}\n\n description
|
/// create text from title and description: {title}\n\n description
|
||||||
@@ -75,7 +68,7 @@ public:
|
|||||||
bool isPopupWindow() const override;
|
bool isPopupWindow() const override;
|
||||||
|
|
||||||
static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);
|
static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);
|
||||||
static void createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo &comps = CInfoWindow::TCompsInfo());
|
static void createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo & comps = CInfoWindow::TCompsInfo());
|
||||||
static void createAndPush(const std::string & txt, std::shared_ptr<CComponent> component);
|
static void createAndPush(const std::string & txt, std::shared_ptr<CComponent> component);
|
||||||
static void createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment = ETextAlignment::BOTTOMRIGHT);
|
static void createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment = ETextAlignment::BOTTOMRIGHT);
|
||||||
};
|
};
|
||||||
@@ -84,6 +77,7 @@ public:
|
|||||||
class CRClickPopupInt : public CRClickPopup
|
class CRClickPopupInt : public CRClickPopup
|
||||||
{
|
{
|
||||||
std::shared_ptr<CIntObject> inner;
|
std::shared_ptr<CIntObject> inner;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CRClickPopupInt(std::shared_ptr<CIntObject> our);
|
CRClickPopupInt(std::shared_ptr<CIntObject> our);
|
||||||
virtual ~CRClickPopupInt();
|
virtual ~CRClickPopupInt();
|
||||||
@@ -94,6 +88,7 @@ class CInfoBoxPopup : public CWindowObject
|
|||||||
{
|
{
|
||||||
std::shared_ptr<CIntObject> tooltip;
|
std::shared_ptr<CIntObject> tooltip;
|
||||||
Point toScreen(Point pos);
|
Point toScreen(Point pos);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CInfoBoxPopup(Point position, const CGTownInstance * town);
|
CInfoBoxPopup(Point position, const CGTownInstance * town);
|
||||||
CInfoBoxPopup(Point position, const CGHeroInstance * hero);
|
CInfoBoxPopup(Point position, const CGHeroInstance * hero);
|
||||||
@@ -108,6 +103,4 @@ public:
|
|||||||
void madeChoice(); //looks for selected component and calls callback
|
void madeChoice(); //looks for selected component and calls callback
|
||||||
void madeChoiceAndClose();
|
void madeChoiceAndClose();
|
||||||
CSelWindow(const std::string & text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath,CFunctionList<void()> > > &Buttons, QueryID askID);
|
CSelWindow(const std::string & text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath,CFunctionList<void()> > > &Buttons, QueryID askID);
|
||||||
|
|
||||||
//notification - this class inherits important destructor from CInfoWindow
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user