Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: pslim on Thu 29/06/2006 03:05:02

Title: GUI List Boxes--pgup/down or sliders?
Post by: pslim on Thu 29/06/2006 03:05:02
I'm working on making a GUI-based in game journal. So far I've created the GUI and added a list box to it, and experimented with adding items to the list box both in the global script and from the room script. All of that works fine thanks to the help I got in my Strings question.

I'm realizing now, though, that the list boxes have some peculiarities which make them seem not very well-suited to journaling for someone who knows as little about scripting as I do. For example, if there is a way to word wrap inside a list box, I'm not aware of it. To get the entries to fit into the GUI, I've had to break them up into multiple strings and format manually. This is not really a serious hardship, but it seems an inefficient way to go about it; I just don't know enough to think of a better way.

The main issue I have right now, though, is that only one (or two, max) journal entries will fit on the GUI at one time. I need a way to allow the player to scroll down in the list box, or turn pages in the list box. The only way I can think of to do it is to have multiple identical GUIs and have the page flip buttons send you to the next GUI, which displays the next entry, but looks identical to the first. But that's going to leave me with like 20 journal GUIs, which, again, seems like the most inefficient method possible.

Could someone maybe point me in the direction of a better way to do this?  :=
Title: Re: GUI List Boxes--pgup/down or sliders?
Post by: Akumayo on Thu 29/06/2006 03:24:59
Well, the first thing that comes to mind, isn't practical at all, but would do exatly what you want it to.

