Skip to content

Commit

Permalink
feat: show plus/minus weapon only when they are functional
Browse files Browse the repository at this point in the history
  • Loading branch information
mokurin000 committed Feb 17, 2024
1 parent 451002e commit 2b7bb1a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/weapon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ const MAX_WEAPON_NUM: usize = 7;
pub fn draw_window(ui: &mut Ui, weapon_num: &mut usize, weapon: &mut [Weapon]) {
ui.horizontal(|ui| {
// do not set the 8th weapon, you may go into issue.
if ui.button(" + ").clicked() && *weapon_num < MAX_WEAPON_NUM {
if (*weapon_num == 0
|| weapon
.get(*weapon_num - 1)
.is_some_and(|w| w.classification != WeaponType::None))
&& *weapon_num < MAX_WEAPON_NUM
&& ui.button(" + ").clicked()
{
*weapon_num += 1
}
if ui.button(" - ").clicked() && *weapon_num > 0 {

if *weapon_num > 0 && ui.button(" - ").clicked() {
*weapon_num -= 1;
weapon[*weapon_num] = Weapon::default();
}
Expand Down

0 comments on commit 2b7bb1a

Please sign in to comment.