1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Optimize button responsiveness during pregame options

This commit is contained in:
Dydzio 2019-04-20 18:26:54 +02:00
parent ec536e613c
commit c428e326b9
4 changed files with 35 additions and 19 deletions

View File

@ -173,34 +173,47 @@ InfoCard::InfoCard()
labelGroupPlayersAssigned = std::make_shared<CLabelGroup>(FONT_SMALL, TOPLEFT, Colors::WHITE);
labelGroupPlayersUnassigned = std::make_shared<CLabelGroup>(FONT_SMALL, TOPLEFT, Colors::WHITE);
disableLabelRedraws();
}
setChat(false);
}
void InfoCard::disableLabelRedraws()
{
labelSaveDate->setAutoRedraw(false);
mapName->setAutoRedraw(false);
mapDescription->label->setAutoRedraw(false);
labelVictoryConditionText->setAutoRedraw(false);
labelLossConditionText->setAutoRedraw(false);
labelDifficulty->setAutoRedraw(false);
labelDifficultyPercent->setAutoRedraw(false);
}
void InfoCard::changeSelection()
{
if(!SEL->getMapInfo())
auto mapInfo = SEL->getMapInfo();
if(!mapInfo)
return;
labelSaveDate->setText(SEL->getMapInfo()->date);
mapName->setText(SEL->getMapInfo()->getName());
mapDescription->setText(SEL->getMapInfo()->getDescription());
labelSaveDate->setText(mapInfo->date);
mapName->setText(mapInfo->getName());
mapDescription->setText(mapInfo->getDescription());
mapDescription->label->scrollTextTo(0);
mapDescription->label->scrollTextTo(0, false);
if(mapDescription->slider)
mapDescription->slider->moveToMin();
if(SEL->screenType == ESelectionScreen::campaignList)
return;
iconsMapSizes->setFrame(SEL->getMapInfo()->getMapSizeIconId());
const CMapHeader * header = SEL->getMapInfo()->mapHeader.get();
iconsMapSizes->setFrame(mapInfo->getMapSizeIconId());
const CMapHeader * header = mapInfo->mapHeader.get();
iconsVictoryCondition->setFrame(header->victoryIconIndex);
labelVictoryConditionText->setText(header->victoryMessage);
iconsLossCondition->setFrame(header->defeatIconIndex);
labelLossConditionText->setText(header->defeatMessage);
flagbox->recreate();
labelDifficulty->setText(CGI->generaltexth->arraytxt[142 + SEL->getMapInfo()->mapHeader->difficulty]);
labelDifficulty->setText(CGI->generaltexth->arraytxt[142 + mapInfo->mapHeader->difficulty]);
iconDifficulty->setSelected(SEL->getCurrentDifficulty());
const std::array<std::string, 5> difficultyPercent = {"80%", "100%", "130%", "160%", "200%"};
labelDifficultyPercent->setText(difficultyPercent[SEL->getCurrentDifficulty()]);

View File

@ -101,6 +101,7 @@ public:
std::shared_ptr<CToggleGroup> iconDifficulty;
InfoCard();
void disableLabelRedraws();
void changeSelection();
void toggleChat();
void setChat(bool activateChat);

View File

@ -102,13 +102,14 @@ CMultiLineLabel::CMultiLineLabel(Rect position, EFonts Font, EAlignment Align, c
{
pos.w = position.w;
pos.h = position.h;
splitText(Text);
splitText(Text, true);
}
void CMultiLineLabel::setVisibleSize(Rect visibleSize)
void CMultiLineLabel::setVisibleSize(Rect visibleSize, bool redrawElement)
{
this->visibleSize = visibleSize;
redraw();
if(redrawElement)
redraw();
}
void CMultiLineLabel::scrollTextBy(int distance)
@ -116,16 +117,16 @@ void CMultiLineLabel::scrollTextBy(int distance)
scrollTextTo(visibleSize.y + distance);
}
void CMultiLineLabel::scrollTextTo(int distance)
void CMultiLineLabel::scrollTextTo(int distance, bool redrawAfterScroll)
{
Rect size = visibleSize;
size.y = distance;
setVisibleSize(size);
setVisibleSize(size, redrawAfterScroll);
}
void CMultiLineLabel::setText(const std::string &Txt)
{
splitText(Txt);
splitText(Txt, false); //setText used below can handle redraw
CLabel::setText(Txt);
}
@ -221,7 +222,7 @@ void CMultiLineLabel::showAll(SDL_Surface * to)
}
}
void CMultiLineLabel::splitText(const std::string &Txt)
void CMultiLineLabel::splitText(const std::string &Txt, bool redrawAfter)
{
lines.clear();
@ -234,7 +235,8 @@ void CMultiLineLabel::splitText(const std::string &Txt)
textSize.x = 0;
for(const std::string &line : lines)
vstd::amax( textSize.x, f->getStringWidth(line.c_str()));
redraw();
if(redrawAfter)
redraw();
}
Rect CMultiLineLabel::getTextLocation()

View File

@ -80,7 +80,7 @@ class CMultiLineLabel : public CLabel
// area of text that actually will be printed, default is widget size
Rect visibleSize;
void splitText(const std::string &Txt);
void splitText(const std::string &Txt, bool redrawAfter);
Rect getTextLocation();
public:
// total size of text, x = longest line of text, y = total height of lines
@ -91,9 +91,9 @@ public:
void setText(const std::string &Txt) override;
void showAll(SDL_Surface * to) override;
void setVisibleSize(Rect visibleSize);
void setVisibleSize(Rect visibleSize, bool redrawElement = true);
// scrolls text visible in widget. Positive value will move text up
void scrollTextTo(int distance);
void scrollTextTo(int distance, bool redrawAfterScroll = true);
void scrollTextBy(int distance);
};