Implementing the GUI with the SheetGui interface.

This commit is contained in:
Pcornat 2022-10-30 18:59:05 +01:00
parent 281ce134c4
commit 5514ecda67
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
2 changed files with 74 additions and 19 deletions

View File

@ -1,5 +1,7 @@
use eframe::egui;
use billy_sheet::gui::SheetGui;
fn main() {
let options = eframe::NativeOptions::default();
eframe::run_native(
@ -58,29 +60,17 @@ impl eframe::App for Gui {
// let mut in_col1 = &mut two_columns[0];
// let mut in_col2 = &mut two_columns[1];
two_columns[0].vertical_centered_justified(|ui| {
ui.heading("Habileté");
ui.columns(2, |columns| {
let mut column = &mut columns[0];
{
column.label("Base");
column.label("Carac.");
column.label("Matériel");
}
column = &mut columns[1];
{
let mut base = self.test.skill().base;
let mut carac = self.test.skill().carac;
let mut materiel = self.test.skill().materiel;
column.add(egui::widgets::DragValue::new(&mut base));
column.add(egui::widgets::DragValue::new(&mut carac));
column.add(egui::widgets::DragValue::new(&mut materiel));
}
})
self.test.gui_skill(ui);
self.test.gui_stamina(ui);
});
two_columns[1].vertical_centered_justified(|ui| {
ui.heading("Adresse");
self.test.gui_address(ui);
self.test.gui_luck(ui);
});
});
columns[1].vertical_centered_justified(|ui| {
self.test.secondary_stats(ui);
});
});
});
if ctx.input_mut().consume_key(egui::Modifiers::CTRL, egui::Key::Q)

View File

@ -1,3 +1,8 @@
use eframe::egui::Ui;
use eframe::egui::widgets::DragValue;
use crate::gui::SheetGui;
#[derive(Debug)]
pub enum Classe {
Warrior,
@ -66,6 +71,66 @@ impl CharacterSheet {
}
}
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");
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_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_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));
});
});
}
}
#[derive(Debug)]
pub struct Characteristic {
characteristic_type: CharacteristicType,