-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathVersionOverlay.cpp
More file actions
101 lines (96 loc) · 3.64 KB
/
Copy pathVersionOverlay.cpp
File metadata and controls
101 lines (96 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* This file is part of PKSM
* Copyright (C) 2016-2022 Bernardo Giordano, Admiral Fish, piepie62
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "VersionOverlay.hpp"
#include "Configuration.hpp"
#include "gui.hpp"
#include "i18n_ext.hpp"
#include "pkx/PKX.hpp"
#include <algorithm>
VersionOverlay::VersionOverlay(ReplaceableScreen& screen, pksm::PKX& pkm)
: ReplaceableScreen(&screen), pkm(pkm), hid(15, 2)
{
const auto& gameStrings = i18n::rawGames(Configuration::getInstance().language());
for (size_t i = 0; i < gameStrings.size(); i++)
{
if (!gameStrings[i].empty())
{
games.emplace_back(pksm::GameVersion(i), gameStrings[i]);
}
}
hid.update(games.size());
hid.select(std::distance(
games.begin(), std::find_if(games.begin(), games.end(),
[&pkm](const std::pair<pksm::GameVersion, const std::string&>& pair)
{ return pair.first == pkm.version(); })));
}
void VersionOverlay::drawBottom() const
{
dim();
Gui::text(i18n::localize("EDITOR_INST"), 160, 115, FONT_SIZE_18, COLOR_WHITE, TextPosX::CENTER,
TextPosY::TOP);
}
void VersionOverlay::drawTop() const
{
Gui::sprite(ui_sheet_part_editor_10x2_idx, 0, 0);
int x = hid.index() < hid.maxVisibleEntries() / 2 ? 2 : 200;
int y = (hid.index() % (hid.maxVisibleEntries() / 2)) * 24;
Gui::drawSolidRect(x, y, 198, 23, COLOR_MASKBLACK);
Gui::drawSolidRect(x, y, 198, 1, COLOR_YELLOW);
Gui::drawSolidRect(x, y, 1, 23, COLOR_YELLOW);
Gui::drawSolidRect(x, y + 22, 198, 1, COLOR_YELLOW);
Gui::drawSolidRect(x + 197, y, 1, 23, COLOR_YELLOW);
for (size_t i = 0; i < hid.maxVisibleEntries(); i++)
{
x = i < hid.maxVisibleEntries() / 2 ? 4 : 203;
if (hid.page() * hid.maxVisibleEntries() + i < games.size())
{
Gui::text(std::to_string((int)games[hid.page() * hid.maxVisibleEntries() + i].first) +
" - " + games[hid.page() * hid.maxVisibleEntries() + i].second,
x, (i % (hid.maxVisibleEntries() / 2)) * 24, FONT_SIZE_18, COLOR_WHITE,
TextPosX::LEFT, TextPosY::TOP);
}
else
{
break;
}
}
}
void VersionOverlay::update(touchPosition* touch)
{
hid.update(games.size());
u32 downKeys = hidKeysDown();
if (downKeys & KEY_A)
{
pkm.version(games[hid.fullIndex()].first);
parent->removeOverlay();
return;
}
else if (downKeys & KEY_B)
{
parent->removeOverlay();
return;
}
}