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

rmb; bugfix; tabs

This commit is contained in:
Laserlicht 2023-09-23 14:51:39 +02:00 committed by GitHub
parent d2398b804a
commit e3edcb6cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 289 additions and 260 deletions

View File

@ -600,6 +600,8 @@ void CServerHandler::startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameSta
CMM->disable();
client = new CClient();
calc = nullptr;
switch(si->mode)
{
case StartInfo::NEW_GAME:
@ -674,8 +676,11 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
std::shared_ptr<CampaignState> ourCampaign = cs;
if (!cs)
{
ourCampaign = si->campState;
if(calc == nullptr)
{
calc = std::make_shared<HighScoreCalculation>();
calc->isCampaign = true;
calc->parameters.clear();
}

View File

@ -91,6 +91,8 @@ CreatureID HighScoreCalculation::getCreatureForPoints(int points, bool campaign)
CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted)
: CWindowObject(BORDERED), highscorepage(highscorepage), highlighted(highlighted)
{
addUsedEvents(SHOW_POPUP);
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
pos = center(Rect(0, 0, 800, 600));
updateShadow();
@ -99,6 +101,20 @@ CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted)
addButtons();
}
void CHighScoreScreen::showPopupWindow(const Point & cursorPosition)
{
for (int i = 0; i < 11; i++)
{
Rect r = Rect(80, 40 + i * 50, 635, 50);
if(r.isInside(cursorPosition - pos))
{
std::string tmp = persistentStorage["highscore"][highscorepage == HighScorePage::SCENARIO ? "scenario" : "campaign"][std::to_string(i)]["datetime"].String();
if(!tmp.empty())
CRClickPopup::createAndPush(tmp);
}
}
}
void CHighScoreScreen::addButtons()
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
@ -165,6 +181,7 @@ void CHighScoreScreen::addHighScores()
texts.push_back(std::make_shared<CLabel>(590, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["points"].Integer())));
}
if(curData["points"].Integer() > 0)
images.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("CPRSMALL"), (*CGI->creh)[HighScoreCalculation::getCreatureForPoints(curData["points"].Integer(), highscorepage == HighScorePage::CAMPAIGN)]->getIconIndex(), 0, 670, y - 15 + i * 50));
}
}
@ -238,18 +255,21 @@ CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc
video = won ? "HSANIM.SMK" : "LOSEGAME.SMK";
}
void CHighScoreInputScreen::addEntry(std::string text) {
int CHighScoreInputScreen::addEntry(std::string text) {
for (int i = 0; i < 11; i++)
{
if(calc.calculate().cheater)
i = 10;
JsonNode node = persistentStorage["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(i)];
if(node["points"].isNull() || node["points"].Integer() <= calc.calculate().total)
{
// move following entries down
for (int j = 10; j > i; j--)
for (int j = 10; j + 1 >= i; j--)
{
JsonNode node = persistentStorage["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(j)];
Settings entry = persistentStorage.write["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(j + 1)];
JsonNode node = persistentStorage["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(j - 1)];
Settings entry = persistentStorage.write["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(j)];
entry->Struct() = node.Struct();
}
@ -258,24 +278,26 @@ void CHighScoreInputScreen::addEntry(std::string text) {
if(calc.isCampaign)
{
Settings entry2 = persistentStorage.write["highscore"]["campaign"][std::to_string(i)]["campaign"];
entry2->String() = calc.parameters[0].campaign;
entry2->String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].campaign;
}
else
{
Settings entry3 = persistentStorage.write["highscore"]["scenario"][std::to_string(i)]["land"];
entry3->String() = calc.parameters[0].land;
entry3->String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].land;
}
Settings entry4 = persistentStorage.write["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(i)]["days"];
entry4->Integer() = calc.calculate().sumDays;
Settings entry5 = persistentStorage.write["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(i)]["points"];
entry5->Integer() = calc.calculate().total;
entry5->Integer() = calc.calculate().cheater ? 0 : calc.calculate().total;
Settings entry6 = persistentStorage.write["highscore"][calc.isCampaign ? "campaign" : "scenario"][std::to_string(i)]["datetime"];
entry6->String() = vstd::getFormattedDateTime(std::time(0));
return;
return i;
}
}
return -1;
}
void CHighScoreInputScreen::show(Canvas & to)
@ -326,9 +348,9 @@ void CHighScoreInputScreen::clickPressed(const Point & cursorPosition)
{
if(!text.empty())
{
addEntry(text);
int pos = addEntry(text);
close();
GH.windows().createAndPushWindow<CHighScoreScreen>(calc.isCampaign ? CHighScoreScreen::HighScorePage::CAMPAIGN : CHighScoreScreen::HighScorePage::SCENARIO);
GH.windows().createAndPushWindow<CHighScoreScreen>(calc.isCampaign ? CHighScoreScreen::HighScorePage::CAMPAIGN : CHighScoreScreen::HighScorePage::SCENARIO, pos);
}
else
close();

View File

@ -53,6 +53,8 @@ private:
void buttonResetClick();
void buttonExitClick();
void showPopupWindow(const Point & cursorPosition) override;
HighScorePage highscorepage;
std::shared_ptr<CPicture> background;
@ -93,7 +95,7 @@ class CHighScoreInputScreen : public CWindowObject
public:
CHighScoreInputScreen(bool won, HighScoreCalculation calc);
void addEntry(std::string text);
int addEntry(std::string text);
void show(Canvas & to) override;
void activate() override;