Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pomme-client/src/app/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,12 @@ impl AppCore {
}
3 => {
game.inventory_open = false;
game.creative_inventory_open = false;
game.close_creative_inventory();
self.apply_cursor_grab(window, Some(game));
}
_ => {
game.inventory_open = true;
game.creative_inventory_open = false;
game.close_creative_inventory();
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion pomme-client/src/app/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct InputState {
selected_slot: u8,
left_click: ClickState,
right_click: ClickState,
middle_click: ClickState,
cursor_pos: (f32, f32),
cursor_moved: bool,
typed_chars: Vec<char>,
Expand Down Expand Up @@ -115,6 +116,7 @@ impl InputState {
selected_slot: 0,
left_click: ClickState::default(),
right_click: ClickState::default(),
middle_click: ClickState::default(),
cursor_pos: (0.0, 0.0),
cursor_moved: false,
typed_chars: Vec::new(),
Expand Down Expand Up @@ -156,7 +158,7 @@ impl InputState {
{
if self.action_just_pressed(Action::ToggleInventory) {
if game.creative_inventory_open {
game.creative_inventory_open = false;
game.close_creative_inventory();
should_apply_cursor_grab = true;
} else if !game.paused
&& !game.dead
Expand Down Expand Up @@ -386,6 +388,8 @@ impl InputState {
self.left_click.just_released = false;
self.right_click.just_pressed = false;
self.right_click.just_released = false;
self.middle_click.just_pressed = false;
self.middle_click.just_released = false;
self.cursor_moved = false;
}

Expand Down Expand Up @@ -622,6 +626,14 @@ impl InputState {
self.recent_actions.insert(Action::Use, false);
}
}
MouseButton::Middle => {
self.middle_click.held = was_pressed;
if was_pressed {
self.middle_click.just_pressed = true;
} else {
self.middle_click.just_released = true;
}
}
_ => (),
}
}
Expand All @@ -638,6 +650,14 @@ impl InputState {
self.right_click.held
}

pub fn middle_just_pressed(&self) -> bool {
self.middle_click.just_pressed
}

pub fn right_just_pressed(&self) -> bool {
self.right_click.just_pressed
}

pub fn on_cursor_moved(&mut self, x: f32, y: f32) {
self.cursor_pos = (x, y);
self.cursor_moved = true;
Expand Down
5 changes: 4 additions & 1 deletion pomme-client/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl ApplicationHandler for App {
} else if game.creative_inventory_open {
match code {
KeyCode::Escape => {
game.creative_inventory_open = false;
game.close_creative_inventory();
self.core
.input
.clear_action(crate::app::input::Action::OpenMenu);
Expand Down Expand Up @@ -560,6 +560,9 @@ impl ApplicationHandler for App {
if let Some(p) = &mut core.presence {
p.playing_multiplayer(&core.version);
}
// In-game screens use the plain arrow like vanilla, not
// the pointer the branded menu may have left set.
gfx.window.set_cursor(winit::window::CursorIcon::Default);
core.apply_cursor_grab(&gfx.window, Some(&mut game));

AppPhase::InGame {
Expand Down
46 changes: 32 additions & 14 deletions pomme-client/src/app/phases/in_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ impl GameState {
self.inventory_open || self.creative_inventory_open
}

pub fn close_creative_inventory(&mut self) {
self.creative_inventory_open = false;
self.creative_state.reset_interaction();
}

/// No menu (pause, inventory, chat) is capturing input.
pub fn input_live(&self) -> bool {
!self.paused
Expand Down Expand Up @@ -1121,42 +1126,55 @@ pub fn update_game(
if game.creative_inventory_open {
let cursor = core.input.cursor_pos();
let clicked = core.input.left_just_pressed();
let middle_clicked = core.input.middle_just_pressed();
let right_clicked = core.input.right_just_pressed();
let scroll_delta = core.input.consume_menu_scroll();
let typed = core.input.drain_typed_chars();
let backspace = core.input.backspace_pressed();
let selected_hotbar = core.input.selected_slot();
let action = crate::ui::creative_inventory::build_creative_inventory(
&mut elements,
&mut game.creative_state,
sw,
sh,
cursor,
clicked,
middle_clicked,
right_clicked,
scroll_delta,
&typed,
backspace,
&game.player.inventory,
selected_hotbar,
gs,
game.advanced_item_tooltips,
core.input.left_held(),
core.input.right_held(),
&|t, s| gfx.renderer.menu_text_width(t, s),
);
use azalea_protocol::packets::game::s_set_creative_mode_slot::ServerboundSetCreativeModeSlot;
let mut set_creative_slot = |slot_num: u16, item: azalea_inventory::ItemStack| {
if game.player.game_mode == 1 {
connection
.packet_tx
.send(ServerboundGamePacket::SetCreativeModeSlot(
ServerboundSetCreativeModeSlot {
slot_num,
item_stack: item.clone(),
},
));
// Optimistic local update; the server echoes via ContainerSetSlot.
game.player.inventory.set_slot(slot_num as usize, item);
}
};
match action {
crate::ui::creative_inventory::CreativeAction::Close => {
close_inventory = true;
}
crate::ui::creative_inventory::CreativeAction::Place(item, slot_num) => {
use azalea_protocol::packets::game::s_set_creative_mode_slot::ServerboundSetCreativeModeSlot;
if game.player.game_mode == 1 {
connection
.packet_tx
.send(ServerboundGamePacket::SetCreativeModeSlot(
ServerboundSetCreativeModeSlot {
slot_num,
item_stack: item,
},
));
crate::ui::creative_inventory::CreativeAction::SetSlot(slot_num, item) => {
set_creative_slot(slot_num, item);
}
crate::ui::creative_inventory::CreativeAction::SetSlots(items) => {
for (slot_num, item) in items {
set_creative_slot(slot_num, item);
}
}
crate::ui::creative_inventory::CreativeAction::None => {}
Expand Down Expand Up @@ -1386,7 +1404,7 @@ pub fn update_game(

if close_inventory {
game.inventory_open = false;
game.creative_inventory_open = false;
game.close_creative_inventory();
core.apply_cursor_grab(&gfx.window, Some(game));
}

Expand Down
38 changes: 24 additions & 14 deletions pomme-client/src/ui/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azalea_inventory::ItemStack;
use azalea_inventory::{ItemStack, ItemStackData};

use crate::benchmark::UploadStatus;
use crate::player::inventory::item_resource_name;
Expand Down Expand Up @@ -243,26 +243,36 @@ pub fn push_slot(
});
}
}
ItemStack::Present(data) => {
elements.push(MenuElement::ItemIcon {
x,
y,
w: size,
h: size,
item_name: item_resource_name(data.kind),
tint: WHITE,
});
if data.count > 1 {
push_item_count(elements, x, y, size, scale, data.count);
}
}
ItemStack::Present(data) => push_item_icon(elements, x, y, size, scale, data),
}
if hovered {
elements.push(highlight(SpriteId::SlotHighlightFront));
}
hovered
}

/// Draws an item icon (and its stack count when > 1) at the given position.
pub fn push_item_icon(
elements: &mut Vec<MenuElement>,
x: f32,
y: f32,
size: f32,
scale: f32,
data: &ItemStackData,
) {
elements.push(MenuElement::ItemIcon {
x,
y,
w: size,
h: size,
item_name: item_resource_name(data.kind),
tint: WHITE,
});
if data.count > 1 {
push_item_count(elements, x, y, size, scale, data.count);
}
}

#[allow(clippy::too_many_arguments)]
pub fn push_button(
elements: &mut Vec<MenuElement>,
Expand Down
Loading
Loading