pub unsafe fn load_unit_icons(&self, data: &HashMap<String, String>) {

        // Clear the current layout.
        clear_layout(&self.unit_icon_label_preview_widget);
        let layout: QPtr<QGridLayout> = self.unit_icon_label_preview_widget.layout().static_downcast();

        let unit_cards = data.iter().filter_map(|(key, value)| if key.starts_with("unit_variants_unit_card") { Some(value) } else { None }).collect::<Vec<&String>>();

        // The icons needs to be pulled up from the dependencies cache on load.
        if !unit_cards.is_empty() {
            let mut icon_paths = vec![];
            for unit_card in unit_cards {
                let icon_path_png = PathType::File(format!("{}{}.png", UNIT_ICONS_PATH.to_owned(), unit_card).split('/').map(|x| x.to_owned()).collect::<Vec<String>>());
                let icon_path_tga = PathType::File(format!("{}{}.tga", UNIT_ICONS_PATH.to_owned(), unit_card).split('/').map(|x| x.to_owned()).collect::<Vec<String>>());

                if !icon_paths.contains(&icon_path_png) {
                    icon_paths.push(icon_path_png);
                }

                if !icon_paths.contains(&icon_path_tga) {
                    icon_paths.push(icon_path_tga);
                }
            }

            let receiver = CENTRAL_COMMAND.send_background(Command::GetPackedFilesFromAllSources(icon_paths.to_vec()));
            let response = CentralCommand::recv(&receiver);
            let images_data = if let Response::HashMapDataSourceHashMapVecStringPackedFile(data) = response { data } else { panic!("{}{:?}", THREADS_COMMUNICATION_ERROR, response); };

            let images_files = icon_paths.iter().filter_map(|path_type| {
                if let PathType::File(path) = path_type {
                    Tool::get_most_relevant_file(&images_data, &path)
                } else { None }
            }).collect::<Vec<PackedFile>>();

            for (column, images_file) in images_files.iter().enumerate() {
                let image_data = images_file.get_raw_data().unwrap();
                let byte_array = QByteArray::from_slice(&image_data);
                let image = QPixmap::new();
                let label = QLabel::from_q_widget(&self.unit_icon_label_preview_widget);
                image.load_from_data_q_byte_array(&byte_array);
                label.set_alignment(QFlags::from(AlignmentFlag::AlignHCenter | AlignmentFlag::AlignVCenter));
                label.set_pixmap(&image);
                layout.add_widget_3a(&label, 0, column as i32);
            }
        } else {
            let label = QLabel::from_q_widget(&self.unit_icon_label_preview_widget);
            label.set_alignment(QFlags::from(AlignmentFlag::AlignHCenter | AlignmentFlag::AlignVCenter));
            label.set_text(&QString::from_std_str("No image available"));
            layout.add_widget_3a(&label, 0, 0);
        }
    }
/// This function loads the unit icon into the tool. If provided with a key, it uses it. If not, it uses whatever key the unit has.
This function loads the unit icon into the tool. If provided with a key, it uses it. If not, it uses whatever key the unit has.
This function loads the unit icon into the tool . If provided with a key it uses it . If not it uses whatever key the unit has .
pub unsafe fn load_unit_icons(&self, data: &HashMap<String, String>) {
        // Clear the current layout.
        clear_layout(&self.unit_icon_label_preview_widget);
        let layout: QPtr<QGridLayout> = self.unit_icon_label_preview_widget.layout().static_downcast();
        let unit_cards = data.iter().filter_map(|(key, value)| if key.starts_with("unit_variants_unit_card") { Some(value) } else { None }).collect::<Vec<&String>>();
        // The icons needs to be pulled up from the dependencies cache on load.
        if !unit_cards.is_empty() {
            let mut icon_paths = vec![];
            for unit_card in unit_cards {
                let icon_path_png = PathType::File(format!("{}{}.png", UNIT_ICONS_PATH.to_owned(), unit_card).split('/').map(|x| x.to_owned()).collect::<Vec<String>>());
                let icon_path_tga = PathType::File(format!("{}{}.tga", UNIT_ICONS_PATH.to_owned(), unit_card).split('/').map(|x| x.to_owned()).collect::<Vec<String>>());
                if !icon_paths.contains(&icon_path_png) {
                    icon_paths.push(icon_path_png);
                }
                if !icon_paths.contains(&icon_path_tga) {
                    icon_paths.push(icon_path_tga);
                }
            }
            let receiver = CENTRAL_COMMAND.send_background(Command::GetPackedFilesFromAllSources(icon_paths.to_vec()));
            let response = CentralCommand::recv(&receiver);
            let images_data = if let Response::HashMapDataSourceHashMapVecStringPackedFile(data) = response { data } else { panic!("{}{:?}", THREADS_COMMUNICATION_ERROR, response); };
            let images_files = icon_paths.iter().filter_map(|path_type| {
                if let PathType::File(path) = path_type {
                    Tool::get_most_relevant_file(&images_data, &path)
                } else { None }
            }).collect::<Vec<PackedFile>>();
            for (column, images_file) in images_files.iter().enumerate() {
                let image_data = images_file.get_raw_data().unwrap();
                let byte_array = QByteArray::from_slice(&image_data);
                let image = QPixmap::new();
                let label = QLabel::from_q_widget(&self.unit_icon_label_preview_widget);
                image.load_from_data_q_byte_array(&byte_array);
                label.set_alignment(QFlags::from(AlignmentFlag::AlignHCenter | AlignmentFlag::AlignVCenter));
                label.set_pixmap(&image);
                layout.add_widget_3a(&label, 0, column as i32);
            }
        } else {
            let label = QLabel::from_q_widget(&self.unit_icon_label_preview_widget);
            label.set_alignment(QFlags::from(AlignmentFlag::AlignHCenter | AlignmentFlag::AlignVCenter));
            label.set_text(&QString::from_std_str("No image available"));
            layout.add_widget_3a(&label, 0, 0);
        }
    }
