On-screen inventory & Interface commands

by Kidpaddle45
A basic on-screen inventory library that also teaches some useful interface commands.For Beginners.
ID:1459328
 
Preview of the final result:



In this library you will be learning about the following:

-How to create an on-screen inventory using a 2nd map element.
-How to use interface windows
-How to retrieve information from interface windows
-Basic drag and drop commands.



(FOR BEGINNERS)
Current version: 1.0

Do you like my creations? Donate, it motivates me! =D










this is great but needs to make it where it saves the position of the items u move around and a way to drop items on ground
I was wondering how would you go about adding the items icon to the description?

Drop system :

    verb/Drop()
if(src in usr.contents)
var/obj/Items/n = src
var/obj/Items/C= n.type
new C(usr.loc)
del(n)


Nd i would suggest
for(var/Grid/G in src.client.screen)
del(G)

over
src.client.screen = null

because you delet everything in your screen.
In response to Phat T
Phat T wrote:
Nd i would suggest
> for(var/Grid/G in src.client.screen)
> del(G)

over
src.client.screen = null

because you delet everything in your screen.

That breaks it o,o
yea src.client.screen = null is not a good way to go about thism I really need a work around.
Made a few modifications to add some extra features. Like last position of the inventory window, drag and drop from inventory window and a fix for src.client.screen = null. (the last one is thanks to kaiochao)

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() //list to add grid and inventory items to wipe from the screen

mob/verb/CloseInventory()
last_position = winget(src, "Inventory", "pos")
inventory_open = 0
winshow(src,"Inventory",0) //Hide the inventory window!

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) //Show the inventory window!

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 5) for(var/Row = 1 to 5) //Create a grid composed of 5 columns and 5 rows.
var/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.


obj
MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...
if(!(src in usr.contents)) return // If its not in our inventory...just cancel ...
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 // now lets set the mouse cursor to that.

MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params) //When we drop it...
if(over_control =="inventory.Inv") //If its inside the inventory window.
var/obj/O = over_object
src.screen_loc = O.screen_loc //Move the object on the new slot.

if(over_control == "default.map1")
src.screen_loc = null
src.loc = usr.loc //over_location if you want it to be where the mouse is
In response to Rickoshay
Rickoshay wrote:
Made a few modifications to add some extra features. Like last position of the inventory window, drag and drop from inventory window and a fix for src.client.screen = null. (the last one is thanks to kaiochao)

> 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() //list to add grid and inventory items to wipe from the screen
>
> mob/verb/CloseInventory()
> last_position = winget(src, "Inventory", "pos")
> inventory_open = 0
> winshow(src,"Inventory",0) //Hide the inventory window!
>
> 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) //Show the inventory window!
>
> 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 5) for(var/Row = 1 to 5) //Create a grid composed of 5 columns and 5 rows.
> var/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.
>
>
> obj
> MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...
> if(!(src in usr.contents)) return // If its not in our inventory...just cancel ...
> 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 // now lets set the mouse cursor to that.
>
> MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params) //When we drop it...
> if(over_control =="inventory.Inv") //If its inside the inventory window.
> var/obj/O = over_object
> src.screen_loc = O.screen_loc //Move the object on the new slot.
>
> if(over_control == "default.map1")
> src.screen_loc = null
> src.loc = usr.loc //over_location if you want it to be where the mouse is
>


Wow never notice the comments on my libs. Thank you! Next time I update this demo I'll be sure to add these fixes.
Also add this to MouseDrop(), if it's not there you can drag items on the map because of the default.map1 control.

        if(istype(src, /Grid/))
return
if(!(src in usr.contents)) return
Also a fix I found on the forums earlier. It basically saves the last place you moved your item to, in the inventory window.

mob/proc/AddItems(obj/I)
for(var/Grid/G in src.client.screen)
if(G.used) 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
Picking up/dropping an item should force the output to update. Also I think the item descriptions should be under mouse entered. Also, wouldn't it be easier to just output all the items into a grid?
-Whenever you pick up more than 25 itens, all the new itens collected after then will just dissapear

-You can drop the blue tiles

-If you drag an obj on the map it will teleport to the bottom of the map as if you dropped it from your inv

I'm just listing some bugs, thanks for all the work Kid and Rick