Heres something I think your after. Its not finished and its based on phanlanx's inventory drag and drop system for dbp.
set window on
set display mode 800,600,32
sync on
RANDOMIZE TIMER()
REM IMAGES
load image "background.bmp", 6 ,1
load image "engine1a.bmp", 7 ,1
load image "engine1b.bmp", 8 ,1
load image "engine1c.bmp", 9 ,1
load image "selecticon.bmp",10,1
load image "selecticon1.bmp",11,1
REM inventory grid sizes
grid_x = 4
grid_y = 5
REM size of item icons
icon_size = 42
`Universal item database
Type UID
Type as String
Subtype as String
Class as String
Name as String
Image as Integer
Cost as Integer
Mass as Integer
Hp as Integer
Descript1 as String
Descript2 as String
Stackable as integer
stat1 as Integer
stat2 as Integer
stat3 as Integer
stat4 as Integer
stat5 as Integer
stat6 as Integer
stat7 as Integer
stat8 as Integer
stat9 as Integer
Endtype
Dim Items(3) as UID
Items(1).Type = "Weapon"
Items(1).Subtype = "Energy"
Items(1).Class = "Pulse"
Items(1).Name = "10 MW Laser"
Items(1).Image = 7
Items(1).Cost = 5000
Items(1).Mass = 5
Items(1).HP = 20
Items(1).Descript1 = "A low power"
Items(1).Descript2 = "laser pulse"
Items(1).Stackable = 1
Items(1).stat1 = 10 `.Damage
Items(1).stat2 = 20 `.RechargeRate
Items(1).stat3 = 10 `.PowerDrain
Items(1).stat4 = 100 `.Bulletspeed
Items(1).stat5 = 20 `.Bulletlife
Items(1).stat6 = 0
Items(1).stat7 = 0
Items(1).stat8 = 0
Items(1).stat9 = 0
Items(2).Type = "Engine"
Items(2).Subtype = "Sublight"
Items(2).Class = "Human"
Items(2).Name = "Ion Engine mk1"
Items(2).Image = 8
Items(2).Cost = 50000
Items(2).Mass = 50
Items(2).HP = 200
Items(2).Descript1 = "The most basic"
Items(2).Descript2 = "ion engine"
Items(2).Stackable = 1
Items(2).stat1 = 30 `.Thrust
Items(2).stat2 = 1 `.Accel
Items(2).stat3 = 10 `.PowerDrain
Items(2).stat4 = 2 `.Turnrate
Items(2).stat5 = 0
Items(2).stat6 = 0
Items(2).stat7 = 0
Items(2).stat8 = 0
Items(2).stat9 = 0
Items(3).Type = "Reactor"
Items(3).Subtype = "Power"
Items(3).Class = "Human"
Items(3).Name = "Ion Reactor mk1"
Items(3).Image = 9
Items(3).Cost = 50000
Items(3).Mass = 50
Items(3).HP = 400
Items(3).Descript1 = "The most basic"
Items(3).Descript2 = "ion Reactor"
Items(3).Stackable = 1
Items(3).stat1 = 300 `.Energy Storage
Items(3).stat2 = 1 `.RechargeRate
Items(3).stat3 = 0
Items(3).stat4 = 0
Items(3).stat5 = 0
Items(3).stat6 = 0
Items(3).stat7 = 0
Items(3).stat8 = 0
Items(3).stat9 = 0
type item
id as integer
sprt as integer
static as integer
gx as integer
gy as integer
endtype
REM Create inventory grid(area where items are kept)
dim grid_items(grid_x, grid_y)
REM keeps track of how many items are in 1 grid spot(can only be more
REM than 1 if item at the spot is stackable)
dim grid_count(grid_x, grid_y)
dim grid1_items(6, 4)
dim grid1_count(6, 4)
Cargo_item_total = 20
Store_item_total = 24
REM items in the grid
dim Cargo(Cargo_item_total) as item
dim Store(Store_item_total) as item
REM inventory grid location(top right-hand corner)
Cargo_x = 617
Cargo_y = 66
Store_x = 0
Store_y = 0
for t = 1 to Cargo_item_total
id = rnd(2)+1
Cargo(t).id = id
Cargo(t).sprt = 200 + t
Cargo(t).static = 1
if t => 17 and t <= 20 then t2 = 5
if t => 13 and t <= 16 then t2 = 4
if t => 9 and t <= 12 then t2 = 3
if t => 5 and t <= 8 then t2 = 2
if t => 1 and t <= 4 then t2 = 1
`t2 = round1(3 / 4)
t2a = t2 - 1
t2b = 4 * t2a
t1 = t - t2b
Cargo(t).gy = t2
Cargo(t).gx = t1
grid_items(Cargo(t).gx, Cargo(t).gy) = id
grid_count(Cargo(t).gx, Cargo(t).gy) = grid_count(Cargo(t).gx, Cargo(t).gy) + 1
next t
DO
cls
paste image 6, 0 , 0
gosub inv_mouse
`cargo
for CA = 1 to Cargo_item_total
REM only draw sprites which are static(not moving)
REM (sprite only moves if its been selected and being dragged with the mouse
if Cargo(CA).static = 1
offset_x = Cargo_x+1 + (Cargo(CA).gx-1)*icon_size
offset_y = Cargo_y+1 + (Cargo(CA).gy-1)*icon_size
sprite Cargo(CA).sprt, offset_x, offset_y, Items(Cargo(CA).id).Image
SET SPRITE PRIORITY Cargo(CA).sprt , 0
endif
next CA
for x = 1 to grid_x
for y = 1 to grid_y
if grid_count(x,y) > 1
text_over_sprite(2,(Cargo_x+x*42)-12,(Cargo_y+y*42)-40,str$(grid_count(x,y)))
endif
if grid_count(x,y) = 0
`Delete Sprite 1
endif
next y
next x
`store
for ST1 = 1 to Store_item_total
REM only draw sprites which are static(not moving)
REM (sprite only moves if its been selected and being dragged with the mouse
if Store(ST1).static = 1
offset_sx = Store_x+1 + (Store(ST1).gx-1)*icon_size
offset_sy = Store_y+1 + (Store(ST1).gy-1)*icon_size
sprite Store(ST1).sprt, offset_sx, offset_sy, Items(Store(ST1).id).Image
endif
next ST1
for sx = 1 to 6
for sy = 1 to 4
if grid1_count(sx,sy) > 1
text_over_sprite(1,(Store_x+sx*42)-12,(Store_y+sy*42)-40,str$(grid1_count(sx,sy)))
endif
if grid1_count(sx,sy) = 0
`Delete Sprite 1
endif
next sy
next sx
gosub Dockmenu
sync
LOOP
Dockmenu:
if button(65,250,"Ship Yard ") > 0 then Menu = 1
if button(65,280,"Weapons ") > 0 then Menu = 2
if button(65,310,"Systems ") > 0 then Menu = 3
if button(65,340,"Trade Goods") > 0 then Menu = 4
if button(65,370,"Missions ") > 0 then Menu = 5
if button(65,460,"Undock ") > 0 then end
If Menu = 1 then gosub ShipYardMenu
If Menu = 2 then gosub WeaponMenu
If Menu = 3 then gosub SystemMenu
If Menu = 4 then gosub TradeGoodMenu
If Menu = 5 then gosub MissionMenu
Return
ShipYardMenu:
if button(185,250,"Shuttles ") > 0 then Choice = 1
if button(185,280,"Fighters ") > 0 then Choice = 2
if button(185,310,"Freighters ") > 0 then Choice = 3
if button(185,340,"Small Caps") > 0 then Choice = 4
if button(185,370,"Medium Caps") > 0 then Choice = 5
if button(185,400,"Large Caps") > 0 then Choice = 6
if button(185,430," Buy Ship ") > 0 then Buy = 1
Return
WeaponMenu:
if button(185,250,"Light Weaps") > 0 then Choice = 1
if button(185,280,"Heavy Weaps") > 0 then Choice = 2
if button(185,310,"LightTurret") > 0 then Choice = 3
if button(185,340,"HeavyTurret") > 0 then Choice = 4
if button(185,370,"Ammunition ") > 0 then Choice = 5
if button(155,430,"Buy ") > 0 then Buy = 1
if button(215,430,"Sell") > 0 then Sell = 1
Return
SystemMenu:
if button(185,250,"Shields ") > 0 then Loadonce = 1
if button(185,280,"Armors ") > 0 then Choice = 2
if button(185,310,"Reactors ") > 0 then Choice = 3
if button(185,340,"Engines ") > 0 then Choice = 4
if button(185,370,"Optional ") > 0 then Choice = 5
if button(155,430,"Buy ") > 0 then Buy = 1
if button(215,430,"Sell") > 0 then Sell = 1
If Loadonce = 1
for st = 1 to Store_item_total
id = rnd(2)+1
Store(st).id = id
Store(st).sprt = 100 + st
Store(st).static = 1
if st => 19 and st <= 24 then st2 = 4
if st => 13 and st <= 18 then st2 = 3
if st => 7 and st <= 12 then st2 = 2
if st => 1 and st <= 6 then st2 = 1
`t2 = round1(3 / 4)
st2a = st2 - 1
st2b = 6 * st2a
st1 = st - st2b
Store(st).gy = st2
Store(st).gx = st1
grid_items(Store(st).gx, Store(st).gy) = id
grid_count(Store(st).gx, Store(st).gy) = grid_count(Store(st).gx, Store(st).gy) + 1
next st
Loadonce = 0
endif
Return
TradeGoodMenu:
if button(185,250,"Ordinary ") > 0 then Choice = 1
if button(185,280,"Exoctic ") > 0 then Choice = 2
if button(185,310,"RawMaterial") > 0 then Choice = 3
if button(185,340,"RefMaterial") > 0 then Choice = 4
if button(155,430,"Buy ") > 0 then Buy = 1
if button(215,430,"Sell") > 0 then Sell = 1
Return
MissionMenu:
if button(185,250,"Patrol ") > 0 then Choice = 1
if button(185,280,"Attack ") > 0 then Choice = 2
if button(185,310,"Deliver ") > 0 then Choice = 3
if button(185,340,"Escort ") > 0 then Choice = 4
if button(185,430,"Accept") > 0 then Buy = 1
Return
REM Control the click and drag
inv_mouse:
if mouseclick() = 1 and click = 0
found = 0
click = 1
for C1 = 1 to Cargo_item_total
if found = 0
offset_x = Cargo_x+1 + (Cargo(C1).gx-1)*icon_size
offset_y = Cargo_y+1 + (Cargo(C1).gy-1)*icon_size
if mousex()>offset_x and mousex()<offset_x+icon_size and mousey()>offset_y and mousey()<offset_y+icon_size
`select square
sprite 1,Cargo_x+1 + (Cargo(C1).gx-1)*icon_size,Cargo_y+1 + (Cargo(C1).gy-1)*icon_size, 10
SET SPRITE PRIORITY 1, 0
found = C1
Cargo(C1).static = 0
mouse_offset_x = mousex() - offset_x
mouse_offset_y = mousey() - offset_y
endif
endif
next C1
endif
if mouseclick() = 0 and click = 0
found = 0
click = 0
for C1 = 1 to Cargo_item_total
if found = 0
offset_x = Cargo_x+1 + (Cargo(C1).gx-1)*icon_size
offset_y = Cargo_y+1 + (Cargo(C1).gy-1)*icon_size
if mousex()>offset_x and mousex()<offset_x+icon_size and mousey()>offset_y and mousey()<offset_y+icon_size
`select square
sprite 2,Cargo_x+1 + (Cargo(C1).gx-1)*icon_size,Cargo_y+1 + (Cargo(C1).gy-1)*icon_size, 11
SET SPRITE PRIORITY 2, 0
endif
if (mousex()-Cargo_x)/icon_size + 1 < 1 OR (mousex()-Cargo_x)/icon_size + 1 > grid_x OR (mousey()-Cargo_y)/icon_size + 1 < 1 OR (mousey()-Cargo_y)/icon_size + 1 > grid_y `if you want to block a spot `or temp_x = 3 and Temp_y =3
if SPRITE exist(2)=1
delete sprite 2
endif
endif
endif
next C1
endif
Rem MouseOver ItemDisplay
ink rgb(255,255,255),0
for MO = 1 to Cargo_item_total
MouseOver = MO
offset_x1 = Cargo_x+1 + (Cargo(MO).gx-1)*icon_size
offset_y1 = Cargo_y+1 + (Cargo(MO).gy-1)*icon_size
if mousex()>offset_x1 and mousex()<offset_x1+icon_size and mousey()>offset_y1 and mousey()<offset_y1+icon_size
`item info
center text 700,430,Items(Cargo(MouseOver).id).Name
center text 700,445,Items(Cargo(MouseOver).id).type
center text 700,520,Items(Cargo(MouseOver).id).Descript1
center text 700,535,Items(Cargo(MouseOver).id).Descript2
endif
next MO
REM Make item sprite follow mouse
if mouseclick() = 1 and click = 1 and found <> 0
SET SPRITE PRIORITY Cargo(found).sprt , 1
sprite Cargo(found).sprt, mousex()-mouse_offset_x, mousey()-mouse_offset_y, Items(Cargo(found).id).Image
endif
REM When mouse button is released, assign item to new grid location
if mouseclick() = 0
click = 0
if found <> 0
Cargo(found).static = 1
temp_x = (mousex()-Cargo_x)/icon_size + 1
temp_y = (mousey()-Cargo_y)/icon_size + 1
if temp_x < 1 OR temp_x > grid_x OR temp_y < 1 OR temp_y > grid_y `if you want to block a spot `or temp_x = 3 and Temp_y =3
REM item is positioned outside of inventory grid, so do nothing and keep old position
else
REM if grid spot is occupied
if grid_count(temp_x, temp_y) > 0
REM if item in occupied slot matches selected item, and its a stackable item
if grid_items(temp_x, temp_y) = Cargo(found).id AND Items(grid_items(temp_x, temp_y)).Stackable = 1
REM item is within inventory grid, assign the new position
grid_count(Cargo(found).gx, Cargo(found).gy) = grid_count(Cargo(found).gx, Cargo(found).gy) - 1
grid_items(Cargo(found).gx, Cargo(found).gy) = 0
Cargo(found).gx = temp_x
Cargo(found).gy = temp_y
grid_count(temp_x, temp_y) = grid_count(temp_x, temp_y) + 1
grid_items(temp_x, temp_y) = Cargo(found).id
endif
else
REM item is within inventory grid, assign the new position
grid_count(Cargo(found).gx, Cargo(found).gy) = grid_count(Cargo(found).gx, Cargo(found).gy) - 1
grid_items(Cargo(found).gx, Cargo(found).gy) = 0
Cargo(found).gx = temp_x
Cargo(found).gy = temp_y
grid_count(temp_x, temp_y) = grid_count(temp_x, temp_y) + 1
grid_items(temp_x, temp_y) = Cargo(found).id
endif
endif
found = 0
endif
endif
RETURN
function text_over_sprite(spritenumber,x,y,text$)
Rem Big Thankz To Ric for the original function
create bitmap 31,screen width(),screen height()
text 0,0,text$
get image 31,0,0,text width(text$),text height(text$),1
delete bitmap 31
sprite spritenumber,x,y,31
endfunction
function button(cx,cy,text$)
tx = text width(text$)/2
ty = text height(text$)/2
mouseover =0
pressed = 0
mclick# = 1
if mousex() > cx - tx - 10 and mousex() < cx + tx + 10
if mousey() > cy - ty - 5 and mousey() < cy + ty + 5
mouseover = 1
endif
endif
if mouseover = 1
rem turns button red when mouse is over it
box cx - tx - 11, cy - ty - 6, cx + tx + 11, cy + ty + 6,RGB(0,0,0),RGB(0,0,0),RGB(0,0,0),RGB(0,0,0) `border
box cx - tx - 10, cy - ty - 5, cx + tx + 10, cy + ty + 5,RGB(196,96,96),RGB(128,128,128),RGB(196,96,96),RGB(128,128,128)
else
rem button is grey since mouse isn't over it
box cx - tx - 11, cy - ty - 6, cx + tx + 11, cy + ty + 6,RGB(0,0,0),RGB(0,0,0),RGB(0,0,0),RGB(0,0,0) `border
box cx - tx - 10, cy - ty - 5, cx + tx + 10, cy + ty + 5,RGB(96,96,96),RGB(128,128,128),RGB(96,96,96),RGB(128,128,128)
endif
ink 0,0
center text cx,cy - ty, text$
if mouseover = 1 and mouseclick() = 1
rem turns box blue when you press it down like standard button
box cx - tx - 11, cy - ty - 6, cx + tx + 11, cy + ty + 6,RGB(0,0,0),RGB(0,0,0),RGB(0,0,0),RGB(0,0,0) `border
box cx - tx - 10, cy - ty - 5, cx + tx + 10, cy + ty + 5,RGB(96,96,196),RGB(96,96,196),RGB(96,96,196),RGB(96,96,196)
ink 0,0
center text cx,cy - ty, text$
pressed = 1
mouseclick() = 0
endif
endfunction pressed
function rounding(originalnumber#)as double float
intnumber#=int(originalnumber#)
finalnumber=intnumber# + (originalnumber#-intnumber# > 0.0)
endfunction finalnumber
function round(number#)
`rounds a number up or down depending on if the first decimal is over .5 or not.
fraction#=number#-int(number#)
if fraction#>0.1 then result=int(number#+1) else result=int(number#)
endfunction result
save the code as a project or source and download the zip and unzip the images in the same folder as the project/source file.
Its not complete. I still haven't figured out how to design a format to drag and drop the slots onto the ship (wondering if I do a grid and lock some grids to a type or do a x,y thing for boxes that only accept a type) also the 2 grids don't exchange items with each other yet.