Render a non-interactive inventory?

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Render a non-interactive inventory?

Post by Gambit37 »

I'd like to render a champion's inventory as a snapshot view on my champion selector. It doesn't need to be fully interactive (ie, I don't need drag and drop), although I'll need some way of the player being able to click the item icons to get the name of the item. I've looked through the various base files to see what I can pilfer and hack, but couldn't quite seem to find everything.

Is there something I can work from as a base, or is this something I'll have to do from scratch?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Render a non-interactive inventory?

Post by Sophia »

There is no base for this, unfortunately, but it's not terribly difficult, either.

Really, the basic idea is that you just want to iterate over the inventory slots, dsb_fetch what's in the slot, and, if something's there, draw the appropriate icon, which you can pull out of the obj table. Of course, that's an extremely high level outline, so if you want code samples, I can try to work something out eventually.
(I had kind of a rough afternoon so I'm a little out of sorts now-- not a good time for coding!)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

Sorry to hear you had a bad day, hope you feel better?

Don't worry about code examples for this, I'm going to see if I can do it myself. It will be good practice. I'll holler if I get stuck :-)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

Blimey, I got it to work, it was actually really easy using the information in inventory_info.lua and viewing the code for sys_render_attack_options in render.lua.

It's non interactive, but to be honest that's fine as I only really need a quick visual overview of what a champion is carrying.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

So, after a day basking in my success, I want more :P

I think my inventory would make more sense with tooltips for the items. So when the player hovers over or clicks the icon, I can display some basic info: name & weight for example.
Questions
1) Can I respond to a mouse "hover" within a full screen renderer? IE, are the X & Y values constantly updating?
2) Again, within a full screen renderer, how can I continually monitor a bunch of coordinates stored in an array? Imagine a copy of inventory_info[] -- how can I monitor each set of icon position coordinates?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Render a non-interactive inventory?

Post by Sophia »

Gambit37 wrote:Can I respond to a mouse "hover" within a full screen renderer? IE, are the X & Y values constantly updating?
If you use the function that is called every frame, then every frame the X and Y coordinates will be current. Remember, you're not building a "scene" or anything like that. Your code is actually redrawing the image every frame, so if you want to change something, all you have to do is draw it differently.
Gambit37 wrote:Again, within a full screen renderer, how can I continually monitor a bunch of coordinates stored in an array? Imagine a copy of inventory_info[] -- how can I monitor each set of icon position coordinates?
The best way is to put all of the coordinates into a table (as you mentioned) and then just iterate over the table, checking to see if the x and y coordinates are greater than the upper left corner coordinates and less than the lower right corner coordinates. If you're inside one of these "zones," then you act appropriately for that zone-- probably by checking to see if there's an item in the spot occupied by that zone (linking the zone to an inventory slot and then calling dsb_fetch on the slot can do that) and printing the item's name or whatever else you want to do.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

OK, thanks, I was on the right lines (I've just been trying it out). The bit I'm confused about is how and where I do the looping over the table of coordinates?

I've already built buttons by having a string of checks for (x > ? and x < ?) AND (y > ? and y < ?). What construct do I need for the loop? I tried doing a for/next loop in a final else block, but nothing seemed to happen (although it ran fine with no errors).

This code below is my current routine without any checking for the inventory coordinates -- how should I update this to work correctly?

Code: Select all

function champion_selector(x, y, buttonpressed)

	if (buttonpressed == 1) then

		if ((x > ? and x < ?) AND (y > ? and y < ?)) then
			(...set vars to be used by drawing function...)

		elseif ((x > ? and x < ?) AND (y > ? and y < ?)) then
			(...set vars to be used by drawing function...)

		elseif ((x > ? and x < ?) AND (y > ? and y < ?)) then
			(...set vars to be used by drawing function...)

		end
	end
end
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Render a non-interactive inventory?

Post by Sophia »

Code: Select all

valid_coords = {
   { 10, 20, 30, 40 },
   { 0, 0, 5, 5 }
   -- etc
}
for zone in pairs(valid_coords) do
   local x1 = valid_coords[zone][1]
   local y1 = valid_coords[zone][2]
   local x2 = valid_coords[zone][3]
   local y2 = valid_coords[zone][4]

   if (x > x1 and x < x2 and y > y1 and y < y2) then
      -- do whatever, according to value of zone
      break
   end
end
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

Thank you, but I still don't understand where Im supposed to put this code in context of my fullscreen renderer?

This is my current fullscreen function call:

Code: Select all

dsb_fullscreen(champion_selector_draw, champion_selector_click, nil, true, true)
Are you saying I need a new function called on every frame, eg:

Code: Select all

dsb_fullscreen(champion_selector_draw, champion_selector_click, champion_selector_move, true, true)

function champion_selector_move()
   --- your code above ----
end
I tried doing something like that already but DSB didn't seem to understand my checks against the x and y coordinates of the mouse, says "attempt to compare number with nil"
"
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

Woo, I got it to work by putting my code in the draw function and checking the mx and my coordinates. This means I can have floating tooltips :-)
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Render a non-interactive inventory?

Post by Sophia »

Right, that's what I meant.
The drawing function is executed every frame, so you will always have correct mouse coordinates.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

Can I find the length of a dsb_bitmap_textout in pixels? I'd like to render a box behind the text, but don't know how big it is.
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Render a non-interactive inventory?

Post by Sophia »

Not currently. That would be useful, though. I'll add it.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Render a non-interactive inventory?

Post by Gambit37 »

Cool, thank you :-)
Post Reply