enter and exit solution editor

This commit is contained in:
Crispy 2024-10-06 16:00:12 +02:00
parent 44b7d63cde
commit c4381ac1a1
8 changed files with 195 additions and 41 deletions

View file

@ -11,7 +11,7 @@ mod marble_engine;
mod solution;
mod util;
use editor::Editor;
use editor::{Editor, ExitState};
use level::Level;
use marble_engine::board::Board;
use solution::Solution;
@ -67,6 +67,16 @@ impl Game {
if let Some(editor) = &mut self.open_editor {
editor.input(&d);
editor.draw(&mut d, &self.textures);
match editor.get_exit_state() {
ExitState::Dont => (),
ExitState::ExitNoSave => self.open_editor = None,
ExitState::ExitAndSave => {
self.solutions.get_mut(editor.level_id()).unwrap()
[self.selected_solution]
.board = editor.source_board().to_string();
self.open_editor = None;
}
}
} else {
self.draw(&mut d);
}
@ -165,7 +175,7 @@ impl Game {
if simple_button(d, level_list_width + 10, y, solution_entry_width, 30) {
let n = solutions.len();
solutions.push(Solution::new(level.id().to_owned(), n));
solutions.push(Solution::new(&level, n));
}
d.draw_text(
"new solution",
@ -179,7 +189,7 @@ impl Game {
let bounds = Rectangle {
x: (level_list_width + 10 + solution_entry_width + 10) as f32,
y: 60.,
width: 240.,
width: 220.,
height: 30.,
};
text_input(
@ -188,6 +198,12 @@ impl Game {
&mut solution.name,
&mut self.editing_solution_name,
);
let button_x = level_list_width + solution_entry_width + 20;
if simple_button(d, button_x, 100, 220, 30) {
self.open_editor = Some(Editor::new(solution.clone(), level.clone()));
}
d.draw_text("edit", button_x + 5, 105, 20, Color::WHITE);
}
} else {
self.solutions.insert(level.id().to_owned(), Vec::new());