|
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; |
2 | 6 |
|
3 | 7 | use crate::editorinterface::{EditorState, emptyscreen::open_file_dialog_and_load_project}; |
4 | 8 |
|
@@ -26,6 +30,30 @@ pub fn draw_editor_menu(editor: &mut EditorState, ctx: &egui::Context) { |
26 | 30 | editor.reload_project(); |
27 | 31 | } |
28 | 32 |
|
| 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 | + |
29 | 57 | egui::TopBottomPanel::top("toppanel").show(ctx, |ui| { |
30 | 58 | ui.horizontal(|ui| { |
31 | 59 | ui.label(RichText::new("Vectarine Editor").size(18.0)); |
@@ -100,9 +128,48 @@ pub fn draw_editor_menu(editor: &mut EditorState, ctx: &egui::Context) { |
100 | 128 | editor.save_config(); |
101 | 129 | } |
102 | 130 | }); |
| 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 | + }); |
103 | 155 | }); |
104 | 156 | }); |
105 | 157 | // let window_handle = editor.window.borrow().raw(); |
106 | 158 | // sdl2_sys::SDL_SetWindowHitTest(window_handle, callback, callback_data) |
107 | 159 | }); |
108 | 160 | } |
| 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 | +} |
0 commit comments