This commit is contained in:
Pcornat 2022-11-25 21:12:16 +01:00
parent 5514ecda67
commit c489be9c78
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
7 changed files with 293 additions and 236 deletions

15
.fleet/run.json Normal file
View File

@ -0,0 +1,15 @@
{
"configurations": [
{
"type": "cargo",
"name": "Build release",
"cargoArgs": ["build", "--release"],
},
{
"type": "cargo",
"name": "Run release",
"cargoArgs": ["run", "--release"],
},
]
}

32
Cargo.lock generated
View File

@ -196,7 +196,8 @@ name = "billy_sheet"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"eframe", "eframe",
"json", "serde",
"serde_json",
] ]
[[package]] [[package]]
@ -1033,6 +1034,12 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "itoa"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]] [[package]]
name = "jni" name = "jni"
version = "0.19.0" version = "0.19.0"
@ -1062,12 +1069,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "json"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
[[package]] [[package]]
name = "khronos_api" name = "khronos_api"
version = "3.1.0" version = "3.1.0"
@ -1623,6 +1624,12 @@ dependencies = [
"ordered-multimap", "ordered-multimap",
] ]
[[package]]
name = "ryu"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]] [[package]]
name = "safe_arch" name = "safe_arch"
version = "0.5.2" version = "0.5.2"
@ -1685,6 +1692,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "serde_json"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]] [[package]]
name = "serde_repr" name = "serde_repr"
version = "0.1.9" version = "0.1.9"

View File

@ -7,4 +7,5 @@ edition = "2021"
[dependencies] [dependencies]
eframe = { version = "*", features = ["dark-light"] } eframe = { version = "*", features = ["dark-light"] }
json = "*" serde = { version = "*", features = ["derive"] }
serde_json = "*"

View File

@ -1,13 +1,22 @@
use eframe::egui;
use eframe::egui::Ui; use eframe::egui::Ui;
use crate::sheet::{Characteristic, CharacterSheet}; use crate::sheet::Characteristic;
pub trait SheetGui where Self: Sized { pub trait SheetGui
fn shortcut(&self, _ui: &mut Ui, category: &str, character_field: &Characteristic) -> (u32, u32, u32) { (0, 0, 0) } where
fn gui_address(&mut self, ui: &mut Ui); Self: Sized,
fn gui_stamina(&mut self, ui: &mut Ui); {
fn gui_luck(&mut self, ui: &mut Ui); fn shortcut(
fn gui_skill(&mut self, ui: &mut Ui); &self,
fn secondary_stats(&mut self, ui: &mut Ui); _ui: &mut Ui,
_category: &str,
_character_field: &Characteristic,
) -> (u32, u32, u32) {
(0, 0, 0)
}
fn gui_address(&mut self, ui: &mut Ui);
fn gui_stamina(&mut self, ui: &mut Ui);
fn gui_luck(&mut self, ui: &mut Ui);
fn gui_skill(&mut self, ui: &mut Ui);
fn secondary_stats(&mut self, ui: &mut Ui);
} }

View File

@ -1,2 +1,2 @@
pub mod sheet;
pub mod gui; pub mod gui;
pub mod sheet;

View File

@ -3,79 +3,82 @@ use eframe::egui;
use billy_sheet::gui::SheetGui; use billy_sheet::gui::SheetGui;
fn main() { fn main() {
let options = eframe::NativeOptions::default(); let options = eframe::NativeOptions::default();
eframe::run_native( eframe::run_native(
"Billy Sheet editor", "Billy Sheet editor",
options, options,
Box::new(|_ctx| { Box::new(|_ctx| {
// ctx.egui_ctx.options().screen_reader = true; // ctx.egui_ctx.options().screen_reader = true;
Box::new(Gui::default()) Box::new(Gui::default())
}), }),
); );
} }
#[derive(Debug)] #[derive(Debug)]
struct Gui { struct Gui {
test: billy_sheet::sheet::CharacterSheet, test: billy_sheet::sheet::CharacterSheet,
edit_mode: bool, edit_mode: bool,
} }
impl Default for Gui { impl Default for Gui {
fn default() -> Self { fn default() -> Self {
Self { Self {
test: billy_sheet::sheet::CharacterSheet::default(), test: billy_sheet::sheet::CharacterSheet::default(),
edit_mode: true, edit_mode: true,
} }
} }
} }
impl eframe::App for Gui { impl eframe::App for Gui {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::TopBottomPanel::top("menu").show(ctx, |ui| { egui::TopBottomPanel::top("menu").show(ctx, |ui| {
egui::menu::bar(ui, |ui| { egui::menu::bar(ui, |ui| {
egui::widgets::global_dark_light_mode_buttons(ui); egui::widgets::global_dark_light_mode_buttons(ui);
ui.menu_button("File", |ui| { ui.menu_button("File", |ui| {
if ui.button("Open (Ctrl + O)").clicked() {} if ui.button("Open (Ctrl + O)").clicked() {}
if ui.button("Quit (Ctrl + Q)").clicked() { if ui.button("Quit (Ctrl + Q)").clicked() {
_frame.close(); _frame.close();
} }
}); });
if ui.button(format!("Edit mode {}", self.edit_mode)).clicked() { if ui.button(format!("Edit mode {}", self.edit_mode)).clicked() {
self.edit_mode = !self.edit_mode.clone(); self.edit_mode = !self.edit_mode.clone();
} }
}); });
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("My egui Application"); ui.heading("My egui Application");
ui.separator(); ui.separator();
ui.vertical_centered_justified(|ui| { ui.label("Caractère");
let mut tmp_str = self.test.character().to_string(); ui.vertical_centered_justified(|ui| {
ui.text_edit_multiline(&mut tmp_str); let mut tmp_str = self.test.character().to_string();
self.test.character = tmp_str; ui.text_edit_multiline(&mut tmp_str);
}); self.test.character = tmp_str;
ui.columns(2, |columns| { });
// let mut col_1_ui = &mut columns[0]; ui.columns(2, |columns| {
// let mut col_2_ui = &mut columns[1]; // let mut col_1_ui = &mut columns[0];
columns[0].columns(2, |two_columns| { // let mut col_2_ui = &mut columns[1];
// let mut in_col1 = &mut two_columns[0]; columns[0].columns(2, |two_columns| {
// let mut in_col2 = &mut two_columns[1]; // let mut in_col1 = &mut two_columns[0];
two_columns[0].vertical_centered_justified(|ui| { // let mut in_col2 = &mut two_columns[1];
self.test.gui_skill(ui); two_columns[0].vertical_centered_justified(|ui| {
self.test.gui_stamina(ui); self.test.gui_skill(ui);
}); self.test.gui_stamina(ui);
two_columns[1].vertical_centered_justified(|ui| { });
self.test.gui_address(ui); two_columns[1].vertical_centered_justified(|ui| {
self.test.gui_luck(ui); self.test.gui_address(ui);
}); self.test.gui_luck(ui);
}); });
columns[1].vertical_centered_justified(|ui| { });
self.test.secondary_stats(ui); columns[1].vertical_centered_justified(|ui| {
}); self.test.secondary_stats(ui);
}); });
}); });
if ctx.input_mut().consume_key(egui::Modifiers::CTRL, egui::Key::Q) });
{ if ctx
_frame.close(); .input_mut()
} .consume_key(egui::Modifiers::CTRL, egui::Key::Q)
} {
_frame.close();
}
}
} }

View File

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