1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Multiplayer: make chat history visible in lobby and improve CTextBox

Now we'll also play sound when new message added.
CTextBox::setText now will automatically change text height for slider.
This commit is contained in:
ArseniyShestakov
2015-03-13 18:45:07 +03:00
parent 1f1f61cf15
commit 67aa869a33
2 changed files with 4 additions and 2 deletions

View File

@@ -1920,6 +1920,7 @@ CChatBox::CChatBox(const Rect &rect)
pos += rect; pos += rect;
addUsedEvents(KEYBOARD | TEXTINPUT); addUsedEvents(KEYBOARD | TEXTINPUT);
captureAllKeys = true; captureAllKeys = true;
type |= REDRAW_PARENT;
const int height = graphics->fonts[FONT_SMALL]->getLineHeight(); const int height = graphics->fonts[FONT_SMALL]->getLineHeight();
inputBox = new CTextInput(Rect(0, rect.h - height, rect.w, height)); inputBox = new CTextInput(Rect(0, rect.h - height, rect.w, height));
@@ -1942,6 +1943,7 @@ void CChatBox::keyPressed(const SDL_KeyboardEvent & key)
void CChatBox::addNewMessage(const std::string &text) void CChatBox::addNewMessage(const std::string &text)
{ {
CCS->soundh->playSound("CHAT");
chatHistory->setText(chatHistory->label->text + text + "\n"); chatHistory->setText(chatHistory->label->text + text + "\n");
if(chatHistory->slider) if(chatHistory->slider)
chatHistory->slider->moveToMax(); chatHistory->slider->moveToMax();
@@ -1994,8 +1996,7 @@ InfoCard::InfoCard( bool Network )
if(network) if(network)
{ {
playerListBg = new CPicture("CHATPLUG.bmp", 16, 276); playerListBg = new CPicture("CHATPLUG.bmp", 16, 276);
chat = new CChatBox(descriptionRect); chat = new CChatBox(Rect(26, 132, 340, 132));
chat->chatHistory->addChild(new CPicture(*bg, chat->chatHistory->pos - pos), true); //move subpicture bg to our description control (by default it's our (Infocard) child)
chatOn = true; chatOn = true;
mapDescription->disable(); mapDescription->disable();

View File

@@ -292,6 +292,7 @@ void CTextBox::setText(const std::string &text)
// decrease width again if slider still used // decrease width again if slider still used
label->pos.w = pos.w - 32; label->pos.w = pos.w - 32;
label->setText(text); label->setText(text);
slider->setAmount(label->textSize.y);
} }
else if(label->textSize.y > label->pos.h) else if(label->textSize.y > label->pos.h)
{ {