If all else fails:
Use inventory items.Ã,  Delete the listbox in favor of an inventory box, and make each entry an inventory item (with the text as the sprite).Ã,  Then use the ScrollUp() / ScrollDown() functions to control it.
(As I said, last resort, I'm sure someone will come up with something FAR more practical)

On a more practical note:

You could use two labels.Ã,  One on the top of the journal, one on the bottom (for two entries).Ã,  Then make an array

#DEFINE Max_JournalEntries 16
String JournalEntry[Max_JournalEntries];

To represent, say 16 JournalEntry Strings.Ã,  These can be set when needed like:

JournalEntry[0].Text = String.Format("This is the first journal entry.");
JournalEntry[1].Text = String.Format("This is the second journal entry.");


Now, you can control what is displayed with two more variables


int labelA_entry = 0;
int labelB_entry = 1;
//since these are real entries by default, you must set the values of JournalEntry[0].Text and JournalEntry[1].Text, probably in the game_startup() script.Ã,  You can make them blank by JournalEntry[0].Text = " ";


Now you have the basis to create the Journal.Ã,  The code below will control what entry is being displayed by each label

repeatedly_excecute() {
Ã,  if (labelA_entry != -1)Ã,  JournalLabelA.Text = labelA_entry;
Ã,  if (labelB_entry != -1)Ã,  JournalLabelB.Text = labelB_entry;
}


Then, for the Scroll Up / Down buttons:

//Scroll Up button pressed code
if (labelA_entry != 0) {
Ã,  labelA_entry --;
Ã,  labelB_entry --;
}

//Scroll Down button pressed code
if (labelB_entry != Max_JournalEntries - 1) {
Ã,  labelA_entry ++;
Ã,  labelB_entry ++;
}




And there you have it, a crude journal with 16 possible entries.

-Regards, Akumayo
Title: Re: GUI List Boxes--pgup/down or sliders?
Post by: pslim on Thu 29/06/2006 03:40:42
Thanks for the quick reply!

I think the code you posted might be a little beyond me at this point (though hopefully not when I'm all finished).


The inventory thing would work great, I think, especially since it would give me more direct control over the font and formatting. I'm going to give it a shot and maybe come back to the other when I've learned more. Thanks.  :D
Title: Re: GUI List Boxes--pgup/down or sliders?
Post by: Ashen on Thu 29/06/2006 10:42:52
Have a go with Akumayo's code, it's really not as complicated to do as it sounds. The only problems with it are, where it says:

JournalEntry[0].Text = String.Format("This is the first journal entry.");
JournalEntry[1].Text = String.Format("This is the second journal entry.");

and:

repeatedly_excecute() {
  if (labelA_entry != -1)  JournalLabelA.Text = labelA_entry;
  if (labelB_entry != -1)  JournalLabelB.Text = labelB_entry;
}


It should be:

JournalEntry[0] = "This is the first journal entry.";
JournalEntry[1] = "This is the second journal entry.";

(Unless String.Text has been added in V2.72? And, the String = String.Format("blah") method is only needed if you want to include variables in the String, e.g. String Say = String.Format("Hello, %s", player.Name);)
and:

repeatedly_excecute_always() {
  if (labelA_entry != -1)  JournalLabelA.Text = JournalEntry[labelA_entry];
  if (labelB_entry != -1)  JournalLabelB.Text = JournalEntry[labelB_entry];
}

(rep_ex_always, in case your Journal GUI is popup modal.)

However, your original question:
QuoteI need a way to allow the player to scroll down in the list box, or turn pages in the list box.

What's wrong with the built-in ways? When a ListBox has more items than it can display, a slider bar automatically appears to let the player scroll though it. This is kind of ugly, though, and mightn't fit with your Journal GUI. (You can disable it by selecting 'Hide Border' on the list box's Properties window.) In which case, reading the manual comes in handy - you can use the ListBox.TopItem property (http://www.adventuregamestudio.co.uk/manual/ListBox.TopItem.htm) to scroll it yourself. E.g. (assumes the ListBox is called lstJournal):


// Scroll Up button:
if (lstJournal.TopItem > 0) lstJournal.TopItem -= 2; // Scroll Up 2 items, if possible

//Scroll Down button:
if (lstJournal.TopItem < (lstJournal.ItemCount - 2)) lstJournal.TopItem += 2; // Scroll Down 2 items, if possible


But, if you can get to grips with Akumayo's suggestion (like I said - looks more intimidating than it is), it might well be the better solution.
Title: Re: GUI List Boxes--pgup/down or sliders?
Post by: Akumayo on Thu 29/06/2006 10:48:07
QuoteHave a go with Akumayo's code, it's really not as complicated to do as it sounds. The only problems with it are

Meh, nothing's perfectÃ,  :)

pslim:
Ã,  Due to this topic, I had an idea for a module to handle this sort of thing.Ã,  It should be ready within two hours of right now.Ã,  I'll post the link to the topic here, so you can have a go at it.

EDIT:

As promised:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27158.0
Title: Re: GUI List Boxes--pgup/down or sliders?
Post by: pslim on Thu 29/06/2006 19:19:59
Thanks for the comments, Ashen. I'm saving all of this and I think I'm going to give it a shot, although I'm really liking the color/font combination I used for my test of the inventory window method, so it remains to be seen which I'll prefer in the end.


Quote from: Ashen on Thu 29/06/2006 10:42:52
However, your original question:
QuoteI need a way to allow the player to scroll down in the list box, or turn pages in the list box.

What's wrong with the built-in ways? When a ListBox has more items than it can display, a slider bar automatically appears to let the player scroll though it. This is kind of ugly, though, and mightn't fit with your Journal GUI. (You can disable it by selecting 'Hide Border' on the list box's Properties window.)

Ahh. See, I hid the border before I tested it, so I didn't realize this happened.  :=

Scrolling is really my choice of last resort. I would much prefer a page turn, because, as you guessed, a scroll bar just isn't ideal for my GUI style. Also, depending on the number and length of entries, I think it could prove to be something of a hassle to have to scroll through them once you get far enough into the game to have had several of them show up.

You guys have given me several options to consider, though, and I think I'll try more than one and compare them before I make a final decision. Thanks again to both Ashen and Akumayo.Ã,  :)


PS: Akumayo, I'll be checking out that module later tonight when I have the chance.Ã,  :D