From 39550d93c8384b909fb032f3297f155fb5f00992 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Fri, 16 Aug 2024 16:51:45 -0400 Subject: [PATCH] add button to reset seed and save states, dont show local settings for a frame in net manager ui --- noita-proxy/Cargo.lock | 51 +++++++++++++++--------------------------- noita-proxy/Cargo.toml | 2 +- noita-proxy/src/lib.rs | 32 +++++++++++++++++--------- noita-proxy/src/net.rs | 36 +++++++++++++++++++---------- 4 files changed, 65 insertions(+), 56 deletions(-) diff --git a/noita-proxy/Cargo.lock b/noita-proxy/Cargo.lock index a79d066c..fe5aed57 100644 --- a/noita-proxy/Cargo.lock +++ b/noita-proxy/Cargo.lock @@ -128,12 +128,6 @@ dependencies = [ "x11rb", ] -[[package]] -name = "arc-swap" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" - [[package]] name = "argh" version = "0.1.12" @@ -331,18 +325,18 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.3" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" +checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" dependencies = [ "proc-macro2", "quote", @@ -442,9 +436,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.11" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189" +checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" dependencies = [ "jobserver", "libc", @@ -1148,9 +1142,9 @@ dependencies = [ [[package]] name = "fluent-template-macros" -version = "0.9.4" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77d2bcae1f3ec390c50161fcf130d3228750e9ecf965618584e046d884199b83" +checksum = "da77a943b6ad467c33ea31ce0998c33b3c566c5ef3f64416995ed61b4c473404" dependencies = [ "flume", "ignore", @@ -1163,23 +1157,20 @@ dependencies = [ [[package]] name = "fluent-templates" -version = "0.9.4" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197feb1e37209c6b3d29f0754b11fc070890efb2b1d761caac4e5287a200e9db" +checksum = "4e311f7dcf02d2af6c66cf6fda01348cefb912976698ac99abf0498ee2a62155" dependencies = [ - "arc-swap", "fluent", "fluent-bundle", "fluent-langneg", "fluent-syntax", "fluent-template-macros", "flume", - "heck", "ignore", "intl-memoizer", "log", "once_cell", - "serde_json", "thiserror", "unic-langid", ] @@ -1464,12 +1455,6 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -1788,9 +1773,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.156" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a" [[package]] name = "libloading" @@ -2927,18 +2912,18 @@ checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" [[package]] name = "serde" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", @@ -2947,9 +2932,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.124" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ "itoa", "memchr", diff --git a/noita-proxy/Cargo.toml b/noita-proxy/Cargo.toml index 1cdfabac..cd6ee09c 100644 --- a/noita-proxy/Cargo.toml +++ b/noita-proxy/Cargo.toml @@ -38,7 +38,7 @@ self-replace = "1.3.7" bytemuck = { version = "1.16.0", features = ["derive"] } bincode = "1.3.3" rustc-hash = "2.0.0" -fluent-templates = "0.9.4" +fluent-templates = "0.10.0" unic-langid = { version = "0.9.5", features = ["serde"] } fluent-bundle = "0.15.3" crc = "3.2.1" diff --git a/noita-proxy/src/lib.rs b/noita-proxy/src/lib.rs index b376b04b..fe037be7 100644 --- a/noita-proxy/src/lib.rs +++ b/noita-proxy/src/lib.rs @@ -206,6 +206,7 @@ pub struct App { /// `true` if we haven't started noita automatically yet. can_start_automatically: bool, player_image: RgbaImage, + end_run_confirmation: bool, } const MODMANAGER: &str = "modman"; @@ -287,6 +288,7 @@ impl App { can_start_automatically: false, run_save_state, player_image, + end_run_confirmation: false } } @@ -458,7 +460,7 @@ impl App { filled_group(ui, |ui| { ui.set_min_size(ui.available_size()); ScrollArea::both().auto_shrink(false).show(ui, |ui| { - self.show_game_settings(ui); + self.show_game_settings(ui, true); }); }); }); @@ -524,7 +526,7 @@ impl App { }); } - fn show_game_settings(&mut self, ui: &mut Ui) { + fn show_game_settings(&mut self, ui: &mut Ui, show_local: bool) { heading_with_underline(ui, tr("connect_settings")); let game_settings = &mut self.app_saved_state.game_settings; ui.label("Game mode"); @@ -593,7 +595,7 @@ impl App { ); ui.add_space(20.0); ui.checkbox(&mut game_settings.friendly_fire, "Friendly fire"); - if !self.show_settings { + if show_local { heading_with_underline(ui, tr("connect_settings_local")); ui.checkbox( &mut self.app_saved_state.start_game_automatically, @@ -811,6 +813,16 @@ impl eframe::App for App { } if netman.peer.is_host() { + ui.add_space(15.0); + if !self.end_run_confirmation && ui.button("End run").clicked() + { + self.end_run_confirmation = true + } + else if self.end_run_confirmation && ui.button("Confirm").clicked() + { + self.end_run_confirmation = false; + netman.end_run.store(true, Ordering::Relaxed) + } ui.add_space(15.0); if ui.button(tr("netman_show_settings")).clicked() { self.show_settings = true; @@ -862,10 +874,10 @@ impl eframe::App for App { if netman.peer.is_host() { let mut show = self.show_settings; let netman = netman.clone(); - egui::Window::new(tr("connect_settings")) + Window::new(tr("connect_settings")) .open(&mut show) .show(ctx, |ui| { - self.show_game_settings(ui); + self.show_game_settings(ui, false); if ui.button(tr("netman_apply_settings")).clicked() { *netman.pending_settings.lock().unwrap() = self.app_saved_state.game_settings.clone(); @@ -886,7 +898,7 @@ impl eframe::App for App { } AppState::ModManager => { egui::CentralPanel::default().show(ctx, draw_bg); - egui::Window::new(tr("modman")) + Window::new(tr("modman")) .auto_sized() .anchor(Align2::CENTER_CENTER, [0.0, 0.0]) .show(ctx, |ui| { @@ -904,7 +916,7 @@ impl eframe::App for App { } AppState::SelfUpdate => { egui::CentralPanel::default().show(ctx, draw_bg); - egui::Window::new(tr("selfupdate")) + Window::new(tr("selfupdate")) .auto_sized() .anchor(Align2::CENTER_CENTER, [0.0, 0.0]) .show(ctx, |ui| { @@ -914,7 +926,7 @@ impl eframe::App for App { } AppState::LangPick => { egui::CentralPanel::default().show(ctx, draw_bg); - egui::Window::new(tr("lang_picker")) + Window::new(tr("lang_picker")) .auto_sized() .anchor(Align2::CENTER_CENTER, [0.0, 0.0]) .show(ctx, |ui| { @@ -933,7 +945,7 @@ impl eframe::App for App { }); } AppState::AskSavestateReset => { - egui::Window::new(tr("An-in-progress-run-has-been-detected")) + Window::new(tr("An-in-progress-run-has-been-detected")) .auto_sized() .anchor(Align2::CENTER_CENTER, [0.0, 0.0]) .show(ctx, |ui| { @@ -1028,4 +1040,4 @@ fn peer_role(peer: net::omni::OmniPeerId, netman: &Arc) -> Stri } else { tr("player_player") } -} +} \ No newline at end of file diff --git a/noita-proxy/src/net.rs b/noita-proxy/src/net.rs index 2d576d6f..25332ffa 100644 --- a/noita-proxy/src/net.rs +++ b/noita-proxy/src/net.rs @@ -117,6 +117,7 @@ pub struct NetManager { pub init_settings: NetManagerInit, pub world_info: WorldInfo, pub enable_recorder: AtomicBool, + pub end_run: AtomicBool, } impl NetManager { @@ -133,6 +134,7 @@ impl NetManager { init_settings: init, world_info: Default::default(), enable_recorder: AtomicBool::new(false), + end_run: AtomicBool::new(false), } .into() } @@ -225,6 +227,11 @@ impl NetManager { ), ); while self.continue_running.load(atomic::Ordering::Relaxed) { + if self.end_run.load(atomic::Ordering::Relaxed) + { + self.end_run(&mut state); + self.end_run.store(false, atomic::Ordering::Relaxed); + } self.local_connected .store(state.ws.is_some(), atomic::Ordering::Relaxed); if state.ws.is_none() && self.accept_local.load(atomic::Ordering::SeqCst) { @@ -492,17 +499,7 @@ impl NetManager { Some("game_over") => { if self.is_host() { info!("Game over, resending game settings"); - self.init_settings.save_state.reset(); - { - let mut settings = self.pending_settings.lock().unwrap().clone(); - if !settings.use_constant_seed { - settings.seed = rand::random(); - } - info!("New seed: {}", settings.seed); - *self.settings.lock().unwrap() = settings; - state.world.reset() - } - self.resend_game_settings(); + self.end_run(state) } } Some("peer_pos") => { @@ -537,6 +534,21 @@ impl NetManager { } } } + + fn end_run(&self, state: &mut NetInnerState) + { + self.init_settings.save_state.reset(); + { + let mut settings = self.pending_settings.lock().unwrap().clone(); + if !settings.use_constant_seed { + settings.seed = rand::random(); + } + info!("New seed: {}", settings.seed); + *self.settings.lock().unwrap() = settings; + state.world.reset() + } + self.resend_game_settings(); + } } impl Drop for NetManager { @@ -551,4 +563,4 @@ impl Drop for NetManager { info!("Skip saving run info: not a host"); } } -} +} \ No newline at end of file