This commit is contained in:
fdenef 2022-11-18 10:53:36 +01:00
parent 94ba4b698c
commit 505aed8138

View File

@ -1,183 +1,192 @@
use eframe::egui::Ui;
use eframe::egui::widgets::DragValue;
use eframe::egui::Ui;
use crate::gui::SheetGui;
#[derive(Debug)]
pub enum Classe {
Warrior,
Cautious,
Farmer,
Resourceful,
Warrior,
Cautious,
Farmer,
Resourceful,
}
#[derive(Debug)]
enum CharacteristicType {
Address,
Stamina,
Luck,
Skill,
Address,
Stamina,
Luck,
Skill,
}
#[derive(Debug)]
pub struct CharacterSheet {
character_class: Classe,
/// Field to write the personality/
pub character: String,
address: Characteristic,
stamina: Characteristic,
luck: Characteristic,
skill: Characteristic,
health: u32,
armor: u32,
damage: u32,
glory: u32,
money: u32,
character_class: Classe,
/// Field to write the personality/
pub character: String,
address: Characteristic,
stamina: Characteristic,
luck: Characteristic,
skill: Characteristic,
health: u32,
armor: u32,
damage: u32,
glory: u32,
money: u32,
}
impl CharacterSheet {
pub fn character_class(&self) -> &Classe {
&self.character_class
}
pub fn character(&self) -> &str {
&self.character
}
pub fn address(&self) -> &Characteristic {
&self.address
}
pub fn stamina(&self) -> &Characteristic {
&self.stamina
}
pub fn luck(&self) -> &Characteristic {
&self.luck
}
pub fn skill(&self) -> &Characteristic {
&self.skill
}
pub fn health(&self) -> u32 {
self.health
}
pub fn armor(&self) -> u32 {
self.armor
}
pub fn damage(&self) -> u32 {
self.damage
}
pub fn glory(&self) -> u32 {
self.glory
}
pub fn money(&self) -> u32 {
self.money
}
pub fn character_class(&self) -> &Classe {
&self.character_class
}
pub fn character(&self) -> &str {
&self.character
}
pub fn address(&self) -> &Characteristic {
&self.address
}
pub fn stamina(&self) -> &Characteristic {
&self.stamina
}
pub fn luck(&self) -> &Characteristic {
&self.luck
}
pub fn skill(&self) -> &Characteristic {
&self.skill
}
pub fn health(&self) -> u32 {
self.health
}
pub fn armor(&self) -> u32 {
self.armor
}
pub fn damage(&self) -> u32 {
self.damage
}
pub fn glory(&self) -> u32 {
self.glory
}
pub fn money(&self) -> u32 {
self.money
}
}
impl SheetGui for CharacterSheet {
fn shortcut(&self, ui: &mut Ui, category: &str, character_field: &Characteristic) -> (u32, u32, u32) {
let mut base = character_field.base;
let mut carac = character_field.carac;
let mut materiel = character_field.materiel;
ui.heading(category);
ui.columns(2, |columns| {
let mut ui_column = &mut columns[0];
ui_column.label("Base");
ui_column.label("Carac.");
ui_column.label("Matériel");
fn shortcut(
&self,
ui: &mut Ui,
category: &str,
character_field: &Characteristic,
) -> (u32, u32, u32) {
let mut base = character_field.base;
let mut carac = character_field.carac;
let mut materiel = character_field.materiel;
ui.heading(category);
ui.columns(2, |columns| {
let mut ui_column = &mut columns[0];
ui_column.label("Base");
ui_column.label("Carac.");
ui_column.label("Matériel");
ui_column = &mut columns[1];
ui_column.add(DragValue::new(&mut base));
ui_column.add(DragValue::new(&mut carac));
ui_column.add(DragValue::new(&mut materiel));
});
return (base, carac, materiel);
}
ui_column = &mut columns[1];
ui_column.add(DragValue::new(&mut base));
ui_column.add(DragValue::new(&mut carac));
ui_column.add(DragValue::new(&mut materiel));
});
return (base, carac, materiel);
}
fn gui_address(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.address.base, self.address.carac, self.address.materiel) = self.shortcut(ui, "Habileté", workaround.address());
ui.label("Ne peut dépasser 5");
}
fn gui_address(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.address.base, self.address.carac, self.address.materiel) =
self.shortcut(ui, "Habileté", workaround.address());
ui.label("Ne peut dépasser 5");
}
fn gui_stamina(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.stamina.base, self.stamina.carac, self.stamina.materiel) = self.shortcut(ui, "Endurance", workaround.stamina());
}
fn gui_stamina(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.stamina.base, self.stamina.carac, self.stamina.materiel) =
self.shortcut(ui, "Endurance", workaround.stamina());
}
fn gui_luck(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.luck.base, self.luck.carac, self.luck.materiel) = self.shortcut(ui, "Chance", workaround.luck());
}
fn gui_luck(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.luck.base, self.luck.carac, self.luck.materiel) =
self.shortcut(ui, "Chance", workaround.luck());
}
fn gui_skill(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.skill.base, self.skill.carac, self.skill.materiel) = self.shortcut(ui, "Habileté", workaround.skill());
}
fn gui_skill(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
(self.skill.base, self.skill.carac, self.skill.materiel) =
self.shortcut(ui, "Habileté", workaround.skill());
}
fn secondary_stats(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
ui.heading("Stat. secondaires");
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
ui.label("Dégâts");
ui.label("Armure");
ui.label("Critique");
});
columns[1].vertical_centered_justified(|ui| {
let mut damage = workaround.damage;
let mut armor = workaround.armor;
ui.add(DragValue::new(&mut damage));
ui.add(DragValue::new(&mut armor));
});
});
}
fn secondary_stats(&mut self, ui: &mut Ui) {
let workaround: &CharacterSheet = self;
ui.heading("Stat. secondaires");
ui.columns(2, |columns| {
columns[0].vertical_centered_justified(|ui| {
ui.label("Dégâts");
ui.label("Armure");
ui.label("Critique");
});
columns[1].vertical_centered_justified(|ui| {
let mut damage = workaround.damage;
let mut armor = workaround.armor;
ui.add(DragValue::new(&mut damage));
ui.add(DragValue::new(&mut armor));
});
});
}
}
#[derive(Debug)]
pub struct Characteristic {
characteristic_type: CharacteristicType,
pub base: u32,
pub carac: u32,
pub materiel: u32,
pub additional: u32,
characteristic_type: CharacteristicType,
pub base: u32,
pub carac: u32,
pub materiel: u32,
pub additional: u32,
}
impl Default for CharacterSheet {
fn default() -> Self {
Self {
character_class: Classe::Warrior,
character: "Billy".to_string(),
address: Characteristic {
characteristic_type: CharacteristicType::Address,
base: 0,
carac: 0,
materiel: 0,
additional: 1,
},
stamina: Characteristic {
characteristic_type: CharacteristicType::Stamina,
base: 2,
carac: 0,
materiel: 0,
additional: 0,
},
luck: Characteristic {
characteristic_type: CharacteristicType::Luck,
base: 3,
carac: 0,
materiel: 0,
additional: 0,
},
skill: Characteristic {
characteristic_type: CharacteristicType::Skill,
base: 2,
carac: 0,
materiel: 0,
additional: 0,
},
health: 0,
armor: 0,
damage: 0,
glory: 0,
money: 0,
}
}
fn default() -> Self {
Self {
character_class: Classe::Warrior,
character: "Billy".to_string(),
address: Characteristic {
characteristic_type: CharacteristicType::Address,
base: 0,
carac: 0,
materiel: 0,
additional: 1,
},
stamina: Characteristic {
characteristic_type: CharacteristicType::Stamina,
base: 2,
carac: 0,
materiel: 0,
additional: 0,
},
luck: Characteristic {
characteristic_type: CharacteristicType::Luck,
base: 3,
carac: 0,
materiel: 0,
additional: 0,
},
skill: Characteristic {
characteristic_type: CharacteristicType::Skill,
base: 2,
carac: 0,
materiel: 0,
additional: 0,
},
health: 0,
armor: 0,
damage: 0,
glory: 0,
money: 0,
}
}
}