Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description
- if(keyboard_check_pressed((ord("I")))) show_inventory = !show_inventory; // Toggle Inventory
- if((show_inventory) and keyboard_check_pressed(vk_escape)) show_inventory = false; // Close Inventory with Escape
- if(!show_inventory) exit; // Don't run anything under this if the inventory is shut
- #region Mouse Slot Selection
- mousex = device_mouse_x_to_gui(0);
- mousey = device_mouse_y_to_gui(0);
- var cell_xbuff = (cell_size+x_buffer)*scale;
- var cell_ybuff = (cell_size+y_buffer)*scale;
- var i_mousex = mousex - slots_x;
- var i_mousey = mousey - slots_y;
- var nx = i_mousex div cell_xbuff;
- var ny = i_mousey div cell_ybuff;
- //Only update slots if mouse is inside inventory
- if ((nx >= 0 and nx < inv_slots_width) and (ny >= 0 and ny < inv_slots_height)) {
- var sx = i_mousex - (nx*cell_xbuff);
- var sy = i_mousey - (ny*cell_ybuff);
- if((sx < cell_size*scale) and (sy < cell_size*scale)) {
- m_slotx = nx;
- m_sloty = ny;
- // Find what slot is currently selected
- selected_slot = min(inv_slots-1 ,m_slotx + (m_sloty*inv_slots_width));
- }
- } else {
- selected_slot = 0;
- }
- #endregion
- #region Item Selection & Movement
- var inv_grid = ds_inventory;
- var ss_item = inv_grid[# 0, selected_slot];
- if(pickup_slot != -1) {
- if(mouse_check_button_pressed(mb_left)) {
- if(ss_item == item.none) { // If placing the item in an empty slot
- inv_grid[# 0, selected_slot] = inv_grid[# 0, pickup_slot];
- inv_grid[# 1, selected_slot] = inv_grid[# 1, pickup_slot];
- inv_grid[# 0, pickup_slot] = item.none;
- inv_grid[# 1, pickup_slot] = 0;
- pickup_slot = -1;
- } else if (ss_item == inv_grid[# 0, pickup_slot]) { // If placing the item in a slot with the same item
- if(selected_slot != pickup_slot) {
- inv_grid[# 1, selected_slot] += inv_grid[# 1, pickup_slot];
- inv_grid[# 0, pickup_slot] = item.none;
- inv_grid[# 1, pickup_slot] = 0;
- pickup_slot = -1;
- } else { // If the slot is the same as the one picked up from
- pickup_slot = -1;
- }
- } else { // If placing the item on a slot with a different item
- var ss_item_num = inv_grid[# 1, selected_slot];
- inv_grid[# 0, selected_slot] = inv_grid[# 0, pickup_slot];
- inv_grid[# 1, selected_slot] = inv_grid[# 1, pickup_slot];
- inv_grid[# 0, pickup_slot] = ss_item;
- inv_grid[# 1, pickup_slot] = ss_item_num;
- }
- }
- } else if(ss_item != inv_grid[# 0, 0]){
- //Drop Item Into World
- if(keyboard_check_pressed(ord("Q"))) {
- inv_grid[# 1, selected_slot] -=1; //Remove one item from stack
- //Check if it was the last item
- if(inv_grid[# 1, selected_slot] == 0) {
- inv_grid[# 0, selected_slot] = item.none;
- }
- //Spawn the Item
- var inst = instance_create_layer(e_player.x, e_player.y, "Instances", e_item);
- with(inst) {
- item_num = ss_item;
- x_frame = item_num mod (s_width/cell_size);
- y_frame = item_num div (s_width/cell_size);
- }
- show_debug_message("An item was dropped!")
- }
- //Pickup Item From Slot
- if(mouse_check_button_pressed(mb_left)) {
- pickup_slot = selected_slot;
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement