Is there anyway to make you own custom GUI for when you save or load a game. That gray background is pretty boring. Anyone?
:P
Well, if you want something that works the same way as the default GUI, but want a different look, you could try this:
Make two new GUIs. Give one the name SAVE, and name the other one LOAD (make sure both names are in all caps). Change the dimensions of both GUIs so that they are big enough to work with (you can change them later). Go to the SAVE GUI, and add the following objects in this exact order:
0. Button (for the "ok" button)
1. Button (for the "cancel" button)
2. List Box (for the list of saved games)
3. Text Box (to enter the name of saved files)
The objects have to be in that exact order, or else you'll have to go inand change all the numbers in the script .
Now go to the LOAD GUI, and add the following:
0. Button (for the "ok" button)
1. Button (for the "cancel" button)
2. List Box (for the list of saved games)
Now click "Edit Script", and put the following at the end of the GUI script:
//INTERFACE 3 - SAVE GAME
if (interface == SAVE) {
// List element was clicked, copy selected item's text to the TextBox
if (button==2) {
bg_save_idx = ListBoxGetSelected(SAVE,2);
ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
if (StrComp(bg_save_buf,"<new>")==0) StrCopy(bg_save_buf,"");
SetTextBoxText(SAVE,3,bg_save_buf);
}
// SAVE button was pressed, save the game
else if (button==0) {
SetRestartPoint(); // Restart here
bg_save_idx=ListBoxGetSelected(SAVE,2); // Save game in new save game slot
ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
if (StrComp(bg_save_buf,"<new>")==0) {
bg_save_slot = ListBoxGetNumItems(SAVE,2);
GetTextBoxText(SAVE,3,bg_save_buf);
if (StrComp(bg_save_buf,"")==0) StrFormat(bg_save_buf,"Game-%d",bg_save_slot);
}
else { // Over-write an existing save game
bg_save_slot=savegameindex[bg_save_idx]; // slot with name from textbox.
GetTextBoxText(SAVE,3,bg_save_buf);
if (StrComp(bg_save_buf,"")==0) ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
}
GUIOff(SAVE); // Close dialog amd return
//TURN ON NORMAL GAME GUIs HERE
SaveGameSlot(bg_save_slot, bg_save_buf); // Perform save operation last otherwise
//Display("Saved as: %s", bg_save_buf); // SAVE dialog will be active on restore
}
// CANCEL button was pressed, cancel operation
else if (button==1) {
GUIOff(SAVE); // Close dialog and return
//TURN ON NORMAL GAME GUIs HERE
}
}
//INTERFACE 4 - RESTORE GAME
if (interface == LOAD) {
// CANCEL button was pressed, cancel operation
if (button==1) {
GUIOff(LOAD); // Close dialog and return
//TURN ON NORMAL GAME GUIs HERE
}
// RESTORE button was pressed, restore the game
else if (button==0) {
bg_restore_idx=ListBoxGetSelected(LOAD,2); // Perform save operation
if (bg_restore_idx==-1) { // No selection, nothing to restore
Display("Please make a slection first...");
}
else // Ok continue restoring game
{
ListBoxGetItemText(LOAD,2,bg_restore_idx,bg_restore_buf);
RestoreGameSlot(savegameindex[bg_restore_idx]);
//Display("Restored from: %s",bg_restore_buf);
PaletteSat(100, 0, 0, 0, 0, 245);
GUIOff(LOAD);
}
}
Almost done..
From the "Script" menu, select on_key_press. When you find this line:
if (keycode==363) SaveGameDialog();
Delete it, and replace it with this:
if (keycode==363) {
ListBoxSaveGameList(SAVE,2); // Populate listbox with previous saves
bg_save_idx = ListBoxGetNumItems(SAVE,2);
if (bg_save_idx <= 20) { // Less than max saves
ListBoxAdd(SAVE,2,"<new>");
}
else { // Max number of saves exceeded
bg_save_idx = 0; // Setup overwrite of existing slot
ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
}
ListBoxSetSelected(SAVE,2,bg_save_idx);
ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
if (StrComp(bg_save_buf,"<new>")==0) StrCopy(bg_save_buf,"");
SetTextBoxText(SAVE,3,bg_save_buf); // Setup text entry box
//CLOSE NORMAL GAME GUIs HERE
GUIOn(SAVE);
} // F5
And when you see this line:
if (keycode==365) RestoreGameDialog();
Delete it and replace it with this:
if (keycode==365) {
GUIOff(0);
GUIOn(LOAD);
ListBoxSaveGameList(SAVE,2);
} // F7
Now you can import your own graphics and change the appearance of the two dialogs in the GUI editor.
That GUI script is from RickJ's BlueGUI, by the way, with just a few changes by me.. Remember to give him credit, if yu decide to use this.
I know this looks complicated (okay, it is :P ), but feel free to ask here if you have any more questions..
Error (line 35): Undefined token 'bg_save_idx'
Did I do something wrong here?
function on_key_press(int keycode) {
Ã, // called when a key is pressed. keycode holds the key's ASCII code
Ã, if (IsGamePaused() == 1) keycode=0;Ã, // game paused, so don't react to keypresses
Ã, if (keycode==17)Ã, QuitGame(1);Ã, Ã, // Ctrl-Q
if (keycode==363) {
Ã, Ã, Ã, ListBoxSaveGameList(SAVE,2); // Populate listbox with previous saves
Ã, Ã, Ã, bg_save_idx = ListBoxGetNumItems(SAVE,2);
Ã, Ã, Ã, if (bg_save_idx <= 20) {Ã, Ã, Ã, Ã, Ã, Ã, // Less than max saves
Ã, Ã, Ã, Ã, ListBoxAdd(SAVE,2,"<new>");
Ã, Ã, Ã, }
Ã, Ã, Ã, else {Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, // Max number of saves exceeded
Ã, Ã, Ã, Ã, bg_save_idx = 0;Ã, Ã, Ã, Ã, Ã, Ã, Ã, Ã, // Setup overwrite of existing slot
Ã, Ã, Ã, Ã, ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
Ã, Ã, Ã, }
Ã, Ã, Ã, ListBoxSetSelected(SAVE,2,bg_save_idx);
Ã, Ã, Ã, ListBoxGetItemText(SAVE,2,bg_save_idx,bg_save_buf);
Ã, Ã, Ã, if (StrComp(bg_save_buf,"<new>")==0) StrCopy(bg_save_buf,"");
Ã, Ã, Ã, SetTextBoxText(SAVE,3,bg_save_buf); // Setup text entry box
Ã, Ã, Ã, //CLOSE NORMAL GAME GUIs HERE
Ã, Ã, Ã, GUIOn(SAVE);
Ã, }Ã, Ã, // F5
Ã, Ã, if (keycode==365) {
Ã, Ã, Ã, GUIOff(0);
Ã, Ã, Ã, GUIOn(LOAD);Ã, Ã, Ã, Ã,Â
Ã, Ã, Ã, ListBoxSaveGameList(SAVE,2);
Ã, }Ã, // F7
Ã, if (keycode==367) RestartGame();Ã, // F9
Ã, if (keycode==434) SaveScreenShot("scrnshot.bmp");Ã, // F12
Ã, if (keycode==9)Ã, Ã, show_inventory_window();Ã, // Tab, show inventory
Ã, if (keycode==27) {
Ã, Ã, if (IsGUIOn(1)==0) GUIOn(1);
Ã, Ã, else GUIOff(1);
Ã, if (keycode==19)Ã, Debug(0,0);Ã, // Ctrl-S, give all inventory
Ã, if (keycode==22)Ã, Debug(1,0);Ã, // Ctrl-V, version
Ã, if (keycode==1)Ã, Ã, Debug(2,0);Ã, // Ctrl-A, show walkable areas
Ã, if (keycode==24)Ã, Debug(3,0);Ã, // Ctrl-X, teleport to room
}
Ã, }
There are some variables in the script that haven't been declared. You can declare them at the top of the global script but I'd recommend to consult the BlueGui script to check: http://www.gaia-spa.com/blusoft/Download/download.html
// main global script
int bg_save_idx, bg_save_slot, bg_restore_idx;
string bg_restore_buf, bg_save_buf;
Sorry for reviving this topic but Ben's script gave me this error:
---------------------------
Adventure Game Studio
---------------------------
An error has occured. Please contact the game author for support, as this
is likely to be a scripting error and not a bug in AGS.
(ACI version 2.61.747)
(Global script line 273)
Error: ListBoxGetItemText: invalid item specified
---------------------------
OKÃ, Ã,Â
---------------------------
EDIT: I now used the ones Ben specified. Anything wrong?
i had the same problem as edwin
Error: ListBoxGetItemText: invalid item specified
i dont know how to fix it and i did not understand his edit.
Someone that knows the GUI should make one up for us that get lost in space working on a GUI .
You could give BlueGui a try. Just follow the link im my signature line below or click here: BluSoft.tk (http://blusoft.tk). It is pretty much the classic Sierra interface. The sprites can simply be replaced with ones of your own design.
There are also quite a few GUI templates by Rui Pires on his website skimbleshanks (http://www.freewebs.com/skimbleshanks/).
i dont understand the blue GUI thing as its for my course work i have to explain the scripting as wellas i dont want to loos my other GUIs i have already made.
i tried just removing the offening line but then the saves do not go into the list box on my GUIS but do on the defult save/load.
just a reminder of the error
Error: ListBoxGetItemText: invalid item specified
Quote
ListBoxGetItemText: invalid item specified
It means that the "item" parameter, in ListBoxGetItemText (int gui, int object, int item, string buffer), is pointing to something that doesn't exist. For example if item is equal to 5 and there are only 3 items in the list you will get this error. Your program will first need to validate the item number using ListBoxGetNumItems (int gui, int object).
Here is an example of how I did it.
//=========================================================================
// SAVE GAME DIALOG - The following functions implement the Save Game
// interface. The SAVE GAME dialog is normally activated via a user
// click on the ICON BAR.
//
// bgSave(state)
// This function opens the dialog box and performs the operations initiated
// by controls within the dialog box.
//
// state - This parameter determines the behavior of dialog as follows:
// DIALOG - Open the Save dialog box
// CANCEL - Close dialog box without performing any operation
// OK - Save the selected game slot
// LIST - Get user selection from listbox
//
//=========================================================================
string bg_save_buf; // text buffer
int bg_save_idx; // index
int bg_save_slot; // save game id
function bgSave(int state) {
// SAVE icon was pressed, open dialog
if (state==DIALOG) {
bgCursor(POINTER);
GUIOff(bgICON_BAR);
GUIOn(bgSAVE_DLG);
GUIOff(bgDEBUG_DLG);
ListBoxSaveGameList(bgSAVE_DLG,bgSAVE_LIST); // Populate listbox with previous saves
bg_save_idx = ListBoxGetNumItems(bgSAVE_DLG,bgSAVE_LIST);
if (bg_save_idx <= 20) { // Less than max saves
ListBoxAdd(bgSAVE_DLG,bgSAVE_LIST,"<new>");
}
else { // Max number of saves exceeded
bg_save_idx = 0; // Setup overwrite of existing slot
ListBoxGetItemText(bgSAVE_DLG,bgSAVE_LIST,bg_save_idx,bg_save_buf);
}
ListBoxSetSelected(bgSAVE_DLG,bgSAVE_LIST,bg_save_idx);
ListBoxGetItemText(bgSAVE_DLG,bgSAVE_LIST,bg_save_idx,bg_save_buf);
if (StrComp(bg_save_buf,"<new>")==0) StrCopy(bg_save_buf,"");
SetTextBoxText(bgSAVE_DLG,bgSAVE_TEXT,bg_save_buf); // Setup text entry box
}
// List element was clicked, copy selected item's text to the TextBox
else if (state==LIST) {
bg_save_idx = ListBoxGetSelected(bgSAVE_DLG,bgSAVE_LIST);
ListBoxGetItemText(bgSAVE_DLG,bgSAVE_LIST,bg_save_idx,bg_save_buf);
if (StrComp(bg_save_buf,"<new>")==0) StrCopy(bg_save_buf,"");
SetTextBoxText(bgSAVE_DLG,bgSAVE_TEXT,bg_save_buf);
}
// SAVE button was pressed, save the game
else if (state==OK) {
SetRestartPoint(); // Restart here
bg_save_idx=ListBoxGetSelected(bgSAVE_DLG,bgSAVE_LIST); // Save game in new save game slot
ListBoxGetItemText(bgSAVE_DLG,bgSAVE_LIST,bg_save_idx,bg_save_buf);
if (StrComp(bg_save_buf,"<new>")==0) {
bg_save_slot = ListBoxGetNumItems(bgSAVE_DLG,bgSAVE_LIST);
GetTextBoxText(bgSAVE_DLG,bgSAVE_TEXT,bg_save_buf);
if (StrComp(bg_save_buf,"")==0) StrFormat(bg_save_buf,"Game-%d",bg_save_slot);
}
else { // Over-write an existing save game
bg_save_slot=savegameindex[bg_save_idx]; // slot with name from textbox.
GetTextBoxText(bgSAVE_DLG,bgSAVE_TEXT,bg_save_buf);
if (StrComp(bg_save_buf,"")==0) ListBoxGetItemText(bgSAVE_DLG,bgSAVE_LIST,bg_save_idx,bg_save_buf);
}
GUIOff(bgSAVE_DLG); // Close dialog amd return
GUIOn(bgICON_BAR); // to normal interface
if (bg_debug_flag==1) GUIOn(bgDEBUG_DLG);
SaveGameSlot(bg_save_slot, bg_save_buf); // Perform save operation last otherwise
Display("Saved as: %s", bg_save_buf); // SAVE dialog will be active on restore
bgCursor(DEFAULT);
}
// CANCEL button was pressed, cancel operation
else if (state==CANCEL) {
GUIOff(bgSAVE_DLG); // Close dialog and return
GUIOn(bgICON_BAR); // to normal interface
if (bg_debug_flag==1) GUIOn(bgDEBUG_DLG);
bgCursor(DEFAULT);
}
}
//=========================================================================
// RESTORE GAME DIALOG - The following routines implement restore game
// interface. The RESTORE GAME dialog is normally activated via a user
// click on the ICON BAR.
//
// bgRestore(state)
// This function opens the dialog box and performs the operations initiated
// by controls within the dialog box.
//
// state - This parameter determines the behavior of dialog as follows:
// DIALOG - Open the Restore dialog box
// CANCEL - Close dialog box without performin any operation
// OK - Restore the selected game slot
// LIST - Get user selection from listbox
//
//=========================================================================
string bg_restore_buf; // text buffer
int bg_restore_idx; // index
function bgRestore(int state) {
// RESTORE icon was pressed, open dialog
if (state==DIALOG) {
bgCursor(POINTER);
GUIOff(bgICON_BAR);
GUIOn(bgRESTORE_DLG);
ListBoxSaveGameList(bgRESTORE_DLG,bgRESTORE_LIST);
}
// CANCEL button was pressed, cancel operation
else if (state==CANCEL) {
GUIOff(bgRESTORE_DLG); // Close dialog and return
if (bg_intro_flag==0) GUIOn(bgICON_BAR); // to normal interface
bgCursor(DEFAULT);
}
// RESTORE button was pressed, restore the game
else if (state==OK) {
bg_restore_idx=ListBoxGetSelected(bgRESTORE_DLG,bgRESTORE_LIST); // Perform save operation
if (bg_restore_idx==-1) { // No selection, nothing to restore
Display("Please make a slection first...");
}
else // Ok continue restoring game
{
ListBoxGetItemText(bgRESTORE_DLG,bgRESTORE_LIST,bg_restore_idx,bg_restore_buf);
RestoreGameSlot(savegameindex[bg_restore_idx]);
Display("Restored from: %s",bg_restore_buf);
GUIOff(bgRESTORE_DLG);
GUIOn(bgICON_BAR);
bgCursor(DEFAULT);
}
}
// LIST box was clicked
else if (state==LIST) {
// nothing to do
}
}
:
:
function interface_click(int interface, int object) {
// Executed when user clicks a GUI object
:
:
// SAVE DIALOG
else if (interface==bgSAVE_DLG) {
if (object==bgSAVE_LIST) bgSave(LIST);
else if (object==bgSAVE_TEXT) bgSave(OK);
else if (object==bgSAVE_OK) bgSave(OK);
else if (object==bgSAVE_CANCEL) bgSave(CANCEL);
}
// RESTORE DIALOG
else if (interface==bgRESTORE_DLG) {
if (object==bgRESTORE_LIST) bgRestore(LIST);
else if (object==bgRESTORE_OK) bgRestore(OK);
else if (object==bgRESTORE_CANCEL) bgRestore(CANCEL);
}
// BROWSE FILES
else if (interface==bgBROWSE_FILES) {
if (object==bgBROWSE_FILES_CLOSE) bgBrowse(CLOSE,"","");
else if (object==bgBROWSE_FILES_LIST) bgBrowse(LIST,"","");
}
// BROWSE TEXT on transparent background
else if (interface==bgBROWSE_TRANS) {
bgBrowse(CLOSE,"","");
}
else if (interface==bgDEBUG_QUERRY) {
if (object==bgDEBUG_TEXT) bg_debug_input();
}
}
I'm sorry if you find the above confusing but there are no short cuts in making a proper GUI. This code is thorough and as simple as I know how to make it. There are lots of things to keep track of and lots of things that can go wrong. That's why we try to disuade people from rolling their own GUI the first time out with AGS. Cheers.
thanks for all your help but were abouts do i put it in the script editor thank you again for yor help.
Well, just from looking at the script I can already tell it belongs in the game's global script. How do I know? Because it has custom functions, which can only be called from the main script. In this case, the game's global script would be the best choice.