19-04-2007, 02:06 AM
Alright well, on my way to programming my game, I was searching for a Visual Inventory code and found GSD's, but I saw that it was a very long code and was probably laggy, so I decided to remake the code. Then I wondered whether I should rip it from Elysium, and I decided not to, seeing as Elysium is very buggy. It's pretty simple, and will probably be less laggy, considering it doesn't re-load the item surface into a picture box and stuff. As you might notice, there are some similarities between GSD's and the Elysium and my tut.
So first things first, this isn't a full tutorial. I have completed the code, but I want people to learn, and figuring out how to code things is the best way. Of course, you can ask questions on how to add the use + drop code in, but it's just not for copy paste. I'm just telling you how to blt the items and how to have a good base. You have to add the code for drop + using items. Oh my god, how hard :wink:
So first, make a picture box called PicInventory, or whatever you want. Now, inside it, make 12 picInv boxes so it's an array. (However, make sure to start at 1 and not 0, so you have picInv 1 - picinv 12 and not picInv 0 - picInv - 11)
Also, add a shape called SelectedItem with the following stats :
BorderWidth = 2
Left = The left of the first picInv, - 1
Top = The top of the first picInv, - 1
Width = 35
Height = 35
Now, this is for a base base base mirage, with 24 inventory slots.
Also, add a label or picturebox, whichever you want called PicUp and PicDown. These will be our scrollers.
Now, at the top of frmMirage's code, add this :
And add this in modGlobals
Now, the inventory scrolling set set for a layout like this :
x | x | x | x
x | x | x | x
x | x | x | x
So if you want a differnt layout, figure it out
Then add this code :
This is what sets the scrolling and selecting. Now for the blitting.
Make a timer called tmrBltInv with an interval of 50 or 100 (your choice) and the enabled set to false
Now add this code :
What this does is it clears the picture boxes that have items in them, and then if there is an item found, it blits it.
We're almost done! Now, in sub initDirectX, under the code
Add :
And there you have it! You now have an optimized visual inventory system. Instead of blitting 24, it only blits 12 items, and instead of making picItems in the memory again as a picturebox on frmMirage, it blits directly from the surface.
Now, up to you to add the drop / use code :wink: I was even nice enough to set up the Item Selected variable for you
Any bug reports or comments, feel free to say so
So first things first, this isn't a full tutorial. I have completed the code, but I want people to learn, and figuring out how to code things is the best way. Of course, you can ask questions on how to add the use + drop code in, but it's just not for copy paste. I'm just telling you how to blt the items and how to have a good base. You have to add the code for drop + using items. Oh my god, how hard :wink:
So first, make a picture box called PicInventory, or whatever you want. Now, inside it, make 12 picInv boxes so it's an array. (However, make sure to start at 1 and not 0, so you have picInv 1 - picinv 12 and not picInv 0 - picInv - 11)
Also, add a shape called SelectedItem with the following stats :
BorderWidth = 2
Left = The left of the first picInv, - 1
Top = The top of the first picInv, - 1
Width = 35
Height = 35
Now, this is for a base base base mirage, with 24 inventory slots.
Also, add a label or picturebox, whichever you want called PicUp and PicDown. These will be our scrollers.
Now, at the top of frmMirage's code, add this :
Code:
Private InvScroll As Byte
And add this in modGlobals
Code:
' Used for visual inventory
public InvSelected as byte
Now, the inventory scrolling set set for a layout like this :
x | x | x | x
x | x | x | x
x | x | x | x
So if you want a differnt layout, figure it out

Then add this code :
Code:
Private Sub picDown_Click()
If InvScroll 3 Then
InvScroll = InvScroll + 1
End If
End Sub
Private Sub picUp_Click()
If InvScroll 0 Then
InvScroll = InvScroll - 1
End If
End Sub
Private Sub picInv_Click(Index As Integer)
SelectedItem.Left = picInv(Index).Left - 1
SelectedItem.top = picInv(Index).top - 1
ItemSelected = index + (invscroll * 4)
End Sub
This is what sets the scrolling and selecting. Now for the blitting.
Make a timer called tmrBltInv with an interval of 50 or 100 (your choice) and the enabled set to false
Now add this code :
Code:
Private Sub tmrBltInv_Timer()
Dim I As Long
Dim Src As RECT
For I = 1 To (picInv.Count)
If picInv(I).Picture LoadPicture() Then
picInv(I).Picture = LoadPicture()
End If
'Else
If GetPlayerInvItemNum(MyIndex, I + (InvScroll * 4)) = 0 Then
picInv(I).Picture = LoadPicture()
Else
With Src
.top = Item(GetPlayerInvItemNum(MyIndex, I + (InvScroll * 4))).Pic * PIC_Y
.Bottom = .top + PIC_Y
.Left = 0
.Right = .Left + PIC_X
End With
With rec
.top = 0
.Bottom = .top + PIC_X
.Left = 0
.Right = .Left + PIC_X
End With
Call DD_ItemSurf.BltToDC(picInv(I).hdc, Src, rec)
End If
'End If
Next I
End Sub
We're almost done! Now, in sub initDirectX, under the code
Code:
frmMirage.show
Add :
Code:
frmMirage.tmrBltInv.Enabled = True
And there you have it! You now have an optimized visual inventory system. Instead of blitting 24, it only blits 12 items, and instead of making picItems in the memory again as a picturebox on frmMirage, it blits directly from the surface.
Now, up to you to add the drop / use code :wink: I was even nice enough to set up the Item Selected variable for you

Any bug reports or comments, feel free to say so
