Skip to content

Commit

Permalink
Hack in the enemy battler picker
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jul 2, 2024
1 parent da7269b commit af1a447
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
19 changes: 19 additions & 0 deletions crates/modals/src/graphic_picker/hue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ impl Modal {
});
});

egui::TopBottomPanel::top(self.id_source.with("top")).show_inside(ui, |ui| {
ui.add_space(1.0); // pad out the top
ui.horizontal(|ui| {
ui.label("Hue");
if ui.add(egui::Slider::new(hue, 0..=360)).changed() {
match selected {
Selected::Entry { sprite, .. } => {
sprite
.sprite
.graphic
.set_hue(&update_state.graphics.render_state, *hue);
}
Selected::None => {}
}
}
});
ui.add_space(1.0); // pad out the bottom
});

egui::TopBottomPanel::bottom(self.id_source.with("bottom")).show_inside(ui, |ui| {
ui.add_space(ui.style().spacing.item_spacing.y);
luminol_components::close_options_ui(ui, &mut keep_open, &mut needs_save);
Expand Down
59 changes: 49 additions & 10 deletions crates/ui/src/windows/enemies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// Program grant you additional permission to convey the resulting work.

use luminol_components::UiExt;
use luminol_core::Modal;
use luminol_modals::graphic_picker::hue::Modal as GraphicPicker;

#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
#[derive(strum::Display, strum::EnumIter)]
Expand All @@ -35,18 +37,36 @@ pub enum TreasureType {
Armor,
}

#[derive(Default)]
pub struct Window {
selected_enemy_name: Option<String>,
previous_enemy: Option<usize>,

graphic_picker: GraphicPicker,

collapsing_view: luminol_components::CollapsingView,
view: luminol_components::DatabaseView,
}

impl Window {
pub fn new() -> Self {
Default::default()
pub fn new(update_state: &luminol_core::UpdateState<'_>) -> Self {
let enemies = update_state.data.enemies();
let enemy = &enemies.data[0];
Self {
selected_enemy_name: None,
previous_enemy: None,

graphic_picker: GraphicPicker::new(
update_state,
"Graphics/Battlers".into(),
enemy.battler_name.as_deref(),
enemy.battler_hue,
egui::vec2(196., 256.),
"enemy_battler_picker",
),

collapsing_view: luminol_components::CollapsingView::new(),
view: luminol_components::DatabaseView::new(),
}
}

fn show_action_header(
Expand Down Expand Up @@ -279,13 +299,32 @@ impl luminol_core::Window for Window {
self.selected_enemy_name = Some(enemy.name.clone());

ui.with_padded_stripe(false, |ui| {
modified |= ui
.add(luminol_components::Field::new(
"Name",
egui::TextEdit::singleline(&mut enemy.name)
.desired_width(f32::INFINITY),
))
.changed();
ui.horizontal(|ui| {
modified |= ui
.add(luminol_components::Field::new(
"Graphic",
self.graphic_picker.button(
(&mut enemy.battler_name, &mut enemy.battler_hue),
update_state,
),
))
.changed();
if self.previous_enemy != Some(enemy.id) {
// avoid desyncs by resetting the modal if the item has changed
self.graphic_picker.reset(
update_state,
(&mut enemy.battler_name, &mut enemy.battler_hue),
);
}

modified |= ui
.add(luminol_components::Field::new(
"Name",
egui::TextEdit::singleline(&mut enemy.name)
.desired_width(f32::INFINITY),
))
.changed();
});
});

ui.with_padded_stripe(true, |ui| {
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/windows/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Window {
menu_se_picker: SoundPicker::new(luminol_audio::Source::SE, "item_menu_se_picker"),
graphic_picker: GraphicPicker::new(
update_state,
camino::Utf8PathBuf::from("Graphics/Icons"),
"Graphics/Icons".into(),
item.icon_name.as_deref(),
egui::vec2(32., 32.),
"item_icon_picker",
Expand Down
2 changes: 1 addition & 1 deletion src/app/top_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl TopBar {
if ui.button("Enemies").clicked() {
update_state
.edit_windows
.add_window(luminol_ui::windows::enemies::Window::new());
.add_window(luminol_ui::windows::enemies::Window::new(update_state));
}

ui.add_enabled_ui(false, |ui| {
Expand Down

0 comments on commit af1a447

Please sign in to comment.