mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Restore slot interaction functionality
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
img_ids::{Imgs, ImgsRot},
|
img_ids::{Imgs, ImgsRot},
|
||||||
item_imgs::{ItemImgs, ItemKey},
|
item_imgs::ItemImgs,
|
||||||
slot_kinds::{HudSlotManager, InventorySlot},
|
slot_kinds::{HudSlotManager, InventorySlot},
|
||||||
Event as HudEvent, Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
|
Event as HudEvent, Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
|
||||||
XP_COLOR,
|
XP_COLOR,
|
||||||
@ -15,7 +15,7 @@ use crate::{
|
|||||||
use client::Client;
|
use client::Client;
|
||||||
use common::comp::Stats;
|
use common::comp::Stats;
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color, image,
|
color,
|
||||||
widget::{self, Button, Image, Rectangle, Text},
|
widget::{self, Button, Image, Rectangle, Text},
|
||||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
@ -32,10 +32,7 @@ widget_ids! {
|
|||||||
inv_slots_0,
|
inv_slots_0,
|
||||||
map_title,
|
map_title,
|
||||||
inv_slots[],
|
inv_slots[],
|
||||||
items[],
|
//tooltip[],
|
||||||
amounts[],
|
|
||||||
amounts_bg[],
|
|
||||||
tooltip[],
|
|
||||||
bg,
|
bg,
|
||||||
bg_frame,
|
bg_frame,
|
||||||
char_ico,
|
char_ico,
|
||||||
@ -106,6 +103,7 @@ pub struct Bag<'a> {
|
|||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
rot_imgs: &'a ImgsRot,
|
rot_imgs: &'a ImgsRot,
|
||||||
tooltip_manager: &'a mut TooltipManager,
|
tooltip_manager: &'a mut TooltipManager,
|
||||||
|
slot_manager: &'a mut HudSlotManager,
|
||||||
_pulse: f32,
|
_pulse: f32,
|
||||||
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
||||||
stats: &'a Stats,
|
stats: &'a Stats,
|
||||||
@ -120,6 +118,7 @@ impl<'a> Bag<'a> {
|
|||||||
fonts: &'a ConrodVoxygenFonts,
|
fonts: &'a ConrodVoxygenFonts,
|
||||||
rot_imgs: &'a ImgsRot,
|
rot_imgs: &'a ImgsRot,
|
||||||
tooltip_manager: &'a mut TooltipManager,
|
tooltip_manager: &'a mut TooltipManager,
|
||||||
|
slot_manager: &'a mut HudSlotManager,
|
||||||
pulse: f32,
|
pulse: f32,
|
||||||
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
||||||
stats: &'a Stats,
|
stats: &'a Stats,
|
||||||
@ -133,6 +132,7 @@ impl<'a> Bag<'a> {
|
|||||||
common: widget::CommonBuilder::default(),
|
common: widget::CommonBuilder::default(),
|
||||||
rot_imgs,
|
rot_imgs,
|
||||||
tooltip_manager,
|
tooltip_manager,
|
||||||
|
slot_manager,
|
||||||
_pulse: pulse,
|
_pulse: pulse,
|
||||||
localized_strings,
|
localized_strings,
|
||||||
stats,
|
stats,
|
||||||
@ -143,7 +143,6 @@ impl<'a> Bag<'a> {
|
|||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
img_id_cache: Vec<Option<(ItemKey, image::Id)>>,
|
|
||||||
selected_slot: Option<usize>,
|
selected_slot: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +160,6 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
State {
|
State {
|
||||||
ids: Ids::new(id_gen),
|
ids: Ids::new(id_gen),
|
||||||
img_id_cache: Vec::new(),
|
|
||||||
selected_slot: None,
|
selected_slot: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -607,8 +605,6 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Display inventory contents
|
// Display inventory contents
|
||||||
// TODO: add slot manager
|
|
||||||
let slot_manager: Option<&mut HudSlotManager> = None;
|
|
||||||
let mut slot_maker = SlotMaker {
|
let mut slot_maker = SlotMaker {
|
||||||
background: self.imgs.inv_slot,
|
background: self.imgs.inv_slot,
|
||||||
selected_background: self.imgs.inv_slot_sel,
|
selected_background: self.imgs.inv_slot_sel,
|
||||||
@ -621,7 +617,7 @@ impl<'a> Widget for Bag<'a> {
|
|||||||
amount_text_color: TEXT_COLOR,
|
amount_text_color: TEXT_COLOR,
|
||||||
content_source: inventory,
|
content_source: inventory,
|
||||||
image_source: self.item_imgs,
|
image_source: self.item_imgs,
|
||||||
slot_manager,
|
slot_manager: Some(self.slot_manager),
|
||||||
};
|
};
|
||||||
for (i, item) in inventory.slots().iter().enumerate() {
|
for (i, item) in inventory.slots().iter().enumerate() {
|
||||||
let x = i % 9;
|
let x = i % 9;
|
||||||
|
@ -36,7 +36,7 @@ use crate::{
|
|||||||
i18n::{i18n_asset_key, LanguageMetadata, VoxygenLocalization},
|
i18n::{i18n_asset_key, LanguageMetadata, VoxygenLocalization},
|
||||||
render::{AaMode, CloudMode, Consts, FluidMode, Globals, Renderer},
|
render::{AaMode, CloudMode, Consts, FluidMode, Globals, Renderer},
|
||||||
scene::camera::{self, Camera},
|
scene::camera::{self, Camera},
|
||||||
ui::{fonts::ConrodVoxygenFonts, Graphic, Ingameable, ScaleMode, Ui},
|
ui::{fonts::ConrodVoxygenFonts, slot, Graphic, Ingameable, ScaleMode, Ui},
|
||||||
window::{Event as WinEvent, GameInput},
|
window::{Event as WinEvent, GameInput},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
@ -234,6 +234,8 @@ pub enum Event {
|
|||||||
CharacterSelection,
|
CharacterSelection,
|
||||||
UseInventorySlot(usize),
|
UseInventorySlot(usize),
|
||||||
SwapInventorySlots(usize, usize),
|
SwapInventorySlots(usize, usize),
|
||||||
|
SwapInventoryArmor(usize, slot_kinds::ArmorSlot),
|
||||||
|
SwapArmorSlots(slot_kinds::ArmorSlot, slot_kinds::ArmorSlot),
|
||||||
DropInventorySlot(usize),
|
DropInventorySlot(usize),
|
||||||
Logout,
|
Logout,
|
||||||
Quit,
|
Quit,
|
||||||
@ -441,6 +443,7 @@ pub struct Hud {
|
|||||||
pulse: f32,
|
pulse: f32,
|
||||||
velocity: f32,
|
velocity: f32,
|
||||||
voxygen_i18n: std::sync::Arc<VoxygenLocalization>,
|
voxygen_i18n: std::sync::Arc<VoxygenLocalization>,
|
||||||
|
slot_manager: slot_kinds::HudSlotManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hud {
|
impl Hud {
|
||||||
@ -509,6 +512,7 @@ impl Hud {
|
|||||||
pulse: 0.0,
|
pulse: 0.0,
|
||||||
velocity: 0.0,
|
velocity: 0.0,
|
||||||
voxygen_i18n,
|
voxygen_i18n,
|
||||||
|
slot_manager: slot_kinds::HudSlotManager::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1646,6 +1650,7 @@ impl Hud {
|
|||||||
&self.fonts,
|
&self.fonts,
|
||||||
&self.rot_imgs,
|
&self.rot_imgs,
|
||||||
tooltip_manager,
|
tooltip_manager,
|
||||||
|
&mut self.slot_manager,
|
||||||
self.pulse,
|
self.pulse,
|
||||||
&self.voxygen_i18n,
|
&self.voxygen_i18n,
|
||||||
&player_stats,
|
&player_stats,
|
||||||
@ -1952,6 +1957,38 @@ impl Hud {
|
|||||||
.set(self.ids.free_look_txt, ui_widgets);
|
.set(self.ids.free_look_txt, ui_widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maintain slot manager
|
||||||
|
for event in self.slot_manager.maintain(ui_widgets) {
|
||||||
|
use slot_kinds::HudSlotKinds;
|
||||||
|
match event {
|
||||||
|
slot::Event::Dragged(
|
||||||
|
HudSlotKinds::Inventory(from),
|
||||||
|
HudSlotKinds::Inventory(to),
|
||||||
|
) => {
|
||||||
|
// Swap between inventory slots
|
||||||
|
events.push(Event::SwapInventorySlots(from.0, to.0));
|
||||||
|
},
|
||||||
|
slot::Event::Dragged(HudSlotKinds::Armor(from), HudSlotKinds::Armor(to)) => {
|
||||||
|
// Swap between two armor slots
|
||||||
|
events.push(Event::SwapArmorSlots(from, to));
|
||||||
|
},
|
||||||
|
slot::Event::Dragged(HudSlotKinds::Inventory(inv), HudSlotKinds::Armor(arm))
|
||||||
|
| slot::Event::Dragged(HudSlotKinds::Armor(arm), HudSlotKinds::Inventory(inv)) => {
|
||||||
|
// Swap between inventory and armor slot
|
||||||
|
events.push(Event::SwapInventoryArmor(inv.0, arm));
|
||||||
|
},
|
||||||
|
slot::Event::Dropped(HudSlotKinds::Inventory(from)) => {
|
||||||
|
// Drop item from inventory
|
||||||
|
events.push(Event::DropInventorySlot(from.0));
|
||||||
|
},
|
||||||
|
slot::Event::Used(HudSlotKinds::Inventory(inv)) => {
|
||||||
|
// Item in inventory used (selected and then clicked again)
|
||||||
|
events.push(Event::UseInventorySlot(inv.0));
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,6 +647,15 @@ impl PlayState for SessionState {
|
|||||||
HudEvent::SwapInventorySlots(a, b) => {
|
HudEvent::SwapInventorySlots(a, b) => {
|
||||||
self.client.borrow_mut().swap_inventory_slots(a, b)
|
self.client.borrow_mut().swap_inventory_slots(a, b)
|
||||||
},
|
},
|
||||||
|
HudEvent::SwapInventoryArmor(inv_slot, armor_slot) => {
|
||||||
|
// Swapping between inventory and armor slot
|
||||||
|
// TODO: don't do this
|
||||||
|
self.client.borrow_mut().use_inventory_slot(inv_slot)
|
||||||
|
},
|
||||||
|
HudEvent::SwapArmorSlots(from, to) => {
|
||||||
|
// Only works with rings currently
|
||||||
|
// TODO: implement
|
||||||
|
},
|
||||||
HudEvent::DropInventorySlot(x) => {
|
HudEvent::DropInventorySlot(x) => {
|
||||||
self.client.borrow_mut().drop_inventory_slot(x)
|
self.client.borrow_mut().drop_inventory_slot(x)
|
||||||
},
|
},
|
||||||
|
@ -111,7 +111,7 @@ enum Interaction {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event<K> {
|
pub enum Event<K> {
|
||||||
// Dragged to another slot
|
// Dragged to another slot
|
||||||
Dragged(K, K),
|
Dragged(K, K),
|
||||||
// Dragged to open space
|
// Dragged to open space
|
||||||
@ -130,6 +130,25 @@ impl<K> SlotManager<K>
|
|||||||
where
|
where
|
||||||
K: SlotKinds,
|
K: SlotKinds,
|
||||||
{
|
{
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
state: ManagerState::Idle,
|
||||||
|
events: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn maintain(&mut self, ui: &conrod_core::Ui) -> Vec<Event<K>> {
|
||||||
|
// Detect drops by of selected item by clicking in empty space
|
||||||
|
if let ManagerState::Selected(_, slot) = self.state {
|
||||||
|
if ui.widget_input(ui.window).clicks().left().next().is_some() {
|
||||||
|
self.state = ManagerState::Idle;
|
||||||
|
self.events.push(Event::Dropped(slot))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mem::replace(&mut self.events, Vec::new())
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, widget: widget::Id, slot: K, ui: &conrod_core::Ui) -> Interaction {
|
fn update(&mut self, widget: widget::Id, slot: K, ui: &conrod_core::Ui) -> Interaction {
|
||||||
// If this is the selected/dragged widget make sure the slot value is up to date
|
// If this is the selected/dragged widget make sure the slot value is up to date
|
||||||
match &mut self.state {
|
match &mut self.state {
|
||||||
@ -377,15 +396,15 @@ where
|
|||||||
Image::new(content_image)
|
Image::new(content_image)
|
||||||
.x_y(x, y)
|
.x_y(x, y)
|
||||||
.wh(if let Interaction::Selected = interaction {
|
.wh(if let Interaction::Selected = interaction {
|
||||||
content_size
|
|
||||||
} else {
|
|
||||||
selected_content_size
|
selected_content_size
|
||||||
|
} else {
|
||||||
|
content_size
|
||||||
}
|
}
|
||||||
.map(|e| e as f64)
|
.map(|e| e as f64)
|
||||||
.into_array())
|
.into_array())
|
||||||
.parent(id)
|
.parent(id)
|
||||||
.graphics_for(id)
|
.graphics_for(id)
|
||||||
.set(state.ids.icon, ui);
|
.set(state.ids.content, ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw amount
|
// Draw amount
|
||||||
@ -393,11 +412,15 @@ where
|
|||||||
let amount = format!("{}", &amount);
|
let amount = format!("{}", &amount);
|
||||||
// Text shadow
|
// Text shadow
|
||||||
Text::new(&amount)
|
Text::new(&amount)
|
||||||
.parent(id)
|
|
||||||
.graphics_for(id)
|
|
||||||
.font_id(amount_font)
|
.font_id(amount_font)
|
||||||
.font_size(amount_font_size)
|
.font_size(amount_font_size)
|
||||||
.top_right_with_margins_on(id, amount_margins.x as f64, amount_margins.y as f64)
|
.top_right_with_margins_on(
|
||||||
|
state.ids.content,
|
||||||
|
amount_margins.x as f64,
|
||||||
|
amount_margins.y as f64,
|
||||||
|
)
|
||||||
|
.parent(id)
|
||||||
|
.graphics_for(id)
|
||||||
.color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
|
.color(Color::Rgba(0.0, 0.0, 0.0, 1.0))
|
||||||
.set(state.ids.amount_bg, ui);
|
.set(state.ids.amount_bg, ui);
|
||||||
Text::new(&amount)
|
Text::new(&amount)
|
||||||
|
Reference in New Issue
Block a user