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