Skip to content

Commit 8c284d1

Browse files
cgytrusmatcool
andauthored
more run info features (#29)
* decimal places * show in percentage * show in progress bar --------- Co-authored-by: matcool <[email protected]>
1 parent ff8adf5 commit 8c284d1

File tree

3 files changed

+79
-20
lines changed

3 files changed

+79
-20
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches:
7-
- "main"
7+
- "**"
88

99
jobs:
1010
build:
@@ -58,4 +58,3 @@ jobs:
5858
with:
5959
name: Build Output
6060
path: ${{ steps.build.outputs.build-output }}
61-

run-info/main.cpp

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
#include <Geode/modify/PlayLayer.hpp>
33
#include <nodes.hpp>
44
#include <fmt/core.h>
5-
#include <string_view>
5+
#include <array>
66

77
using namespace geode::prelude;
88

9+
constexpr float truncate(float x, int precision) {
10+
constexpr std::array powers { 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f };
11+
return std::floorf(x * powers[precision]) / powers[precision];
12+
}
13+
914
class RunInfoWidget : public CCNodeRGBA {
1015
public:
1116
CCLabelBMFont* m_status_label = nullptr;
@@ -141,13 +146,9 @@ class RunInfoWidget : public CCNodeRGBA {
141146
m_was_practice = false;
142147
}
143148

144-
bool decimal = Mod::get()->getSettingValue<bool>("use-decimal");
145-
146-
if (decimal) {
147-
m_info_label->setString(fmt::format("From {:.2f}%", percent).c_str());
148-
} else {
149-
m_info_label->setString(fmt::format("From {}%", int(percent)).c_str());
150-
}
149+
int decimal = Mod::get()->getSettingValue<int>("decimal-places");
150+
percent = truncate(percent, decimal);
151+
m_info_label->setString(fmt::format("From {1:.{0}f}%", decimal, percent).c_str());
151152

152153
m_top_layout->updateLayout();
153154
this->updateLayout();
@@ -159,13 +160,18 @@ class $modify(PlayLayer) {
159160
struct Fields {
160161
RunInfoWidget* m_widget = nullptr;
161162
float m_initial_percent = 0;
163+
bool m_show_in_percentage = false;
164+
bool m_show_in_progress_bar = false;
162165
};
163166

164167
bool init(GJGameLevel* level, bool unk1, bool unk2) {
165168
if (!PlayLayer::init(level, unk1, unk2)) return false;
166169

167170
if (!Mod::get()->getSettingValue<bool>("enabled")) return true;
168171

172+
m_fields->m_show_in_percentage = Mod::get()->getSettingValue<bool>("show-in-percentage");
173+
m_fields->m_show_in_progress_bar = Mod::get()->getSettingValue<bool>("show-in-progress-bar");
174+
169175
// removes the testmode label gd creates
170176
if (this->getChildrenCount()) {
171177
CCArrayExt<CCNode*> children = this->getChildren();
@@ -197,6 +203,12 @@ class $modify(PlayLayer) {
197203
return true;
198204
}
199205

206+
void update_labels() {
207+
if (!m_fields->m_widget || !Mod::get()->getSettingValue<bool>("enabled")) return;
208+
m_fields->m_widget->update_labels(this, m_fields->m_initial_percent);
209+
m_fields->m_widget->setVisible(m_isPracticeMode || m_isTestMode);
210+
}
211+
200212
void update_position() {
201213
auto const position = Mod::get()->getSettingValue<std::string>("position");
202214
this->update_position(
@@ -242,10 +254,29 @@ class $modify(PlayLayer) {
242254
this->update_position();
243255
}
244256

245-
void update_labels() {
246-
if (!m_fields->m_widget || !Mod::get()->getSettingValue<bool>("enabled")) return;
247-
m_fields->m_widget->update_labels(this, m_fields->m_initial_percent);
248-
m_fields->m_widget->setVisible(m_isPracticeMode || m_isTestMode);
257+
void updateProgressbar() {
258+
PlayLayer::updateProgressbar();
259+
260+
if (m_isPlatformer) return;
261+
if (!(m_isPracticeMode || m_isTestMode)) return;
262+
if (!Mod::get()->getSettingValue<bool>("enabled")) return;
263+
264+
auto from = m_fields->m_initial_percent;
265+
auto to = this->getCurrentPercent();
266+
267+
if (m_percentageLabel && m_fields->m_show_in_percentage) {
268+
int decimal = Mod::get()->getSettingValue<int>("decimal-places");
269+
auto from_trunc = truncate(from, decimal);
270+
auto to_trunc = truncate(to, decimal);
271+
m_percentageLabel->setString(fmt::format("{1:.{0}f}-{2:.{0}f}%", decimal, from_trunc, to_trunc).c_str());
272+
}
273+
274+
if (m_progressFill && m_fields->m_show_in_progress_bar) {
275+
float x = from / 100.0f * m_progressWidth;
276+
float width = (to - from) / 100.0f * m_progressWidth;
277+
m_progressFill->setTextureRect({ x, 0.0f, width, m_progressHeight });
278+
m_progressFill->setPositionX(2.0f + x);
279+
}
249280
}
250281
};
251282

@@ -262,4 +293,12 @@ class $modify(PlayLayer) {
262293

263294
Mod::get()->setSettingValue<std::string>("position", top ? (left ? "Top Left" : "Top Right") : (left ? "Bottom Left" : "Bottom Right"));
264295
}
265-
}
296+
if (container.contains("use-decimal")) {
297+
auto use_decimal = container["use-decimal"].asBool().unwrapOr(false);
298+
log::debug("Migrating from old settings: use-decimal={}", use_decimal);
299+
300+
container.erase("use-decimal");
301+
302+
Mod::get()->setSettingValue<int>("decimal-places", use_decimal ? 2 : 0);
303+
}
304+
}

run-info/mod.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"mac": "2.2074",
77
"ios": "2.2074"
88
},
9-
"version": "2.0.1",
9+
"version": "2.1.0",
1010
"id": "mat.run-info",
1111
"name": "Run Info",
1212
"developer": "mat",
@@ -18,11 +18,20 @@
1818
"default": true,
1919
"description": "Enable the mod"
2020
},
21-
"use-decimal": {
21+
"decimal-places": {
2222
"name": "Percentage decimals",
23-
"type": "bool",
24-
"default": false,
25-
"description": "Use decimal percentage for level progress"
23+
"description": "Amount of decimal places used for level progress percentage",
24+
"type": "int",
25+
"default": 0,
26+
"min": 0,
27+
"max": 4,
28+
"control": {
29+
"arrows": true,
30+
"arrow-step": 1,
31+
"big-arrows": false,
32+
"slider": false,
33+
"input": false
34+
}
2635
},
2736
"position": {
2837
"name": "Position",
@@ -58,6 +67,18 @@
5867
"default": true,
5968
"description": "Shows from which % the current run is from"
6069
},
70+
"show-in-percentage": {
71+
"name": "Show in percentage",
72+
"type": "bool",
73+
"default": false,
74+
"description": "Shows the current run in the main \"x%\" text at the top, e.g. \"3-57%\""
75+
},
76+
"show-in-progress-bar": {
77+
"name": "Show in progress bar",
78+
"type": "bool",
79+
"default": false,
80+
"description": "Shows the starting % of the current run in the progress bar"
81+
},
6182
"use-start-pos": {
6283
"name": "Use startpos icon",
6384
"type": "bool",

0 commit comments

Comments
 (0)