ID:1913650
 
Code:
mob
var
tmp
last_position
inventory_open //helps with last position if you just re-open inventory when it's already open.
inventory_list = new/list()

mob/verb/CloseInventory()
last_position = winget(src, "Inventory", "pos")
inventory_open = 0
winshow(src,"Inventory",0)

mob/verb/Inventory()
if(inventory_open)
last_position = winget(src, "Inventory", "pos")

src.client.screen -= inventory_list
inventory_list = new/list()

inventory_open = 1
winshow(src,"Inventory",1)

var/Position
if(last_position)
Position = last_position
else
Position = winget(src, "default", "pos") // Get the position of the "default" window and assign it to a var called "Position"
winset(src,"Inventory","pos='[Position]'") // Set the position of the "Inventory" window to the same position as our main window.

for(var/Column = 1 to 10) for(var/Row = 1 to 8) //Create a grid composed of 5 columns and 5 rows.
var/obj/Grid/G = new
G.screen_loc = "Inv:[Row],[Column]"
src.client.screen += G
inventory_list += G

for(var/obj/I in src.contents)
inventory_list += I
src.AddItems(I) //Generate the items on slots.

mob/proc/AddItems(obj/I)
for(var/obj/Grid/G in src.client.screen)
if(G.used==1) continue
if(!I.screen_loc) //only set if it doesn't have a screen location.
//if picking up a new object, you'll want to set it to null
I.screen_loc = G.screen_loc
src.client.screen+=I
G.used=1
return

obj/Grid
parent_type = /obj
icon = 'QuickMenu.dmi'
icon_state="slot"
obj/var/used=0

obj
MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...

if(!(src in usr.contents))
//T.used=1
return
var/icon/I = new(src.icon,src.icon_state)//this is so the cursor icon transforms into the item itself...cool little effect.
mouse_drag_pointer = I


MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params) //When we drop it...
if(!(src in usr.contents)) return


if(over_control =="Inventory.Inv") //If its inside the inventory window.
var/obj/Grid/G = over_object
var/icon/I = new(src.icon,src.icon_state)//this is so the cursor icon transforms into the item itself...cool little effect.
mouse_drag_pointer = I
if(!G)
src.screen_loc=src.screen_loc
return
if(G.used==1)
G.used=1
src.screen_loc=src.screen_loc
return
src.ClearSlot(G)
src.screen_loc=G.screen_loc
G.used=1
if(over_control == "default.map1")
src.screen_loc = null
src.loc = usr.loc
if(!(src in usr.contents)) return

obj
proc
ClearSlot(obj)
for(var/obj/Grid/Z)
Z.used=0
usr<<"test"


Problem description: So I'm using a snippet from an inventory library, editing it up a bit so that the user can drag and drop items around in the inventory and it saves the location for the next time you open it. Currently there are two issues I'm having. 1. If the item is dragged in between two points on the grid it'll still move to the occupied slot even if it is already occupied. 2. The add items proc seems to continue to fill the last available slot even if the previous slots have become vacant.

If any extra details are needed let me know as I realize it is a little difficult for me to explain exactly what is happening.

As an aside, the ClearSlot() proc was made to make things semi-functional and to help troubleshoot what was going on.