extract skins
This commit is contained in:
		
							parent
							
								
									7cbfcd91af
								
							
						
					
					
						commit
						18fd825c99
					
				
							
								
								
									
										144
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										144
									
								
								src/main.rs
								
								
								
								
							| 
						 | 
				
			
			@ -4,6 +4,7 @@ mod asteroids;
 | 
			
		|||
mod nn;
 | 
			
		||||
mod player;
 | 
			
		||||
mod population;
 | 
			
		||||
mod skins;
 | 
			
		||||
mod world;
 | 
			
		||||
 | 
			
		||||
use nn::{ActivationFunc, NN};
 | 
			
		||||
| 
						 | 
				
			
			@ -11,7 +12,7 @@ use tinyfiledialogs::*;
 | 
			
		|||
 | 
			
		||||
use macroquad::{
 | 
			
		||||
    prelude::*,
 | 
			
		||||
    ui::{hash, root_ui, widgets, Skin},
 | 
			
		||||
    ui::{hash, root_ui, widgets},
 | 
			
		||||
};
 | 
			
		||||
use population::{AutoSwitch, Population};
 | 
			
		||||
use world::World;
 | 
			
		||||
| 
						 | 
				
			
			@ -95,144 +96,9 @@ async fn main() {
 | 
			
		|||
    let nums = &[
 | 
			
		||||
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    let skin = {
 | 
			
		||||
        let window_style = root_ui()
 | 
			
		||||
            .style_builder()
 | 
			
		||||
            .background(Image {
 | 
			
		||||
                width: 1,
 | 
			
		||||
                height: 1,
 | 
			
		||||
                bytes: vec![0; 4],
 | 
			
		||||
            })
 | 
			
		||||
            .background_margin(RectOffset::new(0., 0., 0., 0.))
 | 
			
		||||
            .color_inactive(WHITE)
 | 
			
		||||
            .build();
 | 
			
		||||
        let button_style = root_ui()
 | 
			
		||||
            .style_builder()
 | 
			
		||||
            .background(Image {
 | 
			
		||||
                width: 3,
 | 
			
		||||
                height: 3,
 | 
			
		||||
                bytes: vec![
 | 
			
		||||
                    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                    0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                    255, 255, 255,
 | 
			
		||||
                ],
 | 
			
		||||
            })
 | 
			
		||||
            .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
            .color_hovered(RED)
 | 
			
		||||
            .color_clicked(BLUE)
 | 
			
		||||
            .text_color(WHITE)
 | 
			
		||||
            .text_color_hovered(WHITE)
 | 
			
		||||
            .text_color_clicked(WHITE)
 | 
			
		||||
            .margin(RectOffset::new(10., 10., 8., 8.))
 | 
			
		||||
            .color_inactive(WHITE)
 | 
			
		||||
            .build();
 | 
			
		||||
        let label_style = root_ui()
 | 
			
		||||
            .style_builder()
 | 
			
		||||
            .text_color(WHITE)
 | 
			
		||||
            .font_size(24)
 | 
			
		||||
            .margin(RectOffset::new(5., 5., 4., 4.))
 | 
			
		||||
            // .text_color_hovered(LIGHTGRAY)
 | 
			
		||||
            // .text_color_clicked(WHITE)
 | 
			
		||||
            .build();
 | 
			
		||||
        let group_style = root_ui()
 | 
			
		||||
            .style_builder()
 | 
			
		||||
            .color(Color::new(1., 0., 0., 0.))
 | 
			
		||||
            .build();
 | 
			
		||||
        let editbox_style = root_ui()
 | 
			
		||||
            .style_builder()
 | 
			
		||||
            .background(Image {
 | 
			
		||||
                width: 3,
 | 
			
		||||
                height: 3,
 | 
			
		||||
                bytes: vec![
 | 
			
		||||
                    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                    0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                    255, 255, 255,
 | 
			
		||||
                ],
 | 
			
		||||
            })
 | 
			
		||||
            .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
            .text_color(WHITE)
 | 
			
		||||
            .build();
 | 
			
		||||
        let combobox_style = root_ui()
 | 
			
		||||
            .style_builder()
 | 
			
		||||
            .background(Image {
 | 
			
		||||
                width: 3,
 | 
			
		||||
                height: 3,
 | 
			
		||||
                bytes: vec![
 | 
			
		||||
                    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                    0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                    255, 255, 255,
 | 
			
		||||
                ],
 | 
			
		||||
            })
 | 
			
		||||
            .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
            .color_hovered(WHITE)
 | 
			
		||||
            .color_selected_hovered(WHITE)
 | 
			
		||||
            .color_inactive(WHITE)
 | 
			
		||||
            .color_clicked(WHITE)
 | 
			
		||||
            .color(WHITE)
 | 
			
		||||
            .build();
 | 
			
		||||
 | 
			
		||||
        Skin {
 | 
			
		||||
            window_style,
 | 
			
		||||
            button_style,
 | 
			
		||||
            label_style,
 | 
			
		||||
            group_style,
 | 
			
		||||
            editbox_style,
 | 
			
		||||
            combobox_style,
 | 
			
		||||
            margin: 0.,
 | 
			
		||||
            ..root_ui().default_skin()
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let mut skin2 = skin.clone();
 | 
			
		||||
    skin2.label_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .font_size(16)
 | 
			
		||||
        .text_color_hovered(LIGHTGRAY)
 | 
			
		||||
        .text_color_clicked(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
    skin2.button_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
 | 
			
		||||
                0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                255, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .color_hovered(GREEN)
 | 
			
		||||
        .color_clicked(GREEN)
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .text_color_hovered(WHITE)
 | 
			
		||||
        .text_color_clicked(GREEN)
 | 
			
		||||
        .margin(RectOffset::new(4., 4., 2., 2.))
 | 
			
		||||
        .color_inactive(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
 | 
			
		||||
    let mut skin3 = skin2.clone();
 | 
			
		||||
    skin3.button_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 255, 0,
 | 
			
		||||
                255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .color_hovered(GREEN)
 | 
			
		||||
        .color_clicked(GREEN)
 | 
			
		||||
        .text_color(GREEN)
 | 
			
		||||
        .text_color_hovered(GREEN)
 | 
			
		||||
        .text_color_clicked(GREEN)
 | 
			
		||||
        .margin(RectOffset::new(4., 4., 2., 2.))
 | 
			
		||||
        .color_inactive(GREEN)
 | 
			
		||||
        .build();
 | 
			
		||||
    let skin = skins::get_ui_skin();
 | 
			
		||||
    let skin2 = skins::get_white_buttons_skin();
 | 
			
		||||
    let skin3 = skins::get_green_buttons_skin();
 | 
			
		||||
 | 
			
		||||
    root_ui().push_skin(&skin);
 | 
			
		||||
    loop {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,143 @@
 | 
			
		|||
use macroquad::{prelude::*, ui::*};
 | 
			
		||||
 | 
			
		||||
pub fn get_ui_skin() -> Skin {
 | 
			
		||||
    let window_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 1,
 | 
			
		||||
            height: 1,
 | 
			
		||||
            bytes: vec![0; 4],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(0., 0., 0., 0.))
 | 
			
		||||
        .color_inactive(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
    let button_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
 | 
			
		||||
                0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                255, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .color_hovered(RED)
 | 
			
		||||
        .color_clicked(BLUE)
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .text_color_hovered(WHITE)
 | 
			
		||||
        .text_color_clicked(WHITE)
 | 
			
		||||
        .margin(RectOffset::new(10., 10., 8., 8.))
 | 
			
		||||
        .color_inactive(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
    let label_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .font_size(24)
 | 
			
		||||
        .margin(RectOffset::new(5., 5., 4., 4.))
 | 
			
		||||
        .build();
 | 
			
		||||
    let group_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .color(Color::new(1., 0., 0., 0.))
 | 
			
		||||
        .build();
 | 
			
		||||
    let editbox_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
 | 
			
		||||
                0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                255, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
    let combobox_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
 | 
			
		||||
                0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                255, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .color_hovered(WHITE)
 | 
			
		||||
        .color_selected_hovered(WHITE)
 | 
			
		||||
        .color_inactive(WHITE)
 | 
			
		||||
        .color_clicked(WHITE)
 | 
			
		||||
        .color(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
 | 
			
		||||
    Skin {
 | 
			
		||||
        window_style,
 | 
			
		||||
        button_style,
 | 
			
		||||
        label_style,
 | 
			
		||||
        group_style,
 | 
			
		||||
        editbox_style,
 | 
			
		||||
        combobox_style,
 | 
			
		||||
        margin: 0.,
 | 
			
		||||
        ..root_ui().default_skin()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn get_white_buttons_skin() -> Skin {
 | 
			
		||||
    let mut skin2 = get_ui_skin();
 | 
			
		||||
    skin2.label_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .font_size(16)
 | 
			
		||||
        .text_color_hovered(LIGHTGRAY)
 | 
			
		||||
        .text_color_clicked(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
    skin2.button_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
 | 
			
		||||
                0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 | 
			
		||||
                255, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .color_hovered(GREEN)
 | 
			
		||||
        .color_clicked(GREEN)
 | 
			
		||||
        .text_color(WHITE)
 | 
			
		||||
        .text_color_hovered(WHITE)
 | 
			
		||||
        .text_color_clicked(GREEN)
 | 
			
		||||
        .margin(RectOffset::new(4., 4., 2., 2.))
 | 
			
		||||
        .color_inactive(WHITE)
 | 
			
		||||
        .build();
 | 
			
		||||
    skin2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn get_green_buttons_skin() -> Skin {
 | 
			
		||||
    let mut skin3 = get_white_buttons_skin();
 | 
			
		||||
    skin3.button_style = root_ui()
 | 
			
		||||
        .style_builder()
 | 
			
		||||
        .background(Image {
 | 
			
		||||
            width: 3,
 | 
			
		||||
            height: 3,
 | 
			
		||||
            bytes: vec![
 | 
			
		||||
                0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 0, 0, 255, 0,
 | 
			
		||||
                255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
 | 
			
		||||
            ],
 | 
			
		||||
        })
 | 
			
		||||
        .background_margin(RectOffset::new(1., 1., 1., 1.))
 | 
			
		||||
        .color_hovered(GREEN)
 | 
			
		||||
        .color_clicked(GREEN)
 | 
			
		||||
        .text_color(GREEN)
 | 
			
		||||
        .text_color_hovered(GREEN)
 | 
			
		||||
        .text_color_clicked(GREEN)
 | 
			
		||||
        .margin(RectOffset::new(4., 4., 2., 2.))
 | 
			
		||||
        .color_inactive(GREEN)
 | 
			
		||||
        .build();
 | 
			
		||||
    skin3
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue