mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added better item manipulation
This commit is contained in:
parent
fc49293874
commit
b3cae2f3dd
@ -169,6 +169,10 @@ impl Client {
|
||||
.send_message(ClientMsg::SwapInventorySlots(a, b))
|
||||
}
|
||||
|
||||
pub fn drop_inventory_slot(&mut self, x: usize) {
|
||||
self.postbox.send_message(ClientMsg::DropInventorySlot(x))
|
||||
}
|
||||
|
||||
pub fn view_distance(&self) -> Option<u32> {
|
||||
self.view_distance
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ pub enum ClientMsg {
|
||||
ori: comp::Ori,
|
||||
},
|
||||
SwapInventorySlots(usize, usize),
|
||||
DropInventorySlot(usize),
|
||||
TerrainChunkRequest {
|
||||
key: Vec2<i32>,
|
||||
},
|
||||
|
@ -498,6 +498,14 @@ impl Server {
|
||||
.map(|inv| inv.swap_slots(a, b));
|
||||
state.write_component(entity, comp::InventoryUpdate);
|
||||
}
|
||||
ClientMsg::DropInventorySlot(x) => {
|
||||
state
|
||||
.ecs()
|
||||
.write_storage::<comp::Inventory>()
|
||||
.get_mut(entity)
|
||||
.map(|inv| inv.remove(x)); // TODO: Spawn an item drop entity
|
||||
state.write_component(entity, comp::InventoryUpdate);
|
||||
}
|
||||
ClientMsg::Character { name, body } => match client.client_state {
|
||||
// Become Registered first.
|
||||
ClientState::Connected => {
|
||||
|
@ -46,6 +46,7 @@ impl<'a> Bag<'a> {
|
||||
|
||||
pub struct State {
|
||||
ids: Ids,
|
||||
selected_slot: Option<usize>,
|
||||
}
|
||||
|
||||
const BAG_SCALE: f64 = 4.0;
|
||||
@ -63,6 +64,7 @@ impl<'a> Widget for Bag<'a> {
|
||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||
State {
|
||||
ids: Ids::new(id_gen),
|
||||
selected_slot: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,6 +130,8 @@ impl<'a> Widget for Bag<'a> {
|
||||
let x = i % 5;
|
||||
let y = i / 5;
|
||||
|
||||
let is_selected = Some(i) == state.selected_slot;
|
||||
|
||||
// Slot
|
||||
if Button::image(self.imgs.inv_slot)
|
||||
.top_left_with_margins_on(
|
||||
@ -137,11 +141,28 @@ impl<'a> Widget for Bag<'a> {
|
||||
) // conrod uses a (y,x) format for placing...
|
||||
.parent(state.ids.inv_alignment) // Avoids the background overlapping available slots
|
||||
.w_h(40.0, 40.0)
|
||||
.image_color(if is_selected {
|
||||
color::WHITE
|
||||
} else {
|
||||
color::DARK_YELLOW
|
||||
})
|
||||
.floating(true)
|
||||
.set(state.ids.inv_slots[i], ui)
|
||||
.was_clicked()
|
||||
{
|
||||
event = Some(Event::HudEvent(HudEvent::SwapInventorySlots(0, i)));
|
||||
let selected_slot = match state.selected_slot {
|
||||
Some(a) => {
|
||||
if a == i {
|
||||
event = Some(Event::HudEvent(HudEvent::DropInventorySlot(i)));
|
||||
} else {
|
||||
event = Some(Event::HudEvent(HudEvent::SwapInventorySlots(a, i)));
|
||||
}
|
||||
None
|
||||
}
|
||||
None if item.is_some() => Some(i),
|
||||
None => None,
|
||||
};
|
||||
state.update(|s| s.selected_slot = selected_slot);
|
||||
}
|
||||
|
||||
// Item
|
||||
|
@ -142,6 +142,7 @@ pub enum Event {
|
||||
UiScale(ScaleChange),
|
||||
CharacterSelection,
|
||||
SwapInventorySlots(usize, usize),
|
||||
DropInventorySlot(usize),
|
||||
Logout,
|
||||
Quit,
|
||||
}
|
||||
|
@ -321,6 +321,9 @@ impl PlayState for SessionState {
|
||||
HudEvent::SwapInventorySlots(a, b) => {
|
||||
self.client.borrow_mut().swap_inventory_slots(a, b)
|
||||
}
|
||||
HudEvent::DropInventorySlot(x) => {
|
||||
self.client.borrow_mut().drop_inventory_slot(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user