Labels Question

Started by Interference, Thu 12/06/2003 10:52:00

Previous topic - Next topic

Interference

Does anyone know an easy way to store to a string what's written on a label? I need this for a message log window.

This window is sent a message which is then placed at the bottom of the window while all other previous messages scroll up one line, the last falling off the list. I can't seem to find a function that lets me read from one label and copy its text to another. I know I could use list boxes but visually speaking, they're not what I'm after and it's a lot less convenient to make them run from bottom to top rather than top to bottom.

In case anyone's wondering, I'm coding a Baldur's Gate GUI set as a little side project and this is needed for it to look fairly authentic.
-- Interference

"Wasting people's valuable time since 1984"


Scorpiorus

#1
QuoteDoes anyone know an easy way to store to a string what's written on a label? I need this for a message log window.

Well, there is no GetLabelText() function in AGS. So what you could do is to store all messages as strings separately from labels. (see Set/GetGlobalString()) Then just refresh all labels depending on what message is the top one.

Quote
This window is sent a message which is then placed at the bottom of the window while all other previous messages scroll up one line, the last falling off the list. I can't seem to find a function that lets me read from one label and copy its text to another. I know I could use list boxes but visually speaking, they're not what I'm after and it's a lot less convenient to make them run from bottom to top rather than top to bottom.

I'm not sure why you don't want to use ListBox... do you need messages of different colors? IMO it is the situation that can prove the usage of listbox. You need the messages to scroll up, right? But actually that is how list box does it (depends on view point). All you need is to add a bit of blank ("") lines before the first message appeared. The next code I dug from my HD. I changed it a little to make it suitable for RPG scroll lists. Originally I used it for debug purposes.


ScrollBox script code:


//  Place those lines ontop of the Global Script:

int scroll_gui = -1;  // scroll box GUI number
int scroll_obj = -1;  // scroll box object num
int scroll_itm = -1;  // scroll box number of items which are visible
int scroll_top = -1;  // scroll box top visible item

// AGS 2.55 list box items limit (do not change)
#define AGS_LISTBOX_ITEMS_MAX 150

// resets the scroll box 'object' of 'num_items' on GUI 'gui'
function ScrollBoxReset(int gui, int object, int num_items) {

scroll_gui = gui;
scroll_obj = object;
scroll_itm = num_items;
scroll_top = 0;

ListBoxClear(scroll_gui, scroll_obj);
ListBoxSetSelected(scroll_gui, scroll_obj, -1);
ListBoxSetTopItem(scroll_gui, scroll_obj, scroll_top);

int i = scroll_top; while (i < scroll_itm) { ListBoxAdd(gui, object, ""); i++; }
}

// adds a new message
function ScrollBoxAdd(string message) {
 
 if (ListBoxGetNumItems(scroll_gui, scroll_obj) == AGS_LISTBOX_ITEMS_MAX)
                                ScrollBoxReset(scroll_gui ,scroll_obj, scroll_itm);
                 
 ListBoxAdd(scroll_gui, scroll_obj, message);
 scroll_top++;
 ListBoxSetTopItem(scroll_gui, scroll_obj, scroll_top);
 
}


// Now these go to Script Header:

import function ScrollBoxReset(int gui, int object, int num_items);
import function ScrollBoxAdd(string message);




Now a word about usage.
You make a gui and add listbox object ( checking Hide borders maybe )

Then place ScrollBoxReset() into game_start() function:

function game_start() {
 
 ScrollBoxReset(<gui>, <listbox_object>, <num_items>);

}

A note about num_items: it determines how many items to step out from top of the listbox. Just make sure that number is less than the maximum of visible listbox items.

Now whenever you need to add a message you use ScrollBoxAdd(string message);

// somewhere in the script:

ScrollBoxAdd("Skill rises to 10");


etc....

EDIT: Oh, if you want to prevent the player to select a listbox item you just uncheck GUI Clickable option.

QuoteIn case anyone's wondering, I'm coding a Baldur's Gate GUI set as a little side project and this is needed for it to look fairly authentic.
Very intresting project. Would be nice to see something like this made in AGS. Template maybe? :P


-Cheers

Interference

Thanks for the help, I'll give those suggestions a try. As it happens, I indeed do hope to release the BG GUI as a template, complete with funky icon to give it a vague semblance of professionalism. Not sure when I'll get to release it, thought. My home PC only has a 56k modem so it might take a while to upload (I'm currently using a Uni computer, which I won't have access to when the summer break begins).
-- Interference

"Wasting people's valuable time since 1984"


SMF spam blocked by CleanTalk