Hi guys, need some help with working out the inventory scroll bar formula. I will refine the code, turn it into functions and etc... but for now I just want to get it working. I think I've taken the right approach in simulating the Morrowind inventory system, your see what I mean. Thank in advance
I can't figure out the Scroll bit when the window increases or decrease size.
The code:
sync on : sync rate 60
load dll "user32.dll",1
sWidth = call dll( 1 , "GetSystemMetrics" , 0 )
sHeight = call dll( 1 , "GetSystemMetrics" , 1 )
delete dll 1
set display mode sWidth , sHeight , 32
type str_inventory
ID as integer
SlotID as integer
slotUsed as boolean
SlotX as integer
endtype
dim Inventory(999) as str_inventory
global KeyPress as boolean
global SBarSBarGrab as boolean
global ScrollX
global OffsetX
global MX
global Scroll `= 1
global begin = 1
CurWidth = 256
CurHeight = 128
MaxWidth = 256
MaxHeight = 128
sizeX = 32
sizeY = 32
Blocks = 42
for x = 1 to Blocks
InsertIntoSlot()
next x
do : cls
if MaxHeight >= CurHeight+sizeY
CurHeight = MaxHeight
endif
if MaxHeight <= CurHeight-sizeY
CurHeight = MaxHeight
endif
MX = mousex()
for x = 1-(Scroll*sizeX) to CurWidth-(Scroll*sizeX) step sizeX
for y = 1 to CurHeight step sizeY
inc Slot
Inventory(Slot).SlotX = x+sizeX
MaxSlots = (CurWidth/sizeX) * (CurHeight/sizeY)
if GetUsedSlots() > MaxSlots
CurWidth = CurWidth + sizeX
endif
if GetUsedSlots() < MaxSlots-(CurHeight/sizeY)
CurWidth = CurWidth - sizeX
endif
if CurWidth > MaxWidth
TotalSlotX = CurWidth / sizeX
else
TotalSlotX = 0
Scroll = 0
endif
if TotalSlotX > (MaxWidth/sizeX)
if mousex()>ScrollX and mousex()<ScrollToX
if mousey()>MaxHeight and mousey()<MaxHeight+12
if mouseclick() = 1
SBarGrab = 1
endif
endif
endif
if SBarGrab = 1
ScrollX = (MX-OffsetX)
else
OffsetX = MX-ScrollX
endif
if mouseclick() = 0
SBarGrab = 0
endif
Percent = (((MaxWidth/sizeX))*MaxWidth )/TotalSlotX
if ScrollX < 0 then ScrollX = 0
if ScrollToX > MaxWidth then ScrollX = MaxWidth-Percent
`I can't seem to work out the forumla, so I just put a random number in the end
Scroll = ((ScrollX - 32)/10)
ScrollToX = ScrollX+Percent
box ScrollX,MaxHeight,ScrollToX,MaxHeight+12
endif
if Inventory(Slot).SlotX < (MaxWidth+sizeX)
if Inventory(Slot).SlotUsed > 0
ink RGB(255,0,0),0
box x , y , x+sizeX-1 , y+sizeY-1
ink RGB(255,255,255),0
center text x+(sizeX/2) , y+(sizeY/2),str$(Slot)
else
ink RGB(255,255,255),0
dot x+(sizeX/2) , y+(sizeY/2)
endif
endif
next y
next x
Slot = 0
ink RGB(255,255,255),0
line 0,MaxHeight+1,MaxWidth+1,MaxHeight+1
line MaxWidth+1,0,MaxWidth+1,MaxHeight+1
if inkey$() = "m" and KeyPress = 0
MaxHeight = MaxHeight + sizeY
KeyPress = 1
endif
if inkey$() = "n" and KeyPress = 0
if MaxHeight > sizeY
MaxHeight = MaxHeight - sizeY
endif
KeyPress = 1
endif
if inkey$() = "b" and KeyPress = 0
MaxWidth = MaxWidth + sizeX
KeyPress = 1
endif
if inkey$() = "v" and KeyPress = 0
if MaxWidth > sizeX
MaxWidth = MaxWidth - sizeX
endif
KeyPress = 1
endif
if inkey$() = "i" and KeyPress = 0
InsertIntoSlot()
KeyPress = 1
endif
if inkey$() = "r" and KeyPress = 0
RemoveSlot()
KeyPress = 1
endif
if scancode() = 0 then KeyPress = 0
text 0,screen height()-text size()*12,"[Instructions] - Press:"
text 0,screen height()-text size()*11,"M - to increase the Height of the window"
text 0,screen height()-text size()*10,"N - to decrease the Height of the window"
text 0,screen height()-text size()*9,"B - to increase the Width of the window"
text 0,screen height()-text size()*8,"V - to decrease the Width of the window"
text 0,screen height()-text size()*7,"I - to add an inventory block"
text 0,screen height()-text size()*6,"R - to remove an inventory block"
text 0,screen height()-text size()*4,"Total Slots X: "+str$(TotalSlotX)
sync
loop
function InsertIntoSlot()
for x = 1 to array count(Inventory())
if Inventory(x).SlotUsed = 0
Inventory(x).SlotID = x
Inventory(x).SlotUsed = 1
exitfunction
endif
next x
endfunction
function RemoveSlot()
for x = array count(Inventory()) to 1 step - 1
if Inventory(x).SlotUsed = 1
Inventory(x).SlotUsed = 0
Inventory(x).SlotID = 0
exitfunction
endif
next x
endfunction
function GetUsedSlots()
for x = 1 to array count(Inventory())
if Inventory(x).SlotUsed = 1
inc i
endif
next x
endfunction i
A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.