Added file selection

Still need to do launcher
This commit is contained in:
2023-05-31 23:13:49 +01:00
parent b871c48c60
commit 5a8d57ee4f
2 changed files with 24 additions and 22 deletions

View File

@@ -7,3 +7,4 @@ edition = "2021"
[dependencies] [dependencies]
eframe = "0.21.3" eframe = "0.21.3"
rfd = "*"

View File

@@ -25,16 +25,8 @@ impl Default for RustDoomLauncher {
fn default() -> Self { fn default() -> Self {
Self { Self {
launchers: vec!["GZDoom 1.9".to_string(), "PRBoom+".to_string()], launchers: vec!["GZDoom 1.9".to_string(), "PRBoom+".to_string()],
all_iwads: vec![ all_iwads: Vec::new(),
"DOOM2.WAD".to_string(), all_pwads: Vec::new(),
"DOOM.WAD".to_string(),
"FREEDOOM.WAD".to_string(),
],
all_pwads: vec![
"DOOM2.WAD".to_string(),
"DOOM.WAD".to_string(),
"FREEDOOM.WAD".to_string(),
],
selected_launcher: None, selected_launcher: None,
selected_iwad: None, selected_iwad: None,
selected_pwads: Vec::new(), selected_pwads: Vec::new(),
@@ -49,9 +41,7 @@ impl eframe::App for RustDoomLauncher {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Launcers"); ui.label("Launcers");
if ui.button("Add Launcher").clicked() { if ui.button("Add Launcher").clicked() {
// Open file selector todo!();
// Add to the launchers list
// done?
} }
}); });
for launcher in &self.launchers { for launcher in &self.launchers {
@@ -69,9 +59,11 @@ impl eframe::App for RustDoomLauncher {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("IWADs"); ui.label("IWADs");
if ui.button("Add IWAD").clicked() { if ui.button("Add IWAD").clicked() {
// Open file selector if let Some(paths) = rfd::FileDialog::new().pick_files() {
// Add to the IWADS list for path in paths {
// done? self.all_iwads.push(path.display().to_string());
}
}
} }
}); });
for iwad in &self.all_iwads { for iwad in &self.all_iwads {
@@ -89,9 +81,11 @@ impl eframe::App for RustDoomLauncher {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("PWADs"); ui.label("PWADs");
if ui.button("Add PWAD").clicked() { if ui.button("Add PWAD").clicked() {
// Open file selector if let Some(paths) = rfd::FileDialog::new().pick_files() {
// Add to the PWADS list for path in paths {
// done? self.all_pwads.push(path.display().to_string());
}
}
} }
}); });
for pwad in &self.all_pwads { for pwad in &self.all_pwads {
@@ -107,7 +101,8 @@ impl eframe::App for RustDoomLauncher {
} }
ui.label("Command"); ui.label("Command");
ui.horizontal(|ui| { ui.horizontal(|ui| {
// I don't actually think using SelectableLabel is correct here - but it'll at least do the highlighting when hovered correctly // I don't actually think using SelectableLabel is correct here -
// but it'll at least do the highlighting when hovered nicely
if let Some(l) = &self.selected_launcher { if let Some(l) = &self.selected_launcher {
if ui.add(egui::SelectableLabel::new(false, l)).clicked() { if ui.add(egui::SelectableLabel::new(false, l)).clicked() {
self.selected_launcher = None; self.selected_launcher = None;
@@ -123,9 +118,15 @@ impl eframe::App for RustDoomLauncher {
ui.label("Select an iwad plz"); ui.label("Select an iwad plz");
} }
// This feels ver much more C-like, but I think it works? // This feels ver much more C-like, but I think it works?
let mut pos = 0 as usize; let mut pos = 0_usize;
while pos < self.selected_pwads.len() { while pos < self.selected_pwads.len() {
if ui.add(egui::SelectableLabel::new(false, self.selected_pwads[pos].clone())).clicked() { if ui
.add(egui::SelectableLabel::new(
false,
self.selected_pwads[pos].clone(),
))
.clicked()
{
self.selected_pwads.remove(pos); self.selected_pwads.remove(pos);
continue; continue;
} }