diff --git a/src/framework/ui.rs b/src/framework/ui.rs index ec621bc..ba51452 100644 --- a/src/framework/ui.rs +++ b/src/framework/ui.rs @@ -126,7 +126,7 @@ impl UI { let mut ui = imgui.frame(); - scene.debug_overlay_draw(&mut self.components, state, ctx2, &mut ui)?; + scene.imgui_draw(&mut self.components, state, ctx2, &mut ui)?; let draw_data = ui.render(); render_imgui(ctx2, draw_data)?; diff --git a/src/scene/editor_scene.rs b/src/scene/editor_scene.rs new file mode 100644 index 0000000..d5c83a5 --- /dev/null +++ b/src/scene/editor_scene.rs @@ -0,0 +1,53 @@ +use imgui::MenuItem; + +use crate::framework::ui::Components; +use crate::scene::title_scene::TitleScene; +use crate::{Context, GameResult, Scene, SharedGameState}; + +pub struct EditorScene {} + +impl EditorScene { + pub fn new() -> Self { + EditorScene {} + } + + fn exit_editor(&mut self, state: &mut SharedGameState) { + state.next_scene = Some(Box::new(TitleScene::new())); + } +} + +impl Scene for EditorScene { + fn init(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult { + state.sound_manager.play_song(0, &state.constants, &state.settings, ctx)?; + + Ok(()) + } + + fn draw(&self, _state: &mut SharedGameState, _ctx: &mut Context) -> GameResult { + Ok(()) + } + + fn imgui_draw( + &mut self, + _game_ui: &mut Components, + state: &mut SharedGameState, + _ctx: &mut Context, + ui: &mut imgui::Ui, + ) -> GameResult { + if let Some(menu_bar) = ui.begin_main_menu_bar() { + if let Some(menu) = ui.begin_menu("File") { + MenuItem::new("Open stage").shortcut("Ctrl+O").build(ui); + ui.separator(); + + if MenuItem::new("Exit editor").build(ui) { + self.exit_editor(state); + } + + menu.end(); + } + menu_bar.end(); + } + + Ok(()) + } +} diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index d563e90..7e44975 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -3,7 +3,7 @@ use std::ops::Range; use log::info; use crate::caret::CaretType; -use crate::common::{interpolate_fix9_scale, Color, Direction, FadeDirection, FadeState, Rect}; +use crate::common::{Color, Direction, FadeDirection, FadeState, interpolate_fix9_scale, Rect}; use crate::components::boss_life_bar::BossLifeBar; use crate::components::credits::Credits; use crate::components::draw_common::Alignment; @@ -15,23 +15,23 @@ use crate::components::stage_select::StageSelect; use crate::components::water_renderer::WaterRenderer; use crate::entity::GameEntity; use crate::frame::{Frame, UpdateTarget}; +use crate::framework::{filesystem, graphics}; use crate::framework::backend::SpriteBatchCommand; use crate::framework::context::Context; use crate::framework::error::GameResult; -use crate::framework::graphics::{draw_rect, BlendMode, FilterMode}; +use crate::framework::graphics::{BlendMode, draw_rect, FilterMode}; use crate::framework::ui::Components; -use crate::framework::{filesystem, graphics}; use crate::input::touch_controls::TouchControlType; use crate::inventory::{Inventory, TakeExperienceResult}; use crate::map::WaterParams; +use crate::npc::{NPC, NPCLayer}; use crate::npc::boss::BossNPC; use crate::npc::list::NPCList; -use crate::npc::{NPCLayer, NPC}; -use crate::physics::{PhysicalEntity, OFFSETS}; +use crate::physics::{OFFSETS, PhysicalEntity}; use crate::player::{Player, TargetPlayer}; use crate::rng::XorShift; -use crate::scene::title_scene::TitleScene; use crate::scene::Scene; +use crate::scene::title_scene::TitleScene; use crate::scripting::tsc::credit_script::CreditScriptVM; use crate::scripting::tsc::text_script::{ ConfirmSelection, ScriptMode, TextScriptExecutionState, TextScriptLine, TextScriptVM, @@ -39,8 +39,8 @@ use crate::scripting::tsc::text_script::{ use crate::shared_game_state::{SharedGameState, TileSize}; use crate::stage::{BackgroundType, Stage}; use crate::texture_set::SpriteBatch; -use crate::weapon::bullet::BulletManager; use crate::weapon::{Weapon, WeaponType}; +use crate::weapon::bullet::BulletManager; pub struct GameScene { pub tick: u32, @@ -542,7 +542,7 @@ impl GameScene { if let TextScriptExecutionState::WaitConfirmation(_, _, _, wait, selection) = state.textscript_vm.state { let pos_y = if wait > 14 { - state.canvas_size.1 - off_bottom - 96.0 + (wait as f32 + 2.0) + state.canvas_size.1 - off_bottom - 96.0 + (wait as f32 + 2.0) } else { state.canvas_size.1 - off_bottom - 96.0 }; @@ -2282,7 +2282,7 @@ impl Scene for GameScene { Ok(()) } - fn debug_overlay_draw( + fn imgui_draw( &mut self, components: &mut Components, state: &mut SharedGameState, diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 5534c1d..146a489 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -8,6 +8,7 @@ pub mod game_scene; pub mod loading_scene; pub mod no_data_scene; pub mod title_scene; +pub mod editor_scene; /// Implement this trait on any object that represents an interactive game screen. pub trait Scene { @@ -25,5 +26,5 @@ pub trait Scene { fn draw(&self, _state: &mut SharedGameState, _ctx: &mut Context) -> GameResult { Ok(()) } /// Independent draw meant for debug overlay, that lets you mutate the game state. - fn debug_overlay_draw(&mut self, _game_ui: &mut Components, _state: &mut SharedGameState, _ctx: &mut Context, _frame: &mut imgui::Ui) -> GameResult { Ok(()) } + fn imgui_draw(&mut self, _game_ui: &mut Components, _state: &mut SharedGameState, _ctx: &mut Context, _frame: &mut imgui::Ui) -> GameResult { Ok(()) } } diff --git a/src/scene/title_scene.rs b/src/scene/title_scene.rs index 686f053..82977d3 100644 --- a/src/scene/title_scene.rs +++ b/src/scene/title_scene.rs @@ -142,6 +142,13 @@ impl Scene for TitleScene { MenuSelectionResult::Selected(2, _) => { self.current_menu = CurrentMenu::OptionMenu; } + MenuSelectionResult::Selected(3, _) => { + #[cfg(feature = "editor")] + { + use crate::scene::editor_scene::EditorScene; + state.next_scene = Some(Box::new(EditorScene::new())); + } + } MenuSelectionResult::Selected(4, _) => { state.shutdown(); }