home *** CD-ROM | disk | FTP | other *** search
/ Freelog 17 / Freelog017.iso / BeOS / ababelone / Sources / FenetreChangementDePartie.cpp < prev    next >
C/C++ Source or Header  |  2000-11-12  |  8KB  |  212 lines

  1. /*
  2.     Copyright (C) 2000 by Herv├⌐ PHILIPPE <rv@bemail.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public
  15.     License along with this library; if not, write to the Free
  16.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. #include "FenetreChangementDePartie.h"
  20.  
  21.   /////////////////////////////////////////////////
  22.  // CONSTRUCTEUR de "FenetreChangementDePartie" //
  23. /////////////////////////////////////////////////-----------------------------------------
  24. // Affiche la fen├¬tre permettant de choisir le type des joueurs (humain, ordinateur...) --
  25. //----------------------------------------------------------------------------------------
  26. FenetreChangementDePartie::FenetreChangementDePartie(BWindow* fenetre_abalone, uint8* tableau_joueurs, uint8* ptr_nombre_joueurs, TextesDuLogiciel* textes, bool nouvelle_partie)
  27. // 5 PARAMETRES :                                ENTREE/SORTIE (envoie message)        ENTREE/SORTIE            ENTREE/SORTIE                    ENTREE                    ENTREE
  28.     : BWindow(POSITION_FENETRE_NOUVELLE_PARTIE, LABEL_FENETRE_NOUVELLE_PARTIE, B_MODAL_WINDOW, B_NOT_CLOSABLE | B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
  29. {
  30.     BRect rect;
  31.     BRadioButton* radio_bouton;
  32.     char chaine[100];
  33.     int niveau;
  34.     int i;
  35.  
  36.     m_FenetreAbalone = fenetre_abalone;
  37.     m_TableauJoueurs = tableau_joueurs;
  38.     m_ptrNombreJoueurs = ptr_nombre_joueurs;
  39.     m_NombreJoueursSauvegarde = *m_ptrNombreJoueurs;
  40.     m_NouvellePartie = nouvelle_partie;
  41.     m_TableauJoueursSauvegarde = new uint8[NOMBRE_JOUEURS_MAXI];
  42.     for (i=0; i < NOMBRE_JOUEURS_MAXI; i++)
  43.         m_TableauJoueursSauvegarde[i] = m_TableauJoueurs[i];
  44.  
  45.     m_TableauGroupeJoueurs = new (BBox*)[NOMBRE_JOUEURS_MAXI];
  46.     if (NOMBRE_JOUEURS_MAXI == 2)
  47.         ResizeBy(150*NOMBRE_JOUEURS_MAXI, 20 * NIVEAU_MAXIMUM_ORDINATEUR - 30);
  48.     else
  49.         ResizeBy(150*NOMBRE_JOUEURS_MAXI, 20 * NIVEAU_MAXIMUM_ORDINATEUR);
  50.     rect = POSITION_GROUPE_JOUEURS;
  51.     rect.right += 150*NOMBRE_JOUEURS_MAXI;
  52.     rect.bottom += 20 * NIVEAU_MAXIMUM_ORDINATEUR;
  53.     if (NOMBRE_JOUEURS_MAXI == 2)
  54.         rect.bottom -= 30;
  55.     m_GroupeJoueurs = new BBox(rect,textes->Texte(31));
  56.     m_GroupeJoueurs->SetLabel(textes->Texte(31));
  57.     rect = POSITION_BOUTON_COMMENCER_PARTIE;
  58.     rect.top += 20 * NIVEAU_MAXIMUM_ORDINATEUR;
  59.     rect.bottom += 20 * NIVEAU_MAXIMUM_ORDINATEUR;
  60.     if (NOMBRE_JOUEURS_MAXI == 2) {
  61.         rect.top -= 30;
  62.         rect.bottom -= 30;
  63.     }
  64.     m_BoutonCommencer = new BButton(rect, textes->Texte(33), textes->Texte(33),
  65.                         new BMessage(MSG_COMMENCER_PARTIE), B_FOLLOW_ALL);
  66.     m_BoutonCommencer->MakeDefault(true);
  67.     rect.right = POSITION_BOUTON_ANNULER.right;
  68.     rect.left = POSITION_BOUTON_ANNULER.left;
  69.     m_BoutonAnnuler = new BButton(rect, textes->Texte(28), textes->Texte(28),
  70.                         new BMessage(MSG_ANNULER), B_FOLLOW_ALL);
  71.     m_Fond = new BView(Bounds(), "Fond", B_FOLLOW_ALL, B_WILL_DRAW);
  72.  
  73.     m_TableauBoutonsRadio = new (BRadioButton**)[NOMBRE_JOUEURS_MAXI];
  74.     for (i=0; i < NOMBRE_JOUEURS_MAXI; i++) {
  75.         m_TableauBoutonsRadio[i] = new (BRadioButton*)[NIVEAU_MAXIMUM_ORDINATEUR+1];    // +1 = HUMAIN
  76.         sprintf(chaine, "%s%d", textes->Texte(32), i+1);
  77.         rect = POSITION_GROUPE_JOUEUR1;
  78.         rect.left += 150 * i;
  79.         rect.right += 150 * i;
  80.         rect.bottom += 20 * NIVEAU_MAXIMUM_ORDINATEUR;
  81.         m_TableauGroupeJoueurs[i] = new BBox(rect,chaine);
  82.         m_TableauGroupeJoueurs[i]->SetLabel(chaine);
  83.         niveau = 0;
  84.         rect = POSITION_HUMAIN;
  85.         m_TableauBoutonsRadio[i][0] = new BRadioButton(rect, textes->Texte(24), textes->Texte(24), new BMessage(MSG_HUMAIN_JOUEUR1+256*i+niveau));
  86.         if (m_TableauJoueurs[i] == 0)
  87.             m_TableauBoutonsRadio[i][0]->SetValue(1);
  88.         m_TableauGroupeJoueurs[i]->AddChild(m_TableauBoutonsRadio[i][0]);
  89.  
  90.         for (niveau=1; niveau <= NIVEAU_MAXIMUM_ORDINATEUR; niveau++) {
  91.             rect.top += 20;
  92.             rect.bottom += 20;
  93.             sprintf(chaine, "%s %s %d", textes->Texte(25), textes->Texte(29), niveau);
  94.             m_TableauBoutonsRadio[i][niveau] = new BRadioButton(rect, chaine, chaine, new BMessage(MSG_HUMAIN_JOUEUR1+256*i+niveau));
  95.             if (m_TableauJoueurs[i] == niveau)
  96.                 m_TableauBoutonsRadio[i][niveau]->SetValue(1);
  97.             m_TableauGroupeJoueurs[i]->AddChild(m_TableauBoutonsRadio[i][niveau]);
  98.         }
  99.         m_GroupeJoueurs->AddChild(m_TableauGroupeJoueurs[i]);
  100.     }
  101.  
  102.     if (NOMBRE_JOUEURS_MAXI > 2)
  103.         for (i=0; i < NOMBRE_JOUEURS_MAXI-1; i++) {
  104.             rect = POSITION_RADIO_2JOUEURS;
  105.             rect.top += 20 * NIVEAU_MAXIMUM_ORDINATEUR;
  106.             rect.bottom += 20 * NIVEAU_MAXIMUM_ORDINATEUR;
  107.             rect.left += 70 * i;
  108.             rect.right += 70 * i;
  109.             sprintf(chaine, "%d %s", i+2, textes->Texte(30));
  110.             radio_bouton = new BRadioButton(rect, chaine, chaine, new BMessage(MSG_2JOUEURS+i));
  111.             m_GroupeJoueurs->AddChild(radio_bouton);
  112.             if (*m_ptrNombreJoueurs == 2 + i)
  113.                 radio_bouton->SetValue(1);
  114.  
  115.             if (nouvelle_partie == false)
  116.                 radio_bouton->SetEnabled(false);
  117.         }
  118.     GriserJoueurs();
  119.     m_Fond->AddChild(m_GroupeJoueurs);
  120.     m_Fond->AddChild(m_BoutonCommencer);
  121.     m_Fond->AddChild(m_BoutonAnnuler);
  122.     m_Fond->SetViewColor(216,216,216);
  123.     AddChild(m_Fond);
  124.     Show();
  125. }
  126.  
  127.   ////////////////////////////////////////////////
  128.  // DESTRUCTEUR de "FenetreChangementDePartie" //
  129. ////////////////////////////////////////////////-------
  130. // D├⌐truit les tableaux allou├⌐s dans le constructeur --
  131. //-----------------------------------------------------
  132. FenetreChangementDePartie::~FenetreChangementDePartie()
  133. // AUCUN PARAMETRE
  134. {
  135.     delete m_TableauGroupeJoueurs;
  136.     delete m_TableauJoueursSauvegarde;
  137. }
  138.  
  139.   ////////////////////////////////
  140.  // FONCTION "MessageReceived" //
  141. ////////////////////////////////--------------------------------------
  142. // Re├ºoit et traite tous les messages pour la gestion de la fen├¬tre --
  143. //--------------------------------------------------------------------
  144. void        // AUCUNE VALEUR DE RETOUR
  145. FenetreChangementDePartie::MessageReceived(BMessage* message)
  146. // 1 PARAMETRE :                                ENTREE
  147. {
  148.     int i;
  149.  
  150.     switch(message->what)
  151.     {
  152.         case MSG_COMMENCER_PARTIE:
  153.             if (m_FenetreAbalone->Lock()) {
  154.                 if (m_NouvellePartie == true)
  155.                     m_FenetreAbalone->PostMessage(MSG_COMMENCER_NOUVELLE_PARTIE);
  156.                 else
  157.                     m_FenetreAbalone->PostMessage(MSG_COMMENCER_PARTIE);
  158.                 m_FenetreAbalone->Unlock();
  159.             }
  160.         break;
  161.         case MSG_ANNULER:
  162.             for (i=0; i < NOMBRE_JOUEURS_MAXI; i++)
  163.                 m_TableauJoueurs[i] = m_TableauJoueursSauvegarde[i];
  164.             *m_ptrNombreJoueurs = m_NombreJoueursSauvegarde;
  165.             PostMessage(B_QUIT_REQUESTED);
  166.         break;
  167.         default:
  168.             for (i=0; i < NOMBRE_JOUEURS_MAXI; i++) {
  169.                 if (message->what >= uint32(MSG_HUMAIN_JOUEUR1+256*i) && message->what <= uint32(MSG_HUMAIN_JOUEUR1+256*i+NIVEAU_MAXIMUM_ORDINATEUR))
  170.                     m_TableauJoueurs[i] = message->what - MSG_HUMAIN_JOUEUR1-256*i;
  171.                 if (message->what == uint32(MSG_2JOUEURS+i)) {
  172.                     *m_ptrNombreJoueurs = 2 + i;
  173.                     GriserJoueurs();
  174.                 }
  175.             }
  176.         break;
  177.     }
  178.  
  179. }
  180.  
  181.   /////////////////////
  182.  // FONCTION "Quit" //
  183. /////////////////////-
  184. // Ferme la fen├¬tre --
  185. //--------------------
  186. void        // AUCUNE VALEUR DE RETOUR
  187. FenetreChangementDePartie::Quit()
  188. // AUCUN PARAMETRE
  189. {
  190.     BWindow::Quit();
  191. }
  192.  
  193.   //////////////////////////////
  194.  // FONCTION "GriserJoueurs" //
  195. //////////////////////////////-----------
  196. // Grise les joueurs qui ne jouent pas --
  197. //---------------------------------------
  198. void        // AUCUNE VALEUR DE RETOUR
  199. FenetreChangementDePartie::GriserJoueurs()
  200. // AUCUN PARAMETRE
  201. {
  202.     int i, niveau;
  203.     bool grise;
  204.  
  205.     for (i=0; i < NOMBRE_JOUEURS_MAXI; i++) {
  206.         grise = i < *m_ptrNombreJoueurs;
  207.         for (niveau=0; niveau <= NIVEAU_MAXIMUM_ORDINATEUR; niveau++)
  208.             m_TableauBoutonsRadio[i][niveau]->SetEnabled(grise);
  209.     }
  210. //m_ptrNombreJoueurs;
  211. }
  212.