Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Menuing Help  (Read 1422 times)

0 Members and 1 Guest are viewing this topic.

Xiphirx

wat
Menuing Help
« on: June 21, 2009, 01:11:23 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
I have an array (dynamically sized) and I want to display the contents as a menu.

Something like:
BEFORE
Quote



menuitem1
menuitem2
menuitem3
menuitem4
menuitem5

AFTER PRESSING DOWN
Quote


menuitem1
menuitem2
menuitem3
menuitem4
menuitem5


AFTER PRESSING DOWN AGAIN
Quote

menuitem1
menuitem2
menuitem3
menuitem4
menuitem5



Hopefully you see how I want it... The current choice is in the center of all the displayed choices... Or like the PSP's Game XMB menu if that helps...

So, I thought about for loops, and I couldn't get a working algorithm out :(. Another obstacle is that I can only display 6 items at a time.... and  I can't figure out how to limit that.

Help :(

Logged
  • For The Swarm
Re: Menuing Help
« Reply #1 on: June 21, 2009, 01:32:29 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Code: [Select]
int centerY = 100; // Position of the central menu item on the y-axis.
int x = 0; // Position on the x-axis to draw items.
int selectedIndex = 0; // Index of select menu item.
int menuHeight = 10; // Height of each menu item.

for (int i = 0; i < selectedIndex; i++)
{
int y = (centerY - (((selectedIndex - 1) - i) * menuHeight));
DrawMenuItem(i, x, y);
}

DrawMenuItem(selectedIndex, x, y);

for (int i = selectedIndex + 1; i < menuItemCount; i++)
{
int y = centerY + ((i - selectedIndex) * menuHeight);
DrawMenuItem(i, x, y)
}


Bleh, probably an easier way to do it. But its 3am and I'm to tired D:

This algorithem is also assuming the origin of the menu item being drawn is (0,0).
« Last Edit: June 21, 2009, 01:34:16 am by Infini »
Logged

Xiphirx

wat
Re: Menuing Help
« Reply #2 on: June 21, 2009, 01:55:49 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Thank you for that, I have it semi working :D I can probably finish it off.
Logged
  • For The Swarm
Re: Menuing Help
« Reply #3 on: June 21, 2009, 02:16:58 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Wait, why did I tell you to do it like that. Eh;

Code: [Select]
int centerY = 100; // Position of the central menu item on the y-axis.
int x = 0; // Position on the x-axis to draw items.
int selectedIndex = 0; // Index of select menu item.
int menuHeight = 10; // Height of each menu item.
int menuItemCount = 10; // Number of menu items.

for (int i = 0; i < menuItemCount; i++)
{
int y = centerY - (selectedIndex * MenuHeight);
DrawMenuItem(i, x, y);
}

God dam I'm to tired.
Logged

Xiphirx

wat
Re: Menuing Help
« Reply #4 on: June 21, 2009, 02:29:09 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Is there a way to have a comparison for loop in lua?

Shouldn't
Code: [Select]
for i=0, i < selection do
-- code
end

work? :S


EDIT: A flaw in your code,

Code: [Select]
int y = centerY - (selectedIndex * MenuHeight);

The y is the same for all items :S
« Last Edit: June 21, 2009, 02:34:09 am by Xiphirx »
Logged
  • For The Swarm
Re: Menuing Help
« Reply #5 on: June 21, 2009, 07:19:05 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Is there a way to have a comparison for loop in lua?

Shouldn't
Code: [Select]
for i=0, i < selection do
-- code
end

work? :S


EDIT: A flaw in your code,

Code: [Select]
int y = centerY - (selectedIndex * MenuHeight);

The y is the same for all items :S

The flawed code probably has to be:

Code: [Select]
int y = centerY - ((selectedIndex - i) * MenuHeight);

the code inside the loop doesn't do anything with the iteration number of the loop.
And if you want a limit on the number of items displayed you probably need the following check:

Code: [Select]
int nrItemsView = 4; //number of items to display
if( abs(i - selectedIndex) <= nrItemsView) { // don't know exactly how to take absolute numbers in C++

or you could do this, because I don't know how to get an absolute number, so the above code probably won't work.

Code: [Select]
int nrItemsView = 4; //number of items to display above the selected item (also for below)
int k = i - selectedIndex <= nrItemsView;
if( k <= nrItemsView  && k >= -nrItemsView) {
« Last Edit: June 21, 2009, 07:40:56 am by Niek »
Logged
Re: Menuing Help
« Reply #6 on: June 21, 2009, 12:42:11 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629

Code: [Select]
int y = (centerY - (selectedIndex * MenuHeight)) + (i * MenuHeight);
Bleh. w/e. I told you it was 3-4am :P. My mind dosen't work at that time ;).
Logged

Xiphirx

wat
Re: Menuing Help
« Reply #7 on: June 21, 2009, 06:49:12 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Bleh, I solved it at 3-4am :P

I can just limit the number of items by showing or not showing items depending on their y values.

FINISHED CODE: (it's in lua)
Code: [Select]
for i = 1, selection - 1 do
zey = spots[3] - ((selection - i) * 18)
screen.print(19, zey, modarray[i], 0.6, gray,1)
end
screen.print(19, spots[3], modarray[selection], 0.6, black,1)
for i = selection + 1, numberofmods do
zey = spots[3] + ((i - selection) * 18)
screen.print(19, zey, modarray[i], 0.6, gray,1)
end

Thanks for all the help guys :D
Logged
  • For The Swarm
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.234 seconds with 51 queries.