// If an entity is returned, it means that the entity (player) has cancelled the action
If an entity is returned, it means that the entity (player) has cancelled the action
If an entity is returned it means that the entity ( player ) has cancelled the action
fn draw_player_status<'a>(
  player_status: PlayerStatusQuery<'a>,
  player_type: PlayerType,
  spells: &SpellList,
  ui: &mut egui::Ui,
) -> Option<(Entity, EntityPendingAction)> {
  let (p_entity, _, status, health, _, pending_action) = player_status;
  let mut return_val = None;
  let height = ui.available_height();
  ui.add_space(10.);
  ui.label("Health:");
  draw_single_bar(
    ui,
    constants::PLAYER_MAX_HEALTH,
    health.health,
    egui::Color32::GREEN,
    egui::Color32::RED,
  )
  .height();
  ui.add_space(10.);
  if let Some(magika) = status.magika {
    ui.label("Mana: ");
    draw_single_bar(
      ui,
      constants::PLAYER_MAX_MAGIKA,
      magika,
      egui::Color32::BLUE,
      egui::Color32::BLUE,
    )
    .height();
  }
  let used_height = height - ui.available_height();
  ui.add_space((height / 1.8) - used_height);
  ui.label(egui::RichText::new("Actions").strong());
  ui.vertical(|ui| {
    let ui_action = match pending_action.action {
      EntityAction::Move(_) => UIPlayerAction::Move,
      EntityAction::Wait => UIPlayerAction::Wait,
      EntityAction::Cast(_) => UIPlayerAction::Cast,
      EntityAction::Attack(_) => UIPlayerAction::Attack,
      _ => UIPlayerAction::Wait,
    };
    let mut selection = ui_action.clone();
    egui::ComboBox::from_id_source(player_type)
      .selected_text(format!("{:?}", ui_action))
      .show_ui(ui, |ui| {
        ui.selectable_value(&mut selection, UIPlayerAction::Wait, "Wait");
        ui.selectable_value(&mut selection, UIPlayerAction::Move, "Move");
        ui.selectable_value(&mut selection, UIPlayerAction::Attack, "Attack");
        if player_type == PlayerType::Wizard {
          ui.selectable_value(&mut selection, UIPlayerAction::Cast, "Cast");
        }
      })
      .inner;
    let mut new_spell = "".to_owned();
    if let Some(cur_spell) = pending_action.get_spell() {
      let start_index = spells
        .iter()
        .enumerate()
        .find(|(_, spell_name)| **spell_name == cur_spell)
        .map(|(i, _)| i)
        .unwrap_or(0);
      let mut selected_spell = start_index;
      egui::ComboBox::from_id_source("Spells").show_index(
        ui,
        &mut selected_spell,
        spells.len(),
        |i| spells[i].to_owned(),
      );
      if selected_spell != start_index {
        new_spell = spells[selected_spell].to_string();
        return_val = Some((
          p_entity,
          EntityPendingAction {
            action: EntityAction::Cast(new_spell.clone()),
            is_ready: true,
          },
        ));
      }
    }
    if selection != ui_action {
      return_val = Some((
        p_entity,
        match selection {
          UIPlayerAction::Attack => EntityPendingAction::default_attack(),
          UIPlayerAction::Cast => EntityPendingAction {
            action: EntityAction::Cast(new_spell),
            is_ready: false,
          },
          UIPlayerAction::Move => EntityPendingAction {
            action: EntityAction::Move((TilePos::default(), TilePos::default())),
            is_ready: false,
          },
          UIPlayerAction::Wait => EntityPendingAction {
            action: EntityAction::Wait,
            is_ready: true,
          },
        },
      ));
    }
  });
  return_val
}
fn draw_player_status < ' a > ( player_status : PlayerStatusQuery < ' a > , player_type : PlayerType , spells : & SpellList , ui : & mut egui :: Ui , ) -> Option < ( Entity , EntityPendingAction ) > { let ( p_entity , _ , status , health , _ , pending_action ) = player_status ; let mut return_val = None ; let height = ui . available_height ( ) ; ui . add_space ( 10. ) ; ui . label ( " " ) ; draw_single_bar ( ui , constants :: PLAYER_MAX_HEALTH , health . health , egui :: Color32 :: GREEN , egui :: Color32 :: RED , ) . height ( ) ; ui . add_space ( 10. ) ; if let Some ( magika ) = status . magika { ui . label ( " " ) ; draw_single_bar ( ui , constants :: PLAYER_MAX_MAGIKA , magika , egui :: Color32 :: BLUE , egui :: Color32 :: BLUE , ) . height ( ) ; } let used_height = height - ui . available_height ( ) ; ui . add_space ( ( height / 1.8 ) - used_height ) ; ui . label ( egui :: RichText :: new ( " " ) . strong ( ) ) ; ui . vertical ( | ui | { let ui_action = match pending_action . action { EntityAction :: Move ( _ ) => UIPlayerAction :: Move , EntityAction :: Wait => UIPlayerAction :: Wait , EntityAction :: Cast ( _ ) => UIPlayerAction :: Cast , EntityAction :: Attack ( _ ) => UIPlayerAction :: Attack , _ => UIPlayerAction :: Wait , } ; let mut selection = ui_action . clone ( ) ; egui :: ComboBox :: from_id_source ( player_type ) . selected_text ( format ! ( " " ui_action ) ) . show_ui ( ui , | ui | { ui . selectable_value ( & mut selection , UIPlayerAction :: Wait , " " ) ; ui . selectable_value ( & mut selection , UIPlayerAction :: Move , " " ) ; ui . selectable_value ( & mut selection , UIPlayerAction :: Attack , " " ) ; if player_type == PlayerType :: Wizard { ui . selectable_value ( & mut selection , UIPlayerAction :: Cast , " " ) ; } } ) . inner ; let mut new_spell = " " . to_owned ( ) ; if let Some ( cur_spell ) = pending_action . get_spell ( ) { let start_index = spells . iter ( ) . enumerate ( ) . find ( | ( _ , spell_name ) | * * spell_name == cur_spell ) . map ( | ( i , _ ) | i ) . unwrap_or ( 0 ) ; let mut selected_spell = start_index ; egui :: ComboBox :: from_id_source ( " " ) . show_index ( ui , & mut selected_spell , spells . len ( ) , | i | spells [ i ] . to_owned ( ) , ) ; if selected_spell != start_index { new_spell = spells [ selected_spell ] . to_string ( ) ; return_val = Some ( ( p_entity , EntityPendingAction { action : EntityAction :: Cast ( new_spell . clone ( ) ) , is_ready : true , } , ) ) ; } } if selection != ui_action { return_val = Some ( ( p_entity , match selection { UIPlayerAction :: Attack => EntityPendingAction :: default_attack ( ) , UIPlayerAction :: Cast => EntityPendingAction { action : EntityAction :: Cast ( new_spell ) , is_ready : false , } , UIPlayerAction :: Move => EntityPendingAction { action : EntityAction :: Move ( ( TilePos :: default ( ) , TilePos :: default ( ) ) ) , is_ready : false , } , UIPlayerAction :: Wait => EntityPendingAction { action : EntityAction :: Wait , is_ready : true , } , } , ) ) ; } } ) ; return_val }
If an entity is returned, it means that the entity (player) has cancelled the action
If an entity is returned it means that the entity ( player ) has cancelled the action
player_status
PlayerStatusQuery<'a>
player_type
PlayerType
spells
&SpellList
ui
&mut egui::Ui