hgame 0.26.4

CG production management structs, e.g. of assets, personnels, progress, etc.
Documentation
use super::*;
#[cfg(feature = "gui")]
use crate::staff::production_role_options_ui;

#[derive(Debug, Clone)]
pub struct UserGroup {
    mode: MediaMode,

    #[cfg(feature = "gui")]
    /// Used to avoid [`egui::Id`] clashes.
    pub(crate) id_source: u8,

    /// Common `ProductionRole` for this series of [`Staff`].
    role: ProductionRole,

    /// String to be splitted into names of staves for creation. To be input
    /// by users as a text field.
    user_names: String,
    //
    // users: Vec<Staff>,
}

impl Default for UserGroup {
    fn default() -> Self {
        Self {
            mode: Default::default(),
            #[cfg(feature = "gui")]
            id_source: 0,
            role: ProductionRole::Artist,
            user_names: String::new(),
            // users: vec![],
        }
    }
}

fn usernames_from_input(input: &String) -> Vec<String> {
    use mkutil::text::*;
    ascii_from_multiline(
        input,
        SPECIAL_CHARS_EXCEPT_PERIOD,
        MAX_STAFF_NAME_LENGTH as usize,
    )
}

impl UserGroup {
    // pub fn from_role(role: ProductionRole) -> Self {
    //     Self {
    //         role,
    //         ..Default::default()
    //     }
    // }

    // pub fn with_users(mut self, users: Vec<Staff>) -> Self {
    //     self.users = users;
    //     self
    // }

    #[cfg(feature = "gui")]
    pub fn with_id_source(id_source: u8) -> Self {
        Self {
            id_source,
            ..Default::default()
        }
    }

    /// Lists the `ProductionRole` and all input staff names.
    pub fn preview_name(&self) -> Option<String> {
        let user_names = usernames_from_input(&self.user_names);

        if user_names.is_empty() {
            None
        } else {
            Some(format!(
                "{}:\n{}",
                self.role.as_ref(),
                user_names.join("\n")
            ))
        }
    }

    pub fn staffs_from_names(&self) -> Vec<Staff> {
        usernames_from_input(&self.user_names)
            .into_iter()
            .map(|name| Staff::into_unknown_role(name).role(&self.role))
            .collect()
    }
}

impl ReadWriteSuggest for UserGroup {
    fn write_suggest() -> Self {
        Self {
            mode: MediaMode::WriteSuggest,
            ..Default::default()
        }
    }

    fn with_mode(mut self, mode: MediaMode) -> Self {
        self.mode_mut(mode);
        self
    }

    fn mode(&self) -> &MediaMode {
        &self.mode
    }

    fn mode_mut(&mut self, mode: MediaMode) {
        self.mode = mode;
    }

    // fn read_mode_ui(&mut self, _ui: &mut egui::Ui) {}

    // fn write_suggest_ui(&mut self, _ui: &mut egui::Ui) {}

    #[cfg(feature = "gui")]
    fn write_compose_ui(&mut self, ui: &mut egui::Ui) {
        egui::CollapsingHeader::new("Draft New Staffs")
            .id_source(&self.id_source)
            .default_open(true)
            .show(ui, |ui| {
                production_role_options_ui(ui, &mut self.role);
                ui.horizontal(|ui| {
                    ui.label("Staff Name:");
                    ui.weak("(new line for multiple)");
                });
                ui.add(egui::TextEdit::multiline(&mut self.user_names));
            });
    }

    // fn write_edit_ui(&mut self, _ui: &mut egui::Ui) {}
}