1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

More hot-seat GUI in pregame.

This commit is contained in:
Michał W. Urbańczyk 2010-02-15 11:37:47 +00:00
parent da87d25d21
commit 49b99f470f
6 changed files with 75 additions and 18 deletions

@ -126,7 +126,6 @@ public:
CBattleInterface * battleInt; //NULL if no battle CBattleInterface * battleInt; //NULL if no battle
FPSmanager * mainFPSmng; //to keep const framerate FPSmanager * mainFPSmng; //to keep const framerate
CInGameConsole * cingconsole; CInGameConsole * cingconsole;
IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
CCallback * cb; //to communicate with engine CCallback * cb; //to communicate with engine
const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL) 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 ) 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() void CGPreGame::loadGraphics()
@ -255,7 +257,8 @@ void CGPreGame::update()
GH.handleEvents(); GH.handleEvents();
} }
CSelectionScreen::CSelectionScreen( CMenuScreen::EState Type ) CSelectionScreen::CSelectionScreen( CMenuScreen::EState Type, const std::vector<std::string> &PlayerNames )
:playerNames(PlayerNames)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
IShowActivable::type = BLOCK_ADV_HOTKEYS; IShowActivable::type = BLOCK_ADV_HOTKEYS;
@ -384,6 +387,7 @@ void CSelectionScreen::updateStartInfo( const CMapInfo * to )
sInfo.playerInfos.resize(to->playerAmnt); sInfo.playerInfos.resize(to->playerAmnt);
sInfo.mapname = to->filename; sInfo.mapname = to->filename;
playerSerial = playerColor = -1; playerSerial = playerColor = -1;
int placedPlayers = 0;
int serialC=0; int serialC=0;
for (int i = 0; i < PLAYER_LIMIT; i++) for (int i = 0; i < PLAYER_LIMIT; i++)
@ -398,12 +402,15 @@ void CSelectionScreen::updateStartInfo( const CMapInfo * to )
pset.color = i; pset.color = i;
pset.serial = serialC++; 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; pset.human = true;
playerColor = i; if(playerColor < 0)
playerSerial = pset.serial; {
playerColor = i;
playerSerial = pset.serial;
}
} }
else else
{ {
@ -1880,12 +1887,12 @@ CMultiMode::CMultiMode()
blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img blitAt(CPicture("MUMAP.bmp"), 16, 77, *bg); //blit img
pos = bg->center(); //center, window has size of bg graphic 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 = new CTextInput(Rect(19, 436, 334, 16), *bg);
txt->setText(CGI->generaltexth->allTexts[434]); //Player txt->setText(CGI->generaltexth->allTexts[434]); //Player
btns[0] = new AdventureMapButton(CGI->generaltexth->zelp[266], bind(&CMultiMode::openHotseat, this), 373, 78, "MUBHOT.DEF"); 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() void CMultiMode::openHotseat()
@ -1904,4 +1911,21 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
for(int i = 0; i < ARRAY_COUNT(txt); i++) for(int i = 0; i < ARRAY_COUNT(txt); i++)
txt[i] = new CTextInput(Rect(60, 85 + i*30, 280, 16), *bg); 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 CMapHeader;
class CCampaignHeader; class CCampaignHeader;
class CTextInput; class CTextInput;
class CGStatusBar;
class CMapInfo class CMapInfo
{ {
@ -204,8 +205,9 @@ public:
const CMapInfo *current; const CMapInfo *current;
StartInfo sInfo; StartInfo sInfo;
CIntObject *curTab; 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(); ~CSelectionScreen();
void toggleTab(CIntObject *tab); void toggleTab(CIntObject *tab);
void changeSelection(const CMapInfo *to); void changeSelection(const CMapInfo *to);
@ -231,6 +233,7 @@ public:
CPicture *bg; CPicture *bg;
CTextInput *txt; CTextInput *txt;
AdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel AdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel
CGStatusBar *bar;
CMultiMode(); CMultiMode();
void openHotseat(); void openHotseat();
@ -242,8 +245,10 @@ public:
CPicture *bg; CPicture *bg;
CTextInput *txt[8]; CTextInput *txt[8];
AdventureMapButton *ok, *cancel; AdventureMapButton *ok, *cancel;
CGStatusBar *bar;
CHotSeatPlayers(const std::string &firstPlayer); CHotSeatPlayers(const std::string &firstPlayer);
void enterSelectionScreen();
}; };
class CGPreGame : public CIntObject, public IUpdateable class CGPreGame : public CIntObject, public IUpdateable

@ -579,7 +579,7 @@ CIntObject::~CIntObject()
if(children[i]->recActions & DISPOSE) if(children[i]->recActions & DISPOSE)
delete children[i]; delete children[i];
if(parent) if(parent && GH.createdObj.size()) //temporary object destroyed
parent->children -= this; parent->children -= this;
} }

@ -61,6 +61,8 @@ using namespace CSDL_Ext;
extern std::queue<SDL_Event*> events; extern std::queue<SDL_Event*> events;
extern boost::mutex eventsM; extern boost::mutex eventsM;
CTextInput * CTextInput::inputWithFocus;
#undef min #undef min
#undef max #undef max
@ -5120,7 +5122,7 @@ CGStatusBar::CGStatusBar(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment
init(); 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, "") : CLabel(BG->pos.x, BG->pos.y, Font, Align, Color, "")
{ {
init(); 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 ) 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; pos += Pos;
OBJ_CONSTRUCTION; OBJ_CONSTRUCTION;
bg = new CPicture(bgName, bgOffset.x, bgOffset.y); bg = new CPicture(bgName, bgOffset.x, bgOffset.y);
used = LCLICK | KEYBOARD; used = LCLICK | KEYBOARD;
giveFocus();
} }
CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf) CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
: focus(false)
{ {
pos += Pos; pos += Pos;
OBJ_CONSTRUCTION; OBJ_CONSTRUCTION;
@ -5175,22 +5179,25 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
pos.h = bg->pos.h; pos.h = bg->pos.h;
bg->pos = pos; bg->pos = pos;
used = LCLICK | KEYBOARD; used = LCLICK | KEYBOARD;
giveFocus();
} }
void CTextInput::showAll( SDL_Surface * to ) void CTextInput::showAll( SDL_Surface * to )
{ {
CIntObject::showAll(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 ) void CTextInput::clickLeft( tribool down, bool previousState )
{ {
//TODO if(down && !focus)
giveFocus();
} }
void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
{ {
if(key.state != SDL_PRESSED) return; if(!focus || key.state != SDL_PRESSED) return;
switch(key.keysym.sym) switch(key.keysym.sym)
{ {
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
@ -5216,3 +5223,21 @@ void CTextInput::setText( const std::string &nText, bool callCb )
cb(text); 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 std::string getCurrent(); //returns currently displayed text
void show(SDL_Surface * to); //shows statusbar (with current 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(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 = 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(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(); ~CGStatusBar();
}; };
@ -301,14 +301,18 @@ class CTextInput : public CLabel
{ {
public: public:
CFunctionList<void(const std::string &)> cb; 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); 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, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
CTextInput(const Rect &Pos, SDL_Surface *srf); CTextInput(const Rect &Pos, SDL_Surface *srf);
~CTextInput();
void showAll(SDL_Surface * to); void showAll(SDL_Surface * to);
void clickLeft(tribool down, bool previousState); void clickLeft(tribool down, bool previousState);
void keyPressed(const SDL_KeyboardEvent & key); void keyPressed(const SDL_KeyboardEvent & key);
void giveFocus();
static CTextInput *inputWithFocus;
}; };
class CList : public CIntObject class CList : public CIntObject