// Version 1.00 24/03/97  First full release.


int hints_handle;
int hints_status = 0;
int hints_start;
int hints_number;
int hints_total;
string hints_choicespath;


// read choices

void hints_readchoices(void)
{
 int h;
 string s;

 h = fileopen(hints_choicespath, "rb");
 if(h)
 {
  hints_number = filegetc(h);
  hints_start = filegetc(h);
  fileclose(h);
 }
 else
 {
  hints_number = 0;
  hints_start = 1;
 }
}


// write choices

void hints_quit(int user)
{
 int h;

 h = fileopen(hints_choicespath, "wb");
 if(h)
 {
  fileputc(hints_number, h);
  fileputc(hints_start, h);
  fileclose(h);
 }
}


// display the next hint

void hints_message(void)
{
 string s;

 if(++hints_number > hints_total)
  hints_number = 1;
 s = "{HINTS_" + itos(hints_number) + "}";
 translate(s);
 writeicon(hints_handle, 0, "");;
 refresh_icon(0, hints_handle, 0);
 writeicon(hints_handle, 0, s);;
}


// deal with 'Hints' menu entry

int hints_entry(int entry, int subcode)
{
 hints_status = !hints_status;
 if(hints_status)
 {
  display_window(hints_handle, 0, 1);
  hints_message();
 }
 else
  close_window(hints_handle);

 return(0);
}


// tick or un-tick 'Hints' menu entry

int hints_flags(int entry, string &text)
{
 return(hints_status);
}


// handler for mouse clicks in hints box

void hints_clicknext(int handle,int icon,int bits,int mx,int my)
{
 if(icon == 4)
  hints_message();
 if(icon == 5)
  hints_start = !hints_start;
}


// handler for hints window close icon

void hints_closebox(int handle)
{
 close_window(handle);
 hints_status = 0;
}


// create 'Hints' window, read max number of hints and display hint

void main(void)
{
 string s;

 script_menu_initialise();

 hints_choicespath = "OvationPro$AppletsDir";
 getenvs(hints_choicespath);
 hints_choicespath += ".!Hints.Choices";

 addentry_menu(script_handle,"hints_entry","hints_flags","","","{HINTS_00}");

 hints_handle = create_window("hints_main");
 addwindowhandler(0,hints_handle,"hints_clicknext");
 addwindowhandler(2,hints_handle,"hints_closebox");

 addeventhandler(0x004, 0, "hints_quit");

 s = "{HINTS_TOTAL}";
 translate(s);
 hints_total = stoi(s);

 hints_readchoices();
 select_icon(hints_handle, 5, hints_start);
 if(hints_start)
 {
  display_window(hints_handle, 0, 1);
  hints_message();
  hints_status = 1;
 }
}
