1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-11-29 15:56:53 +00:00

some editor barebones

This commit is contained in:
Alula 2022-01-05 04:16:29 +01:00
parent 5a6f7dec59
commit 4134d4754e
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
5 changed files with 72 additions and 11 deletions

View file

@ -126,7 +126,7 @@ impl UI {
let mut ui = imgui.frame(); 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(); let draw_data = ui.render();
render_imgui(ctx2, draw_data)?; render_imgui(ctx2, draw_data)?;

53
src/scene/editor_scene.rs Normal file
View file

@ -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(())
}
}

View file

@ -3,7 +3,7 @@ use std::ops::Range;
use log::info; use log::info;
use crate::caret::CaretType; 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::boss_life_bar::BossLifeBar;
use crate::components::credits::Credits; use crate::components::credits::Credits;
use crate::components::draw_common::Alignment; use crate::components::draw_common::Alignment;
@ -15,23 +15,23 @@ use crate::components::stage_select::StageSelect;
use crate::components::water_renderer::WaterRenderer; use crate::components::water_renderer::WaterRenderer;
use crate::entity::GameEntity; use crate::entity::GameEntity;
use crate::frame::{Frame, UpdateTarget}; use crate::frame::{Frame, UpdateTarget};
use crate::framework::{filesystem, graphics};
use crate::framework::backend::SpriteBatchCommand; use crate::framework::backend::SpriteBatchCommand;
use crate::framework::context::Context; use crate::framework::context::Context;
use crate::framework::error::GameResult; 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::ui::Components;
use crate::framework::{filesystem, graphics};
use crate::input::touch_controls::TouchControlType; use crate::input::touch_controls::TouchControlType;
use crate::inventory::{Inventory, TakeExperienceResult}; use crate::inventory::{Inventory, TakeExperienceResult};
use crate::map::WaterParams; use crate::map::WaterParams;
use crate::npc::{NPC, NPCLayer};
use crate::npc::boss::BossNPC; use crate::npc::boss::BossNPC;
use crate::npc::list::NPCList; use crate::npc::list::NPCList;
use crate::npc::{NPCLayer, NPC}; use crate::physics::{OFFSETS, PhysicalEntity};
use crate::physics::{PhysicalEntity, OFFSETS};
use crate::player::{Player, TargetPlayer}; use crate::player::{Player, TargetPlayer};
use crate::rng::XorShift; use crate::rng::XorShift;
use crate::scene::title_scene::TitleScene;
use crate::scene::Scene; use crate::scene::Scene;
use crate::scene::title_scene::TitleScene;
use crate::scripting::tsc::credit_script::CreditScriptVM; use crate::scripting::tsc::credit_script::CreditScriptVM;
use crate::scripting::tsc::text_script::{ use crate::scripting::tsc::text_script::{
ConfirmSelection, ScriptMode, TextScriptExecutionState, TextScriptLine, TextScriptVM, ConfirmSelection, ScriptMode, TextScriptExecutionState, TextScriptLine, TextScriptVM,
@ -39,8 +39,8 @@ use crate::scripting::tsc::text_script::{
use crate::shared_game_state::{SharedGameState, TileSize}; use crate::shared_game_state::{SharedGameState, TileSize};
use crate::stage::{BackgroundType, Stage}; use crate::stage::{BackgroundType, Stage};
use crate::texture_set::SpriteBatch; use crate::texture_set::SpriteBatch;
use crate::weapon::bullet::BulletManager;
use crate::weapon::{Weapon, WeaponType}; use crate::weapon::{Weapon, WeaponType};
use crate::weapon::bullet::BulletManager;
pub struct GameScene { pub struct GameScene {
pub tick: u32, pub tick: u32,
@ -542,7 +542,7 @@ impl GameScene {
if let TextScriptExecutionState::WaitConfirmation(_, _, _, wait, selection) = state.textscript_vm.state { if let TextScriptExecutionState::WaitConfirmation(_, _, _, wait, selection) = state.textscript_vm.state {
let pos_y = if wait > 14 { 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 { } else {
state.canvas_size.1 - off_bottom - 96.0 state.canvas_size.1 - off_bottom - 96.0
}; };
@ -2282,7 +2282,7 @@ impl Scene for GameScene {
Ok(()) Ok(())
} }
fn debug_overlay_draw( fn imgui_draw(
&mut self, &mut self,
components: &mut Components, components: &mut Components,
state: &mut SharedGameState, state: &mut SharedGameState,

View file

@ -8,6 +8,7 @@ pub mod game_scene;
pub mod loading_scene; pub mod loading_scene;
pub mod no_data_scene; pub mod no_data_scene;
pub mod title_scene; pub mod title_scene;
pub mod editor_scene;
/// Implement this trait on any object that represents an interactive game screen. /// Implement this trait on any object that represents an interactive game screen.
pub trait Scene { pub trait Scene {
@ -25,5 +26,5 @@ pub trait Scene {
fn draw(&self, _state: &mut SharedGameState, _ctx: &mut Context) -> GameResult { Ok(()) } fn draw(&self, _state: &mut SharedGameState, _ctx: &mut Context) -> GameResult { Ok(()) }
/// Independent draw meant for debug overlay, that lets you mutate the game state. /// 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(()) }
} }

View file

@ -142,6 +142,13 @@ impl Scene for TitleScene {
MenuSelectionResult::Selected(2, _) => { MenuSelectionResult::Selected(2, _) => {
self.current_menu = CurrentMenu::OptionMenu; 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, _) => { MenuSelectionResult::Selected(4, _) => {
state.shutdown(); state.shutdown();
} }