Greetings!
A few days ago, I was trying to build my game's options menu. NGUI is a blast, but creating a potentially long list of resolutions meant that I couldn't use NGUI's built-in PopupList, as that component always insists on showing the entire list. I am targeting the PC, and I don't want to do a cheap "here you go, a couple of buttons with pre-determined resolutions" solution. I needed a replacement. Tried using some sort of buttons instantiated at runtime, but it was honestly terrible, so I searched for a replacement. It appears that a member of this forum, by the name of "adam718" had written something like that about two years ago. I tried it, didn't work even after porting. Therefore, I trashed that idea as well.
And so, in the end, despite being quite inexperienced with NGUI (I am well-acquainted with programming, though), I sat down and wrote a new list, based on the current one. This one is scrollable.
So what's this all about? I'm intending to
create a few more components for NGUI, then publish them on the Asset Store (as Aren has stated that he doesn't want his source code floating around everywhere, and the Asset Store should deal with that with the "requires NGUI" thing they've got going on). I'll likely provide the entire pack for free, or for a couple of euro only, as I am quite broke at the moment - as a symbolic price, tribute to the free time I've spent on them.
So, what do you guys think? Is anyone interested in a component pack?
After this scrollable list, I'll do some sort of a list which has got only one element showing up at a time, with left/right arrows for selecting the other elements (Battlefield 3/4 options menu style), which could possibly also show the amount of elements using some sort of a small sprite. I had something else on my mind as well, but I seem to have forgotten it at the moment.
So, if anyone's interested, post here. I am likely to do requests, so if you want to see a specific GUI component NGUI's been lacking, and you can't be arsed/don't know how/don't want to write one yourself, just post here and (if it's not too complicated) I'll make one and include it in the pack.Current projects and Unity 4.6 GUI and whatnot render me unlikely to continue using NGUI, so the above paragraph is very unlikely. However, you can now grab the scrollable list if you want to.In any case, let's get to demonstrating the scrollable list.
Ladies and gentlement, without further ado, I give you the...
> Scrollable Popup ListIt's got its own scrollbar, and can be quite small...
Positioning it above works as expected, and how big it is is up to you to decide.
| | | The Inspector is naturally based on the existing ones from NGUI, but exposes more variables - particularly these relating to the scrollbar.
| | | The Scrollable Popup List is great for displaying long lists, unlike the regular PopupLists which may, at one point, become longer than your screen. This one's "open size" is dictated by the "Max Height" variable exposed in the Inspector. (Setting it to 0 will give the same results as a regular PopupList, and you can change that during run-time if you so desire for whatever reason.) Naturally, you can populate such a list during run-time in rather the same way you'd do with a regular list. The scrollbar handles clicking and dragging, and behaves just as a scrollbar should. Most of it is also exposed (including the colours its foreground and background sprites use), so you can customise it as well.
A scrollable PopupList (or, should I say, a ListBox for those familiar with .NET development) is perfect for displaying a variety of different things. I wrote it because I needed a resolutions list, but it can be used for basically anything - as a debugging tool to display all items in your new RPG, as a complicated dynamic statistics graph filter for that 4X strategy game you're working on, or perhaps as a list of all maps during your new FPS's server hosting screen. It was odd to me that NGUI didn't have one of these by default. One'd think that such functionality is indispensable.
Limitations: - Requires a minimal modification to the UILabel class in order to display the choices on the given label. - Does not support phone-style dragging directly on top of the list. I do things for the PC, not for random portable devices. PC master race FTW.
|
Note: This list does exhibit some strange behaviour from time to time, IIRC, so keep in mind that it's not perfect. YMMV.
DOWNLOAD (.zip, 9.41 KB)
"Installation" instructions:Just like every other UI component, just drop the files in some proper folders. You can use a regular PopupList prefab, and just replace the default list script with this one.
However, one modification should be made to the UILabel class in order to allow the labels to handle updates from this specific kind of list. Open up the label file, and find the
SetCurrentSelection() function and
add the part after my comment from the excerpt below:
/// <summary>
/// Convenience function, in case you wanted to automatically set some label's text
/// by selecting a value in the UIPopupList.
/// </summary>
public void SetCurrentSelection ()
{
if (UIPopupList.current != null)
{
text = UIPopupList.current.isLocalized ?
Localization.Get(UIPopupList.current.value) :
UIPopupList.current.value;
}
// Lumos: Scrollable popup lists
else if (UIScrollablePopupList.current != null)
{
text = UIScrollablePopupList.current.isLocalized ?
Localization.Get(UIScrollablePopupList.current.value) :
UIScrollablePopupList.current.value;
}
}
Hope I've interested someone.
I do feel like doing a few more components.Any comments, opinions, remarks? Let me know.