Save screenshots in save games -General Settings

Started by AnasAbdin, Wed 17/09/2014 09:22:52

Previous topic - Next topic

AnasAbdin

I'm working on the interface of the game. I was trying to find a way to make a use of the "built-in" properties of the engine.
There is a 'Save screenshots in save games' option under the 'Saved Games' in General Settings. I wanted to know what exactly happens when I set it to 'true' and save a game.

Does it save a screenshot IN the savegame file itself? If so, how do I call it to display on a button for the restore GUI for instance?
I've looked in the customized savegame GUIs with screenshots but I didn't find what I am referring to. Does it have to be using dynamic sprites?? :-\

Thanks in advance :)

General info:
AGS 3.3.0
640x400 32bit

Crimson Wizard

#1
Yes, it does save it inside savegame.

You get it out using DynamicSprite.CreateFromSaveGame(int saveSlot, int width, int height). This function returns DynamicSprite object, or null, if there's no such savegame, or no screenshot available.

Example from the manual:
Code: ags

// at top of script, outside event functions
DynamicSprite *buttonSprite;  

// inside an event function
buttonSprite = DynamicSprite.CreateFromSaveGame(1, 50, 50);
if (buttonSprite != null) {
  btnScrnshot.NormalGraphic = buttonSprite.Graphic;
}

AnasAbdin

Thanks Crimson :)

I wrote the code and all, but I seem to have something missing (other than my brain).
I added this to the top of the global script:
Code: ags
DynamicSprite *buttonSprite;


The btnScrnshot belongs to the gRestoreGame GUI of course. I want it to show the savegame screenshot of the selected item in the restore game listbox.
So what I thought I should do is to add the display screenshot code to the restore listbox on selection event:

Code: ags
function lstRestoreGamesList_OnSelectio(GUIControl *control)
{
buttonSprite = DynamicSprite.CreateFromSaveGame(lstRestoreGamesList.SelectedIndex, 80, 140);
if (buttonSprite != null) {
  btnScrnshot.NormalGraphic = buttonSprite.Graphic;
  buttonSprite.Delete();
}
}


For some reason it doesn't work :-\

Crimson Wizard

Well, you delete buttonSprite right after assigning... NormalGraphic and Graphic properties are just numbers. They are used to reference existing dynamic sprite.
The line
Code: ags

btnScrnshot.NormalGraphic = buttonSprite.Graphic;

does not copy sprite. It sets NormalGraphic to your dynamic sprite's index.
But since you delete that sprite, it can't display anything.

AnasAbdin

Hmm.. I moved the delete to when the "Restore" or "Cancel" buttons are clicked.

It's working but the screenshots are different than the saved games!!
Can't figure out what to put for SLOT in:
Code: ags
buttonSprite = DynamicSprite.CreateFromSaveGame(SLOT, 140, 80);


Crimson Wizard

The "slot" is a savegame index, not the index from the list. List may have save slots in different order, or any custom entries.

If you fill the list manually, then you should convert list item into savegame slot manually as well.
If you filled the list with ListBox.FillSaveGameList(), then use ListBox.SaveGameSlots array to translate list index into save slot:

Code: ags

int save_slot = ListBox.SaveGameSlots[ListBox.SelectedIndex];

AnasAbdin

First of all thanks a lot for the explanations and sorry for the bother :-[
I'm getting a little lost in here:
Quote from: Crimson Wizard on Wed 17/09/2014 11:32:40If you fill the list manually, then you should convert list item into savegame slot manually as well.
If you filled the list with ListBox.FillSaveGameList(), then use ListBox.SaveGameSlots array to translate list index into save slot:

I did not create a list of any sort. I was trying to use the listbox(es) already existing in the save/restore GUIs.
But since you mentioned that the save index is not the same as the list index, I guess I'll have to.

where exactly should I create the list and manage to update it (if needed)?

Crimson Wizard

Quote from: AnasAbdin on Wed 17/09/2014 11:51:20
I did not create a list of any sort. I was trying to use the listbox(es) already existing in the save/restore GUIs.
But since you mentioned that the save index is not the same as the list index, I guess I'll have to.

where exactly should I create the list and manage to update it (if needed)?
I guess you are using some template that has these lists then? There's no need to create anything new (unless you want to).
What template is it? It does fill the list somehow. There might already be a call to FillSaveGameList() somewhere in scripts.

If there is, simply change your script this way:
Code: ags

int save_slot = lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex];
buttonSprite = DynamicSprite.CreateFromSaveGame(save_slot, 140, 80);

AnasAbdin

Yeah I used the default game template.
The code worked like a charm thanks ;)

I still get the savegame GUI in the screenshot though >:(

Khris

Instead of saving the game right away, hide the GUI, call Wait(1) then save the game.

AnasAbdin

#10
Thanks Khris 8-)

Here's the whole thing in a tidy way -I hope- for the general public!

AGS 3.3.0
640x400 32bit
Default Game Template


First thing, in the General Settings under 'Saved Games' set the 'Save screenshots in save games': True

In the gRestoreGame I added a button (140x88) right under the 'Cancel' button and named it: btnScrnshot
lstRestoreGamesList is the ListBox containing the saved games.
In the 'OnSelectionChanged' event of the lstRestoreGamesList I added this piece of code:
Code: ags
function lstRestoreGamesList_OnSelectio(GUIControl *control)
{
  int save_slot = lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex];
  buttonSprite = DynamicSprite.CreateFromSaveGame(save_slot, 140, 88);
  if (buttonSprite != null) {
    btnScrnshot.NormalGraphic = buttonSprite.Graphic;
  }
}


top of Global Script:
Code: ags
DynamicSprite *buttonSprite;


In the OnClick events of both the Restore button btnRestoreGame and the Cancel button btnCancelRestore:
Code: ags
if (buttonSprite != null) {
  buttonSprite.Delete();
}


In the Save button btnSaveGame:
Code: ags
//Hiding all GUIs from the screenshot
close_save_game_dialog();
gStatusline.Visible = false;
Wait(1);
//Save the game
SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text);
//Show whatever GUIs your game design require...
gStatusline.Visible = true;


SMF spam blocked by CleanTalk