13#include "absl/strings/str_cat.h"
16#include "extras/IconsFontAwesome6.h"
23void SliderPercent(
const char* label,
float& value) {
24 int percent =
static_cast<int>(std::lround(value * 100.0f));
27 if (ImGui::SliderInt(label, &percent, 0, 100,
"%d%%",
28 ImGuiSliderFlags_AlwaysClamp)) {
29 value =
static_cast<float>(percent) / 100.0f;
35constexpr std::array<std::pair<const char*, const char*>, 21> kKeys = {{
36 {
N_(
"W A S D, or the arrows"),
N_(
"Walk")},
37 {
N_(
"Shift"),
N_(
"Run")},
38 {
N_(
"Space"),
N_(
"Swing what you hold")},
39 {
N_(
"1 to 9, and with Shift"),
N_(
"The hotbar's two rows of skills")},
40 {
N_(
"Click a monster"),
N_(
"Pick it, to fight")},
41 {
N_(
"Double-click the ground"),
N_(
"Walk there")},
42 {
N_(
"Click someone"),
N_(
"Talk, learn or take a quest")},
43 {
N_(
"Q and E, or hold the right button"),
N_(
"Turn the camera")},
44 {
N_(
"Mouse wheel"),
N_(
"Zoom in and out")},
46 {
"C",
N_(
"Your character")},
47 {
"I",
N_(
"Your bag")},
48 {
"T",
N_(
"Your quests")},
49 {
"G",
N_(
"Your guild")},
50 {
"K",
N_(
"Crafting")},
52 {
"O",
N_(
"Settings")},
53 {
N_(
"Enter"),
N_(
"Chat")},
54 {
N_(
"Enter, then /g and a space"),
N_(
"Talk to your guild")},
55 {
N_(
"Escape"),
N_(
"Close what's open, or this menu")},
56 {
N_(
"Drag an item out of the bag"),
N_(
"Throw it away")},
61constexpr float kRound = 23.0f;
62constexpr float kRimRoom = 4.0f;
66bool BarButton(
const char*
id,
const char* icon,
bool on,
const char* tip) {
67 const float radius =
Ui(kRound);
69 ImGui::InvisibleButton(
id, {radius * 2.0f, radius * 2.0f});
70 const bool hovered = ImGui::IsItemHovered();
71 const ImVec2 min = ImGui::GetItemRectMin();
72 DrawRoundButton(ImGui::GetWindowDrawList(), {min.x + radius, min.y + radius},
73 radius, icon, hovered, on);
75 ImGui::SetTooltip(
"%s",
Tr(tip));
83 if (ImGui::BeginTable(
"Keys", 2, ImGuiTableFlags_RowBg)) {
84 for (
const auto& [key, does] : kKeys) {
85 ImGui::TableNextRow();
86 ImGui::TableNextColumn();
87 ImGui::PushFont(
GetFonts().bold, 0.0f);
88 ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(
colors::kGold),
"%s",
91 ImGui::TableNextColumn();
92 ImGui::TextUnformatted(
Tr(does));
102 ImGui::GetBackgroundDrawList()->AddRectFilled(
103 {0.0f, 0.0f}, ImGui::GetIO().DisplaySize,
Faded(IM_COL32_BLACK, 0.45f));
104 const ImVec2 display = ImGui::GetIO().DisplaySize;
105 ImGui::SetNextWindowPos({display.x / 2.0f, display.y * 0.45f},
106 ImGuiCond_Always, {0.5f, 0.5f});
107 ImGui::SetNextWindowSize({
Ui(300.0f), 0.0f});
109 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |
110 ImGuiWindowFlags_NoSavedSettings);
111 const ImVec2 button{-1.0f,
Ui(40.0f)};
112 if (
GameButton(
"Back to the game", button,
true)) {
130 BuildSettings(settings, reset_hotbar);
135void Menu::BuildSettings(
Settings& settings,
bool* reset_hotbar) {
136 const ImVec2 display = ImGui::GetIO().DisplaySize;
137 ImGui::SetNextWindowPos({display.x / 2.0f, display.y / 2.0f},
138 ImGuiCond_Appearing, {0.5f, 0.5f});
139 ImGui::SetNextWindowSize(
Ui(ImVec2{700.0f, 470.0f}));
141 ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings);
150 constexpr std::array<Tab, 4> kPages = {{
151 {Page::kInterface, ICON_FA_TABLE_COLUMNS,
N_(
"Interface")},
152 {Page::kSound, ICON_FA_VOLUME_HIGH,
N_(
"Sound")},
153 {Page::kGraphics, ICON_FA_DISPLAY,
N_(
"Graphics")},
154 {Page::kKeys, ICON_FA_KEYBOARD,
N_(
"Keys")},
156 ImGui::BeginChild(
"Pages", {
Ui(170.0f), 0.0f});
157 for (
const auto& [page, icon, name] : kPages) {
158 ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, {0.0f, 0.5f});
159 const std::string label = absl::StrCat(icon,
" ",
Tr(name),
"###", name);
160 if (ImGui::Selectable(label.c_str(), page_ == page, 0, {0.0f, Ui(34.0f)})) {
163 ImGui::PopStyleVar();
166 ImGui::SameLine(0.0f,
Ui(16.0f));
167 ImGui::BeginChild(
"Page");
168 ImGui::PushItemWidth(
Ui(260.0f));
170 case Page::kInterface: {
171 ImGui::SeparatorText(
Tr(
"Interface"));
175 if (ImGui::BeginCombo(
TrLabel(
"Language"),
180 if (ImGui::Selectable(language.name,
187 if (!ImGui::IsAnyItemActive() || scale_ == 0.0f) {
190 int percent =
static_cast<int>(std::lround(scale_ * 100.0f));
191 if (ImGui::SliderInt(
TrLabel(
"Size"), &percent, 75, 150,
"%d%%",
192 ImGuiSliderFlags_AlwaysClamp)) {
193 scale_ =
static_cast<float>(percent) / 100.0f;
195 if (ImGui::IsItemDeactivatedAfterEdit()) {
199 "%s",
Tr(
"On top of its size for your screen, which grows with it."));
202 ImGui::BeginDisabled(!settings.
ui.
minimap);
203 ImGui::Checkbox(
TrLabel(
"Turn the minimap with the camera"),
205 ImGui::EndDisabled();
207 if (
GameButton(
"Put the hotbar back in order", {0.0f, 0.0f})) {
209 *reset_hotbar =
true;
211 ImGui::TextDisabled(
"%s",
Tr(
"Drag a skill onto another to swap them."));
214 ImGui::SeparatorText(
Tr(
"Names over heads"));
216 "%s",
Tr(
"Each shows while you point at it, or it's picked."));
217 ImGui::TextDisabled(
"%s",
Tr(
"Always show them over:"));
219 ImGui::Checkbox(
TrLabel(
"Monsters"), &plates.monsters);
220 ImGui::SameLine(
Ui(150.0f));
221 ImGui::Checkbox(
TrLabel(
"Other players"), &plates.players);
222 ImGui::Checkbox(
TrLabel(
"NPCs"), &plates.npcs);
223 ImGui::SameLine(
Ui(150.0f));
224 ImGui::Checkbox(
TrLabel(
"You"), &plates.yours);
225 ImGui::TextDisabled(
"%s",
Tr(
"With them:"));
226 ImGui::Checkbox(
TrLabel(
"Health"), &plates.health);
227 ImGui::SameLine(
Ui(150.0f));
228 ImGui::Checkbox(
TrLabel(
"Levels"), &plates.levels);
229 ImGui::Checkbox(
TrLabel(
"Guilds"), &plates.guilds);
233 ImGui::SeparatorText(
Tr(
"Sound"));
241 Tr(
"\"Background Music\" by Pavel Bekirov, from Pixabay"));
243 case Page::kGraphics:
244 ImGui::SeparatorText(
Tr(
"Graphics"));
248 ImGui::SeparatorText(
249 absl::StrCat(ICON_FA_CLOUD_SUN
" ",
Tr(
"Sky")).c_str());
254 ImGui::SeparatorText(
Tr(
"Keys"));
258 ImGui::PopItemWidth();
264 bool* map,
bool* help) {
265 const ImVec2 display = ImGui::GetIO().DisplaySize;
268 const float room =
Ui(kRimRoom);
269 ImGui::SetNextWindowPos(
270 {display.x -
Ui(18.0f) + room, display.y -
Ui(18.0f) + room},
271 ImGuiCond_Always, {1.0f, 1.0f});
272 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {room, room});
273 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,
Ui(ImVec2{10.0f, 10.0f}));
274 ImGui::Begin(
"Buttons",
nullptr,
275 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
276 ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoNav |
277 ImGuiWindowFlags_AlwaysAutoResize |
278 ImGuiWindowFlags_NoFocusOnAppearing |
279 ImGuiWindowFlags_NoSavedSettings);
280 if (BarButton(
"##character", ICON_FA_USER, *character,
"Character (C)")) {
281 *character = !*character;
284 if (BarButton(
"##bag", ICON_FA_BAG_SHOPPING, *bag,
"Bag (I)")) {
288 if (BarButton(
"##quests", ICON_FA_SCROLL, *quests,
"Quests (T)")) {
292 if (BarButton(
"##guild", ICON_FA_SHIELD_HALVED, *guild,
"Guild (G)")) {
296 if (BarButton(
"##map", ICON_FA_MAP, *map,
"Map (M)")) {
300 if (BarButton(
"##help", ICON_FA_CIRCLE_QUESTION, *help,
"Help (H)")) {
304 if (BarButton(
"##menu", ICON_FA_BARS, open_ || settings_,
"Menu (Escape)")) {
308 ImGui::PopStyleVar(2);
constexpr const char * N_(const char *text)
bool BeginPanel(const char *name, bool *open, ImGuiWindowFlags flags, float alpha)
constexpr std::array< Language, 3 > kLanguages
const char * Tr(const char *text)
void DrawRoundButton(ImDrawList *draw, ImVec2 centre, float radius, const char *icon, bool hovered, bool on)
const char * TrLabel(const char *label)
ImU32 Faded(ImU32 color, float share)
The same colour, with its alpha times the share.
bool GameButton(const char *label, ImVec2 size, bool primary, bool enabled)
bool antialias
Smooths the world's edges, with FXAA.
std::vector< uint32_t > hotbar
NameplateSettings nameplates
What the player sets, which the client keeps between runs.
GraphicsSettings graphics
float effects
The sound effects, apart from the music.
float master
Where the sliders are, from nothing to full.