[Solved + Screenshot!] Tracking mouse coords in a grid?

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.

[Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Nash » Wed Mar 04, 2009 10:58 pm

Image

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. :(
Last edited by Nash on Thu Mar 05, 2009 9:54 am, edited 1 time in total.
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: [Help] Tracking mouse coords in a grid?

Postby Isle » Thu Mar 05, 2009 1:29 am

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,
User avatar
Isle
WadAuthor 4 L1F3
 
Joined: 21 Nov 2003
Location: Arizona, USA

Re: [Help] Tracking mouse coords in a grid?

Postby Nash » Thu Mar 05, 2009 9:29 am

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 allExpand view
   // 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;
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: [Help] Tracking mouse coords in a grid?

Postby Cutmanmike » Thu Mar 05, 2009 9:32 am

Looks great btw Nash. I long for a decent rpg zdoom adventure, even if it's just a mod to use with doom2 maps.
User avatar
Cutmanmike
Is it hot in here or is it just ZScript
 
Joined: 06 Oct 2003
Location: United Kingdom
Discord: https://discord.gg/Whts7Bj
Operating System: Windows Vista/7/2008 64-bit

Re: [Help] Tracking mouse coords in a grid?

Postby Nash » Thu Mar 05, 2009 9:53 am

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?

Image
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Cutmanmike » Thu Mar 05, 2009 10:03 am

As a Diablo nut, colour me interested.
User avatar
Cutmanmike
Is it hot in here or is it just ZScript
 
Joined: 06 Oct 2003
Location: United Kingdom
Discord: https://discord.gg/Whts7Bj
Operating System: Windows Vista/7/2008 64-bit

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Osiris Kalev » Thu Mar 05, 2009 10:23 pm

That's shiny Nash.
User avatar
Osiris Kalev
Chaotic....
 
Joined: 21 Aug 2006
Location: Australia, Elsewhere Within

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Gez » Fri Mar 06, 2009 11:51 am

Everybody loves the Daggerfall dagger. ;)
Gez
 
 
 
Joined: 06 Jul 2007

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Captain Proof » Fri Mar 06, 2009 12:04 pm

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.
User avatar
Captain Proof
Yeah, I am as sleazy as this avatar looks
 
Joined: 27 Aug 2008
Location: Henderson

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Nash » Fri Mar 06, 2009 12:46 pm

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...
User avatar
Nash
AKA Nash Muhandes! Twitter/Facebook/Youtube: nashmuhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Twitch ID: nashmuhandes
Github ID: nashmuhandes

Re: [Solved + Screenshot!] Tracking mouse coords in a grid?

Postby Gez » Fri Mar 06, 2009 1:09 pm

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. :3:
Gez
 
 
 
Joined: 06 Jul 2007


Return to Editing (Archive)

Who is online

Users browsing this forum: No registered users and 1 guest