mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Refactor things a bit, allow entering only ip in connect-by-ip screen.
This commit is contained in:
parent
38b90e158e
commit
b822c656b4
1 changed files with 98 additions and 76 deletions
|
@ -21,7 +21,6 @@ use net::{
|
|||
};
|
||||
use self_update::SelfUpdateManager;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::{
|
||||
fmt::Display,
|
||||
net::SocketAddr,
|
||||
|
@ -30,6 +29,7 @@ use std::{
|
|||
thread::JoinHandle,
|
||||
time::Duration,
|
||||
};
|
||||
use std::{net::IpAddr, path::PathBuf};
|
||||
use steamworks::{LobbyId, SteamAPIInitError};
|
||||
use tangled::Peer;
|
||||
use tracing::info;
|
||||
|
@ -48,6 +48,9 @@ pub use bookkeeping::{mod_manager, releases, self_update};
|
|||
mod net;
|
||||
mod player_cosmetics;
|
||||
pub mod recorder;
|
||||
|
||||
const DEFAULT_PORT: u16 = 5123;
|
||||
|
||||
#[derive(Debug, Decode, Encode, Clone, Serialize, Deserialize, PartialEq, Eq, Copy)]
|
||||
pub(crate) enum GameMode {
|
||||
SharedHealth,
|
||||
|
@ -393,7 +396,7 @@ impl App {
|
|||
}
|
||||
|
||||
fn start_server(&mut self) {
|
||||
let bind_addr = "0.0.0.0:5123".parse().unwrap();
|
||||
let bind_addr = SocketAddr::new("0.0.0.0".parse().unwrap(), DEFAULT_PORT);
|
||||
let peer = Peer::host(bind_addr, None).unwrap();
|
||||
let netman = net::NetManager::new(PeerVariant::Tangled(peer), self.get_netman_init());
|
||||
self.set_netman_settings(&netman);
|
||||
|
@ -419,6 +422,7 @@ impl App {
|
|||
*netman.pending_settings.lock().unwrap() = settings.clone();
|
||||
netman.accept_local.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
fn start_connect(&mut self, addr: SocketAddr) {
|
||||
let peer = Peer::connect(addr, None).unwrap();
|
||||
let netman = net::NetManager::new(PeerVariant::Tangled(peer), self.get_netman_init());
|
||||
|
@ -486,6 +490,36 @@ impl App {
|
|||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
|
||||
self.panel_right_bar(ui, ctx);
|
||||
})
|
||||
});
|
||||
|
||||
ui.allocate_ui_at_rect(settings_rect.shrink(group_shrink), |ui| {
|
||||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||
self.show_game_settings(ui, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.allocate_ui_at_rect(steam_connect_rect.shrink(group_shrink), |ui| {
|
||||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
|
||||
self.panel_connect_by_steam(ui);
|
||||
});
|
||||
});
|
||||
ui.allocate_ui_at_rect(ip_connect_rect.shrink(group_shrink), |ui| {
|
||||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
|
||||
self.panel_connect_by_ip(ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn panel_right_bar(&mut self, ui: &mut Ui, ctx: &Context) {
|
||||
let lang_label = self
|
||||
.app_saved_state
|
||||
.lang_id
|
||||
|
@ -513,21 +547,9 @@ impl App {
|
|||
self.modmanager_settings = Default::default();
|
||||
self.state = AppState::LangPick;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
ui.allocate_ui_at_rect(settings_rect.shrink(group_shrink), |ui| {
|
||||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||
self.show_game_settings(ui, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
ui.allocate_ui_at_rect(steam_connect_rect.shrink(group_shrink), |ui| {
|
||||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
}
|
||||
|
||||
fn panel_connect_by_steam(&mut self, ui: &mut Ui) {
|
||||
heading_with_underline(ui, tr("connect_steam"));
|
||||
|
||||
match &self.steam_state {
|
||||
|
@ -559,12 +581,9 @@ impl App {
|
|||
ui.label(format!("Could not init steam networking: {}", err));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.allocate_ui_at_rect(ip_connect_rect.shrink(group_shrink), |ui| {
|
||||
filled_group(ui, |ui| {
|
||||
ui.set_min_size(ui.available_size());
|
||||
}
|
||||
|
||||
fn panel_connect_by_ip(&mut self, ui: &mut Ui) {
|
||||
heading_with_underline(ui, tr("connect_ip"));
|
||||
|
||||
ui.label(tr("ip_note"));
|
||||
|
@ -574,6 +593,12 @@ impl App {
|
|||
|
||||
ui.text_edit_singleline(&mut self.app_saved_state.addr);
|
||||
let addr = self.app_saved_state.addr.parse();
|
||||
|
||||
let ip: Result<IpAddr, _> = self.app_saved_state.addr.parse();
|
||||
let addr2 = ip.map(|ip| SocketAddr::new(ip, DEFAULT_PORT));
|
||||
|
||||
let addr = addr.or(addr2);
|
||||
|
||||
ui.add_enabled_ui(addr.is_ok(), |ui| {
|
||||
if ui.button(tr("ip_connect")).clicked() {
|
||||
if let Ok(addr) = addr {
|
||||
|
@ -581,9 +606,6 @@ impl App {
|
|||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn show_game_settings(&mut self, ui: &mut Ui, show_local: bool) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue