Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0caf7eb

Browse files
committedAug 21, 2023
Allow multiple mod detail windows
1 parent a44abff commit 0caf7eb

File tree

2 files changed

+60
-45
lines changed

2 files changed

+60
-45
lines changed
 

‎src/gui/message.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ async fn self_update_async(
718718
#[derive(Debug)]
719719
pub struct FetchModDetails {
720720
rid: RequestID,
721+
modio_id: u32,
721722
result: Result<ModDetails>,
722723
}
723724

@@ -744,34 +745,44 @@ impl FetchModDetails {
744745
rid,
745746
handle: tokio::task::spawn(async move {
746747
let result = fetch_modio_mod_details(oauth_token, modio_id).await;
747-
tx.send(Message::FetchModDetails(FetchModDetails { rid, result }))
748-
.await
749-
.unwrap();
748+
tx.send(Message::FetchModDetails(FetchModDetails {
749+
rid,
750+
result,
751+
modio_id,
752+
}))
753+
.await
754+
.unwrap();
750755
ctx.request_repaint();
751756
}),
752757
state: (),
753758
}
754759
}
755760

756761
fn receive(self, app: &mut App) {
757-
if Some(self.rid) == app.fetch_mod_details_rid.as_ref().map(|r| r.rid) {
762+
let mut to_remove = None;
763+
764+
if let Some(req) = app.fetch_mod_details_rid.get(&self.modio_id)
765+
&& req.rid == self.rid
766+
{
758767
match self.result {
759768
Ok(mod_details) => {
760769
info!("fetch mod details successful");
761-
app.mod_details = Some(mod_details);
770+
app.mod_details.insert(mod_details.r#mod.id, mod_details);
762771
app.last_action_status =
763772
LastActionStatus::Success("fetch mod details complete".to_string());
764773
}
765774
Err(e) => {
766775
error!("fetch mod details failed");
767776
error!("{:#?}", e);
768-
app.mod_details = None;
769-
app.fetch_mod_details_rid = None;
777+
to_remove = Some(self.modio_id);
770778
app.last_action_status =
771779
LastActionStatus::Failure("fetch mod details failed".to_string());
772780
}
773781
}
774-
app.integrate_rid = None;
782+
}
783+
784+
if let Some(id) = to_remove {
785+
app.fetch_mod_details_rid.remove(&id);
775786
}
776787
}
777788
}

‎src/gui/mod.rs

+41-37
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ pub struct App {
9393
needs_restart: bool,
9494
self_update_rid: Option<MessageHandle<SelfUpdateProgress>>,
9595
original_exe_path: Option<PathBuf>,
96-
detailed_mod_info_window: Option<WindowDetailedModInfo>,
97-
mod_details: Option<ModDetails>,
98-
fetch_mod_details_rid: Option<MessageHandle<()>>,
99-
mod_details_thumbnail_texture_handle: Option<egui::TextureHandle>,
96+
detailed_mod_info_windows: HashMap<u32, WindowDetailedModInfo>,
97+
mod_details: HashMap<u32, ModDetails>,
98+
fetch_mod_details_rid: HashMap<u32, MessageHandle<()>>,
99+
mod_details_thumbnail_texture_handle: HashMap<u32, egui::TextureHandle>,
100100
}
101101

102102
#[derive(Default)]
@@ -156,10 +156,10 @@ impl App {
156156
needs_restart: false,
157157
self_update_rid: None,
158158
original_exe_path: None,
159-
detailed_mod_info_window: None,
160-
mod_details: None,
161-
fetch_mod_details_rid: None,
162-
mod_details_thumbnail_texture_handle: None,
159+
detailed_mod_info_windows: HashMap::default(),
160+
mod_details: HashMap::default(),
161+
fetch_mod_details_rid: HashMap::default(),
162+
mod_details_thumbnail_texture_handle: HashMap::default(),
163163
})
164164
}
165165

@@ -441,9 +441,8 @@ impl App {
441441
.on_hover_text_at_pointer("View details")
442442
.clicked()
443443
{
444-
self.detailed_mod_info_window =
445-
Some(WindowDetailedModInfo { info: info.clone() });
446-
self.fetch_mod_details_rid = Some(message::FetchModDetails::send(
444+
self.detailed_mod_info_windows.insert(modio_id, WindowDetailedModInfo { info: info.clone() });
445+
self.fetch_mod_details_rid.insert(modio_id, message::FetchModDetails::send(
447446
&mut self.request_counter,
448447
ui.ctx(),
449448
self.tx.clone(),
@@ -1411,40 +1410,35 @@ impl App {
14111410
}
14121411
}
14131412

1414-
fn show_detailed_mod_info(&mut self, ctx: &egui::Context) {
1415-
if let Some(WindowDetailedModInfo { info }) = &self.detailed_mod_info_window {
1416-
egui::Area::new("detailed-mod-info-overlay")
1417-
.movable(false)
1418-
.fixed_pos(Pos2::ZERO)
1419-
.order(egui::Order::Background)
1420-
.show(ctx, |ui| {
1421-
egui::Frame::none()
1422-
.fill(Color32::from_rgba_unmultiplied(0, 0, 0, 127))
1423-
.show(ui, |ui| {
1424-
ui.allocate_space(ui.available_size());
1425-
})
1426-
});
1413+
fn show_detailed_mod_info(&mut self, ctx: &egui::Context, modio_id: u32) {
1414+
let mut to_remove = Vec::new();
14271415

1416+
if let Some(WindowDetailedModInfo { info }) = self.detailed_mod_info_windows.get(&modio_id)
1417+
{
14281418
let mut open = true;
14291419

14301420
egui::Window::new(&info.name)
14311421
.open(&mut open)
14321422
.collapsible(false)
1433-
.anchor(Align2::CENTER_TOP, Vec2::new(0.0, 30.0))
1434-
.resizable(false)
1435-
.show(ctx, |ui| self.show_detailed_mod_info_inner(ui));
1423+
.movable(true)
1424+
.resizable(true)
1425+
.show(ctx, |ui| self.show_detailed_mod_info_inner(ui, modio_id));
14361426

14371427
if !open {
1438-
self.detailed_mod_info_window = None;
1439-
self.mod_details = None;
1440-
self.fetch_mod_details_rid = None;
1441-
self.mod_details_thumbnail_texture_handle = None;
1428+
to_remove.push(modio_id);
14421429
}
14431430
}
1431+
1432+
for id in to_remove {
1433+
self.detailed_mod_info_windows.remove(&id);
1434+
self.mod_details.remove(&id);
1435+
self.fetch_mod_details_rid.remove(&id);
1436+
self.mod_details_thumbnail_texture_handle.remove(&id);
1437+
}
14441438
}
14451439

1446-
fn show_detailed_mod_info_inner(&mut self, ui: &mut egui::Ui) {
1447-
if let Some(mod_details) = &self.mod_details {
1440+
fn show_detailed_mod_info_inner(&mut self, ui: &mut egui::Ui, modio_id: u32) {
1441+
if let Some(mod_details) = &self.mod_details.get(&modio_id) {
14481442
let scroll_area_height = (ui.available_height() - 60.0).clamp(0.0, f32::INFINITY);
14491443

14501444
egui::ScrollArea::vertical()
@@ -1455,7 +1449,8 @@ impl App {
14551449
.show(ui, |ui| {
14561450
let texture: &egui::TextureHandle = self
14571451
.mod_details_thumbnail_texture_handle
1458-
.get_or_insert_with(|| {
1452+
.entry(modio_id)
1453+
.or_insert_with(|| {
14591454
ui.ctx().load_texture(
14601455
format!("{} image", mod_details.r#mod.name),
14611456
{
@@ -1628,7 +1623,16 @@ impl eframe::App for App {
16281623
self.show_settings(ctx);
16291624
self.show_lints_toggle(ctx);
16301625
self.show_lint_report(ctx);
1631-
self.show_detailed_mod_info(ctx);
1626+
1627+
let modio_ids = self
1628+
.detailed_mod_info_windows
1629+
.keys()
1630+
.copied()
1631+
.collect::<Vec<_>>();
1632+
1633+
for modio_id in modio_ids {
1634+
self.show_detailed_mod_info(ctx, modio_id);
1635+
}
16321636

16331637
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
16341638
ui.with_layout(egui::Layout::right_to_left(Align::TOP), |ui| {
@@ -1637,8 +1641,8 @@ impl eframe::App for App {
16371641
&& self.update_rid.is_none()
16381642
&& self.lint_rid.is_none()
16391643
&& self.self_update_rid.is_none()
1640-
&& self.detailed_mod_info_window.is_none()
1641-
&& self.fetch_mod_details_rid.is_none()
1644+
&& self.detailed_mod_info_windows.is_empty()
1645+
&& self.fetch_mod_details_rid.is_empty()
16421646
&& self.state.config.drg_pak_path.is_some(),
16431647
|ui| {
16441648
if let Some(args) = &self.args {

0 commit comments

Comments
 (0)