Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in-game log #359

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ copy tool\minimap.re build\practice-windows
copy tool\mapeditor.re build\practice-windows
copy tool\world_options.re build\practice-windows
copy tool\player.re build\practice-windows
copy tool\log.re build\practice-windows
echo Converting lf to crlf
call :convert main.re
call :convert prelude.re
Expand All @@ -53,6 +54,7 @@ call :convert minimap.re
call :convert mapeditor.re
call :convert world_options.re
call :convert player.re
call :convert log.re

echo Don't forget to create a zip
exit /b 0
Expand Down
46 changes: 46 additions & 0 deletions tool/log.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
static mut LOG = Log {
messages: List::new(),
};

struct Log {
messages: List<LogMessage>,
}

struct LogMessage {
content: string,
added_timestamp: int,
}

fn log(content: string) {
let message = LogMessage {
content: content,
added_timestamp: current_time_millis(),
};
LOG.messages.push(message);
}

fn draw_log_messages() {
let mut messages = "";
let millis = current_time_millis();
let mut i = 0;
while i < LOG.messages.len() {
messages = f"{LOG.messages.get(i).unwrap().content}\n{messages}";
if (millis - LOG.messages.get(i).unwrap().added_timestamp) > SETTINGS.log_message_duration {
LOG.messages.remove(i);
} else {
i += 1;
}
}
// Tas::get_text_size ignores newlines (and every other escape sequence for that matter).
let text_size = Tas::get_text_size(messages, SETTINGS.ui_scale);
LukeSaward1 marked this conversation as resolved.
Show resolved Hide resolved
let line_height = text_size.height;
let viewport = Tas::get_viewport_size();
Tas::draw_text(DrawText {
text: messages,
color: COLOR_RED,
x: 10.,
y: viewport.height.to_float() - (line_height * LOG.messages.len().to_float()),
scale: SETTINGS.ui_scale,
scale_position: false,
});
}
2 changes: 2 additions & 0 deletions tool/main.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include "log.re";
include "settings.re";
include "keys.re";
include "component.re"
Expand Down Expand Up @@ -61,6 +62,7 @@ Platforms: {GAME_STATS.current_platforms} (Total: {GAME_STATS.total_platforms})
Resets: {GAME_STATS.total_resets} | Any%: {GAME_STATS.total_runs_completed} | 100%: {GAME_STATS.total_100_runs_completed} | All Platforms: {GAME_STATS.total_all_platforms_runs_completed} | All Cubes: {GAME_STATS.total_all_cubes_runs_completed} | Lowest #Platforms: {GAME_STATS.fewest_platform_run}";
}
start_menu_text.text = text;
draw_log_messages();
}),
selected: 0,
}
Expand Down
20 changes: 20 additions & 0 deletions tool/settings.re
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ fn create_settings_menu() -> Ui {
}
},
}),
UiElement::FloatInput(FloatInput {
label: Text { text: "Log Message Duration (s)" },
input: f"{SETTINGS.log_message_duration.to_float() / 1000.}",
onclick: fn(input: string) {},
onchange: fn(input: string) {
match input.parse_float() {
Result::Ok(val) => {
if 0.0 <= val {
let milliseconds = val * 1000.;
SETTINGS.log_message_duration = milliseconds.round(0).to_int();
SETTINGS.store();
}
},
Result::Err(e) => (),
}
},
}),
UiElement::Button(UiButton {
label: Text { text: "Reset Game Stats" },
onclick: fn(label: Text) { GAME_STATS.reset() },
Expand Down Expand Up @@ -125,6 +142,7 @@ struct Settings {
reticle_h: float,
reticle_scale: float,
reticle_scale_position: bool,
log_message_duration: int,
}
static mut SETTINGS = Settings::load();

Expand Down Expand Up @@ -208,6 +226,7 @@ impl Settings {
reticle_h: get_float("reticle_h", 6.),
reticle_scale: get_float("reticle_scale", 1.),
reticle_scale_position: get_bool("reticle_scale_position", false),
log_message_duration: get_int("log_message_duration", 10000),
}
}

Expand Down Expand Up @@ -249,6 +268,7 @@ impl Settings {
map.insert("reticle_h", f"{SETTINGS.reticle_h}");
map.insert("reticle_scale", f"{SETTINGS.reticle_scale}");
map.insert("reticle_scale_position", f"{SETTINGS.reticle_scale_position}");
map.insert("log_message_duration", f"{SETTINGS.log_message_duration}");
Tas::store_settings(map);
}

Expand Down
Loading