Skip to content

Commit

Permalink
feat: ✨ Global config window
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Sep 5, 2023
1 parent fc7e7e5 commit 8a3b527
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 77 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
77 changes: 11 additions & 66 deletions src/components/top_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ use crate::Pencil;
#[derive(Default)]
pub struct TopBar {
open_project_promise: Option<Promise<Result<(), String>>>,
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<egui::Style>,
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);

Expand Down Expand Up @@ -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())
}
});

Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions src/filesystem/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/luminol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<egui::Style>,
lumi: Lumi,
}

Expand Down Expand Up @@ -105,7 +104,6 @@ impl Luminol {

Self {
top_bar: TopBar::default(),
style,
lumi,
}
}
Expand All @@ -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::<Arc<egui::Style>>(storage, "EguiStyle", &self.style);
}

/// Called each time the UI needs repainting, which may be many times per second.
Expand Down Expand Up @@ -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);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Luminol. If not, see <http://www.gnu.org/licenses/>.
//
//cargo r
// Additional permission under GNU GPL version 3 section 7
//
// If you modify this Program, or any covered work, by linking or combining
Expand Down
93 changes: 93 additions & 0 deletions src/windows/appearance.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//
// 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();
}
});
}
}
40 changes: 40 additions & 0 deletions src/windows/global_config_window.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//
// 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| {});
}
}
2 changes: 2 additions & 0 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/// The about window.
pub mod about;
pub mod appearance;
/// The common event editor.
pub mod common_event_edit;
/// Config window
Expand All @@ -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.
Expand Down

0 comments on commit 8a3b527

Please sign in to comment.