mirror of
				https://github.com/WarrenHood/MCModpackManager.git
				synced 2025-11-04 01:38:41 +00:00 
			
		
		
		
	Load profiles into list view and some minor improvements to the GUI
This commit is contained in:
		
							parent
							
								
									bba534a134
								
							
						
					
					
						commit
						3f9627c738
					
				
							
								
								
									
										127
									
								
								mmm/src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										127
									
								
								mmm/src/main.rs
									
									
									
									
									
								
							| 
						 | 
					@ -1,10 +1,10 @@
 | 
				
			||||||
use std::path::PathBuf;
 | 
					use std::path::PathBuf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use iced::executor;
 | 
					 | 
				
			||||||
use iced::widget::{
 | 
					use iced::widget::{
 | 
				
			||||||
    button, checkbox, column, container, horizontal_rule, pick_list, progress_bar, row, scrollable,
 | 
					    button, checkbox, column, container, horizontal_rule, pick_list, progress_bar, row, scrollable,
 | 
				
			||||||
    slider, text, text_input, toggler, vertical_rule, vertical_space,
 | 
					    slider, text, text_input, toggler, vertical_rule, vertical_space, Column,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					use iced::{executor, Application, Command, Executor};
 | 
				
			||||||
use iced::{Alignment, Element, Length, Sandbox, Settings, Theme};
 | 
					use iced::{Alignment, Element, Length, Sandbox, Settings, Theme};
 | 
				
			||||||
use mcmpmgr::profiles::{self, Profile};
 | 
					use mcmpmgr::profiles::{self, Profile};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,7 @@ struct ManagerGUI {
 | 
				
			||||||
    theme: Theme,
 | 
					    theme: Theme,
 | 
				
			||||||
    selected_profile: Option<String>,
 | 
					    selected_profile: Option<String>,
 | 
				
			||||||
    userdata: profiles::Data,
 | 
					    userdata: profiles::Data,
 | 
				
			||||||
 | 
					    userdata_load_error: Option<String>,
 | 
				
			||||||
    current_view: ManagerView,
 | 
					    current_view: ManagerView,
 | 
				
			||||||
    previous_view: ManagerView,
 | 
					    previous_view: ManagerView,
 | 
				
			||||||
    profile_edit_settings: ProfileSettings,
 | 
					    profile_edit_settings: ProfileSettings,
 | 
				
			||||||
| 
						 | 
					@ -65,20 +66,34 @@ enum Message {
 | 
				
			||||||
    SaveProfile,
 | 
					    SaveProfile,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Sandbox for ManagerGUI {
 | 
					impl Application for ManagerGUI {
 | 
				
			||||||
    type Message = Message;
 | 
					    type Message = Message;
 | 
				
			||||||
 | 
					    type Executor = executor::Default;
 | 
				
			||||||
 | 
					    type Theme = Theme;
 | 
				
			||||||
 | 
					    type Flags = ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn new() -> Self {
 | 
					    fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) {
 | 
				
			||||||
        let mut gui = ManagerGUI::default();
 | 
					        let mut gui = ManagerGUI::default();
 | 
				
			||||||
        gui.theme = Theme::GruvboxDark;
 | 
					        gui.theme = Theme::GruvboxDark;
 | 
				
			||||||
        gui
 | 
					        let loaded_userdata = profiles::Data::load();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match loaded_userdata {
 | 
				
			||||||
 | 
					            Ok(userdata) => {
 | 
				
			||||||
 | 
					                gui.userdata = userdata;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Err(err) => {
 | 
				
			||||||
 | 
					                gui.userdata_load_error = Some(err.to_string());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        (gui, Command::none())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn title(&self) -> String {
 | 
					    fn title(&self) -> String {
 | 
				
			||||||
        String::from("Minecraft Modpack Manager")
 | 
					        String::from("Minecraft Modpack Manager")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn update(&mut self, message: Message) {
 | 
					    fn update(&mut self, message: Message) -> Command<Message> {
 | 
				
			||||||
        match message {
 | 
					        match message {
 | 
				
			||||||
            Message::SwitchView(view) => {
 | 
					            Message::SwitchView(view) => {
 | 
				
			||||||
                match &view {
 | 
					                match &view {
 | 
				
			||||||
| 
						 | 
					@ -86,24 +101,46 @@ impl Sandbox for ManagerGUI {
 | 
				
			||||||
                        self.profile_save_error = None;
 | 
					                        self.profile_save_error = None;
 | 
				
			||||||
                        self.profile_edit_settings = ProfileSettings::default();
 | 
					                        self.profile_edit_settings = ProfileSettings::default();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    ManagerView::ProfileSelect => {
 | 
				
			||||||
 | 
					                        let loaded_userdata = profiles::Data::load();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        match loaded_userdata {
 | 
				
			||||||
 | 
					                            Ok(userdata) => {
 | 
				
			||||||
 | 
					                                self.userdata = userdata;
 | 
				
			||||||
 | 
					                                self.userdata_load_error = None;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            Err(err) => {
 | 
				
			||||||
 | 
					                                self.userdata_load_error = Some(err.to_string());
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        };
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                    // TODO: Load profile for EditProfile
 | 
					                    // TODO: Load profile for EditProfile
 | 
				
			||||||
                    _ => {}
 | 
					                    _ => {}
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
                self.current_view = view;
 | 
					                self.current_view = view;
 | 
				
			||||||
 | 
					                Command::none()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Message::BrowseModsDir => {
 | 
					            Message::BrowseModsDir => {
 | 
				
			||||||
                self.profile_edit_settings.mods_dir = rfd::FileDialog::new()
 | 
					                self.profile_edit_settings.mods_dir = rfd::FileDialog::new()
 | 
				
			||||||
                    .set_title("Select your mods folder")
 | 
					                    .set_title("Select your mods folder")
 | 
				
			||||||
                    .pick_folder();
 | 
					                    .pick_folder();
 | 
				
			||||||
 | 
					                Command::none()
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Message::EditProfileName(name) => {
 | 
				
			||||||
 | 
					                self.profile_edit_settings.name = name;
 | 
				
			||||||
 | 
					                Command::none()
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Message::EditPackSource(pack_source) => {
 | 
				
			||||||
 | 
					                self.profile_edit_settings.pack_source = pack_source;
 | 
				
			||||||
 | 
					                Command::none()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Message::EditProfileName(name) => self.profile_edit_settings.name = name,
 | 
					 | 
				
			||||||
            Message::EditPackSource(pack_source) => self.profile_edit_settings.pack_source = pack_source,
 | 
					 | 
				
			||||||
            Message::SaveProfile => {
 | 
					            Message::SaveProfile => {
 | 
				
			||||||
                // TODO: Save profile
 | 
					                // TODO: Save profile
 | 
				
			||||||
                self.profile_save_error = Some(format!(
 | 
					                self.profile_save_error = Some(format!(
 | 
				
			||||||
                    "Unable to save profile '{}'. Saving not implemented",
 | 
					                    "Unable to save profile '{}'. Saving not implemented",
 | 
				
			||||||
                    self.profile_edit_settings.name
 | 
					                    self.profile_edit_settings.name
 | 
				
			||||||
                ))
 | 
					                ));
 | 
				
			||||||
 | 
					                Command::none()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -135,26 +172,53 @@ impl Sandbox for ManagerGUI {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl ManagerGUI {
 | 
					impl ManagerGUI {
 | 
				
			||||||
    fn view_profile_select(&self) -> Element<Message> {
 | 
					    fn view_profile_select(&self) -> Element<Message> {
 | 
				
			||||||
        column![
 | 
					        let mut profile_select = column![text("Profile Select"),];
 | 
				
			||||||
            text("Profile Select"),
 | 
					
 | 
				
			||||||
            button("Add profile").on_press(Message::SwitchView(ManagerView::AddProfile))
 | 
					        let mut profiles_list: Column<Message> = column!();
 | 
				
			||||||
        ]
 | 
					        let mut profile_names = self.userdata.get_profile_names();
 | 
				
			||||||
        .spacing(10)
 | 
					        profile_names.sort();
 | 
				
			||||||
        .padding(10)
 | 
					
 | 
				
			||||||
 | 
					        for profile_name in profile_names.iter() {
 | 
				
			||||||
 | 
					            profiles_list = profiles_list.push(
 | 
				
			||||||
 | 
					                button(text(profile_name))
 | 
				
			||||||
 | 
					                    .on_press(Message::SwitchView(ManagerView::ProfileView {
 | 
				
			||||||
 | 
					                        profile: profile_name.into(),
 | 
				
			||||||
 | 
					                    }))
 | 
				
			||||||
 | 
					                    .width(Length::Fill),
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        profile_select =
 | 
				
			||||||
 | 
					            profile_select.push(profiles_list.align_items(Alignment::Center).spacing(1));
 | 
				
			||||||
 | 
					        profile_select = profile_select
 | 
				
			||||||
 | 
					            .push(button("Add profile").on_press(Message::SwitchView(ManagerView::AddProfile)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        scrollable(
 | 
				
			||||||
 | 
					            profile_select
 | 
				
			||||||
 | 
					                .spacing(10)
 | 
				
			||||||
 | 
					                .align_items(Alignment::Center)
 | 
				
			||||||
 | 
					                .padding(10),
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
        .into()
 | 
					        .into()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn view_profile_view(&self, profile_name: &str) -> Element<Message> {
 | 
					    fn view_profile_view(&self, profile_name: &str) -> Element<Message> {
 | 
				
			||||||
        column![
 | 
					        let mut profile_view = column![
 | 
				
			||||||
            text(format!("Modpack Profile: {profile_name}")),
 | 
					            text(format!("Modpack Profile: {profile_name}")),
 | 
				
			||||||
            button("Back").on_press(Message::SwitchView(ManagerView::ProfileSelect)),
 | 
					            row![
 | 
				
			||||||
            button("Edit profile").on_press(Message::SwitchView(ManagerView::EditProfile {
 | 
					                button("Back").on_press(Message::SwitchView(ManagerView::ProfileSelect)),
 | 
				
			||||||
                profile: profile_name.into()
 | 
					                button("Edit profile").on_press(Message::SwitchView(ManagerView::EditProfile {
 | 
				
			||||||
            }))
 | 
					                    profile: profile_name.into()
 | 
				
			||||||
        ]
 | 
					                }))
 | 
				
			||||||
        .spacing(20)
 | 
					            ]
 | 
				
			||||||
        .padding(20)
 | 
					            .spacing(5)
 | 
				
			||||||
        .into()
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if let Some(err) = &self.userdata_load_error {
 | 
				
			||||||
 | 
					            profile_view = profile_view.push(text(err));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        profile_view.spacing(20).padding(20).into()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn view_profile_edit(
 | 
					    fn view_profile_edit(
 | 
				
			||||||
| 
						 | 
					@ -163,7 +227,7 @@ impl ManagerGUI {
 | 
				
			||||||
        previous_view: ManagerView,
 | 
					        previous_view: ManagerView,
 | 
				
			||||||
    ) -> Element<Message> {
 | 
					    ) -> Element<Message> {
 | 
				
			||||||
        let mut profile_editor = column![
 | 
					        let mut profile_editor = column![
 | 
				
			||||||
            text("Profile Add/Edit"),
 | 
					            text("Profile Add/Edit").horizontal_alignment(iced::alignment::Horizontal::Center),
 | 
				
			||||||
            row![
 | 
					            row![
 | 
				
			||||||
                "Profile name",
 | 
					                "Profile name",
 | 
				
			||||||
                text_input("Enter your profile name", &self.profile_edit_settings.name)
 | 
					                text_input("Enter your profile name", &self.profile_edit_settings.name)
 | 
				
			||||||
| 
						 | 
					@ -181,11 +245,13 @@ impl ManagerGUI {
 | 
				
			||||||
            .spacing(5),
 | 
					            .spacing(5),
 | 
				
			||||||
            row![
 | 
					            row![
 | 
				
			||||||
                "Mods directory",
 | 
					                "Mods directory",
 | 
				
			||||||
                text(if let Some(mods_dir) = &self.profile_edit_settings.mods_dir {
 | 
					                text(
 | 
				
			||||||
                    mods_dir.display().to_string()
 | 
					                    if let Some(mods_dir) = &self.profile_edit_settings.mods_dir {
 | 
				
			||||||
                } else {
 | 
					                        mods_dir.display().to_string()
 | 
				
			||||||
                    "".into()
 | 
					                    } else {
 | 
				
			||||||
                }),
 | 
					                        "".into()
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
                button("Browse").on_press(Message::BrowseModsDir)
 | 
					                button("Browse").on_press(Message::BrowseModsDir)
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
            .spacing(5),
 | 
					            .spacing(5),
 | 
				
			||||||
| 
						 | 
					@ -195,6 +261,7 @@ impl ManagerGUI {
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
            .spacing(10)
 | 
					            .spacing(10)
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					        .align_items(Alignment::Center)
 | 
				
			||||||
        .spacing(10)
 | 
					        .spacing(10)
 | 
				
			||||||
        .padding(20);
 | 
					        .padding(20);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue