Adding is done in new window now
This commit is contained in:
156
src/main.rs
156
src/main.rs
@@ -35,8 +35,17 @@ struct RustDoomLauncher {
|
||||
fast_monsters: bool,
|
||||
respawning_monsters: bool,
|
||||
display_command: bool,
|
||||
add_stuff_window_displayed: bool,
|
||||
selected_file_type: FileType,
|
||||
selected_file_path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum FileType {
|
||||
Iwad,
|
||||
Pwad,
|
||||
Launcher,
|
||||
}
|
||||
// Great name, I know
|
||||
enum MyErrors {
|
||||
NoLauncher,
|
||||
@@ -60,6 +69,9 @@ impl Default for RustDoomLauncher {
|
||||
fast_monsters: false,
|
||||
respawning_monsters: false,
|
||||
display_command: false,
|
||||
add_stuff_window_displayed: false,
|
||||
selected_file_type: FileType::Pwad,
|
||||
selected_file_path: PathBuf::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,12 +102,8 @@ impl RustDoomLauncher {
|
||||
let (launcher, iwad) = match self.launcher_and_iwad() {
|
||||
Err(e) => {
|
||||
let text = match e {
|
||||
MyErrors::NoIwad => {
|
||||
"an IWAD"
|
||||
},
|
||||
MyErrors::NoLauncher => {
|
||||
"a launcher"
|
||||
}
|
||||
MyErrors::NoIwad => "an IWAD",
|
||||
MyErrors::NoLauncher => "a launcher",
|
||||
};
|
||||
if show_dialogs {
|
||||
MessageDialog::new()
|
||||
@@ -106,8 +114,8 @@ impl RustDoomLauncher {
|
||||
.unwrap();
|
||||
}
|
||||
return Err(e);
|
||||
},
|
||||
Ok((l, i)) => (l, i)
|
||||
}
|
||||
Ok((l, i)) => (l, i),
|
||||
};
|
||||
let mut command = vec!["-iwad", iwad.path.to_str().unwrap()];
|
||||
for pwad_index in &self.selected_pwads {
|
||||
@@ -186,15 +194,19 @@ impl eframe::App for RustDoomLauncher {
|
||||
self.config_file_loaded = true;
|
||||
}
|
||||
egui::containers::panel::CentralPanel::default().show(ctx, |ui| {
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.heading("RustDoomLauncher");
|
||||
let button = match self.launcher_and_iwad() {
|
||||
Err(_) => egui::Button::new("PLAY SOME DOOM!"),
|
||||
Ok((_, _)) => egui::Button::new("PLAY SOME DOOM!").fill(Color32::DARK_GREEN)
|
||||
Ok((_, _)) => egui::Button::new("PLAY SOME DOOM!").fill(Color32::DARK_GREEN),
|
||||
};
|
||||
if ui.add(button).clicked() {
|
||||
self.launch_doom();
|
||||
}
|
||||
if ui.button("Add WAD or Launcher").clicked() {
|
||||
self.add_stuff_window_displayed = true;
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
@@ -245,53 +257,6 @@ impl eframe::App for RustDoomLauncher {
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
ui.vertical(|ui| {
|
||||
ui.label("Add WADs etc");
|
||||
ui.set_max_width(180.0);
|
||||
ui.horizontal(|ui| {
|
||||
let name_label = ui.label("Name:");
|
||||
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 these unwraps perhaps? Unsure whether the FileDialog can actually
|
||||
// return something that isn't a file
|
||||
path.file_name().unwrap().to_str().unwrap().to_string()
|
||||
} else {
|
||||
name.clone()
|
||||
}
|
||||
};
|
||||
|
||||
if ui.button("Add Launcher").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
self.all_launchers.push(LauncherInfo {
|
||||
name: get_name(&path, &self.name),
|
||||
path,
|
||||
});
|
||||
}
|
||||
}
|
||||
if ui.button("Add IWAD").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
self.all_iwads.push(WadInfo {
|
||||
name: get_name(&path, &self.name),
|
||||
path,
|
||||
});
|
||||
}
|
||||
}
|
||||
// TODO - add Mod button - or probably just rethink the whole thing
|
||||
if ui.button("Add PWAD or Mod").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
self.all_pwads.push(WadInfo {
|
||||
name: get_name(&path, &self.name),
|
||||
path,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
@@ -390,5 +355,84 @@ impl eframe::App for RustDoomLauncher {
|
||||
});
|
||||
}
|
||||
});
|
||||
egui::Window::new("Add WAD or Launcher")
|
||||
.open(&mut self.add_stuff_window_displayed)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let name_label = ui.label("Name");
|
||||
ui.text_edit_singleline(&mut self.name)
|
||||
.labelled_by(name_label.id);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Path");
|
||||
ui.label(
|
||||
self.selected_file_path
|
||||
.clone()
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.unwrap(),
|
||||
);
|
||||
if ui.button("Find").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
self.selected_file_path = path;
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("What sort of file is it?");
|
||||
if ui
|
||||
.add(egui::SelectableLabel::new(
|
||||
self.selected_file_type == FileType::Pwad,
|
||||
"PWAD",
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
self.selected_file_type = FileType::Pwad
|
||||
}
|
||||
if ui
|
||||
.add(egui::SelectableLabel::new(
|
||||
self.selected_file_type == FileType::Iwad,
|
||||
"IWAD",
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
self.selected_file_type = FileType::Iwad
|
||||
}
|
||||
if ui
|
||||
.add(egui::SelectableLabel::new(
|
||||
self.selected_file_type == FileType::Launcher,
|
||||
"Launcher",
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
self.selected_file_type = FileType::Launcher
|
||||
}
|
||||
});
|
||||
if ui.button("Add!").clicked() {
|
||||
if self.name.is_empty() || self.selected_file_path.as_os_str().is_empty() {
|
||||
return;
|
||||
}
|
||||
match self.selected_file_type {
|
||||
FileType::Iwad => {
|
||||
self.all_iwads.push(WadInfo {
|
||||
name: self.name.clone(),
|
||||
path: self.selected_file_path.clone(),
|
||||
});
|
||||
}
|
||||
FileType::Pwad => {
|
||||
self.all_pwads.push(WadInfo {
|
||||
name: self.name.clone(),
|
||||
path: self.selected_file_path.clone(),
|
||||
});
|
||||
}
|
||||
FileType::Launcher => {
|
||||
self.all_launchers.push(LauncherInfo {
|
||||
name: self.name.clone(),
|
||||
path: self.selected_file_path.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user