home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 51 / PCGamer51_17Demos.iso / games / CM / CyclingManagerDemoCangas.exe / CyclingManagerDemo / scripts / inrace / panel_inrace_chat.cnc < prev    next >
Text File  |  2001-07-05  |  9KB  |  329 lines

  1. // Check box State func
  2. func void Chat_TeamCheckbox (i32x _iComponentID,i32x _iState)
  3. {
  4.     if(_iState & GUI_State_Enabled)
  5.     {
  6.         if(_iState & GUI_State_Checked)
  7.             SetContainerSprite(_iComponentID, 1, 0);
  8.         else
  9.             SetContainerSprite(_iComponentID, 0, 0);
  10.     }
  11.     else
  12.     {
  13.         SetContainerSprite(_iComponentID, 0, 0);
  14.     }
  15.     if(_iState & GUI_State_UnderMouse)
  16.     {
  17.         if(strcmp(GetContainerText(oPanelInraceChat.iHelp),oPanelInraceChat.szTeamHelp[GetContainerHelpIndex(_iComponentID)]) !=0 )
  18.             SetContainerText(oPanelInraceChat.iHelp,oPanelInraceChat.szTeamHelp[GetContainerHelpIndex(_iComponentID)]);
  19.     }
  20.     else
  21.     {
  22.         if(!strcmp(GetContainerText(oPanelInraceChat.iHelp),oPanelInraceChat.szTeamHelp[GetContainerHelpIndex(_iComponentID)]) )
  23.         {
  24.             SetContainerText(oPanelInraceChat.iHelp,"");
  25.         }
  26.     }
  27. }
  28.  
  29.  
  30. //panel inrace chat
  31. func void Panel_Inrace_Chat_Create()
  32. {
  33.     SetComponentNumber(56);
  34.     
  35.     var i32x iID,bUser,boucle,iPosY,iPosX,iTeamID,iUserID;
  36.     var szx szTmp;
  37.  
  38.     // Save context
  39.     oPanelInraceChat.pThis=GetParserComponent();
  40.  
  41.     // Chat background
  42.     iID=Init_LibObject_FilledCadre(tCadreDialbox,500,300);
  43.     SetEvents(iID,GUI_NoEvent);
  44.     
  45.     boucle=0;
  46.     iPosX = 15;
  47.     iPosY = 45;
  48.  
  49.     iID = InitContainer(tFontArialItalique);
  50.     SetEvents(iID,GUI_NoEvent);
  51.     SetContainerText(iID,"");
  52.     SetComponentPosition(iID,5,235);
  53.     SetComponentSize(iID,430,16);
  54.     oPanelInraceChat.iHelp=iID;
  55.  
  56.     //crΘation de la liste de toutes les Θquipes    
  57.     while (boucle<20)
  58.     {
  59.         // TeamID ?
  60.         iTeamID = Join_GetIntFromSortedIndex(g_stInraceJoins.m_jTeam_iId,boucle);
  61.         // Team help string
  62.         iUserID = Join_GetIntFromKey(g_oMenuJoins.m_iTeam_iUserID,iTeamID);
  63.         if(iUserID > 0)
  64.         {
  65.             // Is user connected ?
  66.             if(Join_GetIntFromKey(g_oMenuJoins.m_jUser_iConnected,iUserID)==1)
  67.             {
  68.                 // User connected
  69.                 szTmp = Join_GetStringFromKey(g_oMenuJoins.m_jUser_szPseudo,iUserID);
  70.                 szTmp = strcat("[",szTmp);
  71.                 szTmp = strcat(szTmp,"]");
  72.                 bUser = true;
  73.                 oPanelInraceChat.szTeamHelp[boucle] = strcat(szTmp,Join_GetStringFromKey(g_oMenuJoins.m_iTeamName,iTeamID));
  74.             }
  75.             else
  76.             {
  77.                 // User not connected
  78.                 bUser = false;
  79.                 oPanelInraceChat.szTeamHelp[boucle] = Join_GetStringFromKey(g_oMenuJoins.m_iTeamName,iTeamID);
  80.             }
  81.         }
  82.         else
  83.         {
  84.             // CPU team
  85.             bUser = false;
  86.             oPanelInraceChat.szTeamHelp[boucle] = Join_GetStringFromKey(g_oMenuJoins.m_iTeamName,iTeamID);
  87.         }
  88.  
  89.         // Checkbox
  90.         iID=InitCheckBox(tBtnChat);
  91.         SetContainerStateFunc(iID,Chat_TeamCheckbox);
  92.         SetContainerHelpIndex(iID,boucle);
  93.         SetComponentPosition(iID,iPosX,iPosY);
  94.         oPanelInraceChat.iTeamButton[boucle]=iID;
  95.         SetContainerSize(iID,20,15);
  96.         SetEvents(iID,GetEvents(iID) | GUI_MouseDblClick);
  97.         SetStackEvents(iID,GUI_MouseDblClick);
  98.         SetCheckboxState(iID,1);            
  99.         
  100.         // team name
  101.         iID=InitContainer(tFontArial);
  102.         SetComponentPosition(iID,iPosX+20,iPosY);
  103.         SetContainerText(iID,Join_GetStringFromSortedIndex(g_stInraceJoins.m_jTeam_szAbrev,boucle));
  104.         SetContainerScale(iID,0.90,0.90);
  105.         oPanelInraceChat.iTeamName[boucle]=iID;
  106.         SetEvents(iID,GetEvents(iID) | GUI_MouseDblClick);
  107.         SetStackEvents(iID,GUI_MouseDblClick);
  108.         ResizeComponent(iID);
  109.         if(bUser)
  110.             SetContainerColor(iID,c_Red);
  111.         else
  112.             SetContainerColor(iID,c_White);
  113.  
  114.  
  115.         boucle=boucle+1;
  116.         if((boucle%3)==0)
  117.         {
  118.             iPosX = iPosX + 65;
  119.             iPosY = 45;
  120.         }
  121.         else
  122.         {
  123.             iPosY = iPosY + 15;
  124.         }
  125.     }
  126.  
  127.     //set player team active 
  128.     SetCheckboxState(oPanelInraceChat.iTeamButton[g_oUser.m_iMyInRaceTeamID],1);
  129.  
  130.     
  131.     // Slider background
  132.     iID=InitContainer(tCommonTableBorder);
  133.     SetContainerColor(iID,c_TitleList);
  134.     SetContainerSize(iID,20,98);
  135.     SetComponentPosition(iID,430-20,105);
  136.     
  137.     //crΘation de la fenΩtre de chat
  138.     oPanelInraceChat.iChatWindow=InitList(
  139.                 "Chat List", // List name
  140.                 oPanelInraceChat.iMaxListItems, // Max item number
  141.                 425,98, // Width, height
  142.                 Chat_List_Item_Create,Chat_List_Item_Update,Chat_List_Item_Event, // Item oFunc
  143.                 t_btn_slider, // Slider texture
  144.                 NullButtonState);    // State func for the slider
  145.  
  146.     SetComponentPosition(oPanelInraceChat.iChatWindow,5,105);
  147.  
  148.     // Border line
  149.     // Horizontal line
  150.     iID = InitContainer(tCommonTableBorder);
  151.     SetContainerSize(iID,425,1);
  152.     SetComponentPosition(iID,5,105);
  153.     iID = InitContainer(tCommonTableBorder);
  154.     SetContainerSize(iID,425,1);
  155.     SetComponentPosition(iID,5,105+98);
  156.  
  157.     // Vertical line
  158.     iID = InitContainer(tCommonTableBorder);
  159.     SetContainerSize(iID,1,98);
  160.     SetComponentPosition(iID,5,105);
  161.     iID = InitContainer(tCommonTableBorder);
  162.     SetContainerSize(iID,1,98);
  163.     SetComponentPosition(iID,430-20,105);
  164.     iID = InitContainer(tCommonTableBorder);
  165.     SetContainerSize(iID,1,98);
  166.     SetComponentPosition(iID,430,105);
  167.  
  168.     //crΘation  de la ligne  de commande
  169.  
  170.     // background
  171.     iID = InitContainer(t_Common_Color_White);
  172.     SetContainerColor(iID,c_ListSelection);
  173.     SetContainerSize(iID,430,16);
  174.     SetComponentPosition(iID,5,215);
  175.  
  176.     iID = InitEditBox(tFontArial,196);
  177.     SetContainerText(iID,"");
  178.     SetComponentPosition(iID,5,215);
  179.     SetComponentSize(iID,430,16);
  180.     oPanelInraceChat.iCommandLine=iID;
  181.  
  182.     SetListNbItems(oPanelInraceChat.iChatWindow,oPanelInraceChat.iNbListItems);
  183.  
  184.     SetSelectedComponent(oPanelInraceChat.iCommandLine);
  185.  
  186.     SetObjectSize(450,230);        
  187. }
  188.  
  189. func void Panel_Inrace_Chat_InitMembers ()
  190. {
  191.     oPanelInraceChat.iMaxListItems = 50;
  192.     oPanelInraceChat.iNbListItems = 0;
  193.     oPanelInraceChat.iCursor = 0;
  194.     oPanelInraceChat.oFunc.pcreate=Panel_Inrace_Chat_Create;
  195.     oPanelInraceChat.oFunc.pevent=Panel_Inrace_Chat_Event;
  196. }
  197.  
  198.  
  199. //ajout d'un message α la liste de tous les messages
  200. func void Panel_Inrace_Chat_Update(szx szText)
  201. {
  202.     if (oPanelInraceChat.iMaxListItems==0)
  203.     {
  204.         Panel_Inrace_Chat_InitMembers ();
  205.     }
  206.  
  207.     oPanelInraceChat.szChatTab[oPanelInraceChat.iCursor] = szText;
  208.     oPanelInraceChat.iChatJustified[oPanelInraceChat.iCursor] = 0;
  209.  
  210.     oPanelInraceChat.iCursor = oPanelInraceChat.iCursor + 1;
  211.     oPanelInraceChat.iCursor = oPanelInraceChat.iCursor%oPanelInraceChat.iMaxListItems;
  212.  
  213.     if (oPanelInraceChat.iNbListItems<oPanelInraceChat.iMaxListItems)
  214.     {
  215.         oPanelInraceChat.iNbListItems=oPanelInraceChat.iNbListItems+1;
  216.     }
  217.  
  218.     //update the list if the chat window is open
  219.     if(oRace.iChatWindow != ID_NOT_CREATED)
  220.     {
  221.         var component pold;
  222.  
  223.         if(oPanelInraceChat.pThis != g_poNullComponent)
  224.         {
  225.             // Save current contex
  226.             pold=GetParserComponent();
  227.  
  228.             // Set Chat window context
  229.             SetParserComponent(oPanelInraceChat.pThis);
  230.  
  231.             // Update list
  232.             SetListNbItems(oPanelInraceChat.iChatWindow,oPanelInraceChat.iNbListItems);
  233.             SetListPosition(oPanelInraceChat.iChatWindow,oPanelInraceChat.iNbListItems-1);
  234.  
  235.             //restore context
  236.             SetParserComponent(pold);
  237.         }
  238.     }
  239.  
  240.     // Send chat event
  241.     oRaceChat.m_iNeedUpdate = true;
  242. }
  243.  
  244.  
  245. func i32x Panel_Inrace_Chat_Event(i32x _iComponentID, i32x _iEvent)
  246. {
  247.     var i32x boucle,iBitField,iFlag;
  248.     if(_iEvent==GUI_COMPONENT_MOUSE_LDBLCLICK)
  249.     {
  250.         boucle=0;
  251.         while(boucle<20)
  252.         {
  253.             if(_iComponentID==oPanelInraceChat.iTeamName[boucle]|| _iComponentID==oPanelInraceChat.iTeamButton[boucle])
  254.             {
  255.                 iFlag = GetCheckboxState(oPanelInraceChat.iTeamButton[boucle]);
  256.             }
  257.             boucle=boucle+1;
  258.         }
  259.  
  260.         boucle=0;
  261.         while(boucle<20)
  262.         {
  263.             SetCheckboxState(oPanelInraceChat.iTeamButton[boucle],iFlag);
  264.             boucle=boucle+1;
  265.         }
  266.     }
  267.     if(_iEvent == GUI_EDITBOX_VALID )
  268.     {
  269.         if (strcmp(GetContainerText(oPanelInraceChat.iCommandLine),""))
  270.         {
  271.             iBitField=0;
  272.             boucle=0;
  273.             while(boucle<20)
  274.             {
  275.                 iBitField=SetBit(iBitField,boucle,GetCheckboxState(oPanelInraceChat.iTeamButton[boucle]));
  276.                 boucle=boucle+1;
  277.             }
  278.             g_oMenuServer.m_oServer << mGame_Chat(iBitField,GetContainerText(oPanelInraceChat.iCommandLine));
  279.             SetContainerText(oPanelInraceChat.iCommandLine,"");
  280.         }
  281.     }
  282.  
  283.     if(_iEvent==GUI_COMPONENT_MOUSE_LDOWN)
  284.     {
  285.         boucle=0;
  286.         while(boucle<20)
  287.         {
  288.             if(_iComponentID==oPanelInraceChat.iTeamName[boucle])
  289.             {
  290.                 if (GetCheckboxState(oPanelInraceChat.iTeamButton[boucle]))
  291.                     SetCheckboxState(oPanelInraceChat.iTeamButton[boucle],0);
  292.                 else
  293.                     SetCheckboxState(oPanelInraceChat.iTeamButton[boucle],1);
  294.             }
  295.             boucle=boucle+1;
  296.         }
  297.     }
  298.     if(_iComponentID==-1)
  299.     {
  300.         if(_iEvent == GUI_COMPONENT_DESTRUCTOR)
  301.         {
  302.             oPanelInraceChat.pThis = g_poNullComponent;
  303.         }
  304.     }
  305.     return 1;
  306.     
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------------------------------//
  310. //----------------------------------------------------------------------------------------------------------------//
  311. //SendChat func function called from the menuserver 
  312. //----------------------------------------------------------------------------------------------------------------//
  313. //----------------------------------------------------------------------------------------------------------------//
  314. func void CSendChat_Null(i32x _iTeamID,szx _szMessage)
  315. {
  316. }
  317. func void CSendChat(i32x _iTeamID,szx _szMessage)
  318. {
  319.     var szx szMsg;
  320.  
  321.     szMsg=strcat("[",Join_GetStringFromSortedIndex(g_stInraceJoins.m_jTeam_szAbrev,_iTeamID));
  322.     szMsg=strcat(szMsg,"] ");
  323.     szMsg=strcat(szMsg,_szMessage);
  324.  
  325.     Panel_Inrace_Chat_Update(szMsg);
  326. }
  327.  
  328.  
  329.