/* Loto Client - DMS - june 2000 - by Julien ZORKO */ /* The interface is drawn in the lotowin.pkg file */ /* Defcom */ defcom SrefreshPlayerList=RefreshPlayerList S;; defcom SloginGame=LoginGame S I;; defcom SiHaveIt=IHaveIt S I I;; defcom SgetNewGrid=GetNewGrid;; defcom SlogoutGame=LogoutGame S;; defcom Sadmin=Admin S S;; defcom SsetParams=SetParams S;; /* Objects */ /* here are the comboboxes of the administration window */ typeof cbMaxGames = ObjBox;; typeof cbMaxPlayers = ObjBox;; typeof cbLife = ObjBox;; typeof cbBegin = ObjBox;; typeof cbFlow = ObjBox;; typeof cbEnd = ObjBox;; /* Other functions */ /* copied from _listlib.pkg */ fun posf_in_list (l, f, x)= if l==nil then nil else if exec f with [hd l x] then 0 else 1+posf_in_list tl l f x;; fun strdelspace(s)= let (strlen s)-1 -> len in if (nth_char s 0)==32 then strdelspace (substr s 1 len) else if (nth_char s len)==32 then strdelspace (substr s 0 len) else s;; /* Control functions */ fun _LineToGame(item)= let strfind " (" item 0 -> pos in if pos==nil then item else substr item 0 pos;; fun _GetSelectedName(complist)= let _GETcompListClicked complist -> [_[item _]] in _LineToGame item;; fun _IsSameGame(newitem, olditem)= let [(_LineToGame newitem) (_LineToGame olditem)] -> [ng og] in !strcmp ng og;; /* rempli une compliste */ fun _FillCompList(complist,list)= if list==nil then _PAINTcontainer SerCon else let list -> [first list] in ( _ADDcompList complist 0 [first nil]; _FillCompList complist list);; /* met à jour la liste des joueurs */ fun __UpdatePlayerList(strlist)= let lineextr strlist -> list in ( _RSTcompList scPlayerList; _FillCompList scPlayerList list);; /* sélection d'une partie */ fun _SelectGame(complist,param,gameid)= if gameid!=nil then (set mySelGame = _GetSelectedName scGameList;0) else 0; if !strcmpi param "login" then ( _DMSsend this SloginGame [mySelGame 0]) else 0; _DMSsend this SrefreshPlayerList [mySelGame]; _NewPlayListText mySelGame;; /* sélection d'un joueur */ fun _SelectPlayer(complist,param,id)= let _GETcompListValue complist id -> [txt _] in if txt==nil then nil else _DMSevent this "select" txt nil;; /* mise à jour de la liste des parties */ fun __UpdateGameList(gamelist)= let lineextr gamelist -> gl in (_RSTcompList scGameList; _FillCompList scGameList gl; if (posf_in_list gl @_IsSameGame mySelGame)==nil then let _GETcompListValue scGameList 0 -> [newsel _] in (set mySelGame=_LineToGame newsel;0) else 0 );; /* informe le client que la liste des joueurs a changé */ fun __PlayerListChanged()=_SelectGame scGameList nil nil;; fun _CreateGame(but, param, posx, posy, btn, mask)= let strdelspace _GETcompText txtNewGame -> newgame in if (strlen newgame) < 3 then (_DLGMessageBox _channel nil (_loc this "ERR_MSG_GAME_NAME_TITLE" nil) (_loc this "ERR_MSG_GAME_NAME" nil) 0;0) else ( _DMSsend this SloginGame [newgame 1]);; /* créer une partie */ fun _CreateGame2(ctext,a,type,txt)= _CreateGame nil nil nil nil nil nil;; /* Obtenir une nouvelle grille aléatoire */ fun _GetNewGrid(but, param, posx, posy, btn, mask)= _DMSsend this SgetNewGrid [];; /* Quitter une partie */ fun _LogoutGame(but, param, posx, posy, btn, mask)= _DMSsend this SlogoutGame [myGame]; _CHANGEobjNodeFlags _CONVERTcompRollOverToObjNode butLogoutGame OBJ_HIDE 0; _CHANGEobjNodeFlags _CONVERTcompBitmapToObjNode butToken OBJ_HIDE 0; _CHANGEobjNodeFlags _CONVERTcompRollOverToObjNode butCreateGame OBJ_VISIBLE|OBJ_ENABLE 0; _CHANGEobjNodeFlags _CONVERTcompTextToObjNode txtNewGame OBJ_VISIBLE|OBJ_ENABLE 0; _CHANGEobjNodeFlags _CONVERTcompRollOverToObjNode butNewGrid OBJ_VISIBLE|OBJ_ENABLE 1; _CBcompListDblClick scGameList @_SelectGame "login"; set myGame=nil;; fun _KillContainer(con,b)=_DScontainer con;; /* Définition des callbacks de l'interface client */ fun _DefineCB()= _CBcompRollOverClick butLogoutGame @_LogoutGame nil; _CBcompRollOverClick butCreateGame @_CreateGame nil; _CBcompListDblClick scGameList @_SelectGame "login"; _CBcompListClick scGameList @_SelectGame nil; _CBcompRollOverClick butNewGrid @_GetNewGrid nil; _CBcompListClick scPlayerList @_SelectPlayer nil; _CBcontainerPreDestroy SerCon @_KillContainer myGame; _CBcompTextValidation txtNewGame @_CreateGame2 nil CT_VALIDENTER; /* _CRtoolTipDefault _CONVERTcompBitmapToObjNode butToken nil "Double-Click on the token to get it!" nil nil nil; */ 0;; /* Zone d'infos */ fun _DeleteLines(i)= if i>0 then (_DELcompTextLine zoneInfo 0 CT_END;_DeleteLines i-1;0) else 0;; fun __WriteInfo(txt,style,color)= _ADDcompText zoneInfo strcat txt "\n" _CRfont _channel 12 2000 style "Verdana" [color 0 0 0] CT_END; _DeleteLines (_GETcompTextLineCount zoneInfo)-60; _PAINTcontainer SerCon;; /*------------PLAY!---------------*/ /* entrée dans le jeux */ fun __Login(game)= set myGame=game; set mySelGame=game; _DMSsend this SrefreshPlayerList [game]; _CHANGEobjNodeFlags _CONVERTcompRollOverToObjNode butCreateGame OBJ_HIDE 0; _CHANGEobjNodeFlags _CONVERTcompRollOverToObjNode butNewGrid OBJ_HIDE 0; _CHANGEobjNodeFlags _CONVERTcompTextToObjNode txtNewGame OBJ_HIDE 0; _CHANGEobjNodeFlags _CONVERTcompBitmapToObjNode butToken OBJ_VISIBLE|OBJ_ENABLE 0; _CHANGEobjNodeFlags _CONVERTcompRollOverToObjNode butLogoutGame OBJ_VISIBLE|OBJ_ENABLE 1; _CBcompListDblClick scGameList nil nil;; /* sortie du jeux */ fun __Logout()= _LogoutGame nil nil nil nil nil nil;; /**************************************************************************************** * demande du jeton en cours au serveur ****************************************************************************************/ fun _IWantIt(bmp,param,posx,posy,btn,mask)= _CBcompBitmapDblClick bmp nil nil; let param->[ti1 value] in _DMSsend this SiHaveIt [myGame time-ti1 value]; 0;; /**************************************************************************************** * Affichage du jeton proposé aux joueurs ****************************************************************************************/ fun __DrawToken(value)= let _GETalphaBitmapSize scrToken -> [sw sh] in let _GETalphaBitmaps scrToken -> [bmp _] in ( _FILLbitmap bmp transColor; _CPalphaBitmap bmp 0 0 bmpTokens sw*value 0 sw sh; _CBcompBitmapDblClick butToken @_IWantIt [time value]; _PAINTcontainer SerCon );; /**************************************************************************************** * The following functions allow the administrators to control the game ***************** ****************************************************************************************/ /* ajoute une liste de choix à un comboboxe*/ fun _AddListToCombo(combo,l)= let l -> [first next] in if first==nil then 0 else ( _ADDcombo combo 0 first; _AddListToCombo combo next; 0 );; /* extraction de la chaine de caractère sélectionnée dans une comboboxe */ fun _GetCbTxt(combo)= let _GETcombo combo ->[_ txt] in txt;; /**************************************************************************************** * Cette fonction renvoie les paramètres d'administration au serveur sous la forme d'une * chaîne de caractères. ****************************************************************************************/ fun _SetParams(but,param)= let ("Vmaxgames"::(_GetCbTxt cbMaxGames)::nil):: ("Vmaxplayers"::(_GetCbTxt cbMaxPlayers)::nil):: ("Vlife"::(_GetCbTxt cbLife)::nil):: ("Vbegin"::(_GetCbTxt cbBegin)::nil):: ("Vflow"::(_GetCbTxt cbFlow)::nil):: ("Vend"::(_GetCbTxt cbEnd)::nil):: nil -> s in let strbuild s -> s in _DMSsend this SsetParams [s];; /**************************************************************************************** * fermeture de la fenêtre d'administration ****************************************************************************************/ fun _CloseWin(but,win)=_DSwindow win; _DMSreleaseZone this "Admin";; fun _CloseDlg(zone)= _DMSreleaseZone this zone;; /**************************************************************************************** * Cette fonction ouvre une fenêtre qui permet de modifier dynamiquement les paramètres * du jeu ( c'est la même fenêtre que dans l'éditeur statique, elle est faite avec * l'ancienne lib2d ) ****************************************************************************************/ fun __ModifyParams(s)= let strextr s -> p in let _DMSgetZone this "Admin" @_CloseDlg nil @_CloseDlg ->[wn x y w h] in /* si la fenêtre est affectée à une zone celle-ci est utilisée sinon une fenêtre popup est crée */ let if wn==nil then _CRwindow _channel serWin nil nil 315 190 WN_MENU|WN_MINBOX (_loc this "PARAM_WIN_TITLE" nil) else _CRwindow _channel wn x y w h WN_CHILDINSIDE|WN_NOCAPTION|WN_NOBORDER (_loc this "PARAM_WIN_TITLE" nil) -> editWin in let _CRbutton _channel editWin 3 165 72 20 0 (_loc this "PARAM_SET" nil) -> butSet in let _CRbutton _channel editWin 80 165 72 20 0 (_loc this "PARAM_CLOSE" nil) -> butCancel in ( set cbMaxGames = _CRcombo _channel editWin 265 10 40 100 CB_NOEDIT|CB_AHSCROLL|CB_DOWN ""; set cbMaxPlayers = _CRcombo _channel editWin 265 35 40 100 CB_NOEDIT|CB_AHSCROLL|CB_DOWN ""; set cbLife = _CRcombo _channel editWin 265 60 40 100 CB_NOEDIT|CB_AHSCROLL|CB_DOWN ""; set cbBegin = _CRcombo _channel editWin 265 85 40 100 CB_NOEDIT|CB_AHSCROLL|CB_DOWN ""; set cbFlow = _CRcombo _channel editWin 265 110 40 100 CB_NOEDIT|CB_AHSCROLL|CB_DOWN ""; set cbEnd = _CRcombo _channel editWin 265 135 40 100 CB_NOEDIT|CB_AHSCROLL|CB_DOWN ""; /* les paramètres sont positionnés grâces à des comboboxes dont les listes fournissent les valeurs */ _AddListToCombo cbMaxGames "25"::"20"::"15"::"10"::"5"::"0"::nil; _AddListToCombo cbMaxPlayers "10"::"9"::"8"::"7"::"6"::"5"::"4"::"3"::"2"::nil; _AddListToCombo cbLife "60"::"50"::"40"::"30"::"20"::"10"::nil; _AddListToCombo cbBegin "35"::"30"::"25"::"20"::"15"::"10"::"5"::nil; _AddListToCombo cbFlow "60"::"55"::"50"::"45"::"40"::"35"::"30"::"25"::"20"::"15"::"10"::nil; _AddListToCombo cbEnd "10"::"9"::"8"::"7"::"6"::"5"::"4"::"3"::"2"::"1"::nil; _CRtext _channel editWin 10 15 255 20 ET_ALIGN_RIGHT (_loc this "MAX_NUMBER_OF_GAMES" nil); _CRtext _channel editWin 10 40 255 20 ET_ALIGN_RIGHT (_loc this "MAX_NUMBER_OF_PLAYERS" nil); _CRtext _channel editWin 10 65 255 20 ET_ALIGN_RIGHT (_loc this "TIME_AUTOKILL_GAME" nil); _CRtext _channel editWin 10 90 255 20 ET_ALIGN_RIGHT (_loc this "TIME_BEFORE_BEGIN_GAME" nil); _CRtext _channel editWin 10 115 255 20 ET_ALIGN_RIGHT (_loc this "TIME_BETWEEN_TOKENS" nil); _CRtext _channel editWin 10 140 255 20 ET_ALIGN_RIGHT (_loc this "TIME_BEFORE_ENDING_GAME" nil); _CBbutton butSet @_SetParams nil; _CBbutton butCancel @_CloseWin editWin; _SSELcombo cbLife getInfo p "Vlife"; _SSELcombo cbBegin getInfo p "Vbegin"; _SSELcombo cbEnd getInfo p "Vend"; _SSELcombo cbFlow getInfo p "Vflow"; _SSELcombo cbMaxGames getInfo p "Vmaxgames"; _SSELcombo cbMaxPlayers getInfo p "Vmaxplayers"; 0 );; /**************************************************************************************** * Gère le réflexe de click sur le menu d'administration du module ( seulement accessible * lorque le client est connecté en tant qu' administrateur ) ****************************************************************************************/ fun _Admin(menuitem,action)= if !strcmp action "Params" then ( _DMSsend this Sadmin [action nil]; nil ) else if !strcmp action "kGame" then let _GETcompListClicked scGameList -> [_ [game _]] in if game!=nil then _DMSsend this Sadmin [action (_LineToGame game)] else nil else if !strcmp action "kPlayer" then let _GETcompListClicked scPlayerList -> [_ [player _]] in if player!=nil then _DMSsend this Sadmin [action player] else nil else 0;; /**************************************************************************************** * affiche le menu d'administrateur ****************************************************************************************/ fun _AdminPopup(compbmp,popm,posx,posy,btn,mask)= _DRAWmenu serWin popm adminX adminY+15 PM_TOP_ALIGN|PM_LEFT_ALIGN;; /**************************************************************************************** * Création du menu d'administration ****************************************************************************************/ fun _CreateAdminControl()= let _LDbitmap _channel _checkpack fAdmin -> bmp in let _CRalphaBitmap _channel bmp nil nil 0xffffff -> abmp in let _CRcompRollOver _channel SerCon nil [adminX adminY] OBJ_VISIBLE|OBJ_ENABLE OBJ_CONTAINER_CLICK abmp -> button in let _CRpopupMenu _channel -> popm in ( _CBmenu (_APPitem _channel popm ME_ENABLED (_loc this "PARAM_KILL_PLAYER" nil)) @_Admin "kPlayer"; _CBmenu (_APPitem _channel popm ME_ENABLED (_loc this "PARAM_KILL_GAME" nil)) @_Admin "kGame"; _APPitem _channel popm ME_SEPARATOR ""; _CBmenu (_APPitem _channel popm ME_ENABLED (_loc this "PARAM_MENU" nil)) @_Admin "Params"; _CBcompRollOverClick button @_AdminPopup popm );; /**************************************************************************************** * Called each time when an action port is activated ****************************************************************************************/ fun activate(from,action,param,rep)= if !strcmp action "show" then ( _SHOWwindow serWin WINDOW_UNHIDDEN; _DMSevent this "shown" nil nil; 0 ) else if !strcmp action "hide" then ( _SHOWwindow serWin WINDOW_HIDDEN; _DMSevent this "hidden" nil nil; 0 ) else nil;; /**************************************************************************************** * Main function for the initialization of the client module. ****************************************************************************************/ fun IniDMI(param)= _CreateControl; if !strcmp param "administrateur" then _CreateAdminControl else nil; _DefineCB; _PAINTcontainer SerCon; _DMSregisterDMI this @activate nil; _DMSevent this "shown" nil nil; _DMSevent this "log" (strcat DMSlogin " enters in LOTO") nil; _DMSevent this "in" nil nil; 0;;