Page 1 of 1
[Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Wed Mar 04, 2009 10:58 pm
by Nash
I need some help. I've been trying to figure this out on my own for a few days but I've come to the point where I realize I just don't know how to do this.
In the screenshot above, you can see a grid-based inventory window which is 10 x 10 in size. Each grid is 32 x 32 pixels. What I'm trying to do is, I want to know which grid is the mouse currently hovered over. I want the result to return a number from 0 to 99 (well, to be more specific, there are 100 slots, but since ACS arrays are 0-based, that would mean that the results would be from 0 to 99).
The grid is also ordered from left to right, then top to bottom. That means... as you retrieve items, the grid will first be filled from left to right... once it reaches the last grid on the right, it moves down to the next line and starts from the left again.
I haven't the slightest clue on how to achieve this. I'm horrible at maths. Please help. :(
Re: [Help] Tracking mouse coords in a grid?
Posted: Thu Mar 05, 2009 1:29 am
by Isle
subtract the pointer coords from the top right of the top right square. IE if its at 32, 32: x-32 y-32. this makes the top right zero.
now, since its a nice grid all you have to do is divide x and y by the cell size, then multiply y times 10 and add x;
so if x = 270 and y = 165,
x = x - 32,
y = y - 32,
x = x/32 = 7, (ACS integer math rounds everthing down)
y = y/32 = 4,
index = (y*10)+x = 47,
Re: [Help] Tracking mouse coords in a grid?
Posted: Thu Mar 05, 2009 9:29 am
by Nash
Had to alter it around a bit, but finally got it to work. Thanks Isle, I knew I could count on you for all of this maths-y stuff in ACS. :D You'll be credited!
Code: Select all
// calculate which grid the mouse is currently in
int index, index_x, index_y;
index_x = mousex - GetHUDLeft(640);
index_y = mousey - 32;
index_x = index_x / 32;
index_y = index_y / 32;
index = (index_y * 10) + index_x;
Re: [Help] Tracking mouse coords in a grid?
Posted: Thu Mar 05, 2009 9:32 am
by Cutmanmike
Looks great btw Nash. I long for a decent rpg zdoom adventure, even if it's just a mod to use with doom2 maps.
Re: [Help] Tracking mouse coords in a grid?
Posted: Thu Mar 05, 2009 9:53 am
by Nash
Thanks Cutty.
Behold! Thanks to Isle, we now have a working mouse-based inventory, and hovering the mouse over an item will correctly display the item's data! The sword in the screenshot was defined in the master items database to have a base damage of 25, and durability of 50. As you can see in the shot, that one sword in particular that has been pointed over, has its stats randomized. If I were to point the mouse over the other swords in that screenshot, they'd all have different values. Diablo-style items anyone?

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Thu Mar 05, 2009 10:03 am
by Cutmanmike
As a Diablo nut, colour me interested.
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Thu Mar 05, 2009 10:23 pm
by Osiris Kalev
That's shiny Nash.
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Fri Mar 06, 2009 11:51 am
by Gez
Everybody loves the Daggerfall dagger.

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Fri Mar 06, 2009 12:04 pm
by Captain Proof
Wasn't that an Ebony Dagger?I can't remember,I tried to load Daggerfall on Dosbox but it's being a bitch and saying that it can't detect the CD even after I mounted my damn CDrom.
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Fri Mar 06, 2009 12:46 pm
by Nash
As usual for me, the Daggerfall dagger is a temporary placeholder sprite. This will have 100% original graphics, this effort demonstrated by the new status bar...
Re: [Solved + Screenshot!] Tracking mouse coords in a grid?
Posted: Fri Mar 06, 2009 1:09 pm
by Gez
Captain Proof wrote:Wasn't that an Ebony Dagger?
Yes and no. Daggerfall used translations for the various exotic metals. Iron, steel, silver, dwarven, ebony, adamantium, mithril, orcish, daedric... They all used the same sprites. Just with different colors (green for orcish, black for ebony, red for daedric, etc.). The default color (the one you get if you rip the sprites) corresponds to steel IIRC.
Nash wrote:As usual for me, the Daggerfall dagger is a temporary placeholder sprite. This will have 100% original graphics, this effort demonstrated by the new status bar...
Sorry for the digression.
