pub fn left_panel(
  mut gui: ResMut<EguiContext>,
  //mut blocks: ResMut<UIBlocks>,
  ui_state: Res<TurnUIState>,
  mut turn_event_writer: EventWriter<StartTurn>,
  mut cancel_event_writer: EventWriter<PlayerActionChosen>,
  selected_tile: Query<
    (&TilePos, &DataLayer, &TileTemp),
    (With<SelectedTile>, With<DataLayer>, Without<DrawOnMap>),
  >,
  player_q: Query<PlayerStatusQuery>,
  spells: Query<&AvailableSpell>,
  enemies: Query<(&TilePos, &EntityHealth), With<Enemy>>,
) {
  const PANEL_SIZE_FACTOR: f32 = 4.;

  let eg_window = gui.ctx_mut().available_rect();
  let frame_width = eg_window.width() / PANEL_SIZE_FACTOR;
  let frame_height = eg_window.height();

  let wizard = player_q
    .iter()
    .find(|pd| *pd.4 == MapEntityType::Player(PlayerType::Wizard));
  let warrior = player_q
    .iter()
    .find(|pd| *pd.4 == MapEntityType::Player(PlayerType::Warrior));

  let available_spells: SpellList = spells.iter().map(|s| s.name.as_str()).collect();

  egui::SidePanel::left("core_ui")
    .min_width(frame_width)
    .resizable(false)
    .show(gui.ctx_mut(), |ui| {
      ui.add_space(10.);
      if let (Some(wizard), Some(warrior)) = (wizard, warrior) {
        let actions_enabled = ui_state.status == TurnStatus::PlayerChoosing;

        let top_text = match ui_state.status {
          TurnStatus::PlayerChoosing => "Choose Your Actions...",
          TurnStatus::PlayerRunning => "Player Turn",
          TurnStatus::EnemyRunning => "Enemy Turn",
          _ => "",
        };
        ui.label(egui::RichText::new(top_text).strong());
        ui.horizontal(|ui| {
          ui.set_max_height(frame_height / 3.);
          ui.set_max_width(frame_width / 2.);

          ui.vertical(|ui| {
            ui.allocate_space(EGVec2::new(frame_width / 2., 1.));
            let mut wl = egui::RichText::new("Warrior");
            if selected_tile
              .get_single()
              .ok()
              .filter(|(pos, _, _)| *pos == warrior.1)
              .is_some()
            {
              wl = wl.underline();
            }
            ui.label(wl);
            if let Some((player_entity, action_type)) =
              draw_player_status(warrior, PlayerType::Warrior, &available_spells, ui)
            {
              cancel_event_writer.send(PlayerActionChosen {
                player: player_entity,
                action_type,
              });
            }
          });
          ui.separator();
          ui.vertical(|ui| {
            ui.allocate_space(EGVec2::new(frame_width / 2., 1.));
            let mut wl = egui::RichText::new("Wizard");
            if selected_tile
              .get_single()
              .ok()
              .filter(|(pos, _, _)| *pos == wizard.1)
              .is_some()
            {
              wl = wl.underline();
            }
            ui.label(wl);
            if let Some((player_entity, action_type)) =
              draw_player_status(wizard, PlayerType::Wizard, &available_spells, ui)
            {
              cancel_event_writer.send(PlayerActionChosen {
                player: player_entity,
                action_type,
              });
            }
          });
        });

        ui.allocate_space(EGVec2::new(
          frame_width,
          (frame_height / 3.) - (frame_height - ui.available_height()),
        ));

        ui.vertical_centered(|ui| {
          let can_end_turn = actions_enabled && player_q.iter().all(|pd| pd.5.is_ready);
          let go = ui.add_enabled(can_end_turn, egui::Button::new("End Turn"));
          if go.clicked() {
            turn_event_writer.send(StartTurn(TurnStatus::PlayerRunning));
          }
        });
      } else {
        ui.label("Loading..");
      }
      ui.separator();
      if let Ok((pos, kind, temp)) = selected_tile.get_single() {
        ui.label(format!("Tile ({}, {}) selected", pos.0, pos.1));
        let desc = match kind.kind {
          crate::map::TileKind::Floor => "Ground",
          crate::map::TileKind::Open => "Open Space",
          crate::map::TileKind::Wall => "Solid Wall",
        };
        ui.label(format!("{} - {}° C", desc, temp.temp));
        if let Some(e) = enemies.iter().find(|(epos, ..)| *epos == pos) {
          ui.label(egui::RichText::new("Enemy").strong());
          ui.add_space(10.);
          ui.label("Health");
          draw_single_bar(
            ui,
            constants::PLAYER_MAX_HEALTH,
            e.1.health,
            egui::Color32::RED,
            egui::Color32::DARK_RED,
          );
        }
      } else {
        ui.label("No tile selected");
      }
    });
}
// Does not mutate components directly, instead sends events
Does not mutate components directly, instead sends events
Does not mutate components directly instead sends events
pub fn left_panel(
  mut gui: ResMut<EguiContext>,
  //mut blocks: ResMut<UIBlocks>,
  ui_state: Res<TurnUIState>,
  mut turn_event_writer: EventWriter<StartTurn>,
  mut cancel_event_writer: EventWriter<PlayerActionChosen>,
  selected_tile: Query<
    (&TilePos, &DataLayer, &TileTemp),
    (With<SelectedTile>, With<DataLayer>, Without<DrawOnMap>),
  >,
  player_q: Query<PlayerStatusQuery>,
  spells: Query<&AvailableSpell>,
  enemies: Query<(&TilePos, &EntityHealth), With<Enemy>>,
) {
  const PANEL_SIZE_FACTOR: f32 = 4.;
  let eg_window = gui.ctx_mut().available_rect();
  let frame_width = eg_window.width() / PANEL_SIZE_FACTOR;
  let frame_height = eg_window.height();
  let wizard = player_q
    .iter()
    .find(|pd| *pd.4 == MapEntityType::Player(PlayerType::Wizard));
  let warrior = player_q
    .iter()
    .find(|pd| *pd.4 == MapEntityType::Player(PlayerType::Warrior));
  let available_spells: SpellList = spells.iter().map(|s| s.name.as_str()).collect();
  egui::SidePanel::left("core_ui")
    .min_width(frame_width)
    .resizable(false)
    .show(gui.ctx_mut(), |ui| {
      ui.add_space(10.);
      if let (Some(wizard), Some(warrior)) = (wizard, warrior) {
        let actions_enabled = ui_state.status == TurnStatus::PlayerChoosing;
        let top_text = match ui_state.status {
          TurnStatus::PlayerChoosing => "Choose Your Actions...",
          TurnStatus::PlayerRunning => "Player Turn",
          TurnStatus::EnemyRunning => "Enemy Turn",
          _ => "",
        };
        ui.label(egui::RichText::new(top_text).strong());
        ui.horizontal(|ui| {
          ui.set_max_height(frame_height / 3.);
          ui.set_max_width(frame_width / 2.);
          ui.vertical(|ui| {
            ui.allocate_space(EGVec2::new(frame_width / 2., 1.));
            let mut wl = egui::RichText::new("Warrior");
            if selected_tile
              .get_single()
              .ok()
              .filter(|(pos, _, _)| *pos == warrior.1)
              .is_some()
            {
              wl = wl.underline();
            }
            ui.label(wl);
            if let Some((player_entity, action_type)) =
              draw_player_status(warrior, PlayerType::Warrior, &available_spells, ui)
            {
              cancel_event_writer.send(PlayerActionChosen {
                player: player_entity,
                action_type,
              });
            }
          });
          ui.separator();
          ui.vertical(|ui| {
            ui.allocate_space(EGVec2::new(frame_width / 2., 1.));
            let mut wl = egui::RichText::new("Wizard");
            if selected_tile
              .get_single()
              .ok()
              .filter(|(pos, _, _)| *pos == wizard.1)
              .is_some()
            {
              wl = wl.underline();
            }
            ui.label(wl);
            if let Some((player_entity, action_type)) =
              draw_player_status(wizard, PlayerType::Wizard, &available_spells, ui)
            {
              cancel_event_writer.send(PlayerActionChosen {
                player: player_entity,
                action_type,
              });
            }
          });
        });
        ui.allocate_space(EGVec2::new(
          frame_width,
          (frame_height / 3.) - (frame_height - ui.available_height()),
        ));
        ui.vertical_centered(|ui| {
          let can_end_turn = actions_enabled && player_q.iter().all(|pd| pd.5.is_ready);
          let go = ui.add_enabled(can_end_turn, egui::Button::new("End Turn"));
          if go.clicked() {
            turn_event_writer.send(StartTurn(TurnStatus::PlayerRunning));
          }
        });
      } else {
        ui.label("Loading..");
      }
      ui.separator();
      if let Ok((pos, kind, temp)) = selected_tile.get_single() {
        ui.label(format!("Tile ({}, {}) selected", pos.0, pos.1));
        let desc = match kind.kind {
          crate::map::TileKind::Floor => "Ground",
          crate::map::TileKind::Open => "Open Space",
          crate::map::TileKind::Wall => "Solid Wall",
        };
        ui.label(format!("{} - {}° C", desc, temp.temp));
        if let Some(e) = enemies.iter().find(|(epos, ..)| *epos == pos) {
          ui.label(egui::RichText::new("Enemy").strong());
          ui.add_space(10.);
          ui.label("Health");
          draw_single_bar(
            ui,
            constants::PLAYER_MAX_HEALTH,
            e.1.health,
            egui::Color32::RED,
            egui::Color32::DARK_RED,
          );
        }
      } else {
        ui.label("No tile selected");
      }
    });
}
pub fn left_panel ( mut gui : ResMut < EguiContext > , //mut blocks: ResMut<UIBlocks>, ui_state : Res < TurnUIState > , mut turn_event_writer : EventWriter < StartTurn > , mut cancel_event_writer : EventWriter < PlayerActionChosen > , selected_tile : Query < ( & TilePos , & DataLayer , & TileTemp ) , ( With < SelectedTile > , With < DataLayer > , Without < DrawOnMap > ) , > , player_q : Query < PlayerStatusQuery > , spells : Query < & AvailableSpell > , enemies : Query < ( & TilePos , & EntityHealth ) , With < Enemy > > , ) { const PANEL_SIZE_FACTOR : f32 = 4. ; let eg_window = gui . ctx_mut ( ) . available_rect ( ) ; let frame_width = eg_window . width ( ) / PANEL_SIZE_FACTOR ; let frame_height = eg_window . height ( ) ; let wizard = player_q . iter ( ) . find ( | pd | * pd . 4 == MapEntityType :: Player ( PlayerType :: Wizard ) ) ; let warrior = player_q . iter ( ) . find ( | pd | * pd . 4 == MapEntityType :: Player ( PlayerType :: Warrior ) ) ; let available_spells : SpellList = spells . iter ( ) . map ( | s | s . name . as_str ( ) ) . collect ( ) ; egui :: SidePanel :: left ( " " ) . min_width ( frame_width ) . resizable ( false ) . show ( gui . ctx_mut ( ) , | ui | { ui . add_space ( 10. ) ; if let ( Some ( wizard ) , Some ( warrior ) ) = ( wizard , warrior ) { let actions_enabled = ui_state . status == TurnStatus :: PlayerChoosing ; let top_text = match ui_state . status { TurnStatus :: PlayerChoosing => " " , TurnStatus :: PlayerRunning => " " , TurnStatus :: EnemyRunning => " " , _ => " " , } ; ui . label ( egui :: RichText :: new ( top_text ) . strong ( ) ) ; ui . horizontal ( | ui | { ui . set_max_height ( frame_height / 3. ) ; ui . set_max_width ( frame_width / 2. ) ; ui . vertical ( | ui | { ui . allocate_space ( EGVec2 :: new ( frame_width / 2. , 1. ) ) ; let mut wl = egui :: RichText :: new ( " " ) ; if selected_tile . get_single ( ) . ok ( ) . filter ( | ( pos , _ , _ ) | * pos == warrior . 1 ) . is_some ( ) { wl = wl . underline ( ) ; } ui . label ( wl ) ; if let Some ( ( player_entity , action_type ) ) = draw_player_status ( warrior , PlayerType :: Warrior , & available_spells , ui ) { cancel_event_writer . send ( PlayerActionChosen { player : player_entity , action_type , } ) ; } } ) ; ui . separator ( ) ; ui . vertical ( | ui | { ui . allocate_space ( EGVec2 :: new ( frame_width / 2. , 1. ) ) ; let mut wl = egui :: RichText :: new ( " " ) ; if selected_tile . get_single ( ) . ok ( ) . filter ( | ( pos , _ , _ ) | * pos == wizard . 1 ) . is_some ( ) { wl = wl . underline ( ) ; } ui . label ( wl ) ; if let Some ( ( player_entity , action_type ) ) = draw_player_status ( wizard , PlayerType :: Wizard , & available_spells , ui ) { cancel_event_writer . send ( PlayerActionChosen { player : player_entity , action_type , } ) ; } } ) ; } ) ; ui . allocate_space ( EGVec2 :: new ( frame_width , ( frame_height / 3. ) - ( frame_height - ui . available_height ( ) ) , ) ) ; ui . vertical_centered ( | ui | { let can_end_turn = actions_enabled && player_q . iter ( ) . all ( | pd | pd . 5 . is_ready ) ; let go = ui . add_enabled ( can_end_turn , egui :: Button :: new ( " " ) ) ; if go . clicked ( ) { turn_event_writer . send ( StartTurn ( TurnStatus :: PlayerRunning ) ) ; } } ) ; } else { ui . label ( " " ) ; } ui . separator ( ) ; if let Ok ( ( pos , kind , temp ) ) = selected_tile . get_single ( ) { ui . label ( format ! ( " " pos 0 pos 1 ) ) ; let desc = match kind . kind { crate :: map :: TileKind :: Floor => " " , crate :: map :: TileKind :: Open => " " , crate :: map :: TileKind :: Wall => " " , } ; ui . label ( format ! ( " , esc, emp. emp) ) ; if let Some ( e ) = enemies . iter ( ) . find ( | ( epos , .. ) | * epos == pos ) { ui . label ( egui :: RichText :: new ( " " ) . strong ( ) ) ; ui . add_space ( 10. ) ; ui . label ( " " ) ; draw_single_bar ( ui , constants :: PLAYER_MAX_HEALTH , e . 1 . health , egui :: Color32 :: RED , egui :: Color32 :: DARK_RED , ) ; } } else { ui . label ( " " ) ; } } ) ; }
Does not mutate components directly, instead sends events
Does not mutate components directly instead sends events
gui
ResMut<EguiContext>
ui_state
Res<TurnUIState>
turn_event_writer
EventWriter<StartTurn>
cancel_event_writer
EventWriter<PlayerActionChosen>
selected_tile
Query<
    (&TilePos, &DataLayer, &TileTemp),
    (With<SelectedTile>, With<DataLayer>, Without<DrawOnMap>),
  >
player_q
Query<PlayerStatusQuery>
spells
Query<&AvailableSpell>
enemies
Query<(&TilePos, &EntityHealth), With<Enemy>>
gui
ResMut<EguiContext>
ui_state
Res<TurnUIState>
turn_event_writer
EventWriter<StartTurn>
cancel_event_writer
EventWriter<PlayerActionChosen>
selected_tile
Query<
    (&TilePos, &DataLayer, &TileTemp),
    (With<SelectedTile>, With<DataLayer>, Without<DrawOnMap>),
  >
player_q
Query<PlayerStatusQuery>
spells
Query<&AvailableSpell>
enemies
Query<(&TilePos, &EntityHealth), With<Enemy>>