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

* further console improvements

This commit is contained in:
mateuszb 2009-04-05 14:37:14 +00:00
parent 47bc007d8c
commit ee61a02d12
3 changed files with 44 additions and 6 deletions

View File

@ -4642,6 +4642,8 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
{ {
if(key.type != SDL_KEYDOWN) return; if(key.type != SDL_KEYDOWN) return;
if(!captureAllKeys && key.keysym.sym != SDLK_TAB) return; //because user is not entering any text
switch(key.keysym.sym) switch(key.keysym.sym)
{ {
case SDLK_TAB: case SDLK_TAB:
@ -4677,6 +4679,38 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
} }
break; break;
} }
case SDLK_UP: //up arrow
{
if(prevEntDisp == -1)
{
prevEntDisp = previouslyEntered.size() - 1;
enteredText = previouslyEntered[prevEntDisp] + "_";
refreshEnteredText();
}
else if( prevEntDisp > 0)
{
--prevEntDisp;
enteredText = previouslyEntered[prevEntDisp] + "_";
refreshEnteredText();
}
break;
}
case SDLK_DOWN: //down arrow
{
if(prevEntDisp != -1 && prevEntDisp+1 < previouslyEntered.size())
{
++prevEntDisp;
enteredText = previouslyEntered[prevEntDisp] + "_";
refreshEnteredText();
}
else if(prevEntDisp+1 == previouslyEntered.size()) //useful feature
{
prevEntDisp = -1;
enteredText = "_";
refreshEnteredText();
}
break;
}
default: default:
{ {
if(enteredText.size() > 0) if(enteredText.size() > 0)
@ -4708,10 +4742,12 @@ void CInGameConsole::startEnteringText()
void CInGameConsole::endEnteringText(bool printEnteredText) void CInGameConsole::endEnteringText(bool printEnteredText)
{ {
prevEntDisp = -1;
if(printEnteredText) if(printEnteredText)
{ {
std::string txt = enteredText.substr(0, enteredText.size()-1); std::string txt = enteredText.substr(0, enteredText.size()-1);
LOCPLINT->cb->sendMessage(txt); LOCPLINT->cb->sendMessage(txt);
previouslyEntered.push_back(txt);
print(txt); print(txt);
} }
enteredText = ""; enteredText = "";
@ -4738,7 +4774,7 @@ void CInGameConsole::refreshEnteredText()
} }
} }
CInGameConsole::CInGameConsole() : defaultTimeout(10000), maxDisplayedTexts(10) CInGameConsole::CInGameConsole() : defaultTimeout(10000), maxDisplayedTexts(10), prevEntDisp(-1)
{ {
} }

View File

@ -906,6 +906,8 @@ class CInGameConsole : public IShowActivable, public KeyInterested
{ {
private: private:
std::list< std::pair< std::string, int > > texts; //<text to show, time of add> std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
int defaultTimeout; //timeout for new texts (in ms) int defaultTimeout; //timeout for new texts (in ms)
int maxDisplayedTexts; //hiw many texts can be displayed simultaneously int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
public: public: