Skip to content

Commit

Permalink
Insert events
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jun 29, 2024
1 parent f005b14 commit 1459233
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 142 deletions.
17 changes: 17 additions & 0 deletions crates/components/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,23 @@ impl MapView {
let mut selected_event_rect = None;

for (_, event) in map.events.iter() {
if event.extra_data.modified.get() {
event.extra_data.modified.set(false);
let sprite = luminol_graphics::Event::new_map(
&update_state.graphics,
update_state.filesystem,
&self.map.viewport,
event,
&self.map.atlas,
)
.unwrap(); // FIXME handle
if let Some(sprite) = sprite {
self.map.events.insert(event.id, sprite);
} else {
self.map.events.remove(event.id);
}
}

let sprite = self.map.events.get_mut(event.id);
let has_sprite = sprite.is_some();
let event_size = sprite
Expand Down
1 change: 1 addition & 0 deletions crates/data/src/shared/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct Event {
pub struct EventExtraData {
/// Whether or not the event editor for this event is open
pub is_editor_open: bool,
pub modified: std::cell::Cell<bool>,
}

impl Event {
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/tabs/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl luminol_core::Tab for Tab {
let response = self.view.ui(
ui,
update_state,
&map,
&mut map,
&self.tilepicker,
self.event_drag_info.is_some(),
self.drawing_shape,
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/tabs/map/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl super::Tab {
.add_window(crate::windows::event_edit::Window::new(
update_state,
event,
map.tileset_id,
self.id,
tileset,
));
Some(new_event_id)
Expand Down
301 changes: 161 additions & 140 deletions crates/ui/src/windows/event_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,163 +85,184 @@ impl luminol_core::Window for Window {
open: &mut bool,
update_state: &mut luminol_core::UpdateState<'_>,
) {
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
let id_source = self.id();
let previous_page = self.selected_page;
egui::TopBottomPanel::top(id_source.with("top_panel")).show_inside(ui, |ui| {
ui.horizontal(|ui| {
ui.label("Page: ");
for i in 0..self.event.pages.len() {
ui.selectable_value(&mut self.selected_page, i, format!("{}", i + 1));
}

if ui
.button(egui::RichText::new("Add").color(egui::Color32::LIGHT_GREEN))
.clicked()
{
self.event.pages.push(rpg::EventPage::default());
self.selected_page = self.event.pages.len() - 1;
}

let button = egui::Button::new(
egui::RichText::new("Delete").color(egui::Color32::LIGHT_RED),
);
if ui.add_enabled(self.event.pages.len() > 1, button).clicked() {
self.event.pages.remove(self.selected_page);
self.selected_page = self.selected_page.saturating_sub(1);
}
if ui.button(egui::RichText::new("Clear")).clicked() {
self.event.pages[self.selected_page] = rpg::EventPage::default();
}
});
});

let page = &mut self.event.pages[self.selected_page];
if self.selected_page != previous_page {
// we need to update the modal to prevent desyncs
self.graphic_modal
.update_graphic(update_state, &page.graphic);
}
let mut win_open = true;
let mut needs_save = false;

egui::SidePanel::left(id_source.with("side_panel")).show_inside(ui, |ui| {
ui.label("Conditions");
ui.group(|ui| {
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.switch1_valid, "Switch");
ui.add_enabled(
page.condition.switch1_valid,
self.switch_1_modal
.button(&mut page.condition.switch1_id, update_state),
);
ui.label("is ON");
});
egui::Window::new(self.name())
.open(&mut win_open)
.show(ctx, |ui| {
let id_source = self.id();
let previous_page = self.selected_page;
egui::TopBottomPanel::top(id_source.with("top_panel")).show_inside(ui, |ui| {
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.switch2_valid, "Switch");
ui.add_enabled(
page.condition.switch2_valid,
self.switch_2_modal
.button(&mut page.condition.switch2_id, update_state),
);
ui.label("is ON");
});
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.variable_valid, "Variable");
ui.add_enabled(
page.condition.variable_valid,
self.variable_modal
.button(&mut page.condition.variable_id, update_state),
);
ui.label("is");
ui.add_enabled(
page.condition.variable_valid,
egui::DragValue::new(&mut page.condition.variable_value),
);
ui.label("or above");
});
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.self_switch_valid, "Self Switch");
// TODO add self switch text box (config option)
ui.add_enabled(
// FIXME ensure shrink
page.condition.self_switch_valid,
luminol_components::EnumMenuButton::new(
&mut page.condition.self_switch_ch,
id_source.with("self_switch_ch"),
),
ui.label("Page: ");
for i in 0..self.event.pages.len() {
ui.selectable_value(&mut self.selected_page, i, format!("{}", i + 1));
}

if ui
.button(egui::RichText::new("Add").color(egui::Color32::LIGHT_GREEN))
.clicked()
{
self.event.pages.push(rpg::EventPage::default());
self.selected_page = self.event.pages.len() - 1;
}

let button = egui::Button::new(
egui::RichText::new("Delete").color(egui::Color32::LIGHT_RED),
);
ui.label("is ON");
// ensure we expand to fit the side panel
ui.add_space(ui.available_width());
if ui.add_enabled(self.event.pages.len() > 1, button).clicked() {
self.event.pages.remove(self.selected_page);
self.selected_page = self.selected_page.saturating_sub(1);
}
if ui.button(egui::RichText::new("Clear")).clicked() {
self.event.pages[self.selected_page] = rpg::EventPage::default();
}
});
});

ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.label("Graphic");
let page = &mut self.event.pages[self.selected_page];
if self.selected_page != previous_page {
// we need to update the modal to prevent desyncs
self.graphic_modal
.update_graphic(update_state, &page.graphic);
}

self.graphic_modal
.button(&mut page.graphic, update_state)
.ui(ui);
});
ui.vertical(|ui| {
ui.label("Autonomous Movement");
ui.group(|ui| {
// FIXME these expand to fit, which is kinda annoying
ui.horizontal(|ui| {
ui.label("Move Type");
luminol_components::EnumComboBox::new(
id_source.with("move_type"),
&mut page.move_type,
)
.ui(ui);
});
egui::SidePanel::left(id_source.with("side_panel")).show_inside(ui, |ui| {
ui.label("Conditions");
ui.group(|ui| {
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.switch1_valid, "Switch");
ui.add_enabled(
page.move_type == luminol_data::rpg::MoveType::Custom,
egui::Button::new("Move Route..."),
); // TODO
ui.horizontal(|ui| {
ui.label("Move Speed");
luminol_components::EnumComboBox::new(
id_source.with("move_speed"),
&mut page.move_speed,
)
.ui(ui);
});
ui.horizontal(|ui| {
ui.label("Move Frequency");
luminol_components::EnumComboBox::new(
id_source.with("move_frequency"),
&mut page.move_frequency,
)
page.condition.switch1_valid,
self.switch_1_modal
.button(&mut page.condition.switch1_id, update_state),
);
ui.label("is ON");
});
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.switch2_valid, "Switch");
ui.add_enabled(
page.condition.switch2_valid,
self.switch_2_modal
.button(&mut page.condition.switch2_id, update_state),
);
ui.label("is ON");
});
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.variable_valid, "Variable");
ui.add_enabled(
page.condition.variable_valid,
self.variable_modal
.button(&mut page.condition.variable_id, update_state),
);
ui.label("is");
ui.add_enabled(
page.condition.variable_valid,
egui::DragValue::new(&mut page.condition.variable_value),
);
ui.label("or above");
});
ui.horizontal(|ui| {
ui.checkbox(&mut page.condition.self_switch_valid, "Self Switch");
// TODO add self switch text box (config option)
ui.add_enabled(
// FIXME ensure shrink
page.condition.self_switch_valid,
luminol_components::EnumMenuButton::new(
&mut page.condition.self_switch_ch,
id_source.with("self_switch_ch"),
),
);
ui.label("is ON");
// ensure we expand to fit the side panel
ui.add_space(ui.available_width());
});
});

