[SOLVED] Save game dialog script (help needed)

Started by tor.brandt, Thu 10/11/2016 19:27:29

Previous topic - Next topic

tor.brandt

I am working on implementing a save game dialog in my game, but it turned out to be too difficult for my current scripting skill level.
Therefore I ripped the save game dialog script from the 9 VERB template, and pasted it into my own global script.
I am trying to get it to work with my own graphics, so the dimensions are a bit different than in the template, but I think I've got it corrected to fit my graphics.
Also, I changed the number of max save games from 99 to 19. I'm not presently able to decipher all of the code, so I'm not sure if I have caused some trouble anywhere in the script.
However, I have (at least) one problem still:
When I run the game, and select a slot in the save dialog that is already filled by a previous save game, the listbox text is not updated to match the text of the save textbox - this means that if I delete the save name in the textbox, the name is still visible "beneath" in the listbox, and whatever I type into the textbox is typed on top of the listbox text.
I've read through the script again and again, and I'm just not able to find where the problem is - but then again, I haven't been able to find where the listbox text should actually get its update from.

This is the relevant section from my global script:

Code: ags
int GStopsaveitem = 0;
int listBoxGap = 2;

function GetLucasSavegameListBox(ListBox* lb) {
  // stores savegames in slots
  String buffer, sgdesc;
  int maxsavegames, counter=0;
  maxsavegames=19;
  lb.Clear();
  while (counter<maxsavegames) {
    buffer=String.Format("%d.", counter + 1);
    sgdesc=Game.GetSaveSlotDescription(counter);
    if (sgdesc==null) sgdesc="";
    buffer=buffer.Append(sgdesc);
    lb.AddItem(buffer);
    counter++;
  }
  lb.TopItem=GStopsaveitem;
  lb.SelectedIndex=-1;
}

function btnSave_OnClick(GUIControl *control, MouseButton button)
{
  gOptions.Visible = false;
  GetLucasSavegameListBox(SaveListBox);
  gSave.Visible = true;
}

function Save_Click(GUIControl *control, MouseButton button) {
	int index = SaveListBox.SelectedIndex;
	String buffer;
	if (control==SaveCancel) {
		gSave.Visible=false;
		gSavetextbox.Visible=false;
    gOptions.Visible = true;
	}
	if (control==SaveOK && index >= 0) {
		buffer=SaveTextBox.Text;
		gSave.Visible=false;
		gSavetextbox.Visible=false;
		SaveGameSlot (index, buffer);
    gMainGUI.Visible = true;
    gActionText.Visible = true;
    mouse.Mode = eModeWalk;
    UnPauseGame();
	}
	if (control==SaveScrollUp) {
		gSavetextbox.Visible=false;
		SaveListBox.SelectedIndex=-1;
		if (GStopsaveitem < 5) GStopsaveitem = 0;
		else GStopsaveitem -= 5;
		SaveListBox.TopItem=GStopsaveitem;
	}
	if (control==SaveScrollDown && GStopsaveitem < 9) {
		gSavetextbox.Visible=false;
		SaveListBox.SelectedIndex=-1;
		GStopsaveitem += 5;
		SaveListBox.TopItem=GStopsaveitem;
	}
}

function SaveListBox_Click(GUIControl *control) {
  int saveBox_ypos;
  int saveBox_xpos;
 	int index = SaveListBox.SelectedIndex;

	String buffer = String.Format("%d.", index+1);
	SaveLabel.Text = buffer;
	buffer = Game.GetSaveSlotDescription(index);
	if (buffer==null) buffer="";
	SaveTextBox.Text = buffer;
	
  saveBox_ypos = gSave.Y + SaveListBox.Y + ((index - GStopsaveitem) * (GetTextHeight(SaveLabel.Text, SaveLabel.Font, SaveLabel.Width)+listBoxGap));
  saveBox_xpos = GetTextWidth(SaveLabel.Text, SaveLabel.Font);
  SaveTextBox.SetPosition(saveBox_xpos, 0);
  
  gSavetextbox.SetPosition(gSave.X + SaveListBox.X, saveBox_ypos);
	gSavetextbox.Visible=true;
}

function SaveTextBox_Click(GUI *theGui, MouseButton button) {
  if (mouse.IsButtonDown(eMouseRight)) gSavetextbox.Visible=false;  
}


Any help very much appreciated!

tor.brandt

No wait - So sorry, now I finally figured out what's wrong;
in the template the listbox selected text color is simply set to be the same as the selected background color, thus rendering the selected text invisible, whereas the textbox color is a different color.

Very clever. In fact so clever it took me many hours to figure it out.

SMF spam blocked by CleanTalk