From 8a3b527c3b85f3b4b53e2f2b7903d6b0b5b5127a Mon Sep 17 00:00:00 2001 From: Speak2Erase Date: Tue, 5 Sep 2023 13:05:39 -0700 Subject: [PATCH] feat: :sparkles: Global config window --- Cargo.lock | 16 +++++ Cargo.toml | 3 +- src/components/top_bar.rs | 77 ++++-------------------- src/filesystem/project.rs | 10 ++-- src/luminol.rs | 5 +- src/main.rs | 2 +- src/windows/appearance.rs | 93 +++++++++++++++++++++++++++++ src/windows/global_config_window.rs | 40 +++++++++++++ src/windows/mod.rs | 2 + 9 files changed, 171 insertions(+), 77 deletions(-) create mode 100644 src/windows/appearance.rs create mode 100644 src/windows/global_config_window.rs diff --git a/Cargo.lock b/Cargo.lock index 2ef5c890..fb949feb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1160,6 +1160,21 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" + [[package]] name = "crc32fast" version = "1.3.2" @@ -2997,6 +3012,7 @@ dependencies = [ "cgmath", "color-eyre", "command-lib", + "crc", "crossbeam", "dashmap", "eframe", diff --git a/Cargo.toml b/Cargo.toml index 6d092792..8275d2a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,9 +95,10 @@ rmxp-types = { version = "*", path = "rmxp-types" } luminol-term = { version = "*", path = "luminol-term" } steamworks = { version = "0.10.0", optional = true } +crc = { version = "3.0", optional = true } [features] -steamworks = ["dep:steamworks"] +steamworks = ["dep:steamworks", "crc"] [target.'cfg(windows)'.dependencies] diff --git a/src/components/top_bar.rs b/src/components/top_bar.rs index 79a8e75b..d5054a56 100644 --- a/src/components/top_bar.rs +++ b/src/components/top_bar.rs @@ -30,19 +30,14 @@ use crate::Pencil; #[derive(Default)] pub struct TopBar { open_project_promise: Option>>, - egui_settings_open: bool, + fullscreen: bool, } impl TopBar { /// Display the top bar. #[allow(unused_variables)] - pub fn ui( - &mut self, - ui: &mut egui::Ui, - style: &mut Arc, - frame: &mut eframe::Frame, - ) { + pub fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { let state = state!(); egui::widgets::global_dark_light_mode_switch(ui); @@ -109,57 +104,16 @@ impl TopBar { ui.separator(); - ui.menu_button("Appearance", |ui| { - // Or these together so if one OR the other is true the window shows. - self.egui_settings_open = - ui.button("Egui Settings").clicked() || self.egui_settings_open; - - ui.menu_button("Catppuccin theme", |ui| { - if ui.button("Frappe").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::FRAPPE); - } - if ui.button("Latte").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::LATTE); - } - if ui.button("Macchiato").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::MACCHIATO); - } - if ui.button("Mocha").clicked() { - catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::MOCHA); - } - - *style = ui.ctx().style(); - }); - - let theme = &mut global_config!().theme; - ui.menu_button("Code Theme", |ui| { - theme.ui(ui); - - ui.label("Code sample"); - ui.label(syntax_highlighting::highlight( - ui.ctx(), - *theme, - r#" - class Foo < Array - end - def bar(baz) - end - print 1, 2.0 - puts [0x3, :4, '5'] - "#, - "rb", - )); - }); + ui.menu_button("Edit", |ui| { + // + if ui.button("Preferences").clicked() { + state + .windows + .add_window(global_config_window::Window::default()) + } - if ui - .button("Clear Loaded Textures") - .on_hover_text( - "You may need to reopen maps/windows for any changes to take effect.", - ) - .clicked() - { - state.image_cache.clear(); - state.atlas_cache.clear(); + if ui.button("Appearance").clicked() { + state.windows.add_window(appearance::Window::default()) } }); @@ -267,15 +221,6 @@ impl TopBar { ui.selectable_value(&mut toolbar.pencil, brush, brush.to_string()); } - let ctx = ui.ctx(); - // Because style_ui makes a new style, AND we can't pass the style to a dedicated window, we handle the logic here. - egui::Window::new("Egui Settings") - .open(&mut self.egui_settings_open) - .show(ui.ctx(), |ui| { - ctx.style_ui(ui); - *style = ctx.style(); - }); - if open_project { self.open_project_promise = Some(Promise::spawn_local( state.filesystem.spawn_project_file_picker(), diff --git a/src/filesystem/project.rs b/src/filesystem/project.rs index 8990187d..7db46846 100644 --- a/src/filesystem/project.rs +++ b/src/filesystem/project.rs @@ -216,10 +216,10 @@ impl FileSystem { state!() .toasts - .warning(format!("Failed to find suitable path for rtp {rtp}")); + .warning(format!("Failed to find suitable path for the RTP {rtp}")); state!() .toasts - .info(format!("You may want to set an rtp path for {rtp}")); + .info(format!("You may want to set an RTP path for {rtp}")); } } paths @@ -236,7 +236,7 @@ impl FileSystem { // FIXME: handle vx ace? for rtp in ["RTP1", "RTP2", "RTP3"] { if let Some(rtp) = section.get(rtp) { - if seen_rtps.contains(&rtp) { + if seen_rtps.contains(&rtp) || rtp.is_empty() { continue; } seen_rtps.push(rtp); @@ -251,10 +251,10 @@ impl FileSystem { state!() .toasts - .warning(format!("Failed to find suitable path for rtp {rtp}")); + .warning(format!("Failed to find suitable path for the RTP {rtp}")); state!() .toasts - .info(format!("You may want to set an rtp path for {rtp}")); + .info(format!("You may want to set an RTP path for {rtp}")); } } paths diff --git a/src/luminol.rs b/src/luminol.rs index dad5eb6f..1e009038 100644 --- a/src/luminol.rs +++ b/src/luminol.rs @@ -28,7 +28,6 @@ use crate::prelude::*; /// The main Luminol struct. Handles rendering, GUI state, that sort of thing. pub struct Luminol { top_bar: TopBar, - style: Arc, lumi: Lumi, } @@ -105,7 +104,6 @@ impl Luminol { Self { top_bar: TopBar::default(), - style, lumi, } } @@ -115,7 +113,6 @@ impl eframe::App for Luminol { /// Called by the frame work to save state before shutdown. fn save(&mut self, storage: &mut dyn eframe::Storage) { eframe::set_value(storage, "SavedState", &*global_config!()); - eframe::set_value::>(storage, "EguiStyle", &self.style); } /// Called each time the UI needs repainting, which may be many times per second. @@ -146,7 +143,7 @@ impl eframe::App for Luminol { // Turn off button frame. ui.visuals_mut().button_frame = false; // Show the bar - self.top_bar.ui(ui, &mut self.style, frame); + self.top_bar.ui(ui, frame); }); }); diff --git a/src/main.rs b/src/main.rs index 79aa3c71..f374bc2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU General Public License // along with Luminol. If not, see . -// +//cargo r // Additional permission under GNU GPL version 3 section 7 // // If you modify this Program, or any covered work, by linking or combining diff --git a/src/windows/appearance.rs b/src/windows/appearance.rs new file mode 100644 index 00000000..73f2e645 --- /dev/null +++ b/src/windows/appearance.rs @@ -0,0 +1,93 @@ +// Copyright (C) 2023 Lily Lyons +// +// This file is part of Luminol. +// +// Luminol is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Luminol is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Luminol. If not, see . +// +// Additional permission under GNU GPL version 3 section 7 +// +// If you modify this Program, or any covered work, by linking or combining +// it with Steamworks API by Valve Corporation, containing parts covered by +// terms of the Steamworks API by Valve Corporation, the licensors of this +// Program grant you additional permission to convey the resulting work. +use crate::prelude::*; + +#[derive(Default)] +pub struct Window { + egui_settings_open: bool, +} + +impl super::Window for Window { + fn id(&self) -> egui::Id { + egui::Id::new("luminol_appearance_window") + } + + fn name(&self) -> String { + "Luminol Appearance".to_string() + } + + fn show(&mut self, ctx: &egui::Context, open: &mut bool) { + egui::Window::new(self.name()).open(open).show(ctx, |ui| { + // Or these together so if one OR the other is true the window shows. + self.egui_settings_open = + ui.button("Egui Settings").clicked() || self.egui_settings_open; + + ui.menu_button("Catppuccin theme", |ui| { + if ui.button("Frappe").clicked() { + catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::FRAPPE); + } + if ui.button("Latte").clicked() { + catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::LATTE); + } + if ui.button("Macchiato").clicked() { + catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::MACCHIATO); + } + if ui.button("Mocha").clicked() { + catppuccin_egui::set_theme(ui.ctx(), catppuccin_egui::MOCHA); + } + }); + + let theme = &mut global_config!().theme; + ui.menu_button("Code Theme", |ui| { + theme.ui(ui); + + ui.label("Code sample"); + ui.label(syntax_highlighting::highlight( + ui.ctx(), + *theme, + r#" + class Foo < Array + end + def bar(baz) + end + print 1, 2.0 + puts [0x3, :4, '5'] + "#, + "rb", + )); + }); + + if ui + .button("Clear Loaded Textures") + .on_hover_text( + "You may need to reopen maps/windows for any changes to take effect.", + ) + .clicked() + { + state!().image_cache.clear(); + state!().atlas_cache.clear(); + } + }); + } +} diff --git a/src/windows/global_config_window.rs b/src/windows/global_config_window.rs new file mode 100644 index 00000000..4a62973e --- /dev/null +++ b/src/windows/global_config_window.rs @@ -0,0 +1,40 @@ +// Copyright (C) 2023 Lily Lyons +// +// This file is part of Luminol. +// +// Luminol is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Luminol is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Luminol. If not, see . +// +// Additional permission under GNU GPL version 3 section 7 +// +// If you modify this Program, or any covered work, by linking or combining +// it with Steamworks API by Valve Corporation, containing parts covered by +// terms of the Steamworks API by Valve Corporation, the licensors of this +// Program grant you additional permission to convey the resulting work. + +#[derive(Default)] +pub struct Window {} + +impl super::Window for Window { + fn name(&self) -> String { + "Luminol Preferences".to_string() + } + + fn id(&self) -> egui::Id { + egui::Id::new("luminol_preferences_window") + } + + fn show(&mut self, ctx: &egui::Context, open: &mut bool) { + egui::Window::new(self.name()).open(open).show(ctx, |ui| {}); + } +} diff --git a/src/windows/mod.rs b/src/windows/mod.rs index c25495e0..9d73ee0e 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -24,6 +24,7 @@ /// The about window. pub mod about; +pub mod appearance; /// The common event editor. pub mod common_event_edit; /// Config window @@ -32,6 +33,7 @@ pub mod config_window; pub mod console; /// The event editor. pub mod event_edit; +pub mod global_config_window; /// The Graphic picker. pub mod graphic_picker; /// The item editor.