1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-21 21:22:44 +00:00

Fix for Rust 1.78 (thanks imgui)

This commit is contained in:
Alula 2024-05-29 00:55:57 +02:00
parent 60a6c97834
commit 5434e6dbf5
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
8 changed files with 39 additions and 41 deletions

View file

@ -67,7 +67,7 @@ downcast = "0.11"
encoding_rs = "0.8.33" encoding_rs = "0.8.33"
fern = "0.6.2" fern = "0.6.2"
glutin = { git = "https://github.com/doukutsu-rs/glutin.git", rev = "2dd95f042e6e090d36f577cbea125560dd99bd27", optional = true, default_features = false, features = ["x11"] } 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"] } image = { version = "0.24", default-features = false, features = ["png", "bmp"] }
itertools = "0.10" itertools = "0.10"
lazy_static = "1.4" lazy_static = "1.4"

View file

@ -164,12 +164,12 @@ impl EditorInstance {
} }
fn palette_window(&mut self, state: &mut SharedGameState, ctx: &mut Context, ui: &imgui::Ui) { 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) .size([260.0, 260.0], imgui::Condition::Always)
.position(ui.io().display_size, imgui::Condition::FirstUseEver) .position(ui.io().display_size, imgui::Condition::FirstUseEver)
.position_pivot([1.0, 1.0]) .position_pivot([1.0, 1.0])
.resizable(false) .resizable(false)
.build(ui, || { .build(|| {
let name = &self.stage_textures.deref().borrow().tileset_fg; let name = &self.stage_textures.deref().borrow().tileset_fg;
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, name); let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, name);

View file

@ -1,4 +1,5 @@
use std::any::Any; use std::any::Any;
use std::rc::Rc;
use imgui::DrawData; use imgui::DrawData;

View file

@ -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::error::GameResult;
use crate::framework::filesystem::Filesystem; use crate::framework::filesystem::Filesystem;
use crate::framework::gamepad::GamepadContext; use crate::framework::gamepad::GamepadContext;

View file

@ -110,17 +110,16 @@ impl UI {
pub fn draw(&mut self, state: &mut SharedGameState, ctx: &mut Context, scene: &mut Box<dyn Scene>) -> GameResult { pub fn draw(&mut self, state: &mut SharedGameState, ctx: &mut Context, scene: &mut Box<dyn Scene>) -> GameResult {
let ctx2 = unsafe { &mut *(ctx as *const Context as *mut Context) }; let ctx2 = unsafe { &mut *(ctx as *const Context as *mut Context) };
let imgui = imgui_context(ctx)?; let imgui = imgui_context(ctx)?;
let io = imgui.io_mut();
let now = Instant::now(); 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; 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)?; scene.imgui_draw(&mut self.components, state, ctx2, &mut ui)?;
prepare_imgui(ctx2, &ui); prepare_imgui(ctx2, &ui);
let draw_data = ui.render(); let draw_data = imgui.render();
render_imgui(ctx2, draw_data)?; render_imgui(ctx2, draw_data)?;
Ok(()) Ok(())

View file

@ -78,26 +78,26 @@ impl LiveDebugger {
let x = 0.0 as f32; let x = 0.0 as f32;
let y = state.screen_size.1 - height; let y = state.screen_size.1 - height;
Window::new("Command Line") ui.window("Command Line")
.position([x, y], Condition::FirstUseEver) .position([x, y], Condition::FirstUseEver)
.size([width, height], Condition::FirstUseEver) .size([width, height], Condition::FirstUseEver)
.resizable(false) .resizable(false)
.collapsible(false) .collapsible(false)
.movable(false) .movable(false)
.build(ui, || { .build(|| {
self.draw_left_label(ui, "Command:"); 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 { if !self.command_line_focused {
ui.set_keyboard_focus_here(); ui.set_keyboard_focus_here();
self.command_line_focused = true; 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() { if ui.is_item_active() {
state.control_flags.set_tick_world(false); state.control_flags.set_tick_world(false);
} else { } else {
@ -140,12 +140,12 @@ impl LiveDebugger {
return Ok(()); return Ok(());
} }
Window::new("Debugger") ui.window("Debugger")
.resizable(false) .resizable(false)
.collapsed(true, Condition::FirstUseEver) .collapsed(true, Condition::FirstUseEver)
.position([5.0, 5.0], Condition::FirstUseEver) .position([5.0, 5.0], Condition::FirstUseEver)
.size([400.0, 265.0], Condition::FirstUseEver) .size([400.0, 265.0], Condition::FirstUseEver)
.build(ui, || { .build(|| {
ui.text(format!( ui.text(format!(
"Player position: ({:.1},{:.1}), velocity: ({:.1},{:.1})", "Player position: ({:.1},{:.1}), velocity: ({:.1},{:.1})",
game_scene.player1.x as f32 / 512.0, game_scene.player1.x as f32 / 512.0,
@ -173,7 +173,7 @@ impl LiveDebugger {
ui.text(format!("Game speed ({:.1} TPS):", state.current_tps())); ui.text(format!("Game speed ({:.1} TPS):", state.current_tps()));
let mut speed = state.settings.speed; 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(); ui.same_line();
if ui.button("Reset") { if ui.button("Reset") {
speed = 1.0 speed = 1.0
@ -235,11 +235,11 @@ impl LiveDebugger {
}); });
if self.map_selector_visible { if self.map_selector_visible {
Window::new("Map selector") ui.window("Map selector")
.resizable(false) .resizable(false)
.position([80.0, 80.0], Condition::Appearing) .position([80.0, 80.0], Condition::Appearing)
.size([240.0, 280.0], Condition::Appearing) .size([240.0, 280.0], Condition::Appearing)
.build(ui, || { .build(|| {
if self.stages.is_empty() { if self.stages.is_empty() {
for s in &state.stages { for s in &state.stages {
self.stages.push(ImString::new(s.name.to_owned())); self.stages.push(ImString::new(s.name.to_owned()));
@ -296,11 +296,11 @@ impl LiveDebugger {
} }
if self.events_visible { if self.events_visible {
Window::new("TSC Scripts") ui.window("TSC Scripts")
.resizable(false) .resizable(false)
.position([80.0, 80.0], Condition::Appearing) .position([80.0, 80.0], Condition::Appearing)
.size([300.0, 320.0], Condition::Appearing) .size([300.0, 320.0], Condition::Appearing)
.build(ui, || { .build(|| {
if self.events.is_empty() { if self.events.is_empty() {
self.event_ids.clear(); self.event_ids.clear();
@ -385,10 +385,10 @@ impl LiveDebugger {
} }
if self.flags_visible { if self.flags_visible {
Window::new("Flags") ui.window("Flags")
.position([80.0, 80.0], Condition::FirstUseEver) .position([80.0, 80.0], Condition::FirstUseEver)
.size([280.0, 300.0], Condition::FirstUseEver) .size([280.0, 300.0], Condition::FirstUseEver)
.build(ui, || { .build(|| {
if CollapsingHeader::new("Control flags").default_open(false).build(ui) { if CollapsingHeader::new("Control flags").default_open(false).build(ui) {
ui.checkbox_flags("Tick world", &mut state.control_flags.0, 1); ui.checkbox_flags("Tick world", &mut state.control_flags.0, 1);
ui.checkbox_flags("Control enabled", &mut state.control_flags.0, 2); ui.checkbox_flags("Control enabled", &mut state.control_flags.0, 2);
@ -417,12 +417,12 @@ impl LiveDebugger {
} }
if self.npc_inspector_visible { if self.npc_inspector_visible {
Window::new("NPC Inspector") ui.window("NPC Inspector")
.position([80.0, 80.0], Condition::FirstUseEver) .position([80.0, 80.0], Condition::FirstUseEver)
.size([280.0, 300.0], Condition::FirstUseEver) .size([280.0, 300.0], Condition::FirstUseEver)
.scrollable(true) .scrollable(true)
.always_vertical_scrollbar(true) .always_vertical_scrollbar(true)
.build(ui, || { .build(|| {
for npc in game_scene.npc_list.iter_alive() { for npc in game_scene.npc_list.iter_alive() {
if CollapsingHeader::new(&ImString::from(format!("id={} type={}", npc.id, npc.npc_type))) if CollapsingHeader::new(&ImString::from(format!("id={} type={}", npc.id, npc.npc_type)))
.default_open(false) .default_open(false)
@ -471,11 +471,11 @@ impl LiveDebugger {
} }
if self.hotkey_list_visible { if self.hotkey_list_visible {
Window::new("Hotkeys") ui.window("Hotkeys")
.position([400.0, 5.0], Condition::FirstUseEver) .position([400.0, 5.0], Condition::FirstUseEver)
.size([300.0, 300.0], Condition::FirstUseEver) .size([300.0, 300.0], Condition::FirstUseEver)
.resizable(false) .resizable(false)
.build(ui, || { .build(|| {
let key = vec![ let key = vec![
"ESC + F2 > Quick Reset", "ESC + F2 > Quick Reset",
"F3 > Godmode", "F3 > Godmode",
@ -507,11 +507,11 @@ impl LiveDebugger {
for (idx, (_, title, contents)) in self.text_windows.iter().enumerate() { for (idx, (_, title, contents)) in self.text_windows.iter().enumerate() {
let mut opened = true; let mut opened = true;
Window::new(title) ui.window(title)
.position([100.0, 100.0], Condition::FirstUseEver) .position([100.0, 100.0], Condition::FirstUseEver)
.size([400.0, 300.0], Condition::FirstUseEver) .size([400.0, 300.0], Condition::FirstUseEver)
.opened(&mut opened) .opened(&mut opened)
.build(ui, || { .build(|| {
ui.text_wrapped(contents); ui.text_wrapped(contents);
}); });
@ -525,7 +525,7 @@ impl LiveDebugger {
} }
if self.error.is_some() { if self.error.is_some() {
Window::new("Error!") ui.window("Error!")
.resizable(false) .resizable(false)
.collapsible(false) .collapsible(false)
.position( .position(
@ -533,7 +533,7 @@ impl LiveDebugger {
Condition::Appearing, Condition::Appearing,
) )
.size([300.0, 100.0], Condition::Appearing) .size([300.0, 100.0], Condition::Appearing)
.build(ui, || { .build(|| {
ui.push_item_width(-1.0); ui.push_item_width(-1.0);
ui.text_wrapped(self.error.as_ref().unwrap()); ui.text_wrapped(self.error.as_ref().unwrap());

View file

@ -1,6 +1,4 @@
#[doc(hidden)] #[doc(hidden)]
pub use core::convert::Into;
#[doc(hidden)]
pub use core::fmt; pub use core::fmt;
#[doc(hidden)] #[doc(hidden)]
pub use core::mem::size_of; pub use core::mem::size_of;

View file

@ -237,12 +237,12 @@ impl Scene for EditorScene {
menu_bar.end(); menu_bar.end();
} }
Window::new("Toolbar") ui.window("Toolbar")
.title_bar(false) .title_bar(false)
.resizable(false) .resizable(false)
.position([0.0, menu_bar_size.1], Condition::Always) .position([0.0, menu_bar_size.1], Condition::Always)
.size([menu_bar_size.0, 0.0], Condition::Always) .size([menu_bar_size.0, 0.0], Condition::Always)
.build(ui, || { .build(|| {
if ui.tool_button("Move", self.current_tool == CurrentTool::Move) { if ui.tool_button("Move", self.current_tool == CurrentTool::Move) {
self.current_tool = CurrentTool::Move; self.current_tool = CurrentTool::Move;
} }
@ -321,12 +321,12 @@ impl StageListWindow {
return; return;
} }
Window::new("Stage list") ui.window("Stage list")
.resizable(false) .resizable(false)
.collapsible(false) .collapsible(false)
.position_pivot([0.5, 0.5]) .position_pivot([0.5, 0.5])
.size([300.0, 352.0], Condition::FirstUseEver) .size([300.0, 352.0], Condition::FirstUseEver)
.build(ui, || { .build(|| {
let mut stages = Vec::with_capacity(state.stages.len()); let mut stages = Vec::with_capacity(state.stages.len());
for stage in state.stages.iter() { for stage in state.stages.iter() {
stages.push(stage.name.as_str()); stages.push(stage.name.as_str());