//
// smenu.h
//

int spiel_menu ( void )
{
  int i;
  char save[210*110];

  m_back_restore();
  /*set_pal_out(0, 225, 80);*/ show_smenu();
  m_back_save(); m_place();
  i = go_smenu();
//  LoadPalette("mr-005.dbl", pal); wait_vretrace(); SetPalette(pal); Set_Overscan_Color(0);
  if ( i == 2 ) Init_Spiel(0); 
  if ( i == 1 ) return 1;                                     // 1 = ende
  if ( i == 0 ) return 0;
  return 0;
}

void show_smenu( void )
{
  int i;

  fill_box(20, 50, 240, 160, 240); // das Men an sich
  memset(&VScreen[(50*320)+20] , 243, 220); // Men: helle Linie oben
  memset(&VScreen[(160*320)+20], 242, 221); // Men: dunkle Linie unten
  for (i=50; i<160; i++) { vsetpix(20, i, 243, res_x); vsetpix(240, i, 242, res_x); }

  fill_box(30, 55, 230, 64,  242); // Oberer grauer Balken
  write(100, 58, "Spiel-Menu", 255); write(99, 57, "Spiel-Menu", 229);
  memset(&VScreen[(55*320)+30], 189, 201); // Balken: dunkle Linie oben
  memset(&VScreen[(64*320)+30], 243, 201); // Balken: helle Linie oben
  for (i=56; i<64; i++) { vsetpix(30, i, 243, res_x); vsetpix(230, i, 189, res_x); }


  button_up(50, 70, 160, "spiel speichern");
  button_up(50, 85, 160, "spiel laden"); 
  button_up(50,100, 120, "einstellungen"); 
  button_up(50,144, 60, "ende"); 
  button_up(150,144, 60, "weiter"); 
  cpy2screen();
}

int go_smenu ( void )
{
  char c;

  while ( m_taste != 7 )                                  // sinnlose Abfrage
  {
    m_show_image= 1; maus_pos(); maus_show();

    if ( m_taste == 1 )
    {                                                    
      if ( maus_innen(150, 144, 210, 154) )                     // weiter
      {
        button_punch(150,144, 60, "weiter"); UpdateScreen(); return 0;
      }
      if ( maus_innen(50, 144, 110, 154) )                      // ende
      {
        button_punch(50,144, 60, "ende"); return 1;
      }
      if ( maus_innen(50, 70, 210, 80) )                        // speichern
      {
        button_punch(50, 70, 160, "spiel speichern");  
        save_game("save-001.dat", "1.Mission"); UpdateScreen(); return 0;
      }
      if ( maus_innen(50, 85, 210, 95) )                       // laden
      {
        button_punch(50, 85, 160, "spiel laden");
        cpy2screen();
        load_game("save-001.dat"); delay(700);
        return 2;
      }
      if ( maus_innen(50, 100, 210, 110) )
      {
        show_smenu_einstellung(); go_smenu_einstellung();
        show_smenu();
      }
    }

    m_back_restore();
    if ( maus_innen(50, 70, 210, 80) ) cbutton_up(50, 70, 160, "spiel speichern", 244);
    else button_up(50, 70, 160, "spiel speichern");

    if ( maus_innen(50, 85, 210, 95) ) cbutton_up(50, 85, 160, "spiel laden", 244);
    else button_up(50, 85, 160, "spiel laden");

    if ( maus_innen(50,100, 210,110) ) cbutton_up(50, 100, 160, "einstellungen", 244);
    else button_up(50,100, 160, "einstellungen");

    if ( maus_innen(50, 144, 140, 154) ) cbutton_up(50,144, 60, "ende", 244);
    else button_up(50,144, 60, "ende");

    if ( maus_innen(150, 144, 250, 154) ) cbutton_up(150,144, 60, "weiter", 244);
    else button_up(150,144, 60, "weiter");
    m_back_save(); m_place();

    if ( kbhit() )
    {
      c = getch();
      if ( c == 27 )
      {
        button_down(190,144, 60, "weiter"); wait_retrace(); cpy2screen(); delay(70);
        button_up(190,144, 60, "weiter"); wait_retrace(); cpy2screen(); delay(70);
        UpdateScreen(); return 0;
      }
    } 
    if ( screen_refresh ) cpy2screen(); 
  }
  return 0;
}

void show_smenu_einstellung( void )
{
  fill_box(60, 50, 270, 160, 0); draw_box(61, 51, 269, 159, 247);

  write(95, 69, "Spiel-Tempo", 243); cbutton_up(95, 75, 145, "", 243);
  cbutton_up(83, 75, 10, "-", 243); cbutton_up(242, 75, 11, "+", 243);
  write(95, 94, "Scroll-Tempo", 243); cbutton_up(95, 100, 145, "", 243);
  cbutton_up(83, 100, 10, "-", 243); cbutton_up(242, 100, 11, "+", 243);
  cbutton_up(75,144, 180, "Zurueck zu Optionen", 243); 
  
  cpy2screen();
}

int go_smenu_einstellung ( void )
{

  while ( m_taste != 7 )                                  // sinnlose Abfrage
  {
    m_show_image= 1; maus_pos(); maus_show();

    if ( m_taste == 1 )
    {
      if ( maus_innen(75, 144, 255, 154) )
      {
        button_punch(75,144, 180, "Zurueck zu Optionen");
        return 0;
      }
      if ( maus_innen(83, 75, 93, 85) )
      {
        button_punch(83, 75, 10, "-");
        if ( mann_del < 40 ) mann_del+=4;
      }
      if ( maus_innen(242, 75, 253, 85) )
      {
        button_punch(242, 75, 11, "+");
        if ( mann_del > 0 ) mann_del-=4;
      }
      if ( maus_innen(83, 100, 93, 110) )
      {
        button_punch(83, 100, 10, "-");
        if ( scroll_del < 11 ) scroll_del+=1;
      }
      if ( maus_innen(242, 100, 253, 110) )
      {
        button_punch(242, 100, 11, "+");
        if ( scroll_del > 0 ) scroll_del-=1;
      }
    }

    m_back_restore();
    if ( maus_innen(75, 144, 255, 154) ) cbutton_up(75,144, 180, "Zurueck zu Optionen", 244);
    else cbutton_up(75,144, 180, "Zurueck zu Optionen", 243);

    if ( maus_innen(83, 75, 93, 85) ) cbutton_up(83, 75, 10, "-", 244);
    else cbutton_up(83, 75, 10, "-", 243);

    if ( maus_innen(242, 75, 253, 85) ) cbutton_up(242, 75, 11, "+", 244);
    else cbutton_up(242, 75, 11, "+", 243);

    if ( maus_innen(83, 100, 93, 110) ) cbutton_up(83, 100, 10, "-", 244);
    else cbutton_up(83, 100, 10, "-", 243);

    if ( maus_innen(242, 100, 253, 110) ) cbutton_up(242, 100, 11, "+", 244);
    else cbutton_up(242, 100, 11, "+", 243);

    cbutton_up(95, 75, 145, "", 243); cbutton_up(95, 100, 145, "", 243);
    ccbutton_up(225-mann_del*3, 75, 11, "", 247, 244, 0);
    ccbutton_up(228-scroll_del*12,100, 11, "", 247, 244, 0);

    m_back_save(); m_place();
    cpy2screen();
  }
  return 0;
}
