mirror of
https://github.com/xtreme8000/CavEX.git
synced 2025-01-22 09:11:55 -05:00
Inventory: drop picked item on close
This commit is contained in:
parent
c85dc289fc
commit
5f4db4fb41
5 changed files with 40 additions and 4 deletions
|
@ -104,7 +104,7 @@ static void screen_inventory_update(struct screen* s, float dt) {
|
|||
struct inventory* inv
|
||||
= windowc_get_latest(gstate.windows[WINDOWC_INVENTORY]);
|
||||
|
||||
if(input_pressed(IB_INVENTORY) && !inventory_get_picked_item(inv, NULL)) {
|
||||
if(input_pressed(IB_INVENTORY)) {
|
||||
svin_rpc_send(&(struct server_rpc) {
|
||||
.type = SRPC_WINDOW_CLOSE,
|
||||
.payload.window_close.window = WINDOWC_INVENTORY,
|
||||
|
@ -289,8 +289,7 @@ static void screen_inventory_render2D(struct screen* s, int width, int height) {
|
|||
+= gutil_control_icon(icon_offset, IB_GUI_CLICK_ALT, "Split stack");
|
||||
}
|
||||
|
||||
if(!inventory_get_picked_item(inv, NULL))
|
||||
icon_offset += gutil_control_icon(icon_offset, IB_INVENTORY, "Leave");
|
||||
icon_offset += gutil_control_icon(icon_offset, IB_INVENTORY, "Leave");
|
||||
|
||||
struct item_data item;
|
||||
if(inventory_get_picked_item(inv, &item)) {
|
||||
|
|
|
@ -184,6 +184,18 @@ bool inventory_get_slot(struct inventory* inv, size_t slot,
|
|||
return inv->items[slot].id > 0;
|
||||
}
|
||||
|
||||
void inventory_clear_picked_item(struct inventory* inv) {
|
||||
assert(inv);
|
||||
inv->picked_item.id = 0;
|
||||
inv->picked_item.durability = 0;
|
||||
inv->picked_item.count = 0;
|
||||
}
|
||||
|
||||
void inventory_set_picked_item(struct inventory* inv, struct item_data item) {
|
||||
assert(inv);
|
||||
inv->picked_item = item;
|
||||
}
|
||||
|
||||
bool inventory_get_picked_item(struct inventory* inv, struct item_data* item) {
|
||||
assert(inv);
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#define INVENTORY_SLOT_MAIN 9
|
||||
#define INVENTORY_SLOT_HOTBAR 36
|
||||
|
||||
#define SPECIAL_SLOT_PICKED_ITEM 255
|
||||
|
||||
struct inventory {
|
||||
struct item_data picked_item;
|
||||
struct item_data* items;
|
||||
|
@ -70,6 +72,8 @@ void inventory_set_slot(struct inventory* inv, size_t slot,
|
|||
void inventory_clear_slot(struct inventory* inv, size_t slot);
|
||||
bool inventory_get_slot(struct inventory* inv, size_t slot,
|
||||
struct item_data* item);
|
||||
void inventory_clear_picked_item(struct inventory* inv);
|
||||
void inventory_set_picked_item(struct inventory* inv, struct item_data item);
|
||||
bool inventory_get_picked_item(struct inventory* inv, struct item_data* item);
|
||||
bool inventory_action(struct inventory* inv, size_t slot, bool right);
|
||||
|
||||
|
|
|
@ -137,7 +137,12 @@ void windowc_slot_change(struct window_container* wc, size_t slot,
|
|||
ilist_inventory_it(it, wc->invs);
|
||||
|
||||
struct inventory* prev = ilist_inventory_ref(it);
|
||||
inventory_set_slot(prev, slot, item);
|
||||
|
||||
if(slot == SPECIAL_SLOT_PICKED_ITEM) {
|
||||
inventory_set_picked_item(prev, item);
|
||||
} else {
|
||||
inventory_set_slot(prev, slot, item);
|
||||
}
|
||||
|
||||
ilist_inventory_next(it);
|
||||
|
||||
|
|
|
@ -134,6 +134,22 @@ static void server_local_process(struct server_rpc* call, void* user) {
|
|||
= s->player.inventory.items[k],
|
||||
});
|
||||
}
|
||||
|
||||
struct item_data picked_item;
|
||||
if(inventory_get_picked_item(&s->player.inventory,
|
||||
&picked_item)) {
|
||||
inventory_clear_picked_item(&s->player.inventory);
|
||||
spawn_item((vec3) {s->player.x, s->player.y, s->player.z},
|
||||
&picked_item, true, s);
|
||||
|
||||
clin_rpc_send(&(struct client_rpc) {
|
||||
.type = CRPC_INVENTORY_SLOT,
|
||||
.payload.inventory_slot.window = WINDOWC_INVENTORY,
|
||||
.payload.inventory_slot.slot = NETWORK_SLOT_PICKED_ITEM,
|
||||
.payload.inventory_slot.item
|
||||
= s->player.inventory.picked_item,
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SRPC_BLOCK_DIG:
|
||||
|
|
Loading…
Reference in a new issue