Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Visual Inventory Tutorial
#1
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 :

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 Wink

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
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
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 Tongue

Any bug reports or comments, feel free to say so Big Grin
Reply
#2
Sweet tutorial dude. I'm gonna play with it a little when I get home Tongue

I've been looking for a different way to do the visual inventory Big Grin
Reply
#3
Sonire Wrote:Sweet tutorial dude. I'm gonna play with it a little when I get home Tongue

I've been looking for a different way to do the visual inventory Big Grin

Aha, no problem Smile I did a small edit, just changed the Private ItemSelected to Public and put it in a module because then you can use it with frmDrop :wink:
Reply
#4
When i add this, i get this error: Procedure declaration does not match description of event or procedure having the same name.

It high lites this code:
Code:
Private Sub picInv_Click(Index As Integer
Reply
#5
I have that, what i showed you is what it highlighted. It didn't highlight ")".
Reply
#6
This tutorial is no better than the Elysium way of doing things.

You need to move away from having a large array of bloated controls.

You could easily have done this using only one picture box.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#7
Robin Wrote:This tutorial is no better than the Elysium way of doing things.
Last time I checked es used bitblt?
Reply
#8
William Wrote:
Robin Wrote:This tutorial is no better than the Elysium way of doing things.
Last time I checked es used bitblt?

It doesn't matter if you use BitBlt or BltToDC or if you even set up a clipper to each bloody picture box and render it in DX7.

The point is that using more than one picture box is simply lazy.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#9
That might be the case here, but 2 picture boxes doesn't really matter. But of course, in one sence, it could be called lazy.
Reply
#10
I feel dumb, but anyway,

The use item code is no problem, but I want to drop with right-click. What's the best way of doing that? Another parameter to the function or something like it?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)