Fix map selection interface
This commit is contained in:
parent
cf68bd7887
commit
254aa640fa
@ -110,6 +110,7 @@ impl CliParser {
|
|||||||
map.bind().name.to_string().to_lowercase() == map_name.to_lowercase()
|
map.bind().name.to_string().to_lowercase() == map_name.to_lowercase()
|
||||||
});
|
});
|
||||||
if let Some((map_idx, _)) = map {
|
if let Some((map_idx, _)) = map {
|
||||||
|
game.bind_mut().forced_map_selection = true;
|
||||||
game.bind_mut().change_map_selection(map_idx as u8, true);
|
game.bind_mut().change_map_selection(map_idx as u8, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -167,6 +167,7 @@ impl GameManager {
|
|||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Node, init)]
|
#[class(base=Node, init)]
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
|
pub forced_map_selection: bool,
|
||||||
pub selected_map_idx: u8,
|
pub selected_map_idx: u8,
|
||||||
pub selected_map: Option<Gd<MapResource>>,
|
pub selected_map: Option<Gd<MapResource>>,
|
||||||
pub maps: Array<Gd<MapResource>>,
|
pub maps: Array<Gd<MapResource>>,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use godot::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bgm::{Music, MusicManager},
|
bgm::{Music, MusicManager},
|
||||||
|
cli_parser::CliParser,
|
||||||
game::{
|
game::{
|
||||||
Game, GameManager,
|
Game, GameManager,
|
||||||
opts::{GameOption, GameOptionValue, GameOptions},
|
opts::{GameOption, GameOptionValue, GameOptions},
|
||||||
@ -73,8 +74,10 @@ impl IPanel for LobbyPanel {
|
|||||||
map_selection
|
map_selection
|
||||||
.signals()
|
.signals()
|
||||||
.item_selected()
|
.item_selected()
|
||||||
.connect_other(self, |s, id| {
|
.connect_other(self, |s, _| {
|
||||||
s.update_map_selection(id as u8);
|
if let Some(map_selection) = &s.map_selection {
|
||||||
|
s.update_map_selection(map_selection.get_selected_id() as u8);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +98,26 @@ impl IPanel for LobbyPanel {
|
|||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
if let Some(map_selection) = &mut self.map_selection {
|
if let Some(mut map_selection) = self.map_selection.clone() {
|
||||||
let prev_selection = game.bind().selected_map_idx as i32;
|
let mut prev_selection = game.bind().selected_map_idx;
|
||||||
|
let prev_selection_hidden =
|
||||||
|
if let Some(map) = game.bind().maps.get(prev_selection as usize) {
|
||||||
|
map.bind().hidden
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
if prev_selection_hidden && !game.bind().forced_map_selection {
|
||||||
|
if let Some((id, _)) = game
|
||||||
|
.bind()
|
||||||
|
.maps
|
||||||
|
.iter_shared()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_, m)| !m.bind().hidden)
|
||||||
|
{
|
||||||
|
prev_selection = id as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (id, map) in game.bind().maps.iter_shared().enumerate() {
|
for (id, map) in game.bind().maps.iter_shared().enumerate() {
|
||||||
if map.bind().hidden {
|
if map.bind().hidden {
|
||||||
continue;
|
continue;
|
||||||
@ -113,7 +134,8 @@ impl IPanel for LobbyPanel {
|
|||||||
.done();
|
.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
map_selection.select(prev_selection);
|
let idx = self.find_idx(prev_selection);
|
||||||
|
map_selection.select(idx);
|
||||||
if is_host {
|
if is_host {
|
||||||
self.update_map_selection(prev_selection as u8);
|
self.update_map_selection(prev_selection as u8);
|
||||||
}
|
}
|
||||||
@ -350,24 +372,36 @@ impl LobbyPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_map_selection(&mut self, idx: u8) {
|
pub fn update_map_selection(&mut self, id: u8) {
|
||||||
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
||||||
match peer {
|
match peer {
|
||||||
PeerKind::Client(peer, addr) => {
|
PeerKind::Client(peer, addr) => {
|
||||||
if let Some(map_selection) = &mut self.map_selection {
|
if let Some(mut map_selection) = self.map_selection.clone() {
|
||||||
map_selection.select(idx as i32);
|
map_selection.select(self.find_idx(id));
|
||||||
self.run_deferred(|s| s.update_players(false));
|
self.run_deferred(|s| s.update_players(false));
|
||||||
peer.send_reliable(addr, Package::SelectMap(idx));
|
peer.send_reliable(addr, Package::SelectMap(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PeerKind::Server(peer, _) => {
|
PeerKind::Server(peer, _) => {
|
||||||
if let Some(game) = &mut Game::singleton() {
|
if let Some(game) = &mut Game::singleton() {
|
||||||
game.bind_mut().change_map_selection(idx, false);
|
game.bind_mut().change_map_selection(id, false);
|
||||||
}
|
}
|
||||||
self.run_deferred(|s| s.update_players(false));
|
self.run_deferred(|s| s.update_players(false));
|
||||||
peer.broadcast_reliable(Package::SelectMap(idx));
|
peer.broadcast_reliable(Package::SelectMap(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_idx(&self, map_id: u8) -> i32 {
|
||||||
|
let mut idx = 0;
|
||||||
|
if let Some(map_selection) = &self.map_selection {
|
||||||
|
for i in 0..map_selection.get_item_count() {
|
||||||
|
if map_selection.get_item_id(i) == map_id as i32 {
|
||||||
|
idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
idx
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user