Added start of config stuff

This commit is contained in:
2023-06-04 12:08:42 +01:00
parent 105c6073fb
commit eb4bb58549
4 changed files with 140 additions and 19 deletions

View File

@@ -1,5 +1,9 @@
use eframe::egui;
use std::path::PathBuf;
use infos::{WadInfo, LauncherInfo};
pub mod config;
pub mod infos;
fn main() -> Result<(), eframe::Error> {
println!("Hello, world!");
@@ -13,16 +17,6 @@ fn main() -> Result<(), eframe::Error> {
)
}
struct WadInfo {
path: PathBuf,
name: String,
}
struct LauncherInfo {
path: PathBuf,
name: String,
}
struct RustDoomLauncher {
all_launchers: Vec<LauncherInfo>,
all_iwads: Vec<WadInfo>,
@@ -102,7 +96,6 @@ impl eframe::App for RustDoomLauncher {
});
ui.separator();
ui.vertical(|ui| {
// TODO add default name as the path or something
ui.label("Add WADs etc");
ui.set_max_width(180.0);
ui.horizontal(|ui| {
@@ -110,7 +103,8 @@ impl eframe::App for RustDoomLauncher {
ui.text_edit_singleline(&mut self.name)
.labelled_by(name_label.id);
});
// It kind of feels like the right place to use a closure - unsure whether I need
// to pass both of these vaules in, or what the story is here.
let get_name = |path: &PathBuf, name: &String| {
if self.name.is_empty() {
// Check this perhaps? Unsure whether the FileDialog can actually
@@ -125,7 +119,7 @@ impl eframe::App for RustDoomLauncher {
if let Some(path) = rfd::FileDialog::new().pick_file() {
self.all_launchers.push(LauncherInfo {
name: get_name(&path, &self.name),
path: path
path,
});
}
}
@@ -133,7 +127,7 @@ impl eframe::App for RustDoomLauncher {
if let Some(path) = rfd::FileDialog::new().pick_file() {
self.all_iwads.push(WadInfo {
name: get_name(&path, &self.name),
path: path,
path,
});
}
}
@@ -141,7 +135,7 @@ impl eframe::App for RustDoomLauncher {
if let Some(path) = rfd::FileDialog::new().pick_file() {
self.all_pwads.push(WadInfo {
name: get_name(&path, &self.name),
path: path.clone(),
path,
});
}
}
@@ -153,9 +147,12 @@ impl eframe::App for RustDoomLauncher {
// but it'll at least do the highlighting when hovered nicely
if let Some(l) = self.selected_launcher {
if let Some(iwad) = self.all_launchers.get(l) {
if ui.add(egui::SelectableLabel::new(false, &iwad.name)).clicked() {
self.selected_launcher = None;
}
if ui
.add(egui::SelectableLabel::new(false, &iwad.name))
.clicked()
{
self.selected_launcher = None;
}
} else {
self.selected_launcher = None;
}