On-screen inventory & Interface commands

by Kidpaddle45
A basic on-screen inventory library that also teaches some useful interface commands.For Beginners. [More]
To download this demo for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Kidpaddle45.InventoryLib##version=0

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Kidpaddle45.InventoryLib##version=0

749 downloads
Latest Version
Date added: Dec 30 2013
Last updated: Dec 31 2013
10 fans
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










Comments

Nezeha: (Jul 22 2017, 7:00 pm)
-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
Mav472: (Nov 18 2016, 7:36 am)
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?
Rickoshay: (Jun 5 2015, 5:29 pm)
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
Rickoshay: (Jun 4 2015, 10:15 pm)
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
Kidpaddle45: (Jun 4 2015, 10:12 pm)
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.