Skip to content

Commit

Permalink
Add dropdowns for move types
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Dec 22, 2023
1 parent 8841f88 commit bfb1371
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'e, T> EnumMenuButton<'e, T> {
pub fn new(current_value: &'e mut T) -> Self {
Self {
current_value,
id: egui::Id::new("enum menu button"),
id: egui::Id::new("enum menu button").with(std::any::type_name::<T>()),
}
}

Expand Down
128 changes: 121 additions & 7 deletions crates/data/src/shared/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ pub struct CommonEvent {
pub struct EventPage {
pub condition: EventCondition,
pub graphic: Graphic,
pub move_type: usize,
pub move_speed: usize,
pub move_frequency: usize,
pub move_type: MoveType,
pub move_speed: MoveSpeed,
pub move_frequency: MoveFreq,
pub move_route: MoveRoute,
pub walk_anime: bool,
pub step_anime: bool,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl From<u8> for EventTrigger {
2 => Self::EventTouch,
3 => Self::Autorun,
4 => Self::Parallel,
_ => panic!("wrong value for self switch"),
_ => panic!("wrong value for event trigger"),
}
}
}
Expand All @@ -122,14 +122,128 @@ impl From<EventTrigger> for u8 {
}
}

#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(strum::Display, strum::EnumIter)]
#[serde(from = "u8", into = "u8")]
pub enum MoveType {
Fixed,
Random,
Approach,
Custom,
}

impl From<u8> for MoveType {
fn from(value: u8) -> Self {
match value {
0 => Self::Fixed,
1 => Self::Random,
2 => Self::Approach,
3 => Self::Custom,
_ => panic!("wrong value for move type"),
}
}
}

impl From<MoveType> for u8 {
fn from(val: MoveType) -> Self {
match val {
MoveType::Fixed => 0,
MoveType::Random => 1,
MoveType::Approach => 2,
MoveType::Custom => 3,
}
}
}

#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(strum::Display, strum::EnumIter)]
#[serde(from = "u8", into = "u8")]
pub enum MoveSpeed {
Slowest,
Slower,
Slow,
Fast,
Faster,
Fastest,
}

impl From<u8> for MoveSpeed {
fn from(value: u8) -> Self {
match value {
1 => Self::Slowest,
2 => Self::Slower,
3 => Self::Slow,
4 => Self::Fast,
5 => Self::Faster,
6 => Self::Fastest,
_ => panic!("wrong value for move speed"),
}
}
}

impl From<MoveSpeed> for u8 {
fn from(val: MoveSpeed) -> Self {
match val {
MoveSpeed::Slowest => 1,
MoveSpeed::Slower => 2,
MoveSpeed::Slow => 3,
MoveSpeed::Fast => 4,
MoveSpeed::Faster => 5,
MoveSpeed::Fastest => 6,
}
}
}

#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(strum::Display, strum::EnumIter)]
#[serde(from = "u8", into = "u8")]
pub enum MoveFreq {
Lowest,
Lower,
Low,
High,
Higher,
Highest,
}

impl From<u8> for MoveFreq {
fn from(value: u8) -> Self {
match value {
1 => Self::Lowest,
2 => Self::Lower,
3 => Self::Low,
4 => Self::High,
5 => Self::Higher,
6 => Self::Highest,
_ => panic!("wrong value for move speed"),
}
}
}

impl From<MoveFreq> for u8 {
fn from(val: MoveFreq) -> Self {
match val {
MoveFreq::Lowest => 1,
MoveFreq::Lower => 2,
MoveFreq::Low => 3,
MoveFreq::High => 4,
MoveFreq::Higher => 5,
MoveFreq::Highest => 6,
}
}
}

impl Default for EventPage {
fn default() -> Self {
Self {
condition: EventCondition::default(),
graphic: Graphic::default(),
move_type: 0,
move_speed: 3,
move_frequency: 3,
move_type: MoveType::Approach,
move_speed: MoveSpeed::Slow,
move_frequency: MoveFreq::Low,
move_route: MoveRoute::default(),
walk_anime: true,
step_anime: false,
Expand Down
18 changes: 16 additions & 2 deletions crates/ui/src/windows/event_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,18 @@ impl luminol_core::Window for Window {
.add(luminol_components::EnumMenuBar::vertical(&mut page.trigger));
});
}
Tab::Movement => {}
Tab::Movement => {
ui.horizontal(|ui| {
ui.add(luminol_components::EnumMenuButton::new(&mut page.move_type));
ui.add(luminol_components::EnumMenuButton::new(
&mut page.move_speed,
));
ui.add(luminol_components::EnumMenuButton::new(
&mut page.move_frequency,
));
});
ui.separator();
}
Tab::Commands => {}
Tab::Graphic => {
// fixme handle updating graphic
Expand All @@ -243,7 +254,10 @@ impl luminol_core::Window for Window {
ui.allocate_painter(size, egui::Sense::hover());
graphic.paint(update_state.graphics.clone(), &painter, response.rect);
} else {
ui.allocate_space(egui::vec2(364., 364.));
ui.allocate_space(egui::vec2(
ui.available_width(),
ui.available_width(),
));
}
}
}
Expand Down

0 comments on commit bfb1371

Please sign in to comment.