mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
More hot-seat GUI in pregame.
This commit is contained in:
parent
da87d25d21
commit
49b99f470f
@ -126,7 +126,6 @@ public:
|
||||
CBattleInterface * battleInt; //NULL if no battle
|
||||
FPSmanager * mainFPSmng; //to keep const framerate
|
||||
CInGameConsole * cingconsole;
|
||||
IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
|
||||
|
||||
CCallback * cb; //to communicate with engine
|
||||
const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
|
||||
|
@ -211,7 +211,9 @@ CGPreGame::~CGPreGame()
|
||||
|
||||
void CGPreGame::openSel( CMenuScreen::EState type )
|
||||
{
|
||||
GH.pushInt(new CSelectionScreen(type));
|
||||
std::vector<std::string> names;
|
||||
names.push_back(CGI->generaltexth->allTexts[434]);
|
||||
GH.pushInt(new CSelectionScreen(type, names));
|
||||
}
|
||||
|
||||
void CGPreGame::loadGraphics()
|
||||
@ -255,7 +257,8 @@ void CGPreGame::update()
|
||||
GH.handleEvents();
|
||||
}
|
||||
|
||||
CSelectionScreen::CSelectionScreen( CMenuScreen::EState Type )
|
||||
CSelectionScreen::CSelectionScreen( CMenuScreen::EState Type, const std::vector<std::string> &PlayerNames )
|
||||
:playerNames(PlayerNames)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
IShowActivable::type = BLOCK_ADV_HOTKEYS;
|
||||
@ -384,6 +387,7 @@ void CSelectionScreen::updateStartInfo( const CMapInfo * to )
|
||||
sInfo.playerInfos.resize(to->playerAmnt);
|
||||
sInfo.mapname = to->filename;
|
||||
playerSerial = playerColor = -1;
|
||||
int placedPlayers = 0;
|
||||
|
||||
int serialC=0;
|
||||
for (int i = 0; i < PLAYER_LIMIT; i++)
|
||||
@ -398,12 +402,15 @@ void CSelectionScreen::updateStartInfo( const CMapInfo * to )
|
||||
pset.color = i;
|
||||
pset.serial = serialC++;
|
||||
|
||||
if (pinfo.canHumanPlay && playerColor < 0)
|
||||
if (pinfo.canHumanPlay && placedPlayers < playerNames.size())
|
||||
{
|
||||
pset.name = CGI->generaltexth->allTexts[434]; //Player
|
||||
pset.name = playerNames[placedPlayers++];
|
||||
pset.human = true;
|
||||
playerColor = i;
|
||||
playerSerial = pset.serial;
|
||||
if(playerColor < 0)
|
||||
{
|
||||
playerColor = i;
|
||||
playerSerial = pset.serial;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1880,12 +1887,12 @@ CMultiMode::CMultiMode()
|
||||
blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img
|
||||
pos = bg->center(); //center, window has size of bg graphic
|
||||
|
||||
CGStatusBar *bar = new CGStatusBar(new CPicture(Rect(7, 465, 440, 18), 0), FONT_SMALL, CLabel::CENTER);//226, 472
|
||||
bar = new CGStatusBar(new CPicture(Rect(7, 465, 440, 18), 0));//226, 472
|
||||
txt = new CTextInput(Rect(19, 436, 334, 16), *bg);
|
||||
txt->setText(CGI->generaltexth->allTexts[434]); //Player
|
||||
|
||||
btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF");
|
||||
btns[6] = new AdventureMapButton(CGI->generaltexth->zelp[288], bind(&CGuiHandler::popInt, ref(GH), this), 373, 424, "MUBCANC.DEF");
|
||||
btns[6] = new AdventureMapButton(CGI->generaltexth->zelp[288], bind(&CGuiHandler::popIntTotally, ref(GH), this), 373, 424, "MUBCANC.DEF");
|
||||
}
|
||||
|
||||
void CMultiMode::openHotseat()
|
||||
@ -1904,4 +1911,21 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
|
||||
for(int i = 0; i < ARRAY_COUNT(txt); i++)
|
||||
txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg);
|
||||
|
||||
txt[0]->setText(firstPlayer);
|
||||
txt[0]->giveFocus();
|
||||
|
||||
ok = new AdventureMapButton(CGI->generaltexth->zelp[560], bind(&CHotSeatPlayers::enterSelectionScreen, this), 95, 338, "MUBCHCK.DEF");
|
||||
cancel = new AdventureMapButton(CGI->generaltexth->zelp[561], bind(&CGuiHandler::popIntTotally, ref(GH), this), 205, 338, "MUBCANC.DEF");
|
||||
bar = new CGStatusBar(new CPicture(Rect(7, 381, 348, 18), 0));//226, 472
|
||||
}
|
||||
|
||||
void CHotSeatPlayers::enterSelectionScreen()
|
||||
{
|
||||
std::vector<std::string> playerNames;
|
||||
for(int i = 0; i < ARRAY_COUNT(txt); i++)
|
||||
if(txt[i]->text.length())
|
||||
playerNames.push_back(txt[i]->text);
|
||||
|
||||
GH.popInts(2);
|
||||
GH.pushInt(new CSelectionScreen(CMenuScreen::newGame, playerNames));
|
||||
}
|
@ -21,6 +21,7 @@ struct CMusicHandler;
|
||||
class CMapHeader;
|
||||
class CCampaignHeader;
|
||||
class CTextInput;
|
||||
class CGStatusBar;
|
||||
|
||||
class CMapInfo
|
||||
{
|
||||
@ -204,8 +205,9 @@ public:
|
||||
const CMapInfo *current;
|
||||
StartInfo sInfo;
|
||||
CIntObject *curTab;
|
||||
std::vector<std::string> playerNames;
|
||||
|
||||
CSelectionScreen(CMenuScreen::EState Type);
|
||||
CSelectionScreen(CMenuScreen::EState Type, const std::vector<std::string> &PlayerNames = std::vector<std::string>());
|
||||
~CSelectionScreen();
|
||||
void toggleTab(CIntObject *tab);
|
||||
void changeSelection(const CMapInfo *to);
|
||||
@ -231,6 +233,7 @@ public:
|
||||
CPicture *bg;
|
||||
CTextInput *txt;
|
||||
AdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel
|
||||
CGStatusBar *bar;
|
||||
|
||||
CMultiMode();
|
||||
void openHotseat();
|
||||
@ -242,8 +245,10 @@ public:
|
||||
CPicture *bg;
|
||||
CTextInput *txt[8];
|
||||
AdventureMapButton *ok, *cancel;
|
||||
CGStatusBar *bar;
|
||||
|
||||
CHotSeatPlayers(const std::string &firstPlayer);
|
||||
void enterSelectionScreen();
|
||||
};
|
||||
|
||||
class CGPreGame : public CIntObject, public IUpdateable
|
||||
|
@ -579,7 +579,7 @@ CIntObject::~CIntObject()
|
||||
if(children[i]->recActions & DISPOSE)
|
||||
delete children[i];
|
||||
|
||||
if(parent)
|
||||
if(parent && GH.createdObj.size()) //temporary object destroyed
|
||||
parent->children -= this;
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,8 @@ using namespace CSDL_Ext;
|
||||
extern std::queue<SDL_Event*> events;
|
||||
extern boost::mutex eventsM;
|
||||
|
||||
CTextInput * CTextInput::inputWithFocus;
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
@ -5120,7 +5122,7 @@ CGStatusBar::CGStatusBar(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment
|
||||
init();
|
||||
}
|
||||
|
||||
CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= zwykly*/)
|
||||
CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= CENTER*/, const SDL_Color &Color /*= zwykly*/)
|
||||
: CLabel(BG->pos.x, BG->pos.y, Font, Align, Color, "")
|
||||
{
|
||||
init();
|
||||
@ -5156,15 +5158,17 @@ void CGStatusBar::init()
|
||||
}
|
||||
|
||||
CTextInput::CTextInput( const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB )
|
||||
:cb(CB)
|
||||
:cb(CB), focus(false)
|
||||
{
|
||||
pos += Pos;
|
||||
OBJ_CONSTRUCTION;
|
||||
bg = new CPicture(bgName, bgOffset.x, bgOffset.y);
|
||||
used = LCLICK | KEYBOARD;
|
||||
giveFocus();
|
||||
}
|
||||
|
||||
CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
|
||||
: focus(false)
|
||||
{
|
||||
pos += Pos;
|
||||
OBJ_CONSTRUCTION;
|
||||
@ -5175,22 +5179,25 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
|
||||
pos.h = bg->pos.h;
|
||||
bg->pos = pos;
|
||||
used = LCLICK | KEYBOARD;
|
||||
giveFocus();
|
||||
}
|
||||
|
||||
void CTextInput::showAll( SDL_Surface * to )
|
||||
{
|
||||
CIntObject::showAll(to);
|
||||
CSDL_Ext::printAt(text + "_", pos.x, pos.y, FONT_SMALL, zwykly, to);
|
||||
const std::string toPrint = focus ? text + "_" : text;
|
||||
CSDL_Ext::printAt(toPrint, pos.x, pos.y, FONT_SMALL, zwykly, to);
|
||||
}
|
||||
|
||||
void CTextInput::clickLeft( tribool down, bool previousState )
|
||||
{
|
||||
//TODO
|
||||
if(down && !focus)
|
||||
giveFocus();
|
||||
}
|
||||
|
||||
void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
|
||||
{
|
||||
if(key.state != SDL_PRESSED) return;
|
||||
if(!focus || key.state != SDL_PRESSED) return;
|
||||
switch(key.keysym.sym)
|
||||
{
|
||||
case SDLK_BACKSPACE:
|
||||
@ -5216,3 +5223,21 @@ void CTextInput::setText( const std::string &nText, bool callCb )
|
||||
cb(text);
|
||||
}
|
||||
|
||||
CTextInput::~CTextInput()
|
||||
{
|
||||
if(inputWithFocus == this)
|
||||
inputWithFocus = NULL;
|
||||
}
|
||||
|
||||
void CTextInput::giveFocus()
|
||||
{
|
||||
if(inputWithFocus)
|
||||
{
|
||||
inputWithFocus->focus = false;
|
||||
inputWithFocus->redraw();
|
||||
}
|
||||
|
||||
focus = true;
|
||||
inputWithFocus = this;
|
||||
redraw();
|
||||
}
|
||||
|
@ -290,8 +290,8 @@ public:
|
||||
std::string getCurrent(); //returns currently displayed text
|
||||
void show(SDL_Surface * to); //shows statusbar (with current text)
|
||||
|
||||
CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly, const std::string &Text = "");
|
||||
CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
|
||||
CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
|
||||
CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
|
||||
|
||||
~CGStatusBar();
|
||||
};
|
||||
@ -301,14 +301,18 @@ class CTextInput : public CLabel
|
||||
{
|
||||
public:
|
||||
CFunctionList<void(const std::string &)> cb;
|
||||
bool focus; //only one text input may have focus at once
|
||||
|
||||
void setText(const std::string &nText, bool callCb = false);
|
||||
|
||||
CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
|
||||
CTextInput(const Rect &Pos, SDL_Surface *srf);
|
||||
~CTextInput();
|
||||
void showAll(SDL_Surface * to);
|
||||
void clickLeft(tribool down, bool previousState);
|
||||
void keyPressed(const SDL_KeyboardEvent & key);
|
||||
void giveFocus();
|
||||
static CTextInput *inputWithFocus;
|
||||
};
|
||||
|
||||
class CList : public CIntObject
|
||||
|
Loading…
x
Reference in New Issue
Block a user