From f4c477e0318762a1b56ac61436dbee09872d69c4 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 2 Mar 2023 08:37:06 +0100 Subject: [PATCH] Added ability to rotate blocks inside of inventory --- README.md | 6 +++++- src/screens/build.rs | 33 ++++++++++++++++++--------------- src/ui/item_frame.rs | 5 +++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0370ef0..54a2b67 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ with this 2D game - [ ] zoom camera with pinch gesture - [ ] place block with single click - [ ] destroy block with long click -- [ ] Settings menu (i.e for Keybindings) +- [ ] Settings menu (i.e for Keybindings and audio) - [x] Background music (ambient) - [x] Add more assets - [x] SketchTown Expansion pack @@ -68,6 +68,10 @@ with this 2D game | Close Inventory | `Q`, `I` or `` | | Page down | `` | | Page up | `` | +| rotate blocks: North | `K` | +| rotate blocks: South | `J` | +| rotate blocks: West | `H` | +| rotate blocks: East | `L` | ### Level Select screen | Action | Key(s) / MouseButton | diff --git a/src/screens/build.rs b/src/screens/build.rs index f7190ce..c29c607 100644 --- a/src/screens/build.rs +++ b/src/screens/build.rs @@ -334,6 +334,8 @@ impl GameComponent for BuildScreen { } for (i, slot) in self.inventory_widgets.widgets_slots.iter_mut().enumerate() { + slot.update_dir(&world.inventory.direction); + match slot.ev_loop() { ButtonEvent::LeftClick => { // user selected block @@ -348,7 +350,6 @@ impl GameComponent for BuildScreen { } } else { - // process inventory events if is_key_down(KeyCode::I) { // open inventory @@ -534,20 +535,6 @@ impl GameComponent for BuildScreen { self.mouse_position = None; } - // change block direction - if is_key_pressed(KeyCode::K) { - world.inventory.direction = Direction::North; - } - if is_key_pressed(KeyCode::L) { - world.inventory.direction = Direction::East; - } - if is_key_pressed(KeyCode::J) { - world.inventory.direction = Direction::South; - } - if is_key_pressed(KeyCode::H) { - world.inventory.direction = Direction::West; - } - // save the world if is_key_pressed(KeyCode::S) || is_key_pressed(KeyCode::Q) @@ -569,7 +556,23 @@ impl GameComponent for BuildScreen { return GameEvent::ChangeScreen(Screen::default()); } } + } + // change block direction + // player might do this in following cenarios: + // - in inventory + // - in world + if is_key_pressed(KeyCode::K) { + world.inventory.direction = Direction::North; + } + if is_key_pressed(KeyCode::L) { + world.inventory.direction = Direction::East; + } + if is_key_pressed(KeyCode::J) { + world.inventory.direction = Direction::South; + } + if is_key_pressed(KeyCode::H) { + world.inventory.direction = Direction::West; } } else { // game has no world diff --git a/src/ui/item_frame.rs b/src/ui/item_frame.rs index 803b80e..f222d5e 100644 --- a/src/ui/item_frame.rs +++ b/src/ui/item_frame.rs @@ -94,6 +94,11 @@ impl ItemFrame { } self.direction = direction.clone(); } + /// updates the block orientation + #[allow(dead_code)] + pub fn update_dir(&mut self, direction: &Direction) { + self.direction = direction.clone(); + } } impl Widget for ItemFrame { type Event = ButtonEvent; -- 2.38.5