Skip to content

Commit

Permalink
Show current mappers in tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupeyy committed Jan 16, 2025
1 parent bc8d3a2 commit eb8ff98
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion game/editor/src/action_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub fn merge_actions(actions: &mut Vec<EditorAction>) -> anyhow::Result<()> {
break;
}
} else {
break;
unreachable!();
}
}

Expand Down
2 changes: 1 addition & 1 deletion game/editor/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct EditorClient {
notifications: EditorNotifications,
local_client: bool,

clients: Vec<ClientProps>,
pub(crate) clients: Vec<ClientProps>,

mapper_name: String,
}
Expand Down
2 changes: 1 addition & 1 deletion game/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ impl Editor {
password,
mapper_name,
} => self.new_map(
"loading",
&ip_port.clone(),
MapLoadOptions::WithoutServer {
server_addr: ip_port,
cert_hash: (0..cert_hash.len())
Expand Down
25 changes: 12 additions & 13 deletions game/editor/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ impl EditorServer {
}
}

fn broadcast_client_infos(&self) {
self.network
.send(EditorEvent::Server(EditorEventServerToClient::Infos(
self.clients.values().map(|c| c.props.clone()).collect(),
)));
}

pub fn update(
&mut self,
tp: &Arc<rayon::ThreadPool>,
Expand Down Expand Up @@ -195,13 +202,13 @@ impl EditorServer {
)),
);
}

self.broadcast_client_infos();
}
} else if client.is_authed {
match ev {
EditorEventClientToServer::Action(act) => {
if self.cur_action_group < self.action_groups.len() {
self.action_groups.truncate(self.cur_action_group + 1);
}
self.action_groups.truncate(self.cur_action_group + 1);

if self
.action_groups
Expand Down Expand Up @@ -370,20 +377,12 @@ impl EditorServer {
NetworkEvent::Connected { .. } => {
self.clients.insert(id, Client::default());

self.network.send(EditorEvent::Server(
EditorEventServerToClient::Infos(
self.clients.values().map(|c| c.props.clone()).collect(),
),
));
self.broadcast_client_infos();
}
NetworkEvent::Disconnected { .. } => {
self.clients.remove(&id);

self.network.send(EditorEvent::Server(
EditorEventServerToClient::Infos(
self.clients.values().map(|c| c.props.clone()).collect(),
),
));
self.broadcast_client_infos();
}
_ => {
// ignore
Expand Down
31 changes: 22 additions & 9 deletions game/editor/src/ui/top_tabs/main_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@ pub fn render(ui: &mut egui::Ui, pipe: &mut UiRenderPipe<UserData>) {
ui.horizontal(|ui| {
ui.style_mut().spacing.item_spacing.x = 0.0;
let mut remove_tab = None;
for tab in pipe.user_data.editor_tabs.tabs.keys() {
if ui
.add(
Button::new(tab).selected(pipe.user_data.editor_tabs.active_tab == tab),
)
.clicked()
{
*pipe.user_data.editor_tabs.active_tab = tab.clone();
for (tab_name, tab) in pipe.user_data.editor_tabs.tabs.iter() {
let tab_display_name = if tab.client.clients.len() > 1 {
format!("\u{f0c0} {tab_name}")
} else {
tab_name.clone()
};
let mut btn = ui.add(
Button::new(tab_display_name)
.selected(pipe.user_data.editor_tabs.active_tab == tab_name),
);
if tab.client.clients.len() > 1 {
btn = btn.on_hover_ui(|ui| {
ui.vertical(|ui| {
for client in tab.client.clients.iter() {
ui.label(&client.mapper_name);
}
});
})
}
if btn.clicked() {
*pipe.user_data.editor_tabs.active_tab = tab_name.clone();
}
if ui.add(Button::new("\u{f00d}")).clicked() {
remove_tab = Some(tab.clone());
remove_tab = Some(tab_name.clone());
}
ui.add_space(10.0);
}
Expand Down

0 comments on commit eb8ff98

Please sign in to comment.