diff --git a/examples/imgui_integration/src/context.rs b/examples/imgui_integration/src/context.rs index 3e209a4..e1e6435 100644 --- a/examples/imgui_integration/src/context.rs +++ b/examples/imgui_integration/src/context.rs @@ -86,7 +86,7 @@ impl AppContext for GameContext { } impl GameContext { - pub fn new(mut system: System) -> Result { + pub fn new(system: System) -> Result { let palette = load_palette(Path::new("./assets/db16.pal"))?; let font = load_font(Path::new("./assets/dp.fnt"))?; @@ -97,7 +97,7 @@ impl GameContext { let blue_slime = Rc::new(load_bitmap_atlas_autogrid(Path::new("./assets/blue_slime.pcx"))?); let orange_slime = Rc::new(load_bitmap_atlas_autogrid(Path::new("./assets/orange_slime.pcx"))?); - let mut tilemap = TileMap::load_from(Path::new("./assets/arena.map.json"))?; + let tilemap = TileMap::load_from(Path::new("./assets/arena.map.json"))?; let entities = Entities::new(); let component_systems = ComponentSystems::new(); diff --git a/examples/imgui_integration/src/entities.rs b/examples/imgui_integration/src/entities.rs index d9fc6b2..71aeb6f 100644 --- a/examples/imgui_integration/src/entities.rs +++ b/examples/imgui_integration/src/entities.rs @@ -261,7 +261,7 @@ pub enum Event { fn event_handler(event: &Event, context: &mut CoreContext) -> bool { match event { - Event::AnimationFinished(entity) => { + Event::AnimationFinished(_entity) => { // no-op } Event::MoveForward(entity) => { @@ -471,7 +471,7 @@ fn update_system_pushing(context: &mut CoreContext) { let pusher_bounds = bounds.get(pusher_entity).unwrap(); let pusher_circle = Circle::new(pusher_position.0.x as i32, pusher_position.0.y as i32, pusher_bounds.radius); - for (pushable_entity, pushable) in pushable.iter() { + for (pushable_entity, _pushable) in pushable.iter() { // don't push ourself ... if *pushable_entity == *pusher_entity { continue; @@ -633,7 +633,6 @@ fn update_system_current_entity_activity(context: &mut CoreContext) { context.event_publisher.queue(Event::SetActivity(*entity, EntityActivity::Idle)); } } - _ => {} } } } @@ -648,7 +647,7 @@ fn render_system_sprites(context: &mut CoreContext) { // build up list of entities to be rendered with their positions so we can sort them // and render these entities with a proper y-based sort order for (entity, _) in sprites.iter() { - let mut blit_method = RgbaBlitMethod::Transparent(context.transparent_color); + let blit_method = RgbaBlitMethod::Transparent(context.transparent_color); let position = positions.get(entity).unwrap(); context.sprite_render_list.push((*entity, position.0, blit_method)); diff --git a/examples/imgui_integration/src/main.rs b/examples/imgui_integration/src/main.rs index 0547ad0..7a41e25 100644 --- a/examples/imgui_integration/src/main.rs +++ b/examples/imgui_integration/src/main.rs @@ -3,30 +3,40 @@ mod entities; mod support; mod tilemap; -use anyhow::{Context, Result}; +use anyhow::Result; use crate::context::GameContext; +use crate::entities::{Position, Slime}; use crate::tilemap::{TILE_HEIGHT, TILE_WIDTH}; use ggdt::prelude::*; +use ggdt_imgui::UiSupport; pub struct DemoState; impl AppState for DemoState { - fn update(&mut self, state: State, context: &mut GameContext) -> Option> { + fn update(&mut self, _state: State, context: &mut GameContext) -> Option> { if context.core.system.res.keyboard.is_key_pressed(Scancode::Escape) { return Some(StateChange::Pop(1)); } let ui = context.support.imgui.new_frame(&context.core.system.res.video); - ui.window("Entities").build(|| { - ui.text("TODO: display entity list or something"); - }); + ui.window("Entities") + .position([10.0, 10.0], imgui::Condition::FirstUseEver) + .size([160.0, 200.0], imgui::Condition::FirstUseEver) + .build(|| { + ui.text(format!("Camera: {}, {}", context.core.camera_x, context.core.camera_y)); - let ui_focused = ui.is_window_hovered_with_flags(imgui::WindowHoveredFlags::ANY_WINDOW) - || ui.is_window_focused_with_flags(imgui::WindowFocusedFlags::ANY_WINDOW); + ui.separator(); + ui.text_colored([1.0, 1.0, 0.0, 1.0], "Slimes"); + let positions = context.core.entities.components::().unwrap(); + for (slime, _) in context.core.entities.components::().unwrap().iter() { + let position = positions.get(slime).unwrap(); + ui.text(format!("{:2} @ {:3.0},{:3.0}", *slime, position.0.x, position.0.y)); + } + }); - if !ui_focused { - if context.core.system.res.mouse.is_button_down(1) { + if !ui.is_any_hovered() { + if context.core.system.res.mouse.is_button_down(MouseButton::Right) { context.core.camera_x -= context.core.system.res.mouse.x_delta() * 2; context.core.camera_y -= context.core.system.res.mouse.y_delta() * 2; } @@ -38,7 +48,7 @@ impl AppState for DemoState { None } - fn render(&mut self, state: State, context: &mut GameContext) { + fn render(&mut self, _state: State, context: &mut GameContext) { context.core.system.res.video.clear(context.core.palette[0]); context.core.tilemap.draw( &mut context.core.system.res.video, @@ -52,11 +62,11 @@ impl AppState for DemoState { context.support.imgui.render(&mut context.core.system.res.video); } - fn transition(&mut self, state: State, context: &mut GameContext) -> bool { + fn transition(&mut self, _state: State, _context: &mut GameContext) -> bool { true } - fn state_change(&mut self, new_state: State, old_state: State, context: &mut GameContext) { + fn state_change(&mut self, new_state: State, _old_state: State, context: &mut GameContext) { if new_state == State::Pending { entities::init(context); for _ in 0..10 { @@ -83,7 +93,7 @@ fn main() -> Result<()> { let mut game = GameContext::new(system)?; let mut states = States::new(); - states.push(DemoState); + states.push(DemoState)?; let mut last_ticks = game.core.system.ticks(); @@ -98,7 +108,7 @@ fn main() -> Result<()> { } last_ticks = game.core.update_frame_delta(last_ticks); - states.update(&mut game); + states.update(&mut game)?; game.core.system.update()?; states.render(&mut game); game.core.system.display()?;