Skip to content

Commit

Permalink
Add Stunt/Platform settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanawy committed Jan 2, 2025
1 parent 6c248ac commit 83addc3
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Available data for each run:
- PB improvment _(if PB was beaten by run)_
- No respawn time _(if different from normal time)_

### Contribuutors
### Contributors
[FortTM](https://github.com/Fort-TM)

### Feedback:
Expand Down
2 changes: 1 addition & 1 deletion info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "Run History"
author = "Vanawy"
category = "Overlay"
version = "0.7.1"
version = "0.8.0"

[script]
dependencies = ["MLHook", "MLFeedRaceData"]
Expand Down
8 changes: 7 additions & 1 deletion src/consts.as
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ const string COLOR_WARRIOR = "\\$3cf";
const string COLOR_NO_MEDAL = "\\$555";

// other
const uint MAX_CUSTOM_MEDAL_UPDATE_ATTEMPTS_PER_MAP = 3;
const uint MAX_CUSTOM_MEDAL_UPDATE_ATTEMPTS_PER_MAP = 3;

// game modes
const string GAME_MODE_NONE = "";
const string GAME_MODE_RACE = "TrackMania\\TM_Race";
const string GAME_MODE_PLATFORM = "TrackMania\\TM_Platform";
const string GAME_MODE_STUNT = "TrackMania\\TM_Stunt";
50 changes: 25 additions & 25 deletions src/history_table.as
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class HistoryTable
// uint numCols = 6;

uint numCols =
(settingColumnShowRunId ? 1 : 0)
+ (settingColumnShowMedal ? 1 : 0)
+ (settingColumnShowTime ? 1 : 0)
+ (settingColumnShowDelta ? 1 : 0)
+ (settingColumnShowPBImprovment ? 1 : 0)
+ (settingColumnShowNoRespawnTime ? 1 : 0)
+ (settingColumnShowRespawns ? 1 : 0)
+ (settingColumnShowGrindTime ? 1 : 0)
(TableColumns::ShowRunId() ? 1 : 0)
+ (TableColumns::ShowMedal() ? 1 : 0)
+ (TableColumns::ShowTime() ? 1 : 0)
+ (TableColumns::ShowDelta() ? 1 : 0)
+ (TableColumns::ShowPBImprovment() ? 1 : 0)
+ (TableColumns::ShowNoRespawnTime() ? 1 : 0)
+ (TableColumns::ShowRespawns() ? 1 : 0)
+ (TableColumns::ShowGrindTime() ? 1 : 0)
;

if (numCols < 1) {
Expand Down Expand Up @@ -122,89 +122,89 @@ class HistoryTable
icon = Icons::Spinner;
formattedTime = "-:--.---";
}
if (settingColumnShowRunId) {
if (TableColumns::ShowRunId()) {
UI::TableNextColumn();
UI::Text(icon);
}
if (settingColumnShowMedal) {
if (TableColumns::ShowMedal()) {
UI::TableNextColumn();
if (settingColumnShowRunId) {
if (TableColumns::ShowRunId()) {
UI::Text(ICON_MEDAL);
} else {
UI::Text(icon);
}
}
if (settingColumnShowTime) {
if (TableColumns::ShowTime()) {
UI::TableNextColumn();
UI::Text(formattedTime);
}
if (settingColumnShowDelta) {
if (TableColumns::ShowDelta()) {
UI::TableNextColumn();
UI::Text(Icons::Flag);
}
if (settingColumnShowPBImprovment) {
if (TableColumns::ShowPBImprovment()) {
UI::TableNextColumn();
UI::Text(COLOR_PB + Icons::ChevronUp);
}
if (settingColumnShowNoRespawnTime) {
if (TableColumns::ShowNoRespawnTime()) {
UI::TableNextColumn();
UI::Text(ICON_NORESPAWN);
}
if (settingColumnShowRespawns) {
if (TableColumns::ShowRespawns()) {
UI::TableNextColumn();
UI::Text(ICON_RESPAWN);
}
if (settingColumnShowGrindTime) {
if (TableColumns::ShowGrindTime()) {
UI::TableNextColumn();
UI::Text(ICON_GRIND_TIME);
}
}

void RenderRun(Run@ run)
{
if (settingColumnShowRunId) {
if (TableColumns::ShowRunId()) {
UI::TableNextColumn();
if (run.id > 0) {
UI::Text("" + run.id);
}
}
if (settingColumnShowMedal) {
if (TableColumns::ShowMedal()) {
UI::TableNextColumn();
if (run.beaten !is null) {
UI::Text(run.beaten.coloredIcon());
} else {
UI::Text(COLOR_NO_MEDAL + ICON_NO_MEDAL);
}
}
if (settingColumnShowTime) {
if (TableColumns::ShowTime()) {
UI::TableNextColumn();
if (run.isDNF) {
UI::Text("DNF");
} else {
UI::Text("\\$fff" + Time::Format(run.time));
}
}
if (settingColumnShowDelta) {
if (TableColumns::ShowDelta()) {
UI::TableNextColumn();
run.DrawDelta();
}
if (settingColumnShowPBImprovment) {
if (TableColumns::ShowPBImprovment()) {
UI::TableNextColumn();
run.DrawPBImprovment();
}
if (settingColumnShowNoRespawnTime) {
if (TableColumns::ShowNoRespawnTime()) {
UI::TableNextColumn();
if (run.noRespawnTime > 0) {
UI::Text(run.noRespawn.color + Time::Format(run.noRespawnTime));
}
}
if (settingColumnShowRespawns) {
if (TableColumns::ShowRespawns()) {
UI::TableNextColumn();
if (run.respawns > 0) {
UI::Text("" + run.respawns);
}
}
if (settingColumnShowGrindTime) {
if (TableColumns::ShowGrindTime()) {
UI::TableNextColumn();
if (!run.isDNF) {
auto formatted = Time::Format(run.grindTime);
Expand Down
28 changes: 27 additions & 1 deletion src/main.as
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ enum DefaultTargetMedalOptions {
bronze,
}

enum GameMode {
Race,
Platform,
Stunt,
Unknown,
}


Target@ currentTarget = null;
Thresholds::Table thresholdsTable = Thresholds::Table();
Expand Down Expand Up @@ -48,11 +55,12 @@ uint64 grind_time_start = Time::Now;

DnfHandler dnf_handler = DnfHandler();

GameMode global_active_game_mode = GameMode::Unknown;

void Main()
{

string lastMapId = "";
string lastGhostId = "";
CTrackMania@ trackmania = cast<CTrackMania>(GetApp());
bool newRun = true;

Expand Down Expand Up @@ -137,6 +145,14 @@ void Render()
if (settingWindowHideWithOverlay && !UI::IsOverlayShown()) {
return;
}

if (global_active_game_mode == GameMode::Platform && !setting_show_in_platform) {
return;
}

if (global_active_game_mode == GameMode::Stunt && !setting_show_in_stunt) {
return;
}

if(is_window_visible) {
if(settingWindowLockPosition) {
Expand Down Expand Up @@ -481,6 +497,16 @@ void OnMapChange(CGameCtnChallenge@ map)
pb.time = 0;

grind_time_start = Time::Now;

if (map.MapInfo.MapType == GAME_MODE_RACE) {
global_active_game_mode = GameMode::Race;
} else if (map.MapInfo.MapType == GAME_MODE_PLATFORM) {
global_active_game_mode = GameMode::Platform;
} else if (map.MapInfo.MapType == GAME_MODE_STUNT) {
global_active_game_mode = GameMode::Stunt;
} else {
global_active_game_mode = GameMode::Unknown;
}

auto trackmania = cast<CTrackMania@>(GetApp());
auto network = trackmania.Network;
Expand Down
48 changes: 42 additions & 6 deletions src/settings.as
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ DefaultTargetMedalOptions settingDefaultTarget = DefaultTargetMedalOptions::clos
bool settingNewRunsFirst = false;


[Setting category="Display" name="Hide window"]
bool settingWindowHide = false;
[Setting category="Display" name="Hide with overlay"]
bool settingWindowHideWithOverlay = false;
[Setting category="Display" name="Window position"]
vec2 settingWindowAnchor = vec2(0, 170);
[Setting category="Display" name="Lock window position" description="Prevents the window moving when click and drag or when the game window changes size."]
bool settingWindowLockPosition = false;
[Setting category="Display" name="Hide with overlay"]
bool settingWindowHideWithOverlay = false;
[Setting category="Display" name="Hide window"]
bool settingWindowHide = false;
[Setting category="Display" name="Small action buttons"]
bool settingUseSmallButtons = true;
[Setting category="Display" name="Hide action buttons" description="Actions will stay accesible in Plugins tab in overlay"]
Expand Down Expand Up @@ -49,6 +49,42 @@ bool settingColumnShowGrindTime = false;

[Setting hidden]
string settingDeltasSerialized = DEFAULT_DELTAS;
[Setting hidden]
bool setting_show_in_stunt = false;
[Setting hidden]
bool setting_show_in_platform = true;
[Setting hidden]
bool setting_show_respawns_in_platform = true;

[SettingsTab name="Game Modes" icon="Gamepad"]
void RenderGameModesTab()
{
UI::BeginTabBar("GameModesTabBar");
if (UI::BeginTabItem("Platform")) {
setting_show_in_platform = UI::Checkbox("Show window", setting_show_in_platform);
WindowHiddenWarning();
setting_show_respawns_in_platform = UI::Checkbox("Force show Respawns column", setting_show_respawns_in_platform);
UI::EndTabItem();
}
if (UI::BeginTabItem("Stunt")) {
setting_show_in_stunt = UI::Checkbox("Show window", setting_show_in_stunt);
WindowHiddenWarning();
UI::EndTabItem();
}
if (UI::BeginTabItem("Race / Other")) {
UI::Text("All other modes uses settings from Display tab");
UI::EndTabItem();
}
UI::EndTabBar();
}

void WindowHiddenWarning() {
if (settingWindowHide) {
UI::PushStyleColor(UI::Col::Text, vec4(1, 0, 0, 1));
UI::Text("Window is hidden in Display tab. Setting above won't override it.");
UI::PopStyleColor();
}
}


[SettingsTab name="Feedback" icon="Bug"]
Expand All @@ -60,8 +96,8 @@ void RenderFeedbackTab()
if (UI::Button("GitHub " + Icons::Github)) {
OpenBrowserURL("https://github.com/Vanawy/tm-run-history/issues");
}
if (UI::Button("Twitter " + Icons::Twitter)) {
OpenBrowserURL("https://twitter.com/vanawy");
if (UI::Button("Bluesky " + Icons::Plane)) {
OpenBrowserURL("https://bsky.app/profile/vanawy.dev");
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/table_columns.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace TableColumns {
bool ShowRunId() {
return settingColumnShowRunId;
}
bool ShowMedal() {
return settingColumnShowMedal;
}
bool ShowTime() {
return settingColumnShowTime;
}
bool ShowDelta() {
return settingColumnShowDelta;
}
bool ShowPBImprovment() {
return settingColumnShowPBImprovment;
}
bool ShowNoRespawnTime() {
return settingColumnShowNoRespawnTime;
}
bool ShowRespawns() {
if (global_active_game_mode == GameMode::Platform) {
return setting_show_respawns_in_platform;
}
return settingColumnShowRespawns;
}
bool ShowGrindTime() {
return settingColumnShowGrindTime;
}
}

0 comments on commit 83addc3

Please sign in to comment.