Scroll UP/DOWN in savegame + loadgame **Solved**

Started by Knox, Fri 02/10/2009 17:39:10

Previous topic - Next topic

Knox

Hi!

Ive tried searching the forums without any luck to this specific problem. Ive found some that "kind of" points to some aspects, but not quite.

Its pretty simple I guess, basically all I want to do is when my savegame or loadgame GUI is open, when I flick down or up on the mouse, it will scroll up or down the lists, but selecting each one at the same time (not just scrolling the list up and down as a whole, but scrolling the selection/highlight for each save game or load game). Ive got the scrolling working with arrow buttons, but it only scrolls the whole list up or down, not each individual item.

This is what I tried, and well...doesnt work!

Code: ags

else if (button == eMouseWheelNorth) 
{ 
	if (gSave.Visible)
	{
    		stSaveGames.ScrollUp();
	}
}
else if (button == eMouseWheelSouth) 
{
    	if (gSave.Visible)
    	{
      		lstSaveGames.ScrollDown();
    	}
}
--All that is necessary for evil to triumph is for good men to do nothing.

RickJ

You need to change the SelectedIndex property to scroll the selection.  You can then manipulate the TopItem property to move the listbox window's position so that the selected item remains visible.   

Themodified script below ought (it's untested) to let the selection scroll up/down the listbox window,  When it reaches the top of bottom of the window then the entire list will scroll up/down.    You can of course modify this behavior any way you want.  For example the listbox widow could be  positioned so the the selection is displayed in the center of the window.

Anyway I think the example belowought to give you an idea of how to do these things.

Code: ags

else if (button == eMouseWheelNorth) 
{ 
	if (gSave.Visible)
	{
                if (stSaveGames.SelectedIndex>0) {
                   stSaveGames.SelectedIndex--;
                }
                if (stSaveGames.SelectedIndex<stSaveGames.TopItem) { 
    		   stSaveGames.TopItem = stSaveGames.SelectedIndex;
                }
	}
}
else if (button == eMouseWheelSouth) 
{
    	if (gSave.Visible)
    	{
                if (stSaveGames.SelectedIndex<stSaveGames.ItemCount)  {
                   stSaveGames.SelectedIndex++;
                }
                if (stSaveGames.SelectedIndex>(stSaveGames.TopItem+stSaveGames.RowCount)) { 
    		   stSaveGames.TopItem = stSaveGames.SelectedIndex - stSaveGames.RowCount;
                }
    	}
}

Knox

Hey RickJ,

Thanks pal! It works but I had to comment out " if game is paused dont process mouse clicks" since my save GUI pauses the game when shown.

I get this error however while trying it out (kicks me out of the game and brings me to the script, highlighting this line:
"lstSaveGames.TopItem = lstSaveGames.SelectedIndex;"

The error:
Code: ags

ListBoxSetTopItem: tried to set top beyond top or bottom of list


--All that is necessary for evil to triumph is for good men to do nothing.

RickJ

You will probably have to do some error checking on the index bounds etc.   You can try making the following modification to see if that helps.

Code: ags

else if (button == eMouseWheelNorth) 
{ 
	if (gSave.Visible)
	{
                if (stSaveGames.SelectedIndex>0) {
                   stSaveGames.SelectedIndex--;
                   if (stSaveGames.SelectedIndex<stSaveGames.TopItem) { 
      		      stSaveGames.TopItem = stSaveGames.SelectedIndex;
                   }
                }
	}
}
else if (button == eMouseWheelSouth) 
{
    	if (gSave.Visible)
    	{
                if (stSaveGames.SelectedIndex<stSaveGames.ItemCount)  {
                   stSaveGames.SelectedIndex++;
                   if (stSaveGames.SelectedIndex>(stSaveGames.TopItem+stSaveGames.RowCount)) { 
       		      stSaveGames.TopItem = stSaveGames.SelectedIndex - stSaveGames.RowCount;
                   }
                }
    	}
}

Knox

Yup, it works. I added       
Code: ags

txtSaveName.Text = lstSaveGames.Items[lstSaveGames.SelectedIndex]; 


so it updates the active selected item in the list at the top of my GUI.

If anyone reads this and would like the full script, let me know and Ill post it:)

Thanks RickJ
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk