M src/screens/build.rs => src/screens/build.rs +35 -7
@@ 188,7 188,7 @@ impl GameComponent for BuildScreen {
}
}
- // TODO: Draw selected item (top right)
+ // Draw selected item (top right)
{
let smallest = if screen_width() < screen_height() {
screen_width()
@@ 236,14 236,37 @@ impl GameComponent for BuildScreen {
}
}
fn ev_loop(&mut self) -> GameEvent {
-
+ // process inventory events
if is_key_down(KeyCode::I) {
self.show_inv = true;
}
+ if is_mouse_button_pressed(MouseButton::Left) {
+ let (mx,my) = mouse_position();
+
+ let smallest = if screen_width() < screen_height() {
+ screen_width()
+ } else {
+ screen_height()
+ };
+ // use 70% of screen width for slots
+ let width = smallest * 0.08;
+ // only use 90% of slot width for the actual item
+ // ensures enough space around item
+ let slot_render_dim = width * 0.9;
+
+ let tx = screen_width() - width;
+ let ty = width - slot_render_dim;
+
+ if mx >= tx && mx <= tx + slot_render_dim
+ && my >= ty && my <= ty + slot_render_dim {
+ self.show_inv = true;
+ }
+ }
if self.show_inv {
match self.inv.ev_loop() {
GameEvent::Quit => {
self.show_inv = false;
+ return GameEvent::None;
}
_ => return GameEvent::None
}
@@ 336,6 359,11 @@ impl GameComponent for BuildScreen {
if scale > 0.05 && scale < 6.0 {
self.cam.scale = scale;
}
+ } else {
+ let (mx, my) = mouse_wheel();
+
+ self.cam.center.y += my * 5.0 * (1.0/self.cam.scale);
+ self.cam.center.x += mx * 5.0 * (1.0/self.cam.scale);
}
// keyboard control
@@ 346,23 374,23 @@ impl GameComponent for BuildScreen {
self.cam.center.y -= 1.0 * (1.0/self.cam.scale);
}
if is_key_down(KeyCode::Left) {
- self.cam.center.x -= 1.0 * (1.0/self.cam.scale);
+ self.cam.center.x += 1.0 * (1.0/self.cam.scale);
}
if is_key_down(KeyCode::Right) {
- self.cam.center.x += 1.0 * (1.0/self.cam.scale);
+ self.cam.center.x -= 1.0 * (1.0/self.cam.scale);
}
// change block direction
- if is_key_pressed(KeyCode::N) {
+ if is_key_pressed(KeyCode::W) {
self.inv.direction = Direction::North;
}
- if is_key_pressed(KeyCode::E) {
+ if is_key_pressed(KeyCode::D) {
self.inv.direction = Direction::East;
}
if is_key_pressed(KeyCode::S) {
self.inv.direction = Direction::South;
}
- if is_key_pressed(KeyCode::W) {
+ if is_key_pressed(KeyCode::A) {
self.inv.direction = Direction::West;
}
M src/screens/inventory.rs => src/screens/inventory.rs +20 -3
@@ 203,11 203,29 @@ impl GameComponent for Inventory {
// close inventory
if is_key_down(KeyCode::Q) {
- self.page = 0;
return GameEvent::Quit;
}
+ // change block direction
+ if is_key_pressed(KeyCode::W) {
+ self.direction = Direction::North;
+ }
+ if is_key_pressed(KeyCode::D) {
+ self.direction = Direction::East;
+ }
+ if is_key_pressed(KeyCode::S) {
+ self.direction = Direction::South;
+ }
+ if is_key_pressed(KeyCode::A) {
+ self.direction = Direction::West;
+ }
+
+ // process page naviagtion
let page_count = self.contents.len().div_ceil(SLOTS_PER_PAGE);
+ if self.page >= page_count {
+ // reset page if page is now empty
+ self.page = 0;
+ }
if is_key_pressed(KeyCode::Left) {
if self.page == 0 {
if page_count > 0 {
@@ 217,8 235,6 @@ impl GameComponent for Inventory {
self.page -= 1;
}
}
-
-
if is_key_pressed(KeyCode::Right) {
if self.page +1 >= page_count {
self.page = 0;
@@ 227,6 243,7 @@ impl GameComponent for Inventory {
}
}
+ // detect pressed item
if is_mouse_button_pressed(MouseButton::Left) {
let (mx,my) = mouse_position();
// virtual render cycle