ui.horizontal(|ui| {
ui.vertical(|ui| {
ui.label("Graphic");

self.graphic_modal
.button(&mut page.graphic, update_state)
.ui(ui);
});
ui.vertical(|ui| {
ui.label("Autonomous Movement");
ui.group(|ui| {
// FIXME these expand to fit, which is kinda annoying
ui.horizontal(|ui| {
ui.label("Move Type");
luminol_components::EnumComboBox::new(
id_source.with("move_type"),
&mut page.move_type,
)
.ui(ui);
});
ui.add_enabled(
page.move_type == luminol_data::rpg::MoveType::Custom,
egui::Button::new("Move Route..."),
); // TODO
ui.horizontal(|ui| {
ui.label("Move Speed");
luminol_components::EnumComboBox::new(
id_source.with("move_speed"),
&mut page.move_speed,
)
.ui(ui);
});
ui.horizontal(|ui| {
ui.label("Move Frequency");
luminol_components::EnumComboBox::new(
id_source.with("move_frequency"),
&mut page.move_frequency,
)
.ui(ui);
});
ui.add_space(ui.available_height());
});
ui.add_space(ui.available_height());
});
});
});

ui.columns(2, |columns| {
let [left, right] = columns else {
unreachable!()
};

left.label("Options");
left.group(|ui| {
ui.style_mut().wrap = Some(false);
ui.checkbox(&mut page.walk_anime, "Move Animation");
ui.checkbox(&mut page.step_anime, "Step Animation");
ui.checkbox(&mut page.direction_fix, "Direction Fix");
ui.checkbox(&mut page.through, "Through");
ui.checkbox(&mut page.always_on_top, "Always on Top");
});
ui.columns(2, |columns| {
let [left, right] = columns else {
unreachable!()
};

left.label("Options");
left.group(|ui| {
ui.style_mut().wrap = Some(false);
ui.checkbox(&mut page.walk_anime, "Move Animation");
ui.checkbox(&mut page.step_anime, "Step Animation");
ui.checkbox(&mut page.direction_fix, "Direction Fix");
ui.checkbox(&mut page.through, "Through");
ui.checkbox(&mut page.always_on_top, "Always on Top");
});

right.label("Trigger");
right.group(|ui| {
luminol_components::EnumRadioList::new(&mut page.trigger).ui(ui);
right.label("Trigger");
right.group(|ui| {
luminol_components::EnumRadioList::new(&mut page.trigger).ui(ui);
});
});
});

egui::TopBottomPanel::bottom(id_source.with("bottom_panel")).show_inside(
ui,
|ui| {
ui.add_space(ui.style().spacing.item_spacing.y);
luminol_components::close_options_ui(ui, open, &mut needs_save)
},
);
});
});

if needs_save {
self.event.extra_data.modified.set(true);
let mut map = update_state.data.get_map(self.map_id);
map.events.insert(self.event.id, self.event.clone()); // don't like the extra clone, but it's necessary
}

*open &= win_open;
}

fn requires_filesystem(&self) -> bool {
Expand Down

0 comments on commit 1459233

Please sign in to comment.