cleaned instance rendering
parent
baf64181ec
commit
2b0ba06bf1
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
pokemon::*,
|
pokemon::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::ui::UiAssets;
|
use super::ui::{EguiAsset, UiAssets};
|
||||||
|
|
||||||
pub struct InspectorPlugin;
|
pub struct InspectorPlugin;
|
||||||
|
|
||||||
|
|
@ -42,19 +42,7 @@ pub struct PokemonInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_init(mut inspector: ResMut<Inspector>, pokemon_database: Res<Database<Pokemon>>) {
|
fn test_init(mut inspector: ResMut<Inspector>, pokemon_database: Res<Database<Pokemon>>) {
|
||||||
for name in vec![
|
for name in vec!["baltoy"].iter() {
|
||||||
"baltoy",
|
|
||||||
"claydol",
|
|
||||||
"regirock",
|
|
||||||
"flygon",
|
|
||||||
"shuckle",
|
|
||||||
"swampert",
|
|
||||||
"forretress",
|
|
||||||
"shedinja",
|
|
||||||
"blissey",
|
|
||||||
]
|
|
||||||
.iter()
|
|
||||||
{
|
|
||||||
inspector.enemies.push(PokemonInstance {
|
inspector.enemies.push(PokemonInstance {
|
||||||
pokemon: pokemon_database.map.get(*name).unwrap().clone(),
|
pokemon: pokemon_database.map.get(*name).unwrap().clone(),
|
||||||
ivs: {
|
ivs: {
|
||||||
|
|
@ -77,6 +65,29 @@ fn test_init(mut inspector: ResMut<Inspector>, pokemon_database: Res<Database<Po
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
for name in vec!["seadra", "sceptile", "ampharos", "shedinja"].iter() {
|
||||||
|
inspector.allies.push(PokemonInstance {
|
||||||
|
pokemon: pokemon_database.map.get(*name).unwrap().clone(),
|
||||||
|
ivs: {
|
||||||
|
let mut result = HashMap::new();
|
||||||
|
for stat in BaseStat::all().iter() {
|
||||||
|
result.insert(
|
||||||
|
*stat,
|
||||||
|
match stat {
|
||||||
|
BaseStat::Hp => 31,
|
||||||
|
BaseStat::Attack => 27,
|
||||||
|
BaseStat::Defense => 26,
|
||||||
|
BaseStat::SpecialAttack => 0,
|
||||||
|
BaseStat::SpecialDefense => 21,
|
||||||
|
BaseStat::Speed => 15,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
},
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_changed(
|
fn state_changed(
|
||||||
|
|
@ -99,7 +110,7 @@ fn state_changed(
|
||||||
let weak = handle.clone_weak();
|
let weak = handle.clone_weak();
|
||||||
ui_assets
|
ui_assets
|
||||||
.sprite_map
|
.sprite_map
|
||||||
.insert(pokemon.key(), (handle, contexts.add_image(weak)));
|
.insert(pokemon.key(), EguiAsset(handle, contexts.add_image(weak)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
314
src/ivpeek/ui.rs
314
src/ivpeek/ui.rs
|
|
@ -5,9 +5,11 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::pokemon::*;
|
use crate::pokemon::*;
|
||||||
|
|
||||||
use super::inspector::Inspector;
|
use super::inspector::{Inspector, PokemonInstance};
|
||||||
|
|
||||||
const BAR_HEIGHT: f32 = 12.0;
|
const BAR_HEIGHT: f32 = 12.0;
|
||||||
|
const SPRITE_SIZE: f32 = 128.0;
|
||||||
|
const SPRITE_PADDING: f32 = 32.0;
|
||||||
const BASE_STAT_WIDTH_MULT: f32 = 0.8;
|
const BASE_STAT_WIDTH_MULT: f32 = 0.8;
|
||||||
const IV_WIDTH_MULT: f32 = 4.0;
|
const IV_WIDTH_MULT: f32 = 4.0;
|
||||||
// const EV_WIDTH_MULT: f32 = 1.0;
|
// const EV_WIDTH_MULT: f32 = 1.0;
|
||||||
|
|
@ -51,185 +53,193 @@ impl Plugin for UiPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct EguiAsset(pub Handle<Image>, pub egui::TextureId);
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct UiAssets {
|
pub struct UiAssets {
|
||||||
pub bar_handle: Handle<Image>,
|
pub bar_handle: EguiAsset,
|
||||||
pub sprite_map: HashMap<String, (Handle<Image>, egui::TextureId)>,
|
pub sprite_map: HashMap<String, EguiAsset>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_assets(mut ui_assets: ResMut<UiAssets>, assets: Res<AssetServer>) {
|
fn load_assets(
|
||||||
ui_assets.bar_handle = assets.load("ui/bar.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ui_system(
|
|
||||||
mut contexts: EguiContexts,
|
mut contexts: EguiContexts,
|
||||||
inspector: Res<Inspector>,
|
mut ui_assets: ResMut<UiAssets>,
|
||||||
ui_assets: Res<UiAssets>,
|
assets: Res<AssetServer>,
|
||||||
mut rendered_texture_id: Local<egui::TextureId>,
|
|
||||||
mut is_initialized: Local<bool>,
|
|
||||||
) {
|
) {
|
||||||
if !*is_initialized {
|
ui_assets.bar_handle = load_egui_asset(&mut contexts, &assets);
|
||||||
*is_initialized = true;
|
}
|
||||||
*rendered_texture_id = contexts.add_image(ui_assets.bar_handle.clone_weak());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fn ui_system(mut contexts: EguiContexts, inspector: Res<Inspector>, ui_assets: Res<UiAssets>) {
|
||||||
egui::CentralPanel::default().show(contexts.ctx_mut(), |ui| {
|
egui::CentralPanel::default().show(contexts.ctx_mut(), |ui| {
|
||||||
let sprite_size = egui::Vec2::new(128., 128.);
|
|
||||||
|
|
||||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
for instance in inspector.enemies.iter().chain(inspector.allies.iter()) {
|
ui.heading("Enemy team");
|
||||||
let pokemon = instance.pokemon.clone();
|
for instance in inspector.enemies.iter() {
|
||||||
let nature = instance.nature.clone();
|
ui.add_space(8.);
|
||||||
|
render_pokemon_instance(ui, &ui_assets, instance);
|
||||||
|
ui.add_space(8.);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.heading("Player team");
|
||||||
|
for instance in inspector.allies.iter() {
|
||||||
|
ui.add_space(8.);
|
||||||
|
render_pokemon_instance(ui, &ui_assets, instance);
|
||||||
|
ui.add_space(8.);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_egui_asset(contexts: &mut EguiContexts, assets: &Res<AssetServer>) -> EguiAsset {
|
||||||
|
let handle = assets.load("ui/bar.png");
|
||||||
|
let egui_id = contexts.add_image(handle.clone_weak());
|
||||||
|
EguiAsset(handle, egui_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_pokemon_instance(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
ui_assets: &Res<UiAssets>,
|
||||||
|
instance: &PokemonInstance,
|
||||||
|
) {
|
||||||
|
let sprite_size = egui::Vec2::new(SPRITE_SIZE, SPRITE_SIZE);
|
||||||
|
let pokemon = instance.pokemon.clone();
|
||||||
|
let nature = instance.nature.clone();
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.set_min_width(sprite_size.x + SPRITE_PADDING);
|
||||||
|
ui.set_max_width(sprite_size.x + SPRITE_PADDING);
|
||||||
|
// Name
|
||||||
|
ui.label(egui::RichText::new(&pokemon.full_name).color(egui::Color32::LIGHT_GRAY));
|
||||||
|
|
||||||
|
// Types
|
||||||
|
ui.label(format!(
|
||||||
|
"{} / {}",
|
||||||
|
pokemon.type1.as_ref().map_or("-", |t| t.name.as_str()),
|
||||||
|
pokemon.type2.as_ref().map_or("-", |t| t.name.as_str())
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Headings
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
for (i, width) in COLUMNS.iter().enumerate() {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.set_width(*width);
|
||||||
ui.set_min_width(sprite_size.x + 32.);
|
match i {
|
||||||
ui.set_max_width(sprite_size.x + 32.);
|
1 => {
|
||||||
// Name
|
ui.label(egui::RichText::new("Base stat"));
|
||||||
ui.label(
|
|
||||||
egui::RichText::new(&pokemon.full_name)
|
|
||||||
.color(egui::Color32::LIGHT_GRAY),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Types
|
|
||||||
ui.label(format!(
|
|
||||||
"{} / {}",
|
|
||||||
pokemon.type1.as_ref().map_or("-", |t| t.name.as_str()),
|
|
||||||
pokemon.type2.as_ref().map_or("-", |t| t.name.as_str())
|
|
||||||
));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Headings
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
for (i, width) in COLUMNS.iter().enumerate() {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.set_width(*width);
|
|
||||||
match i {
|
|
||||||
1 => {
|
|
||||||
ui.label(egui::RichText::new("Base stat"));
|
|
||||||
}
|
|
||||||
3 => {
|
|
||||||
ui.label(egui::RichText::new("IV"));
|
|
||||||
}
|
|
||||||
4 => {
|
|
||||||
ui.label(egui::RichText::new("IV range"));
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
3 => {
|
||||||
|
ui.label(egui::RichText::new("IV"));
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
// Sprite
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.set_min_size(sprite_size);
|
||||||
|
ui.set_max_size(sprite_size);
|
||||||
|
if let Some(EguiAsset(_, rendered_texture_id)) =
|
||||||
|
ui_assets.sprite_map.get(&pokemon.key())
|
||||||
|
{
|
||||||
|
ui.add(egui::Image::new(*rendered_texture_id, sprite_size));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(SPRITE_PADDING);
|
||||||
|
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
for stat in BaseStat::all() {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// Sprite
|
let mut column_size = COLUMNS.iter();
|
||||||
|
|
||||||
|
// Base stat number
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.set_min_size(sprite_size);
|
if let Some(width) = column_size.next() {
|
||||||
ui.set_max_size(sprite_size);
|
ui.set_width(*width);
|
||||||
if let Some((_, rendered_texture_id)) =
|
}
|
||||||
ui_assets.sprite_map.get(&pokemon.key())
|
let base_stat = &pokemon.base_value(stat).to_string();
|
||||||
{
|
ui.label(egui::RichText::new(base_stat));
|
||||||
ui.add(egui::Image::new(*rendered_texture_id, sprite_size));
|
});
|
||||||
|
|
||||||
|
// Base stat bar
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if let Some(width) = column_size.next() {
|
||||||
|
ui.set_width(*width);
|
||||||
|
}
|
||||||
|
let base_value = pokemon.base_value(stat);
|
||||||
|
let bar_length = base_value as f32 * BASE_STAT_WIDTH_MULT;
|
||||||
|
let color = base_stat_color(base_value);
|
||||||
|
|
||||||
|
let image =
|
||||||
|
egui::Image::new(ui_assets.bar_handle.1, [bar_length, BAR_HEIGHT])
|
||||||
|
.tint(color);
|
||||||
|
ui.add(image);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Stat name
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if let Some(width) = column_size.next() {
|
||||||
|
ui.set_width(*width);
|
||||||
|
}
|
||||||
|
ui.label(
|
||||||
|
egui::RichText::new(format!("{stat}"))
|
||||||
|
.color(nature_color(stat, nature.as_ref())),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// IV stat
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if let Some(width) = column_size.next() {
|
||||||
|
ui.set_width(*width);
|
||||||
|
}
|
||||||
|
if let Some(iv) = instance.ivs.get(&stat) {
|
||||||
|
ui.label(egui::RichText::new(format!("{iv}")).color(iv_color(*iv)));
|
||||||
|
} else {
|
||||||
|
ui.label("-");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.add_space(32.);
|
// IV stat bar
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if let Some(width) = column_size.next() {
|
||||||
|
ui.set_width(*width);
|
||||||
|
}
|
||||||
|
if let Some(iv) = instance.ivs.get(&stat) {
|
||||||
|
let bar_length = *iv as f32 * IV_WIDTH_MULT;
|
||||||
|
let track_length = 31. * IV_WIDTH_MULT - bar_length;
|
||||||
|
let color = iv_color(*iv);
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
for stat in BaseStat::all() {
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let mut column_size = COLUMNS.iter();
|
ui.spacing_mut().item_spacing = egui::Vec2::ZERO;
|
||||||
|
|
||||||
// Base stat number
|
// Bar
|
||||||
ui.horizontal(|ui| {
|
ui.add(
|
||||||
if let Some(width) = column_size.next() {
|
egui::Image::new(
|
||||||
ui.set_width(*width);
|
ui_assets.bar_handle.1,
|
||||||
}
|
|
||||||
let base_stat = &pokemon.base_value(stat).to_string();
|
|
||||||
ui.label(egui::RichText::new(base_stat));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Base stat bar
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if let Some(width) = column_size.next() {
|
|
||||||
ui.set_width(*width);
|
|
||||||
}
|
|
||||||
let base_value = pokemon.base_value(stat);
|
|
||||||
let bar_length = base_value as f32 * BASE_STAT_WIDTH_MULT;
|
|
||||||
let color = base_stat_color(base_value);
|
|
||||||
|
|
||||||
let image = egui::Image::new(
|
|
||||||
*rendered_texture_id,
|
|
||||||
[bar_length, BAR_HEIGHT],
|
[bar_length, BAR_HEIGHT],
|
||||||
)
|
)
|
||||||
.tint(color);
|
.tint(color),
|
||||||
ui.add(image);
|
);
|
||||||
});
|
// Track
|
||||||
|
ui.add(
|
||||||
// Stat name
|
egui::Image::new(
|
||||||
ui.horizontal(|ui| {
|
ui_assets.bar_handle.1,
|
||||||
if let Some(width) = column_size.next() {
|
[track_length, BAR_HEIGHT],
|
||||||
ui.set_width(*width);
|
)
|
||||||
}
|
.tint(egui::Color32::from_rgb(64, 64, 64)),
|
||||||
ui.label(
|
);
|
||||||
egui::RichText::new(format!("{stat}"))
|
|
||||||
.color(nature_color(stat, nature.as_ref())),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// IV stat
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if let Some(width) = column_size.next() {
|
|
||||||
ui.set_width(*width);
|
|
||||||
}
|
|
||||||
if let Some(iv) = instance.ivs.get(&stat) {
|
|
||||||
ui.label(
|
|
||||||
egui::RichText::new(format!("{iv}"))
|
|
||||||
.color(iv_color(*iv)),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
ui.label("-");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// IV stat bar
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if let Some(width) = column_size.next() {
|
|
||||||
ui.set_width(*width);
|
|
||||||
}
|
|
||||||
if let Some(iv) = instance.ivs.get(&stat) {
|
|
||||||
let bar_length = *iv as f32 * IV_WIDTH_MULT;
|
|
||||||
let track_length = 31. * IV_WIDTH_MULT - bar_length;
|
|
||||||
let color = iv_color(*iv);
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.spacing_mut().item_spacing = egui::Vec2::ZERO;
|
|
||||||
|
|
||||||
// Bar
|
|
||||||
ui.add(
|
|
||||||
egui::Image::new(
|
|
||||||
*rendered_texture_id,
|
|
||||||
[bar_length, BAR_HEIGHT],
|
|
||||||
)
|
|
||||||
.tint(color),
|
|
||||||
);
|
|
||||||
// Track
|
|
||||||
ui.add(
|
|
||||||
egui::Image::new(
|
|
||||||
*rendered_texture_id,
|
|
||||||
[track_length, BAR_HEIGHT],
|
|
||||||
)
|
|
||||||
.tint(egui::Color32::from_rgb(64, 64, 64)),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue