Skip to content

Commit 94b3894

Browse files
committed
🎉 add help section in editor menu
1 parent a75146d commit 94b3894

File tree

7 files changed

+257
-6
lines changed

7 files changed

+257
-6
lines changed

Cargo.lock

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TODO.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
- [ ] Animation system from multiple PNG files
66
- [ ] Rework the resource API to use futures to prevent use of unloaded resources
77
- [ ] In loader add a way to load a text resource
8-
- [ ] Add a help button to the editor menu with the options:
9-
- [ ] Open Manual
10-
- [ ] Open Github
11-
- [ ] About (opens a popup with the version and the commit hash)
128
- [ ] Aseprite support
139
- [ ] Load Aseprite files as images
1410
- [ ] Load Aseprite files as tilesets
@@ -72,6 +68,10 @@
7268

7369
# Done
7470

71+
- [x] Add a help button to the editor menu with the options:
72+
- [x] Open Manual
73+
- [x] Open Github
74+
- [x] About (opens a popup with the version and the commit hash)
7575
- [x] Add search in the resource window
7676
- [x] Allow opening the game folder in the resource window
7777
- [x] Lua performance helper:

editor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ name = "vecta"
2323
path = "src/main.rs"
2424

2525
[build-dependencies]
26+
chrono = "0.4.42"
2627
winresource = "0.1.23"
2728

2829
# https://rust-lang.github.io/rust-clippy/master/index.html

editor/build.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,71 @@
1-
use {std::env, winresource::WindowsResource};
1+
use {
2+
std::{env, fs, io::Write, path::Path},
3+
winresource::WindowsResource,
4+
};
5+
6+
fn get_commit_hash(cargo_manifest_dir: &Path) -> String {
7+
let output = std::process::Command::new("git")
8+
.args(["rev-parse", "HEAD"])
9+
.current_dir(cargo_manifest_dir)
10+
.output()
11+
.expect("Failed to get current commit hash");
12+
String::from_utf8_lossy(&output.stdout).trim().to_string()
13+
}
14+
15+
fn get_git_branch(cargo_manifest_dir: &Path) -> String {
16+
let output = std::process::Command::new("git")
17+
.args(["rev-parse", "--abbrev-ref", "HEAD"])
18+
.current_dir(cargo_manifest_dir)
19+
.output()
20+
.expect("Failed to get current branch");
21+
String::from_utf8_lossy(&output.stdout).trim().to_string()
22+
}
23+
24+
fn get_git_tag(cargo_manifest_dir: &Path) -> String {
25+
let output = std::process::Command::new("git")
26+
.args(["tag", "--points-at", "HEAD"])
27+
.current_dir(cargo_manifest_dir)
28+
.output()
29+
.expect("Failed to get current tag");
30+
String::from_utf8_lossy(&output.stdout).trim().to_string()
31+
}
232

333
fn main() {
434
if env::var_os("CARGO_CFG_TARGET_OS") == Some("windows".into()) {
535
let _ = WindowsResource::new()
636
.set_icon("../assets/icon.ico")
737
.compile();
838
}
39+
40+
// Generate build infos
41+
let dst = Path::new(&env::var("OUT_DIR").expect("OUT_DIR not set")).join("buildinfo.rs");
42+
let binding = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR");
43+
let cargo_manifest_dir = Path::new(&binding);
44+
let mut built_file = fs::File::create(&dst).expect("Failed to create buildinfo.rs");
45+
46+
let current_commit_hash = get_commit_hash(cargo_manifest_dir);
47+
let current_branch = get_git_branch(cargo_manifest_dir);
48+
let current_tag = get_git_tag(cargo_manifest_dir);
49+
50+
let build_timestamp = chrono::Utc::now().to_rfc2822();
51+
52+
// We are generating a file that will be imported by run main program.
53+
let _ = built_file.write_all(
54+
r"//
55+
// EVERYTHING BELOW THIS POINT WAS AUTO-GENERATED DURING COMPILATION. DO NOT MODIFY.
56+
//
57+
58+
"
59+
.as_ref(),
60+
);
61+
let _ = built_file
62+
.write_all(format!("pub const COMMIT_HASH: &str = \"{current_commit_hash}\";\n").as_ref());
63+
let _ = built_file
64+
.write_all(format!("pub const BRANCH_NAME: &str = \"{current_branch}\";\n").as_ref());
65+
let _ =
66+
built_file.write_all(format!("pub const TAG_NAME: &str = \"{current_tag}\";\n").as_ref());
67+
68+
let _ = built_file
69+
.write_all(format!("pub const BUILD_TIMESTAMP: &str = \"{build_timestamp}\";\n").as_ref());
70+
println!("cargo::rerun-if-changed=build.rs");
971
}

editor/src/buildinfo.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub mod built_info {
2+
// The file has been placed there by the build script.
3+
include!(concat!(env!("OUT_DIR"), "/buildinfo.rs"));
4+
}
5+
6+
pub fn get_version() -> &'static str {
7+
#[allow(clippy::const_is_empty)]
8+
// TAG_NAME is generated at compile-time and can be empty or not.
9+
if built_info::TAG_NAME.is_empty() {
10+
built_info::BRANCH_NAME
11+
} else {
12+
built_info::TAG_NAME
13+
}
14+
}

editor/src/editorinterface/editormenu.rs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use egui::{Popup, RichText, UiBuilder};
1+
use std::{cell::Cell, path::PathBuf};
2+
3+
use crate::buildinfo;
4+
use egui::{Modal, Popup, RichText, UiBuilder};
5+
use runtime::console;
26

37
use crate::editorinterface::{EditorState, emptyscreen::open_file_dialog_and_load_project};
48

@@ -26,6 +30,30 @@ pub fn draw_editor_menu(editor: &mut EditorState, ctx: &egui::Context) {
2630
editor.reload_project();
2731
}
2832

33+
thread_local! {
34+
static IS_ABOUT_OPEN: Cell<bool> = const { Cell::new(false) };
35+
}
36+
37+
if IS_ABOUT_OPEN.with(|cell| cell.get()) {
38+
let modal = Modal::new(egui::Id::new("about")).show(ctx, |ui| {
39+
ui.heading("About Vectarine");
40+
ui.label(format!("Version: {}", buildinfo::get_version()));
41+
ui.add_space(8.0);
42+
ui.label(format!(
43+
"Commit Hash: {}",
44+
buildinfo::built_info::COMMIT_HASH
45+
));
46+
ui.label(format!("Branch: {}", buildinfo::built_info::BRANCH_NAME));
47+
ui.label(format!(
48+
"Built on {}",
49+
buildinfo::built_info::BUILD_TIMESTAMP
50+
));
51+
});
52+
if modal.should_close() {
53+
IS_ABOUT_OPEN.with(|cell| cell.set(false));
54+
}
55+
}
56+
2957
egui::TopBottomPanel::top("toppanel").show(ctx, |ui| {
3058
ui.horizontal(|ui| {
3159
ui.label(RichText::new("Vectarine Editor").size(18.0));
@@ -100,9 +128,48 @@ pub fn draw_editor_menu(editor: &mut EditorState, ctx: &egui::Context) {
100128
editor.save_config();
101129
}
102130
});
131+
132+
ui.menu_button("Help", |ui| {
133+
if ui.button("Offline Guide").clicked() {
134+
if let Some(manual_path) = get_manual_path() {
135+
let result = open::that(manual_path);
136+
if let Err(result) = result {
137+
console::print_err(result.to_string());
138+
}
139+
} else {
140+
console::print_err(
141+
"PDF Guide not found, maybe it was deleted?".to_string(),
142+
);
143+
}
144+
}
145+
if ui.button("Github").clicked() {
146+
let result = open::that("https://github.com/vanyle/vectarine");
147+
if let Err(result) = result {
148+
console::print_err(result.to_string());
149+
}
150+
}
151+
if ui.button("About").clicked() {
152+
IS_ABOUT_OPEN.with(|cell| cell.set(true));
153+
}
154+
});
103155
});
104156
});
105157
// let window_handle = editor.window.borrow().raw();
106158
// sdl2_sys::SDL_SetWindowHitTest(window_handle, callback, callback_data)
107159
});
108160
}
161+
162+
fn get_manual_path() -> Option<PathBuf> {
163+
let executable_folder = std::env::current_exe().ok()?;
164+
let executable_folder = executable_folder.parent()?;
165+
let manual_path = executable_folder.join("vectarine-guide.pdf");
166+
if manual_path.exists() {
167+
return Some(manual_path);
168+
}
169+
let cwd = std::env::current_dir().ok()?;
170+
let manual_path = cwd.join("docs/user-manual.pdf");
171+
if manual_path.exists() {
172+
return Some(manual_path);
173+
}
174+
None
175+
}

editor/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
reload::reload_assets_if_needed,
1717
};
1818

19+
pub mod buildinfo;
1920
pub mod editorinterface;
2021
pub mod egui_sdl2_platform;
2122
pub mod exportinterface;

0 commit comments

Comments
 (0)