Skip to content

Commit

Permalink
add more confirm popups
Browse files Browse the repository at this point in the history
  • Loading branch information
Nertsal committed Oct 20, 2024
1 parent 3949a93 commit e7fff07
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/editor/action/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum EditorAction {
ToggleUI,
ToggleGrid,
ToggleGridSnap,
DeleteLevel,
DeleteLevel(usize),
NewLevel,
ChangeLevel(usize),
MoveLevelLow(usize),
Expand Down Expand Up @@ -51,7 +51,9 @@ impl Editor {
self.render_options.show_grid = !self.render_options.show_grid
}
EditorAction::ToggleGridSnap => self.snap_to_grid = !self.snap_to_grid,
EditorAction::DeleteLevel => self.delete_active_level(),
EditorAction::DeleteLevel(i) => {
self.popup_confirm(ConfirmAction::DeleteLevel(i), "delete this difficulty")
}
EditorAction::NewLevel => self.create_new_level(),
EditorAction::ChangeLevel(i) => self.change_level(i),
EditorAction::MoveLevelLow(i) => self.move_level_low(i),
Expand Down
13 changes: 8 additions & 5 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
pub enum ConfirmAction {
ExitUnsaved,
ChangeLevelUnsaved(usize),
DeleteLevel(usize),
}

pub struct EditorState {
Expand Down Expand Up @@ -443,11 +444,12 @@ impl geng::State for EditorState {
}

impl Editor {
fn delete_active_level(&mut self) {
let Some(level_editor) = self.level_edit.take() else {
return;
};
let level_index = level_editor.static_level.level_index;
fn delete_level(&mut self, level_index: usize) {
if let Some(level_editor) = &self.level_edit {
if level_index == level_editor.static_level.level_index {
self.level_edit = None;
}
}

if !(0..self.group.cached.data.levels.len()).contains(&level_index) {
log::error!(
Expand Down Expand Up @@ -630,6 +632,7 @@ impl Editor {
match popup.action {
ConfirmAction::ExitUnsaved => self.exit(),
ConfirmAction::ChangeLevelUnsaved(index) => self.change_level(index),
ConfirmAction::DeleteLevel(index) => self.delete_level(index),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/editor/ui/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ impl StatefulWidget for EditorConfigWidget {
self.level_delete.show();
self.level_delete.update(delete, context);
if self.level_delete.text.state.clicked {
actions.push(EditorAction::DeleteLevel.into());
let index = level_editor.static_level.level_index;
actions.push(EditorAction::DeleteLevel(index).into());
}
} else {
self.level_name.hide();
Expand Down
4 changes: 4 additions & 0 deletions src/menu/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
pub enum ConfirmAction {
DeleteMusic(Id),
DeleteGroup(Index),
DeleteLevel(Index, usize),
SyncDiscard,
DownloadRecommended,
SyncUpload,
Expand Down Expand Up @@ -168,6 +169,9 @@ impl MenuState {
match popup.action {
ConfirmAction::DeleteMusic(id) => self.context.local.delete_music(id),
ConfirmAction::DeleteGroup(index) => self.context.local.delete_group(index),
ConfirmAction::DeleteLevel(group, level) => {
self.context.local.delete_level(group, level)
}
ConfirmAction::SyncDiscard => {
if let Some(sync) = &mut ui.sync {
if let Some(client) = self.leaderboard.client.clone() {
Expand Down
5 changes: 4 additions & 1 deletion src/menu/level/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ impl MenuUI {
state.edit_level(group, Some(level));
}
LevelSelectAction::DeleteLevel(group, level) => {
self.context.local.delete_level(group, level);
state.popup_confirm(
ConfirmAction::DeleteLevel(group, level),
"delete this difficulty",
);
}
LevelSelectAction::EditGroup(group) => {
state.edit_level(group, None);
Expand Down

0 comments on commit e7fff07

Please sign in to comment.