diff --git a/src/app/states/skirmish_states/board.rs b/src/app/states/skirmish_states/board.rs index 01d9e0b..645150b 100644 --- a/src/app/states/skirmish_states/board.rs +++ b/src/app/states/skirmish_states/board.rs @@ -220,9 +220,10 @@ impl BoardState { let (row, col) = self.marked_cells.selected_unit.get_coords(); let task: Tasks = Tasks::Digging(DiggingTask::new(self.marked_cells.marked_cells.clone())); - let unit: &mut Option = self.get_mut_cell(row, col).get_mut_option_unit(); - unit.set_task(task); + self.get_mut_cell(row, col) + .get_mut_option_unit() + .set_task(task); self.marked_cells.selected_unit = None; self.marked_cells.marked_cells.clear(); diff --git a/src/app/states/skirmish_states/units/miner.rs b/src/app/states/skirmish_states/units/miner.rs index 47e43f0..9c440da 100644 --- a/src/app/states/skirmish_states/units/miner.rs +++ b/src/app/states/skirmish_states/units/miner.rs @@ -57,6 +57,10 @@ impl Unit for MinerUnit { self.coords } + fn get_tasks(&self) -> String { + format!("{:?}", self.tasks) + } + fn set_task(&mut self, task: Tasks) { self.tasks.push_back(task); } diff --git a/src/app/states/skirmish_states/units/unit_trait.rs b/src/app/states/skirmish_states/units/unit_trait.rs index 561f451..2e21800 100644 --- a/src/app/states/skirmish_states/units/unit_trait.rs +++ b/src/app/states/skirmish_states/units/unit_trait.rs @@ -25,6 +25,8 @@ pub trait Unit { fn get_coords(&self) -> (usize, usize); + fn get_tasks(&self) -> String; + fn set_task(&mut self, task: Tasks); fn base_text(&self) -> Vec> { @@ -34,6 +36,7 @@ pub trait Unit { let hp_percent: u16 = hp * 100 / max_hp; let can_dig: bool = self.get_can_dig(); let digging_power: f32 = self.get_digging_power(); + let tasks: String = self.get_tasks(); let mut lines: Vec> = Vec::from([ Line::from_iter(["Owner: ".gray(), owner]), @@ -46,6 +49,7 @@ pub trait Unit { hp_percent.green(), "% )".gray(), ]), + Line::from_iter(["Tasks Queue: ".gray(), tasks.green()]), ]); if can_dig { diff --git a/src/app/states/skirmish_states/units/units_enum.rs b/src/app/states/skirmish_states/units/units_enum.rs index a0681e9..4d4ad4b 100644 --- a/src/app/states/skirmish_states/units/units_enum.rs +++ b/src/app/states/skirmish_states/units/units_enum.rs @@ -58,6 +58,10 @@ impl Unit for Units { self.u().get_coords() } + fn get_tasks(&self) -> String { + self.u().get_tasks() + } + fn set_task(&mut self, task: Tasks) { self.u_mut().set_task(task); } @@ -100,6 +104,10 @@ impl Unit for Option { self.as_ref().map_or((0, 0), |u| u.get_coords()) } + fn get_tasks(&self) -> String { + self.as_ref().map_or("".to_string(), |u| u.get_tasks()) + } + fn set_task(&mut self, task: Tasks) { self.as_mut().map_or((), |u| u.set_task(task)) } diff --git a/src/app/views/skirmish.rs b/src/app/views/skirmish.rs index c4f4bb4..84ac949 100644 --- a/src/app/views/skirmish.rs +++ b/src/app/views/skirmish.rs @@ -132,11 +132,17 @@ pub fn skirmish_view(app: &App, area: Rect, buf: &mut Buffer) { if states.skirmish.side_panel { let row: usize = board.get_focused_cell().get_row(); let col: usize = board.get_focused_cell().get_col(); + let mut is_unit_marked: bool = false; + + if let Some((first_row, first_col)) = board.marked_cells.marked_cells.get(0) { + is_unit_marked = first_row == &row && first_col == &col; + } SidePanelWidget::new( (row, col), &board.get_ref_cell(row, col).get_structure(), - &board.get_ref_cell(row, col).get_option_unit(), + &board.get_ref_cell(row, col).get_ref_option_unit(), + is_unit_marked, ) .render(side_panel_area, buf); } diff --git a/src/app/widgets/side_panel.rs b/src/app/widgets/side_panel.rs index 03dca76..7163049 100644 --- a/src/app/widgets/side_panel.rs +++ b/src/app/widgets/side_panel.rs @@ -17,14 +17,21 @@ pub struct SidePanelWidget<'a> { coords: (usize, usize), structure: &'a Structures, unit: &'a Option, + is_unit_marked: bool, } impl<'a> SidePanelWidget<'a> { - pub fn new(coords: (usize, usize), structure: &'a Structures, unit: &'a Option) -> Self { + pub fn new( + coords: (usize, usize), + structure: &'a Structures, + unit: &'a Option, + is_unit_marked: bool, + ) -> Self { Self { coords, structure, unit, + is_unit_marked, } } @@ -86,9 +93,15 @@ impl Widget for SidePanelWidget<'_> { .render(structure_area, buf); if self.unit.is_unit() { + let mut unit_name: String = self.unit.get_name().to_string(); + + if self.is_unit_marked { + unit_name = format!("> {} <", unit_name); + } + Paragraph::new(self.unit.text()) .alignment(Alignment::Left) - .block(self.get_inner_block(self.unit.get_name().to_string(), Color::Green)) + .block(self.get_inner_block(unit_name, Color::Green)) .render(unit_area, buf); } }