From 5434e6dbf59ac5ce55b8eb3e4dec2204b81fa37e Mon Sep 17 00:00:00 2001 From: Alula <6276139+alula@users.noreply.github.com> Date: Wed, 29 May 2024 00:55:57 +0200 Subject: [PATCH] Fix for Rust 1.78 (thanks imgui) --- Cargo.toml | 2 +- src/editor/mod.rs | 4 +-- src/framework/backend.rs | 1 + src/framework/context.rs | 2 +- src/framework/ui.rs | 7 +++-- src/live_debugger/mod.rs | 54 +++++++++++++++++++-------------------- src/macros.rs | 2 -- src/scene/editor_scene.rs | 8 +++--- 8 files changed, 39 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bcb2608..0f45e40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ downcast = "0.11" encoding_rs = "0.8.33" fern = "0.6.2" glutin = { git = "https://github.com/doukutsu-rs/glutin.git", rev = "2dd95f042e6e090d36f577cbea125560dd99bd27", optional = true, default_features = false, features = ["x11"] } -imgui = "0.8" +imgui = { git = "https://github.com/imgui-rs/imgui-rs.git", rev = "5d771a83b82c5cc3dd58cca3f969d900369262e6" } image = { version = "0.24", default-features = false, features = ["png", "bmp"] } itertools = "0.10" lazy_static = "1.4" diff --git a/src/editor/mod.rs b/src/editor/mod.rs index d3c3287..a5afd55 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -164,12 +164,12 @@ impl EditorInstance { } fn palette_window(&mut self, state: &mut SharedGameState, ctx: &mut Context, ui: &imgui::Ui) { - Window::new("Palette") + ui.window("Palette") .size([260.0, 260.0], imgui::Condition::Always) .position(ui.io().display_size, imgui::Condition::FirstUseEver) .position_pivot([1.0, 1.0]) .resizable(false) - .build(ui, || { + .build(|| { let name = &self.stage_textures.deref().borrow().tileset_fg; let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, name); diff --git a/src/framework/backend.rs b/src/framework/backend.rs index 38a7827..bcb8092 100644 --- a/src/framework/backend.rs +++ b/src/framework/backend.rs @@ -1,4 +1,5 @@ use std::any::Any; +use std::rc::Rc; use imgui::DrawData; diff --git a/src/framework/context.rs b/src/framework/context.rs index 2a06c32..e54359e 100644 --- a/src/framework/context.rs +++ b/src/framework/context.rs @@ -1,4 +1,4 @@ -use crate::framework::backend::{BackendRenderer, init_backend}; +use crate::framework::backend::{init_backend, BackendRenderer}; use crate::framework::error::GameResult; use crate::framework::filesystem::Filesystem; use crate::framework::gamepad::GamepadContext; diff --git a/src/framework/ui.rs b/src/framework/ui.rs index b140f64..6040f5b 100644 --- a/src/framework/ui.rs +++ b/src/framework/ui.rs @@ -110,17 +110,16 @@ impl UI { pub fn draw(&mut self, state: &mut SharedGameState, ctx: &mut Context, scene: &mut Box) -> GameResult { let ctx2 = unsafe { &mut *(ctx as *const Context as *mut Context) }; let imgui = imgui_context(ctx)?; - let io = imgui.io_mut(); let now = Instant::now(); - io.update_delta_time(now - self.last_frame); + imgui.io_mut().update_delta_time(now - self.last_frame); self.last_frame = now; - let mut ui = imgui.frame(); + let mut ui = imgui.new_frame(); scene.imgui_draw(&mut self.components, state, ctx2, &mut ui)?; prepare_imgui(ctx2, &ui); - let draw_data = ui.render(); + let draw_data = imgui.render(); render_imgui(ctx2, draw_data)?; Ok(()) diff --git a/src/live_debugger/mod.rs b/src/live_debugger/mod.rs index 2a3a023..2a56016 100644 --- a/src/live_debugger/mod.rs +++ b/src/live_debugger/mod.rs @@ -78,26 +78,26 @@ impl LiveDebugger { let x = 0.0 as f32; let y = state.screen_size.1 - height; - Window::new("Command Line") + ui.window("Command Line") .position([x, y], Condition::FirstUseEver) .size([width, height], Condition::FirstUseEver) .resizable(false) .collapsible(false) .movable(false) - .build(ui, || { + .build(|| { self.draw_left_label(ui, "Command:"); - let iw = ui.push_item_width(state.screen_size.0 - 150.0); + { + let _iw = ui.push_item_width(state.screen_size.0 - 150.0); - if !self.command_line_focused { - ui.set_keyboard_focus_here(); - self.command_line_focused = true; + if !self.command_line_focused { + ui.set_keyboard_focus_here(); + self.command_line_focused = true; + } + + ui.input_text("", &mut self.command_line_parser.buffer).build(); } - ui.input_text("", &mut self.command_line_parser.buffer).build(); - - iw.pop(ui); - if ui.is_item_active() { state.control_flags.set_tick_world(false); } else { @@ -140,12 +140,12 @@ impl LiveDebugger { return Ok(()); } - Window::new("Debugger") + ui.window("Debugger") .resizable(false) .collapsed(true, Condition::FirstUseEver) .position([5.0, 5.0], Condition::FirstUseEver) .size([400.0, 265.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text(format!( "Player position: ({:.1},{:.1}), velocity: ({:.1},{:.1})", game_scene.player1.x as f32 / 512.0, @@ -173,7 +173,7 @@ impl LiveDebugger { ui.text(format!("Game speed ({:.1} TPS):", state.current_tps())); let mut speed = state.settings.speed; - Slider::new("", 0.1, 3.0).build(ui, &mut speed); + ui.slider("", 0.1, 3.0, &mut speed); ui.same_line(); if ui.button("Reset") { speed = 1.0 @@ -235,11 +235,11 @@ impl LiveDebugger { }); if self.map_selector_visible { - Window::new("Map selector") + ui.window("Map selector") .resizable(false) .position([80.0, 80.0], Condition::Appearing) .size([240.0, 280.0], Condition::Appearing) - .build(ui, || { + .build(|| { if self.stages.is_empty() { for s in &state.stages { self.stages.push(ImString::new(s.name.to_owned())); @@ -296,11 +296,11 @@ impl LiveDebugger { } if self.events_visible { - Window::new("TSC Scripts") + ui.window("TSC Scripts") .resizable(false) .position([80.0, 80.0], Condition::Appearing) .size([300.0, 320.0], Condition::Appearing) - .build(ui, || { + .build(|| { if self.events.is_empty() { self.event_ids.clear(); @@ -385,10 +385,10 @@ impl LiveDebugger { } if self.flags_visible { - Window::new("Flags") + ui.window("Flags") .position([80.0, 80.0], Condition::FirstUseEver) .size([280.0, 300.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { if CollapsingHeader::new("Control flags").default_open(false).build(ui) { ui.checkbox_flags("Tick world", &mut state.control_flags.0, 1); ui.checkbox_flags("Control enabled", &mut state.control_flags.0, 2); @@ -417,12 +417,12 @@ impl LiveDebugger { } if self.npc_inspector_visible { - Window::new("NPC Inspector") + ui.window("NPC Inspector") .position([80.0, 80.0], Condition::FirstUseEver) .size([280.0, 300.0], Condition::FirstUseEver) .scrollable(true) .always_vertical_scrollbar(true) - .build(ui, || { + .build(|| { for npc in game_scene.npc_list.iter_alive() { if CollapsingHeader::new(&ImString::from(format!("id={} type={}", npc.id, npc.npc_type))) .default_open(false) @@ -471,11 +471,11 @@ impl LiveDebugger { } if self.hotkey_list_visible { - Window::new("Hotkeys") + ui.window("Hotkeys") .position([400.0, 5.0], Condition::FirstUseEver) .size([300.0, 300.0], Condition::FirstUseEver) .resizable(false) - .build(ui, || { + .build(|| { let key = vec![ "ESC + F2 > Quick Reset", "F3 > Godmode", @@ -507,11 +507,11 @@ impl LiveDebugger { for (idx, (_, title, contents)) in self.text_windows.iter().enumerate() { let mut opened = true; - Window::new(title) + ui.window(title) .position([100.0, 100.0], Condition::FirstUseEver) .size([400.0, 300.0], Condition::FirstUseEver) .opened(&mut opened) - .build(ui, || { + .build(|| { ui.text_wrapped(contents); }); @@ -525,7 +525,7 @@ impl LiveDebugger { } if self.error.is_some() { - Window::new("Error!") + ui.window("Error!") .resizable(false) .collapsible(false) .position( @@ -533,7 +533,7 @@ impl LiveDebugger { Condition::Appearing, ) .size([300.0, 100.0], Condition::Appearing) - .build(ui, || { + .build(|| { ui.push_item_width(-1.0); ui.text_wrapped(self.error.as_ref().unwrap()); diff --git a/src/macros.rs b/src/macros.rs index 74f3bd7..4900d9f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,6 +1,4 @@ #[doc(hidden)] -pub use core::convert::Into; -#[doc(hidden)] pub use core::fmt; #[doc(hidden)] pub use core::mem::size_of; diff --git a/src/scene/editor_scene.rs b/src/scene/editor_scene.rs index b0c01ad..e76b90a 100644 --- a/src/scene/editor_scene.rs +++ b/src/scene/editor_scene.rs @@ -237,12 +237,12 @@ impl Scene for EditorScene { menu_bar.end(); } - Window::new("Toolbar") + ui.window("Toolbar") .title_bar(false) .resizable(false) .position([0.0, menu_bar_size.1], Condition::Always) .size([menu_bar_size.0, 0.0], Condition::Always) - .build(ui, || { + .build(|| { if ui.tool_button("Move", self.current_tool == CurrentTool::Move) { self.current_tool = CurrentTool::Move; } @@ -321,12 +321,12 @@ impl StageListWindow { return; } - Window::new("Stage list") + ui.window("Stage list") .resizable(false) .collapsible(false) .position_pivot([0.5, 0.5]) .size([300.0, 352.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { let mut stages = Vec::with_capacity(state.stages.len()); for stage in state.stages.iter() { stages.push(stage.name.as_str());