pub unsafe fn load_unit_icons ( & self , data : & HashMap < String , String > ) { // Clear the current layout. clear_layout ( & self . unit_icon_label_preview_widget ) ; let layout : QPtr < QGridLayout > = self . unit_icon_label_preview_widget . layout ( ) . static_downcast ( ) ; let unit_cards = data . iter ( ) . filter_map ( | ( key , value ) | if key . starts_with ( " " ) { Some ( value ) } else { None } ) . collect :: < Vec < & String > > ( ) ; // The icons needs to be pulled up from the dependencies cache on load. if ! unit_cards . is_empty ( ) { let mut icon_paths = vec ! [ ] ; for unit_card in unit_cards { let icon_path_png = PathType :: File ( format ! ( " " UNIT_ICONS_PATH to_owned ( ) unit_card ) . split ( '/' ) . map ( | x | x . to_owned ( ) ) . collect :: < Vec < String > > ( ) ) ; let icon_path_tga = PathType :: File ( format ! ( " " UNIT_ICONS_PATH to_owned ( ) unit_card ) . split ( '/' ) . map ( | x | x . to_owned ( ) ) . collect :: < Vec < String > > ( ) ) ; if ! icon_paths . contains ( & icon_path_png ) { icon_paths . push ( icon_path_png ) ; } if ! icon_paths . contains ( & icon_path_tga ) { icon_paths . push ( icon_path_tga ) ; } } let receiver = CENTRAL_COMMAND . send_background ( Command :: GetPackedFilesFromAllSources ( icon_paths . to_vec ( ) ) ) ; let response = CentralCommand :: recv ( & receiver ) ; let images_data = if let Response :: HashMapDataSourceHashMapVecStringPackedFile ( data ) = response { data } else { panic ! ( " " THREADS_COMMUNICATION_ERROR response ) ; } ; let images_files = icon_paths . iter ( ) . filter_map ( | path_type | { if let PathType :: File ( path ) = path_type { Tool :: get_most_relevant_file ( & images_data , & path ) } else { None } } ) . collect :: < Vec < PackedFile > > ( ) ; for ( column , images_file ) in images_files . iter ( ) . enumerate ( ) { let image_data = images_file . get_raw_data ( ) . unwrap ( ) ; let byte_array = QByteArray :: from_slice ( & image_data ) ; let image = QPixmap :: new ( ) ; let label = QLabel :: from_q_widget ( & self . unit_icon_label_preview_widget ) ; image . load_from_data_q_byte_array ( & byte_array ) ; label . set_alignment ( QFlags :: from ( AlignmentFlag :: AlignHCenter | AlignmentFlag :: AlignVCenter ) ) ; label . set_pixmap ( & image ) ; layout . add_widget_3a ( & label , 0 , column as i32 ) ; } } else { let label = QLabel :: from_q_widget ( & self . unit_icon_label_preview_widget ) ; label . set_alignment ( QFlags :: from ( AlignmentFlag :: AlignHCenter | AlignmentFlag :: AlignVCenter ) ) ; label . set_text ( & QString :: from_std_str ( " " ) ) ; layout . add_widget_3a ( & label , 0 , 0 ) ; } }
This function loads the unit icon into the tool.
This function loads the unit icon into the tool .
&self
data
&HashMap<String, String>
&self
data
&HashMap<String, String>