SquadsScreen.cpp 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390
  1. #include "pch.h"
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Squads Screen
  5. //
  6. //////////////////////////////////////////////////////////////////////////////
  7. //
  8. // Functionality ideas:
  9. //
  10. // Make Tab switch between the fields just like Enter does now. Make ESC
  11. // cancel create/edit.
  12. //
  13. // Allow the selected squad to remain selected when switching between tabs.
  14. //
  15. // OPTimization idea:
  16. //
  17. // We could reduce the Clubserver/SQL server load not sending the squad page requests
  18. // so often, and simply using what is in our cache.
  19. //
  20. class SquadsScreen;
  21. extern SquadsScreen * g_pSquadScreen; // messy but avoids .h file
  22. const int c_cSquadsShown = 21;
  23. class SquadsScreen :
  24. public Screen,
  25. public EventTargetContainer<SquadsScreen>,
  26. public TEvent<ZString>::Sink,
  27. public TrekClientEventSink,
  28. public IItemEvent::Sink
  29. {
  30. private:
  31. TRef<IKeyboardInput> m_pkeyboardInputOldFocus;
  32. TRef<Pane> m_ppane;
  33. //
  34. // Normal buttons
  35. //
  36. TRef<ButtonPane> m_pbuttonZoneClub;
  37. TRef<ButtonPane> m_pbuttonPlayerProfile;
  38. TRef<ButtonPane> m_pbuttonLeaderboard;
  39. TRef<ButtonPane> m_pbuttonEditSquad;
  40. TRef<ButtonPane> m_pbuttonReject;
  41. TRef<ButtonPane> m_pbuttonAccept;
  42. TRef<ButtonPane> m_pbuttonCommission;
  43. TRef<ButtonPane> m_pbuttonDemote;
  44. TRef<ButtonPane> m_pbuttonTransferControl;
  45. TRef<ButtonPane> m_pbuttonRequestJoin;
  46. TRef<ButtonPane> m_pbuttonCancelRequest;
  47. TRef<ButtonPane> m_pbuttonQuitSquad;
  48. TRef<ButtonPane> m_pbuttonCreateSquad;
  49. TRef<ButtonPane> m_pbuttonNext; // goto next group of squads
  50. TRef<ButtonPane> m_pbuttonPrev; // goto prev group of squads
  51. TRef<ButtonPane> m_pbuttonTop; // goto top of squads list
  52. TRef<ButtonPane> m_pbuttonLog;
  53. TRef<ButtonPane> m_pbuttonApply; // apply edit changes
  54. TRef<ButtonPane> m_pbuttonURL;
  55. TRef<ButtonPane> m_pbuttonFindSquad;
  56. //
  57. // Icons
  58. //
  59. TRef<Image> m_pimageOwner;
  60. TRef<Image> m_pimageASL;
  61. TRef<Image> m_pimagePending;
  62. TRef<Image> m_pimageRejected;
  63. TRef<Image> m_pimageMember;
  64. TRef<Image> m_pimageBooted;
  65. TRef<Image> m_pimageQuit;
  66. //
  67. // Tabs
  68. //
  69. enum FilterType
  70. {
  71. FILTER_ALL = 0,
  72. FILTER_MY,
  73. FILTER_DUDEX,
  74. FILTER_MAX
  75. };
  76. FilterType m_filter;
  77. Color m_colorTabText;
  78. Color m_colorTabTextSelected;
  79. TVector<int> m_viTabColumns;
  80. TRef<ButtonBarPane> m_ptabSquads;
  81. TRef<ImagePane> m_ptabSquadsImage;
  82. TRef<StringValue> m_pstringSquadTabAll;
  83. TRef<StringValue> m_pstringSquadTabMy;
  84. TRef<ModifiableString> m_pstringSquadTabDudeX;
  85. //
  86. // Squads Listbox
  87. //
  88. TRef<ButtonBarPane> m_pbuttonbarSquadsHeader;
  89. TRef<ListPane> m_plistPaneSquads;
  90. TRef<ScrollPane> m_pscrollPaneSquads;
  91. TRef<IItemEvent::Source> m_peventSquads;
  92. TRef<TEvent<ItemID>::Sink> m_psinkSquads;
  93. TVector<int> m_viColumns;
  94. TVector<unsigned, DefaultEquals> m_vuSorts; // used for "my" and dudex tabs
  95. static SQUAD_SORT_COLUMN s_column; // currently sorted column for squads
  96. Color m_colorSquadSelectionBar;
  97. XSquads m_listSquads[FILTER_MAX]; // core listbox data; one list for each tab 0 == all, 1 == my, 2 == dudex
  98. XSquads m_listAllSquads; // any squad made that was placed in tab 0 (the ALL tab)
  99. XZonePlayers m_listAllPlayers;
  100. static TRef<IZoneSquad> s_pSelectedSquad;
  101. //
  102. // Squad details data
  103. //
  104. TRef<EditPane> m_peditPaneSquadName;
  105. TRef<EditPane> m_peditPaneSquadDescription;
  106. TRef<EditPane> m_peditPaneSquadURL;
  107. TRef<EditPane> m_peditPaneFind;
  108. TRef<TEvent<ZString>::Source> m_peventNameEdit;
  109. TRef<TEvent<ZString>::Sink> m_psinkNameEdit;
  110. TRef<TEvent<ZString>::Source> m_peventDescEdit;
  111. TRef<TEvent<ZString>::Sink> m_psinkDescEdit;
  112. TRef<TEvent<ZString>::Source> m_peventURLEdit;
  113. TRef<TEvent<ZString>::Sink> m_psinkURLEdit;
  114. TRef<TEvent<ZString>::Source> m_peventFind;
  115. TRef<TEvent<ZString>::Sink> m_psinkFind;
  116. TRef<StringPane> m_pstrpaneRank;
  117. TRef<StringPane> m_pstrpaneRanking;
  118. TRef<StringPane> m_pstrpaneWinsAndLosses;
  119. TRef<StringPane> m_pstrpaneInceptionDate;
  120. TRef<ComboPane> m_pcomboCiv;
  121. //
  122. // Players Listbox
  123. //
  124. TRef<ButtonBarPane> m_pbuttonbarPlayersHeader;
  125. TRef<ListPane> m_plistPanePlayers;
  126. TRef<IItemEvent::Source> m_peventPlayers;
  127. // TRef<IItemEvent::Source> m_peventPlayersDoubleClick;
  128. TRef<TEvent<ItemID>::Sink> m_psinkPlayers;
  129. // TRef<TEvent<ItemID>::Sink> m_psinkPlayersDoubleClick ;
  130. TVector<int> m_viPlayersColumns;
  131. TVector<unsigned, DefaultEquals> m_vuPlayersSorts;
  132. Color m_colorPlayerSelectionBar;
  133. static TRef<IZonePlayer> s_pSelectedPlayer;
  134. static TRef<IZonePlayer> s_pDudeXPlayer;
  135. TRef<IZoneSquad> m_psquadLastDetails; // used only by ForwardSquadMessage
  136. TRef<IZoneSquad> m_psquadPrePage;
  137. TRef<IZoneSquad> m_psquadBeingMade; // NULL else a squad is being created
  138. XZonePlayers m_listPlayers; // players in listbox
  139. int m_nNextCreationID;
  140. int m_nHighestRanking[SSC_MAX]; // highest as in closest to 1
  141. TRef<IZoneSquad> m_psquadHighestRanking[SSC_MAX];
  142. int m_nLowestRanking[SSC_MAX]; // lowest as in closest to infinity
  143. TRef<IZoneSquad> m_psquadLowestRanking[SSC_MAX];
  144. int m_nCurrentRanking; // used in determining which squads get shown; used with c_cSquadsShown
  145. TRef<IZoneSquad> m_psquadLastSelected;
  146. ZString m_strSquadToBeSelected;
  147. int m_nTab; // Currently selected Tab; 0 == ALL; 1 == My; 2 == DudeX
  148. unsigned m_nBestSearchMatch; // used for selecting correct squad of a serach result
  149. int* m_pCivIds;
  150. int m_cCivs;
  151. // remember a coupld bits so we know when a player has clicked in the edit box for the first
  152. // time since creation
  153. bool m_bSquadEditNameReset;
  154. bool m_bSquadEditDescReset;
  155. bool m_bSquadEditURLReset;
  156. bool m_bLeftScreen;
  157. bool m_bSelectorNeedsAutoSet; // set to true if we clear the list of squads; it means: do we need to auto select a squad for user
  158. bool m_bSelectionNotFromSquadClick; // using clicked on something other than a squad to cause a squad to be selected
  159. TRef<IMessageBox> m_pmsgBox;
  160. TRef<ModifiableString> m_pstringDescription;
  161. //
  162. // History Popup List (Ownership Log)
  163. //
  164. friend class HistoryDialogPopup;
  165. class HistoryDialogPopup : public IPopup, public EventTargetContainer<HistoryDialogPopup>
  166. {
  167. private:
  168. TRef<Pane> m_ppane;
  169. TRef<ButtonPane> m_pbuttonOK;
  170. TRef<EditPane> m_peditPane;
  171. TRef<StringListPane> m_plistPaneHistory;
  172. SquadsScreen* m_pparent;
  173. public:
  174. HistoryDialogPopup(TRef<INameSpace> pns, SquadsScreen* pparent)
  175. {
  176. m_pparent = pparent;
  177. CastTo(m_ppane, pns->FindMember("historyDialog" ));
  178. CastTo(m_pbuttonOK, pns->FindMember("historyOkButtonPane" ));
  179. CastTo(m_plistPaneHistory,(Pane*)pns->FindMember("historyListPane" ));
  180. AddEventTarget(OnButtonOK, m_pbuttonOK->GetEventSource());
  181. }
  182. void SetHistory(TList<ZString> * pList)
  183. {
  184. m_plistPaneHistory->GetStringList()->SetEmpty();
  185. TList<ZString>::Iterator it(*pList);
  186. while(!it.End())
  187. {
  188. m_plistPaneHistory->GetStringList()->AddItem(it.Value());
  189. it.Next();
  190. }
  191. }
  192. ~HistoryDialogPopup()
  193. {
  194. }
  195. //
  196. // IPopup methods
  197. //
  198. Pane* GetPane()
  199. {
  200. return m_ppane;
  201. }
  202. /* virtual void SetContainer(IPopupContainer* pcontainer)
  203. {
  204. // GetWindow()->SetFocus(m_peditPane);
  205. IPopup::SetContainer(pcontainer);
  206. }
  207. */
  208. bool OnButtonOK()
  209. {
  210. if (m_ppopupOwner) {
  211. m_ppopupOwner->ClosePopup(this);
  212. } else {
  213. m_pcontainer->ClosePopup(this);
  214. }
  215. return true;
  216. }
  217. };
  218. TRef<HistoryDialogPopup> m_pHistoryDialog;
  219. //
  220. // Other data
  221. //
  222. static TRef<IZonePlayer> s_pActivePlayer; // points to the squad player that the interactive user controls
  223. public:
  224. ~SquadsScreen()
  225. {
  226. OnLeavingScreen();
  227. g_pSquadScreen = NULL;
  228. m_peventSquads->RemoveSink(m_psinkSquads);
  229. m_peventPlayers->RemoveSink(m_psinkPlayers);
  230. // m_peventPlayersDoubleClick->RemoveSink(m_psinkPlayersDoubleClick);
  231. m_listSquads[FILTER_ALL].SetEmpty();
  232. m_listSquads[FILTER_MY].SetEmpty();
  233. m_listSquads[FILTER_DUDEX].SetEmpty();
  234. m_listPlayers.SetEmpty();
  235. m_plistPaneSquads->SetList(new EmptyList); // remove to avoid cyclic destruction
  236. m_plistPanePlayers->SetList(new EmptyList); // remove to avoid cyclic destruction
  237. m_peventNameEdit->RemoveSink(m_psinkNameEdit);
  238. m_peventDescEdit->RemoveSink(m_psinkDescEdit);
  239. m_peventURLEdit->RemoveSink(m_psinkURLEdit);
  240. m_peventFind->RemoveSink(m_psinkFind);
  241. if(m_pCivIds)
  242. delete[] m_pCivIds;
  243. }
  244. SquadsScreen(Modeler* pmodeler, const char * szNameDudeX, int idPlayerDudeX, const char * szSquad):
  245. m_nNextCreationID(0),
  246. m_nCurrentRanking(1),
  247. m_psquadBeingMade(NULL),
  248. m_psquadPrePage(NULL),
  249. m_pmsgBox(NULL),
  250. m_pCivIds(NULL),
  251. m_bLeftScreen(false),
  252. m_bSelectionNotFromSquadClick(false),
  253. m_filter(FILTER_ALL),
  254. m_bSelectorNeedsAutoSet(false),
  255. m_bSquadEditNameReset(false),
  256. m_bSquadEditDescReset(false),
  257. m_bSquadEditURLReset(false)
  258. {
  259. m_pkeyboardInputOldFocus = GetWindow()->GetFocus();
  260. s_column = SSC_SCORE;
  261. s_pSelectedSquad = NULL;
  262. s_pSelectedPlayer = NULL;
  263. s_pDudeXPlayer = NULL;
  264. int i;
  265. for (i = 0; i < SSC_MAX; ++i)
  266. {
  267. m_nHighestRanking[i] = 999999; // a smaller number is actually higher
  268. m_nLowestRanking[i] = -1;
  269. m_psquadHighestRanking[i] = NULL;
  270. m_psquadLowestRanking[i] = NULL;
  271. }
  272. TRef<IZonePlayer> pplayer = FindPlayerByID(trekClient.GetZoneClubID());
  273. if (pplayer == NULL)
  274. pplayer = CreateZonePlayer(trekClient.GetNameLogonClubServer(), trekClient.GetZoneClubID());
  275. s_pActivePlayer = pplayer;
  276. // default to "all" tab being checked
  277. m_nTab = FILTER_ALL;
  278. // if dude x is the useractive user, then we simply use the my tab instead of dudex
  279. if(s_pActivePlayer->GetID() == idPlayerDudeX)
  280. {
  281. m_nTab = FILTER_MY;
  282. m_strSquadToBeSelected = szSquad ? szSquad : "";
  283. szNameDudeX = NULL;
  284. }
  285. else
  286. {
  287. if(szNameDudeX)
  288. {
  289. m_nTab = FILTER_DUDEX;
  290. m_strSquadToBeSelected = szSquad ? szSquad : "";
  291. TRef<IZonePlayer> pplayer = FindPlayerByID(idPlayerDudeX);
  292. if (pplayer == NULL)
  293. pplayer = CreateZonePlayer(szNameDudeX, idPlayerDudeX);
  294. s_pDudeXPlayer = pplayer;
  295. }
  296. else
  297. s_pDudeXPlayer = NULL;
  298. }
  299. //
  300. // SquadScreen exports
  301. //
  302. TRef<INameSpace> pnsData = GetModeler()->CreateNameSpace("squadsscreendata");
  303. pnsData->AddMember("squadTabAllStr", (Value*)(m_pstringSquadTabAll = new ModifiableString("All Squads")));
  304. pnsData->AddMember("squadTabMyStr", (Value*)(m_pstringSquadTabMy = new ModifiableString("My Squads")));
  305. if (s_pDudeXPlayer)
  306. m_pstringSquadTabDudeX = new ModifiableString(s_pDudeXPlayer->GetName());
  307. else
  308. m_pstringSquadTabDudeX = new ModifiableString("");
  309. pnsData->AddMember("squadTabDudeXStr", (Value*)m_pstringSquadTabDudeX);
  310. pnsData->AddMember("descriptionStr",(Value*)(m_pstringDescription = new ModifiableString("")));
  311. //
  312. // SquadScreen Imports
  313. //
  314. TRef<INameSpace> pns = pmodeler->GetNameSpace("squadsscreen");
  315. CastTo(m_ppane, pns->FindMember("screen"));
  316. //
  317. // Normal buttons
  318. //
  319. CastTo(m_pbuttonZoneClub, pns->FindMember("zoneclubButtonPane"));
  320. AddEventTarget(OnButtonZoneClub, m_pbuttonZoneClub->GetEventSource());
  321. CastTo(m_pbuttonPlayerProfile, pns->FindMember("playerProfileButtonPane"));
  322. AddEventTarget(OnButtonPlayerProfile, m_pbuttonPlayerProfile->GetEventSource());
  323. CastTo(m_pbuttonLeaderboard, pns->FindMember("leaderboardButtonPane"));
  324. AddEventTarget(OnButtonLeaderboard, m_pbuttonLeaderboard->GetEventSource());
  325. CastTo(m_pbuttonPrev, pns->FindMember("prevButtonPane"));
  326. AddEventTarget(OnButtonPrev, m_pbuttonPrev->GetEventSource());
  327. CastTo(m_pbuttonNext, pns->FindMember("nextButtonPane"));
  328. AddEventTarget(OnButtonNext, m_pbuttonNext->GetEventSource());
  329. CastTo(m_pbuttonTop, pns->FindMember("topButtonPane"));
  330. AddEventTarget(OnButtonTop, m_pbuttonTop->GetEventSource());
  331. CastTo(m_pbuttonEditSquad, pns->FindMember("editsquadButtonPane"));
  332. AddEventTarget(OnButtonEditSquad, m_pbuttonEditSquad->GetEventSource());
  333. CastTo(m_pbuttonReject, pns->FindMember("rejectButtonPane"));
  334. AddEventTarget(OnButtonReject, m_pbuttonReject->GetEventSource());
  335. CastTo(m_pbuttonAccept, pns->FindMember("acceptButtonPane"));
  336. AddEventTarget(OnButtonAccept, m_pbuttonAccept->GetEventSource());
  337. CastTo(m_pbuttonCommission, pns->FindMember("commissionButtonPane"));
  338. AddEventTarget(OnButtonCommission, m_pbuttonCommission->GetEventSource());
  339. CastTo(m_pbuttonDemote, pns->FindMember("demoteButtonPane"));
  340. AddEventTarget(OnButtonDemote, m_pbuttonDemote->GetEventSource());
  341. CastTo(m_pbuttonTransferControl, pns->FindMember("transfercontrolButtonPane"));
  342. AddEventTarget(OnButtonTransferControl, m_pbuttonTransferControl->GetEventSource());
  343. CastTo(m_pbuttonRequestJoin, pns->FindMember("requestjoinButtonPane"));
  344. AddEventTarget(OnButtonRequestJoin, m_pbuttonRequestJoin->GetEventSource());
  345. CastTo(m_pbuttonCancelRequest, pns->FindMember("cancelrequestButtonPane"));
  346. AddEventTarget(OnButtonCancelRequest, m_pbuttonCancelRequest->GetEventSource());
  347. CastTo(m_pbuttonQuitSquad, pns->FindMember("quitsquadButtonPane"));
  348. AddEventTarget(OnButtonQuitSquad, m_pbuttonQuitSquad->GetEventSource());
  349. CastTo(m_pbuttonCreateSquad, pns->FindMember("createsquadButtonPane"));
  350. AddEventTarget(OnButtonCreateSquad, m_pbuttonCreateSquad->GetEventSource());
  351. m_pbuttonCreateSquad->SetEnabled(true);
  352. CastTo(m_pbuttonLog, pns->FindMember("logButtonPane"));
  353. AddEventTarget(OnButtonLog, m_pbuttonLog->GetEventSource());
  354. m_pbuttonLog->SetEnabled(false);
  355. CastTo(m_pbuttonApply, pns->FindMember("applyButtonPane"));
  356. AddEventTarget(OnButtonApply, m_pbuttonApply->GetEventSource());
  357. m_pbuttonApply->SetEnabled(false);
  358. m_pbuttonApply->SetHidden(true);
  359. CastTo(m_pbuttonURL, pns->FindMember("URLButtonPane"));
  360. AddEventTarget(OnButtonJumpURL, m_pbuttonURL->GetEventSource());
  361. CastTo(m_pbuttonFindSquad, pns->FindMember("squadFindButtonPane"));
  362. AddEventTarget(OnButtonFindSquad, m_pbuttonFindSquad->GetEventSource());
  363. //
  364. // Combo panes
  365. //
  366. CastTo(m_pcomboCiv, pns->FindMember("civComboPane"));
  367. m_pcomboCiv->SetEnabled(false);
  368. int cNames = FillCombo(pns, m_pcomboCiv, "CivNames");
  369. m_cCivs = cNames;
  370. m_pCivIds = new int[cNames];
  371. int cInts = FillIntegerArray(pns, m_pCivIds, "CivIDs");
  372. assert(cInts == cNames);
  373. //
  374. // Icons
  375. //
  376. CastTo(m_pimageOwner, (Value*) pns->FindMember("ownerImage" ));
  377. CastTo(m_pimageASL, (Value*) pns->FindMember("ASLImage" ));
  378. CastTo(m_pimagePending, (Value*) pns->FindMember("PendingImage" ));
  379. CastTo(m_pimageRejected, (Value*) pns->FindMember("RejectedImage"));
  380. CastTo(m_pimageMember, (Value*) pns->FindMember("MemberImage" ));
  381. CastTo(m_pimageBooted, (Value*) pns->FindMember("BootedImage" ));
  382. CastTo(m_pimageQuit, (Value*) pns->FindMember("QuitImage" ));
  383. //
  384. // Tab
  385. //
  386. TRef<IObject> pobjColumns;
  387. TRef<ColorValue> pColor;
  388. CastTo(m_ptabSquads, pns->FindMember("squadTabPane" ));
  389. CastTo(pobjColumns, pns->FindMember("tabColumns" ));
  390. CastTo(pColor, pns->FindMember("squadTabHeaderTextColor"));
  391. m_colorTabText = pColor->GetValue();
  392. CastTo(pColor, pns->FindMember("squadSelectedTabHeaderTextColor"));
  393. m_colorTabTextSelected = pColor->GetValue();
  394. ParseIntVector(pobjColumns, m_viTabColumns);
  395. AddEventTarget(_OnButtonBarTabs, m_ptabSquads->GetEventSource());
  396. m_ptabSquads->SetHidden(FILTER_DUDEX, true);
  397. // m_ptabSquads->SetChecked(m_nTab, true);
  398. // m_ptabSquads->SetChecked2(m_nTab, false);
  399. //
  400. // Squads listbox
  401. //
  402. CastTo(m_plistPaneSquads, (Pane*)pns->FindMember("squadsListPane" ));
  403. CastTo(m_pbuttonbarSquadsHeader, pns->FindMember("squadsListHeader" ));
  404. CastTo(pobjColumns, pns->FindMember("squadsColumns" ));
  405. CastTo(pColor, pns->FindMember("squadSelectColor" ));
  406. m_colorSquadSelectionBar = pColor->GetValue();
  407. AddEventTarget(_OnButtonBarSquads, m_pbuttonbarSquadsHeader->GetEventSource());
  408. ParseIntVector(pobjColumns, m_viColumns);
  409. m_peventSquads = m_plistPaneSquads->GetSelectionEventSource();
  410. m_peventSquads->AddSink(m_psinkSquads = new IItemEvent::Delegate(this));
  411. m_plistPaneSquads->SetItemPainter(new SquadsItemPainter(m_viColumns, this));
  412. m_pscrollPaneSquads = m_plistPaneSquads->GetScrollPane();
  413. m_pscrollPaneSquads->SetHidden(true);
  414. DisableAllOwnerButtons();
  415. DisableAllRegularButtons();
  416. //
  417. // Squad Details Area
  418. //
  419. CastTo(m_peditPaneSquadName, (Pane*)pns->FindMember("squadNameEditPane"));
  420. m_peditPaneSquadName->SetMaxLength(c_cbNameDB);
  421. AddEventTarget(OnSquadNameClick, m_peditPaneSquadName->GetClickEvent());
  422. m_peventNameEdit = m_peditPaneSquadName->GetChangeEvent();
  423. m_peventNameEdit->AddSink(m_psinkNameEdit = new TEvent<ZString>::Delegate(this));
  424. CastTo(m_peditPaneSquadDescription, (Pane*)pns->FindMember("squadDescriptionEditPane"));
  425. m_peditPaneSquadDescription->SetMaxLength(c_cbSquadDescriptionDB);
  426. AddEventTarget(OnSquadDescriptionClick, m_peditPaneSquadDescription->GetClickEvent());
  427. m_peventDescEdit = m_peditPaneSquadDescription->GetChangeEvent();
  428. m_peventDescEdit->AddSink(m_psinkDescEdit = new TEvent<ZString>::Delegate(this));
  429. CastTo(m_peditPaneSquadURL, (Pane*)pns->FindMember("squadURLEditPane"));
  430. m_peditPaneSquadURL->SetMaxLength(c_cbURLDB);
  431. AddEventTarget(OnSquadURLClick, m_peditPaneSquadURL->GetClickEvent());
  432. m_peventURLEdit = m_peditPaneSquadURL->GetChangeEvent();
  433. m_peventURLEdit->AddSink(m_psinkURLEdit = new TEvent<ZString>::Delegate(this));
  434. CastTo(m_peditPaneFind, (Pane*)pns->FindMember("squadFindPane"));
  435. m_peditPaneFind->SetMaxLength(c_cbNameDB);
  436. AddEventTarget(OnFindClick, m_peditPaneFind->GetClickEvent());
  437. m_peventFind = m_peditPaneFind->GetChangeEvent();
  438. m_peventFind->AddSink(m_psinkFind = new TEvent<ZString>::Delegate(this));
  439. m_peditPaneSquadName->SetReadOnly();
  440. m_peditPaneSquadDescription->SetHidden(true);
  441. m_peditPaneSquadURL->SetReadOnly();
  442. CastTo(m_pstrpaneRanking, (Pane*) pns->FindMember("rankingStringPane"));
  443. CastTo(m_pstrpaneRank, (Pane*) pns->FindMember("rankStringPane"));
  444. CastTo(m_pstrpaneWinsAndLosses, (Pane*) pns->FindMember("winsAndLossesStringPane"));
  445. CastTo(m_pstrpaneInceptionDate, (Pane*) pns->FindMember("inceptionDateStringPane"));
  446. //
  447. // Players listbox
  448. //
  449. CastTo(m_plistPanePlayers, (Pane*)pns->FindMember("playersListPane" ));
  450. CastTo(m_pbuttonbarPlayersHeader, pns->FindMember("playersListHeader" ));
  451. CastTo(pobjColumns, pns->FindMember("playersColumns" ));
  452. CastTo(pColor, pns->FindMember("playerSelectColor" ));
  453. m_colorPlayerSelectionBar = pColor->GetValue();
  454. AddEventTarget(OnButtonBarPlayers, m_pbuttonbarPlayersHeader->GetEventSource());
  455. ParseIntVector(pobjColumns, m_viPlayersColumns);
  456. m_peventPlayers = m_plistPanePlayers->GetSelectionEventSource();
  457. m_peventPlayers->AddSink(m_psinkPlayers = new IItemEvent::Delegate(this));
  458. m_plistPanePlayers->SetItemPainter(new PlayersItemPainter(m_viPlayersColumns, this));
  459. AddEventTarget(OnDoubleClickPlayer, m_plistPanePlayers->GetDoubleClickEventSource());
  460. // m_peventPlayersDoubleClick = m_plistPanePlayers->GetDoubleClickEventSource();
  461. // m_peventPlayersDoubleClick->AddSink(m_psinkPlayersDoubleClick = new IItemEvent::Delegate(this));
  462. //
  463. // History Dialog
  464. //
  465. m_pHistoryDialog = new HistoryDialogPopup(pns, this);
  466. if (s_pDudeXPlayer)
  467. {
  468. m_pstringSquadTabDudeX->SetValue(s_pDudeXPlayer->GetName());
  469. m_ptabSquads->SetHidden(FILTER_DUDEX, false);
  470. }
  471. //
  472. // Unload namespace
  473. //
  474. pmodeler->UnloadNameSpace(pns);
  475. //pmodeler->UnloadNameSpace(pnsData);
  476. // check column with the default sort
  477. m_pbuttonbarSquadsHeader->SetChecked(s_column, true);
  478. m_pbuttonbarSquadsHeader->SetChecked2(s_column, false);
  479. m_pbuttonbarPlayersHeader->SetChecked(2, true); // 2 == status
  480. m_pbuttonbarPlayersHeader->SetChecked2(2, false);
  481. m_vuPlayersSorts.PushEnd(1); // 1 == rank; player rank is the default secondary sort
  482. m_vuPlayersSorts.PushEnd(2); // 2 == status; player status is the default primary sort
  483. // Request a starting page of squads
  484. int nTemp = m_nTab;
  485. m_nTab = -1; // force switch
  486. ZString temp(m_strSquadToBeSelected);
  487. OnButtonBarTabs(nTemp);
  488. m_strSquadToBeSelected = temp; // quick fix hack
  489. //
  490. // Temporary, throw some squads in there
  491. //
  492. /*
  493. for (int i = 0; i < 30; ++i)
  494. {
  495. TRef<IZoneSquad> psquad = CreateZoneSquad();
  496. psquad->SetName("Marco's Squad");
  497. psquad->SetDescription("Right mix of Pro's and Newbies");
  498. psquad->SetURL("home.sprintmail.com/~mcurrie");
  499. psquad->SetInceptionDate("12/11/99");
  500. psquad->SetWins(55-i);
  501. psquad->SetLosses(3+i);
  502. psquad->SetRanking((i+1)*2-1);
  503. psquad->SetRank(IZoneSquad::Rank((i+1)%3+1));
  504. psquad->SetCivID((i+2)%4-1);
  505. psquad->SetScore((i+2)%4-1);
  506. psquad->AppendOwnershipLog("Jack Smith", "1/1/98");
  507. psquad->AppendOwnershipLog("Tom Daly", "3/19/98");
  508. int j;
  509. TRef<IZonePlayer> pplayer;
  510. for (j = 0; j < 35 - i; ++j)
  511. {
  512. pplayer = CreateZonePlayer();
  513. pplayer->Randomize();
  514. psquad->AddPlayer(*pplayer, IZonePlayer::DSTAT_MEMBER);
  515. }
  516. psquad->SetOwner(pplayer);
  517. AddSquadToScreen(psquad);
  518. psquad = CreateZoneSquad();
  519. psquad->SetName("Marco's Squad 2");
  520. psquad->SetDescription("Come meet your doom.");
  521. psquad->SetURL("www.dkeep.com/marco");
  522. psquad->SetInceptionDate("12/12/99");
  523. psquad->SetWins(50-i);
  524. psquad->SetLosses(7+i);
  525. psquad->SetRanking((i+1)*2);
  526. psquad->SetRank(IZoneSquad::Rank(i%3+1));
  527. psquad->SetCivID(i%4-1);
  528. psquad->SetScore(i%4-1);
  529. psquad->AppendOwnershipLog("Mary Wilson", "8/10/99");
  530. psquad->AppendOwnershipLog("Steve Smith", "10/11/99");
  531. psquad->AppendOwnershipLog("Jack Reed", "11/12/99");
  532. for (j = 0; j < 32 - i; ++j)
  533. {
  534. pplayer = CreateZonePlayer();
  535. pplayer->Randomize();
  536. psquad->AddPlayer(*pplayer, IZonePlayer::DSTAT_MEMBER);
  537. }
  538. psquad->SetOwner(pplayer);
  539. s_pActivePlayer = pplayer; // make the last player
  540. AddSquadToScreen(psquad);
  541. }
  542. */
  543. }
  544. void OnLeavingScreen()
  545. {
  546. // ensure called only once
  547. if (m_bLeftScreen)
  548. return;
  549. m_bLeftScreen = true;
  550. if(m_pkeyboardInputOldFocus)
  551. GetWindow()->SetFocus(m_pkeyboardInputOldFocus);
  552. }
  553. bool IsRankingOnScreen(int nRanking)
  554. {
  555. if (nRanking == -1)
  556. return false;
  557. if (m_nCurrentRanking <= 1+c_cSquadsShown/2)
  558. return nRanking <= c_cSquadsShown;
  559. return nRanking >= m_nCurrentRanking - c_cSquadsShown / 2 &&
  560. nRanking <= m_nCurrentRanking + c_cSquadsShown / 2;
  561. }
  562. /*
  563. int FindRanking_ForMiddleSquad()
  564. {
  565. XSquadsIt it(m_listSquads[FILTER_ALL]);
  566. int nLowest = 99999999;
  567. int nHighest = -1;
  568. while(!it.End())
  569. {
  570. int nRank = it.Value()->GetRanking(s_column);
  571. if (nRank < nLowest)
  572. {
  573. nLowest = nRank;
  574. }
  575. if (nRank > nHighest)
  576. {
  577. nHighest = nRank;
  578. }
  579. it.Next();
  580. }
  581. if (nHighest != -1 && nLowest + c_cSquadsShown / 2 <= nHighest)
  582. return nLowest + c_cSquadsShown / 2;
  583. else
  584. return -1;
  585. }
  586. */
  587. /*-------------------------------------------------------------------------
  588. * FindSquadByID()
  589. *-------------------------------------------------------------------------
  590. * Returns:
  591. * A squad given its id.
  592. */
  593. TRef<IZoneSquad> FindSquadByID(int nID)
  594. {
  595. XSquadsIt it(m_listAllSquads);
  596. while(!it.End())
  597. {
  598. if (it.Value()->GetID() == nID)
  599. {
  600. return it.Value();
  601. }
  602. it.Next();
  603. }
  604. return NULL;
  605. }
  606. /*-------------------------------------------------------------------------
  607. * FindSquadByCreationID()
  608. *-------------------------------------------------------------------------
  609. * Returns:
  610. * A squad given its creation id.
  611. */
  612. TRef<IZoneSquad> FindSquadByCreationID(int nID)
  613. {
  614. XSquadsIt it(m_listAllSquads);
  615. while(!it.End())
  616. {
  617. if (it.Value()->GetCreationID() == nID)
  618. {
  619. return it.Value();
  620. }
  621. it.Next();
  622. }
  623. return NULL;
  624. }
  625. /*-------------------------------------------------------------------------
  626. * FindSquadByRanking()
  627. *-------------------------------------------------------------------------
  628. * Returns:
  629. * A squad given its ranking.
  630. *
  631. * Remarks:
  632. * Rankings are unique at a given snap shot of time.
  633. */
  634. TRef<IZoneSquad> FindSquadByRanking(SQUAD_SORT_COLUMN column, int nRanking)
  635. {
  636. XSquadsIt it(m_listAllSquads);
  637. while(!it.End())
  638. {
  639. if (it.Value()->GetRanking(column) == nRanking)
  640. {
  641. return it.Value();
  642. }
  643. it.Next();
  644. }
  645. return NULL;
  646. }
  647. /*-------------------------------------------------------------------------
  648. * FindPlayerByID()
  649. *-------------------------------------------------------------------------
  650. * Returns:
  651. * A member given his id.
  652. */
  653. TRef<IZonePlayer> FindPlayerByID(int nID)
  654. {
  655. XZonePlayersIt it(m_listAllPlayers);
  656. while(!it.End())
  657. {
  658. if (it.Value()->GetID() == nID)
  659. {
  660. return it.Value();
  661. }
  662. it.Next();
  663. }
  664. return NULL;
  665. }
  666. /*-------------------------------------------------------------------------
  667. * CreateZoneSquad()
  668. *-------------------------------------------------------------------------
  669. * Returns:
  670. * A new squad, after putting in mother list.
  671. */
  672. TRef<IZoneSquad> CreateZoneSquad()
  673. {
  674. TRef<IZoneSquad> psquad = ::CreateZoneSquad();
  675. m_listAllSquads.PushEnd(psquad);
  676. return psquad;
  677. }
  678. TRef<IZonePlayer> CreateZonePlayer(const char *szName, int nID)
  679. {
  680. TRef<IZonePlayer> pPlayer = ::CreateZonePlayer(szName, nID);
  681. m_listAllPlayers.PushEnd(pPlayer);
  682. return pPlayer;
  683. }
  684. /*-------------------------------------------------------------------------
  685. * SEND_FOR_ACTIVE_MEMBER()
  686. *-------------------------------------------------------------------------
  687. *
  688. * Purpose: Send a message that has just one paramter: nSquadID
  689. *
  690. * The member is question is assumed to be the Interactive member.
  691. *
  692. * This applies to the following messages:
  693. *
  694. * SQUAD_QUIT, SQUAD_CANCEL_JOIN_REQUEST, SQUAD_MAKE_JOIN_REQUEST
  695. * SQUAD_DETAILS_REQ,
  696. *-------------------------------------------------------------------------
  697. */
  698. #define SEND_FOR_ACTIVE_MEMBER(MessageType) \
  699. { \
  700. debugf("Sending %s; squad %d (%s)\n", #MessageType, s_pSelectedSquad->GetID(), s_pSelectedSquad->GetName()); \
  701. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmSquadMessage, C, MessageType) \
  702. END_PFM_CREATE \
  703. pfmSquadMessage->nSquadID = s_pSelectedSquad->GetID(); \
  704. trekClient.SendClubMessages(); \
  705. }
  706. /*-------------------------------------------------------------------------
  707. * SEND_FOR_SELECTED_MEMBER()
  708. *-------------------------------------------------------------------------
  709. *
  710. * Purpose: Send a message that has just two paramters: nSquadID, nMemberID
  711. *
  712. * This applies to the following messages:
  713. *
  714. * SQUAD_REJECT_JOIN_REQUEST, SQUAD_ACCEPT_JOIN_REQUEST,
  715. * SQUAD_BOOT_MEMBER, SQUAD_PROMOTE_TO_ASL, SQUAD_DEMOTE_TO_MEMBER,
  716. * SQUAD_TRANSFER_CONTROL
  717. *-------------------------------------------------------------------------
  718. */
  719. #define SEND_FOR_SELECTED_MEMBER(MessageType) \
  720. { \
  721. debugf("Sending %s; member %d (%s)\n; squad %d (%s)", #MessageType, s_pSelectedPlayer->GetID(), s_pSelectedPlayer->GetName(), s_pSelectedSquad->GetID(), s_pSelectedSquad->GetName()); \
  722. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmSquadMessage, C, MessageType) \
  723. END_PFM_CREATE \
  724. pfmSquadMessage->nMemberID = s_pSelectedPlayer->GetID(); \
  725. pfmSquadMessage->nSquadID = s_pSelectedSquad->GetID(); \
  726. trekClient.SendClubMessages(); \
  727. }
  728. void ResetHighLowRanges()
  729. {
  730. //
  731. // reset highest/lowest
  732. //
  733. m_nHighestRanking[s_column] = 999999;
  734. m_nLowestRanking[s_column] = -1;
  735. m_psquadHighestRanking[s_column] = NULL;
  736. m_psquadLowestRanking[s_column] = NULL;
  737. TRef<IZoneSquad> psquad = NULL;
  738. if (m_nCurrentRanking != -1)
  739. psquad = FindSquadByRanking(s_column, m_nCurrentRanking);
  740. if (psquad)
  741. {
  742. UpdateHighLowRanges(psquad, m_nCurrentRanking, s_column);
  743. }
  744. }
  745. /*-------------------------------------------------------------------------
  746. * RequestPage()
  747. *-------------------------------------------------------------------------
  748. *
  749. * Purpose: Request a list of squads
  750. *
  751. * Parameters: psquad: the basis squad used to get info
  752. *-------------------------------------------------------------------------
  753. */
  754. void RequestPage(TRef<IZoneSquad> psquad, bool bNewColumn = false, bool bSwitchingToAllTab = false)
  755. {
  756. m_psquadPrePage = psquad;
  757. // Ask server for data
  758. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmNextPage, C, SQUAD_NEXT_PAGE_ALL)
  759. END_PFM_CREATE
  760. // update s_column as needed
  761. if (bNewColumn || bSwitchingToAllTab)
  762. {
  763. if (psquad && psquad->GetRanking(s_column) != -1)
  764. {
  765. m_nCurrentRanking = psquad->GetRanking(s_column);
  766. // reset highest/lowest
  767. m_nHighestRanking[s_column] = psquad->GetRanking(s_column);
  768. m_nLowestRanking[s_column] = psquad->GetRanking(s_column);
  769. m_psquadHighestRanking[s_column] = psquad;
  770. m_psquadLowestRanking[s_column] = psquad;
  771. }
  772. else
  773. {
  774. m_nCurrentRanking = -1; // we always set this to -1 when changing columns
  775. ResetHighLowRanges();
  776. }
  777. }
  778. pfmNextPage->column = s_column;
  779. if(psquad)
  780. {
  781. pfmNextPage->nSquadID = psquad->GetID();
  782. }
  783. else
  784. {
  785. m_nCurrentRanking = 1+c_cSquadsShown/2; // place in middle of screen
  786. pfmNextPage->nSquadID = -1;
  787. }
  788. debugf("Sending SQUAD_NEXT_PAGE_ALL; squad %d (%s)\n", pfmNextPage->nSquadID, FindSquadByID(pfmNextPage->nSquadID) ? FindSquadByID(pfmNextPage->nSquadID)->GetName() : "TOP");
  789. trekClient.SendClubMessages();
  790. DisplaySquadsInRange();
  791. }
  792. /*-------------------------------------------------------------------------
  793. * DisplaySquadsInRange()
  794. *-------------------------------------------------------------------------
  795. *
  796. * Purpose: Look in cache and display the appropriate squads.
  797. *
  798. *-------------------------------------------------------------------------
  799. */
  800. void DisplaySquadsInRange(bool bShowEvenIfNotFull = false)
  801. {
  802. assert(m_nTab == FILTER_ALL);
  803. // clear screen
  804. m_listSquads[FILTER_ALL].SetEmpty(); // 0 == ALL squads tab
  805. m_bSelectorNeedsAutoSet = true;
  806. if(m_nCurrentRanking==-1)
  807. return;
  808. if(m_nCurrentRanking < 1/*c_cSquadsShown / 2*/)
  809. m_nCurrentRanking = 1+c_cSquadsShown / 2;
  810. if (!bShowEvenIfNotFull)
  811. {
  812. //
  813. // First see is cache has c_cSquadsShown number of squads that we can display
  814. // right now, if not then don't display any of them (due to visional glitches
  815. // when paging up).
  816. //
  817. int nCount = 0;
  818. XSquadsIt it(m_listAllSquads);
  819. while(!it.End())
  820. {
  821. TRef<IZoneSquad> psquad = it.Value();
  822. if (IsRankingOnScreen(psquad->GetRanking(s_column)))
  823. {
  824. nCount++;
  825. }
  826. it.Next();
  827. }
  828. if (nCount < c_cSquadsShown) // if cache isn't complete so quit now
  829. return;
  830. }
  831. //
  832. // Since we know we have enough to show, let's show them
  833. //
  834. debugf("Ranking At Top: %d\n", m_nCurrentRanking);
  835. //
  836. // Let's see if we already have some of the squads we need, if so add it now
  837. //
  838. XSquadsIt it(m_listAllSquads);
  839. while(!it.End())
  840. {
  841. TRef<IZoneSquad> psquad = it.Value();
  842. int ranking = psquad->GetRanking(s_column);
  843. if (IsRankingOnScreen(ranking))
  844. {
  845. AddSquadToScreen(psquad, false);
  846. if ((psquad->GetRanking(s_column) == m_nCurrentRanking) ||
  847. (m_strSquadToBeSelected.GetLength() > 0 && m_strSquadToBeSelected == psquad->GetName()))
  848. {
  849. SelectSquad(*psquad);
  850. }
  851. //
  852. // update highest and lowest; this is also done in when decoding a FM_S_SQUAD_INFO message
  853. //
  854. UpdateHighLowRanges(psquad, ranking, s_column);
  855. }
  856. it.Next();
  857. }
  858. RefreshScreen();
  859. }
  860. /*-------------------------------------------------------------------------
  861. * DisplaySquadsInRangeForDudeX()
  862. *-------------------------------------------------------------------------
  863. *
  864. * Purpose: Look in cache and display the appropriate squads.
  865. *
  866. *-------------------------------------------------------------------------
  867. */
  868. void DisplaySquadsInRangeForDudeX(int nTab, TRef<IZonePlayer> pplayer)
  869. {
  870. m_listSquads[nTab].SetEmpty();
  871. m_bSelectorNeedsAutoSet = true;
  872. XSquadsIt it(m_listAllSquads);
  873. while(!it.End())
  874. {
  875. TRef<IZoneSquad> psquad = it.Value();
  876. if(pplayer->GetStatus(*psquad) != IZonePlayer::DSTAT_NO_ASSOCIATION)
  877. {
  878. m_listSquads[nTab].PushEnd(psquad);
  879. if (m_strSquadToBeSelected.GetLength() > 0 && m_strSquadToBeSelected == psquad->GetName())
  880. {
  881. m_strSquadToBeSelected = "";
  882. SelectSquad(*psquad);
  883. }
  884. }
  885. it.Next();
  886. }
  887. RefreshScreen();
  888. }
  889. /*-------------------------------------------------------------------------
  890. * UpdateHighLowRanges()
  891. *-------------------------------------------------------------------------
  892. *
  893. * Purpose: These ranges help us decide which psquad to use as a basis
  894. * in our query for most squad info messages.
  895. *
  896. *-------------------------------------------------------------------------
  897. */
  898. void UpdateHighLowRanges(TRef<IZoneSquad> psquad, int nRanking, int column)
  899. {
  900. assert(nRanking != -1);
  901. if(nRanking < m_nHighestRanking[column])
  902. {
  903. m_nHighestRanking[column] = nRanking;
  904. m_psquadHighestRanking[column] = psquad;
  905. }
  906. if(nRanking > m_nLowestRanking[column])
  907. {
  908. m_nLowestRanking[column] = nRanking;
  909. m_psquadLowestRanking[column] = psquad;
  910. }
  911. }
  912. /*-------------------------------------------------------------------------
  913. * ForwardSquadMessage()
  914. *-------------------------------------------------------------------------
  915. *
  916. * Purpose: Process server generated message for squad screen.
  917. *
  918. *-------------------------------------------------------------------------
  919. */
  920. void ForwardSquadMessage(FEDMESSAGE *pSquadMessage)
  921. {
  922. switch (pSquadMessage->fmid)
  923. {
  924. case FM_S_SQUAD_INFO:
  925. {
  926. CASTPFM(pfmInfo, S, SQUAD_INFO, pSquadMessage);
  927. SQUAD_SORT_COLUMN column = (SQUAD_SORT_COLUMN)pfmInfo->column;
  928. TRef<IZoneSquad> psquad = NULL;
  929. // ensure rankings are unique; find any existing squads with this rank and reset it
  930. psquad = FindSquadByRanking(column, pfmInfo->nRanking);
  931. if(psquad && psquad->GetID() != pfmInfo->nSquadID)
  932. {
  933. // check for Ranking discontinuity. That happens if ranking has changed
  934. // and the cache is out-of-date.
  935. debugf("Ranking discontinuity detected in column %d, Ranking of %d\n", column, pfmInfo->nRanking);
  936. ResetHighLowRanges();
  937. psquad->SetRanking(column, -1);
  938. // remove from screen
  939. if(m_listSquads[FILTER_ALL].Remove(psquad))
  940. RefreshScreen();
  941. psquad = NULL;
  942. }
  943. if (psquad == NULL)
  944. psquad = FindSquadByID(pfmInfo->nSquadID); // see if we already know about the squad sent from club server
  945. if (psquad == NULL)
  946. {
  947. psquad = CreateZoneSquad();
  948. psquad->SetID(pfmInfo->nSquadID);
  949. }
  950. char *szName = FM_VAR_REF(pfmInfo, szName);
  951. if(szName == NULL)
  952. szName = "";
  953. psquad->SetName(szName);
  954. psquad->SetRanking(column, pfmInfo->nRanking);
  955. psquad->SetWins(pfmInfo->cWins);
  956. psquad->SetLosses(pfmInfo->cLosses);
  957. psquad->SetScore(pfmInfo->nScore);
  958. //
  959. // update highest and lowest; this is also done in DisplaySquadsInRange()
  960. //
  961. UpdateHighLowRanges(psquad, pfmInfo->nRanking, column);
  962. //
  963. // Add squad to screen as needed
  964. //
  965. if (column != s_column || m_nTab != FILTER_ALL)
  966. break;
  967. if (pfmInfo->bSearchResult)
  968. {
  969. unsigned nSearchMatch = CompareStrings(szName, PCC(m_peditPaneFind->GetString()), m_peditPaneFind->GetString().GetLength());
  970. if (m_nCurrentRanking == -1)
  971. m_nCurrentRanking = pfmInfo->nRanking;
  972. if (nSearchMatch < m_nBestSearchMatch)
  973. {
  974. m_nCurrentRanking = pfmInfo->nRanking;
  975. m_nBestSearchMatch = nSearchMatch;
  976. DisplaySquadsInRange(true);
  977. // shouldn't happen, but let's be safe
  978. if(!m_listSquads[FILTER_ALL].Find(psquad))
  979. {
  980. AddSquadToScreen(psquad);
  981. debugf("Warning, Forcing squad to be shown (after search): %s\n", psquad->GetName());
  982. }
  983. SelectSquad(*psquad);
  984. }
  985. else
  986. // if in range, show it
  987. if (IsRankingOnScreen(pfmInfo->nRanking))
  988. AddSquadToScreen(psquad, true);
  989. }
  990. else
  991. if (m_nCurrentRanking == -1)
  992. {
  993. // after changing column sorts, make sure the same squad is selected
  994. if (m_psquadPrePage == psquad)
  995. {
  996. m_nCurrentRanking = max(1, psquad->GetRanking(s_column));
  997. DisplaySquadsInRange();
  998. // It's rare, but this can happen if user request lots of pages and switching between columns frequently
  999. if(!m_listSquads[FILTER_ALL].Find(psquad))
  1000. {
  1001. debugf("Warning, pre-column change squad is not on screen when it should, resending Request for Page: %s\n", psquad->GetName());
  1002. ResetHighLowRanges();
  1003. m_nCurrentRanking = psquad->GetRanking(s_column);
  1004. RequestPage(psquad);
  1005. }
  1006. else
  1007. SelectSquad(*psquad);
  1008. }
  1009. else
  1010. RefreshScreen();
  1011. }
  1012. else
  1013. {
  1014. // if in range, show it
  1015. if (IsRankingOnScreen(pfmInfo->nRanking))
  1016. {
  1017. AddSquadToScreen(psquad, false);
  1018. if ((pfmInfo->nRanking == m_nCurrentRanking && m_bSelectorNeedsAutoSet) ||
  1019. (m_strSquadToBeSelected.GetLength() > 0 && m_strSquadToBeSelected == psquad->GetName()))
  1020. {
  1021. SelectSquad(*psquad);
  1022. m_bSelectorNeedsAutoSet = false;
  1023. }
  1024. }
  1025. RefreshScreen();
  1026. }
  1027. }
  1028. break;
  1029. case FM_S_SQUAD_INFO_DUDEX:
  1030. {
  1031. CASTPFM(pfmInfo, S, SQUAD_INFO_DUDEX, pSquadMessage);
  1032. TRef<IZoneSquad> psquad = FindSquadByID(pfmInfo->nSquadID); // see if we already know about the squad sent from club server
  1033. if (psquad == NULL)
  1034. {
  1035. psquad = CreateZoneSquad();
  1036. psquad->SetID(pfmInfo->nSquadID);
  1037. }
  1038. char *szName = FM_VAR_REF(pfmInfo, szName);
  1039. if(szName)
  1040. psquad->SetName(szName);
  1041. psquad->SetWins(pfmInfo->cWins);
  1042. psquad->SetLosses(pfmInfo->cLosses);
  1043. psquad->SetScore(pfmInfo->nScore);
  1044. if (pfmInfo->bMyTab)
  1045. {
  1046. AddSquadToScreen(psquad, true, FILTER_MY);
  1047. if (s_pActivePlayer->GetStatus(*psquad) == IZonePlayer::DSTAT_NO_ASSOCIATION) // if not already on team
  1048. psquad->SetStatus(*s_pActivePlayer, IZonePlayer::DSTAT_UNKNOWN); // assume member until told otherwise
  1049. }
  1050. else
  1051. {
  1052. AddSquadToScreen(psquad, true, FILTER_DUDEX);
  1053. if(s_pDudeXPlayer && s_pDudeXPlayer->GetStatus(*psquad) == IZonePlayer::DSTAT_NO_ASSOCIATION) // if not already on team
  1054. psquad->SetStatus(*s_pDudeXPlayer, IZonePlayer::DSTAT_UNKNOWN); // assume member until told otherwise
  1055. }
  1056. if (m_strSquadToBeSelected.GetLength() > 0 && m_strSquadToBeSelected == psquad->GetName())
  1057. {
  1058. SelectSquad(*psquad);
  1059. m_strSquadToBeSelected = "";
  1060. }
  1061. }
  1062. break;
  1063. case FM_S_SQUAD_DETAILS:
  1064. {
  1065. CASTPFM(pfmDetails, S, SQUAD_DETAILS, pSquadMessage);
  1066. m_psquadLastDetails = FindSquadByID(pfmDetails->nSquadID);
  1067. if (m_psquadLastDetails)
  1068. {
  1069. m_psquadLastDetails->SetEmpty(); // clear membership cache, cause update is coming
  1070. if (s_pSelectedSquad == m_psquadLastDetails)
  1071. m_listPlayers.SetEmpty(); // clear list of players on screen
  1072. m_psquadLastDetails->SetDetailsReceived();
  1073. char * szDesc = FM_VAR_REF(pfmDetails, szDescription);
  1074. char * szURL = FM_VAR_REF(pfmDetails, szURL);
  1075. char * szInceptionDate = FM_VAR_REF(pfmDetails, szInceptionDate);
  1076. if(szDesc)
  1077. m_psquadLastDetails->SetDescription(szDesc);
  1078. else
  1079. m_psquadLastDetails->SetDescription("");
  1080. if(szURL)
  1081. m_psquadLastDetails->SetURL(szURL);
  1082. else
  1083. m_psquadLastDetails->SetURL("");
  1084. m_psquadLastDetails->SetCivID(pfmDetails->civid);
  1085. if(szInceptionDate)
  1086. m_psquadLastDetails->SetInceptionDate(szInceptionDate);
  1087. else
  1088. m_psquadLastDetails->SetInceptionDate("");
  1089. RefreshScreen();
  1090. }
  1091. else {assert(0);} // received details about a squad that doesn't exist
  1092. }
  1093. break;
  1094. case FM_S_SQUAD_DETAILS_PLAYER: // always follows a FM_S_SQUAD_DETAILS message (or another FM_S_SQUAD_DETAILS_PLAYER)
  1095. {
  1096. if (!m_psquadLastDetails)
  1097. {
  1098. assert(0); // client never received a FM_S_SQUAD_DETAILS message
  1099. break;
  1100. }
  1101. CASTPFM(pfmDetails, S, SQUAD_DETAILS_PLAYER, pSquadMessage);
  1102. /* if (!IMemberBase::IsRankValid(pfmDetails->sqRank) ||
  1103. !IMemberBase::IsDetailedStatusValid(pfmDetails->detailedstatus))
  1104. {
  1105. assert(0); // data sent from club is invalid
  1106. break;
  1107. }
  1108. */
  1109. TRef<IZonePlayer> pmember = FindPlayerByID(pfmDetails->nMemberID);
  1110. char * szName = FM_VAR_REF(pfmDetails, szName);
  1111. if (pmember == NULL)
  1112. {
  1113. pmember = CreateZonePlayer(szName ? szName : "?", pfmDetails->nMemberID);
  1114. }
  1115. if (szName)
  1116. pmember->SetName(szName);
  1117. char * szLastPlayed = FM_VAR_REF(pfmDetails, szLastPlayed);
  1118. // set/refresh member data
  1119. pmember->SetRank(pfmDetails->sqRank);
  1120. //
  1121. // Okay, now we actually add the player to the squad, depending on
  1122. // his detailed status.
  1123. //
  1124. switch (pfmDetails->detailedstatus)
  1125. {
  1126. case IZonePlayer::DSTAT_PENDING:
  1127. {
  1128. m_psquadLastDetails->AddJoinRequest(*pmember);
  1129. }
  1130. break;
  1131. case IZonePlayer::DSTAT_MEMBER:
  1132. {
  1133. m_psquadLastDetails->AddPlayer(*pmember, IZonePlayer::DSTAT_MEMBER);
  1134. }
  1135. break;
  1136. case IZonePlayer::DSTAT_ASL:
  1137. {
  1138. m_psquadLastDetails->AddPlayer(*pmember, IZonePlayer::DSTAT_ASL);
  1139. }
  1140. break;
  1141. case IZonePlayer::DSTAT_LEADER:
  1142. {
  1143. m_psquadLastDetails->AddPlayer(*pmember, IZonePlayer::DSTAT_LEADER);
  1144. }
  1145. break;
  1146. default:
  1147. assert(0); // don't know how to add this member to specified squad
  1148. break;
  1149. }
  1150. //
  1151. // Now that member has been added to squad, we can set his date
  1152. //
  1153. if (szLastPlayed)
  1154. pmember->SetLastPlayedDate(*m_psquadLastDetails, szLastPlayed);
  1155. else
  1156. pmember->SetLastPlayedDate(*m_psquadLastDetails, " ");
  1157. // this keeps selected player selected (despite the fact we recently cleared m_listPlayers)
  1158. if (pmember == s_pSelectedPlayer &&
  1159. s_pSelectedSquad && pmember->IsMemberOf(*s_pSelectedSquad) &&
  1160. s_pSelectedPlayer)
  1161. {
  1162. if (!m_listPlayers.Find(pmember)) // make sure he is in list
  1163. m_listPlayers.PushEnd(pmember);
  1164. SelectPlayer(*pmember);
  1165. }
  1166. RefreshScreen();
  1167. }
  1168. break;
  1169. case FM_S_SQUAD_LOG_INFO:
  1170. {
  1171. CASTPFM(pfmLogInfo, S, SQUAD_LOG_INFO, pSquadMessage);
  1172. TRef<IZoneSquad> psquad = FindSquadByID(pfmLogInfo->nSquadID);
  1173. if (psquad)
  1174. {
  1175. psquad->SetOwnershipLog(FM_VAR_REF(pfmLogInfo, LogInfo));
  1176. m_pHistoryDialog->SetHistory(psquad->GetOwnershipLog());
  1177. }
  1178. else
  1179. { // received log info about a squad that doesn't exist
  1180. assert(0);
  1181. }
  1182. }
  1183. break;
  1184. case FM_S_SQUAD_DELETED:
  1185. {
  1186. CASTPFM(pfmDeletedNotice, S, SQUAD_DELETED, pSquadMessage);
  1187. TRef<IZoneSquad> psquad = FindSquadByID(pfmDeletedNotice->nSquadID);
  1188. if (psquad)
  1189. {
  1190. DeleteSquad(psquad);
  1191. }
  1192. }
  1193. break;
  1194. case FM_S_SQUAD_TEXT_MESSAGE:
  1195. {
  1196. CASTPFM(pfmTextMsg, S, SQUAD_TEXT_MESSAGE, pSquadMessage);
  1197. char * szTextMsg = FM_VAR_REF(pfmTextMsg, szMsg);
  1198. MessageBox(szTextMsg);
  1199. }
  1200. break;
  1201. case FM_S_SQUAD_CREATE_ACK:
  1202. {
  1203. CASTPFM(pfmAck, S, SQUAD_CREATE_ACK, pSquadMessage);
  1204. TRef<IZoneSquad> psquad = FindSquadByCreationID(pfmAck->nClientSquadID);
  1205. if (psquad)
  1206. {
  1207. if (pfmAck->bSuccessful)
  1208. {
  1209. // see if there is an existing squad with this id, if so, delete it
  1210. // this can happen is the federation database is out-of-sync
  1211. TRef<IZoneSquad> psquadOld = FindSquadByCreationID(pfmAck->nSquadID);
  1212. if (psquadOld)
  1213. {
  1214. DeleteSquad(psquadOld);
  1215. }
  1216. psquad->SetID(pfmAck->nSquadID);
  1217. if (m_nTab == FILTER_ALL)
  1218. {
  1219. // now that we now the server made the squad, let's displayed the true
  1220. // squads that are supposed to be displayed around this one, given the
  1221. // current sort
  1222. ResetHighLowRanges();
  1223. m_nCurrentRanking = -1;
  1224. RequestPage(psquad);
  1225. }
  1226. }
  1227. else
  1228. {
  1229. DeleteSquad(psquad);
  1230. }
  1231. }
  1232. }
  1233. break;
  1234. }
  1235. }
  1236. /*-------------------------------------------------------------------------
  1237. * MessageBox()
  1238. *-------------------------------------------------------------------------
  1239. */
  1240. void MessageBox(ZString zstr)
  1241. {
  1242. static TRef<IMessageBox> pmsgBox = NULL;
  1243. if (pmsgBox && !GetWindow()->GetPopupContainer()->IsEmpty())
  1244. {
  1245. GetWindow()->GetPopupContainer()->ClosePopup(pmsgBox);
  1246. pmsgBox = NULL;
  1247. }
  1248. debugf(PCC(zstr));
  1249. pmsgBox = CreateMessageBox( zstr );
  1250. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  1251. }
  1252. /*-------------------------------------------------------------------------
  1253. * RefreshScreen()
  1254. *-------------------------------------------------------------------------
  1255. */
  1256. void RefreshScreen()
  1257. {
  1258. RefreshButtonStates();
  1259. RefreshSquadsListBox();
  1260. RefreshPlayersListBox();
  1261. RefreshSquadDetailsArea();
  1262. }
  1263. /*-------------------------------------------------------------------------
  1264. * DisableAllOwnerButtons()
  1265. *-------------------------------------------------------------------------
  1266. */
  1267. void DisableAllOwnerButtons(bool bEvenDisableEditSquad = true)
  1268. {
  1269. m_pbuttonReject->SetEnabled(false);
  1270. m_pbuttonAccept->SetEnabled(false);
  1271. m_pbuttonCommission->SetEnabled(false);
  1272. m_pbuttonDemote->SetEnabled(false);
  1273. m_pbuttonTransferControl->SetEnabled(false);
  1274. if (bEvenDisableEditSquad){
  1275. m_pbuttonEditSquad->SetEnabled(false);
  1276. }
  1277. }
  1278. /*-------------------------------------------------------------------------
  1279. * DisableAllButtons()
  1280. *-------------------------------------------------------------------------
  1281. */
  1282. void DisableAllRegularButtons(bool bEvenDisableApply = true)
  1283. {
  1284. m_pbuttonReject->SetEnabled(false);
  1285. m_pbuttonAccept->SetEnabled(false);
  1286. m_pbuttonCommission->SetEnabled(false);
  1287. m_pbuttonDemote->SetEnabled(false);
  1288. m_pbuttonTransferControl->SetEnabled(false);
  1289. m_pbuttonRequestJoin->SetEnabled(false);
  1290. m_pbuttonCancelRequest->SetEnabled(false);
  1291. m_pbuttonQuitSquad->SetEnabled(false);
  1292. if(bEvenDisableApply)
  1293. m_pbuttonApply->SetEnabled(false);
  1294. }
  1295. /*-------------------------------------------------------------------------
  1296. * RefreshButtonStates()
  1297. *-------------------------------------------------------------------------
  1298. * Purpose:
  1299. * Enable or disable the buttons for everyone (and owners) depending
  1300. * on who is the active user, which squad is selected, and which player
  1301. * is selected
  1302. */
  1303. void RefreshButtonStates()
  1304. {
  1305. m_pbuttonCreateSquad->SetEnabled(m_psquadBeingMade ? false : true);
  1306. //
  1307. // Just in case check for these
  1308. //
  1309. if (!s_pSelectedSquad || !s_pSelectedSquad->WereDetailsReceived())
  1310. {
  1311. DisableAllOwnerButtons();
  1312. DisableAllRegularButtons(s_pSelectedSquad ? false : true);
  1313. return;
  1314. }
  1315. //
  1316. // Set the buttons for regular people
  1317. //
  1318. m_pbuttonRequestJoin->SetEnabled(!s_pActivePlayer->IsMemberOf(*s_pSelectedSquad) &&
  1319. !s_pActivePlayer->IsPendingFor(*s_pSelectedSquad));
  1320. m_pbuttonCancelRequest->SetEnabled(s_pActivePlayer->IsPendingFor(*s_pSelectedSquad));
  1321. m_pbuttonQuitSquad->SetEnabled(s_pActivePlayer->IsMemberOf(*s_pSelectedSquad));
  1322. //
  1323. // Set buttons for Owners
  1324. //
  1325. if (s_pSelectedSquad->GetOwner() == s_pActivePlayer)
  1326. {
  1327. if (s_pSelectedPlayer && s_pActivePlayer != s_pSelectedPlayer)
  1328. {
  1329. m_pbuttonReject->SetEnabled(s_pSelectedPlayer->IsMemberOf(*s_pSelectedSquad) || s_pSelectedPlayer->IsPendingFor(*s_pSelectedSquad));
  1330. m_pbuttonAccept->SetEnabled(s_pSelectedPlayer->IsPendingFor(*s_pSelectedSquad));
  1331. m_pbuttonCommission->SetEnabled(s_pSelectedPlayer->GetPosition(*s_pSelectedSquad) == IZonePlayer::POS_MEMBER);
  1332. m_pbuttonDemote->SetEnabled(s_pSelectedPlayer->GetPosition(*s_pSelectedSquad) == IZonePlayer::POS_ASL);
  1333. m_pbuttonEditSquad->SetEnabled(true);
  1334. m_pbuttonTransferControl->SetEnabled(s_pSelectedPlayer->IsMemberOf(*s_pSelectedSquad));
  1335. }
  1336. else // interactiveGameDestroyed user is leader and has himself selected
  1337. {
  1338. DisableAllOwnerButtons(false);
  1339. m_pbuttonEditSquad->SetEnabled(true);
  1340. }
  1341. }
  1342. else // not owner, or owner that is selecting himself
  1343. {
  1344. DisableAllOwnerButtons();
  1345. }
  1346. }
  1347. //////////////////////////////////////////////////////////////////////////////
  1348. //
  1349. // UI Events
  1350. //
  1351. //////////////////////////////////////////////////////////////////////////////
  1352. bool OnEvent(IItemEvent::Source *pevent, ItemID pitem)
  1353. {
  1354. if (pevent == m_peventSquads)
  1355. {
  1356. OnSquadSelected(*((IZoneSquad*)pitem));
  1357. }
  1358. else
  1359. if (pevent == m_peventPlayers)
  1360. {
  1361. OnPlayerSelected(*((IZonePlayer*)pitem));
  1362. }
  1363. // else
  1364. // if (pevent == m_peventPlayersDoubleClick)
  1365. // {
  1366. // OnDoubleClickPlayer(*((IZonePlayer*)pitem));
  1367. // }
  1368. return true;
  1369. }
  1370. bool OnEvent(TEvent<ZString>::Source* pevent, ZString str)
  1371. {
  1372. if (pevent == m_peventFind)
  1373. {
  1374. OnButtonFindSquad();
  1375. }
  1376. else
  1377. if (pevent == m_peventNameEdit)
  1378. {
  1379. if (m_bSquadEditURLReset)
  1380. {
  1381. m_bSquadEditURLReset=false;
  1382. m_peditPaneSquadURL->SetString("");
  1383. }
  1384. GetWindow()->SetFocus(m_peditPaneSquadURL);
  1385. }
  1386. else
  1387. if (pevent == m_peventDescEdit)
  1388. {
  1389. if (m_bSquadEditNameReset)
  1390. {
  1391. m_bSquadEditNameReset=false;
  1392. m_peditPaneSquadName->SetString("");
  1393. m_pbuttonApply->SetEnabled(true);
  1394. }
  1395. GetWindow()->SetFocus(m_peditPaneSquadName);
  1396. }
  1397. else
  1398. if (pevent == m_peventURLEdit)
  1399. {
  1400. if (m_bSquadEditDescReset)
  1401. {
  1402. m_bSquadEditDescReset=false;
  1403. m_peditPaneSquadDescription->SetString("");
  1404. }
  1405. GetWindow()->SetFocus(m_peditPaneSquadDescription);
  1406. }
  1407. return true;
  1408. }
  1409. //////////////////////////////////////////////////////////////////////////////
  1410. //
  1411. // IKeyboardInput Methods
  1412. //
  1413. //////////////////////////////////////////////////////////////////////////////
  1414. /*
  1415. bool OnKey(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
  1416. {
  1417. if (ks.bDown)
  1418. {
  1419. if (ks.vk == VK_RETURN || ks.vk == VK_ESCAPE)
  1420. {
  1421. return true;
  1422. }
  1423. else if (ks.vk == VK_TAB)
  1424. {
  1425. return true;
  1426. }
  1427. }
  1428. return GetWindow()->GetFocus()->OnKey(pprovider, ks, fForceTranslate);
  1429. }
  1430. */
  1431. bool OnButtonTop()
  1432. {
  1433. if (m_nTab != FILTER_ALL)
  1434. return true;
  1435. UnselectSquad();
  1436. // reset highest/lowest
  1437. m_nHighestRanking[s_column] = 999999;
  1438. m_nLowestRanking[s_column] = -1;
  1439. m_psquadHighestRanking[s_column] = NULL;
  1440. m_psquadLowestRanking[s_column] = NULL;
  1441. m_nCurrentRanking = 1;
  1442. debugf("Paging to Top, m_nCurrentRanking = %d \n", m_nCurrentRanking);
  1443. RequestPage(NULL);
  1444. return true;
  1445. }
  1446. bool OnButtonPrev() // down arrow was pressed
  1447. {
  1448. UnselectSquad();
  1449. int nOriginalCurrentRanking = m_nCurrentRanking;
  1450. m_nCurrentRanking -= (c_cSquadsShown-1);
  1451. if (m_nCurrentRanking < 1)
  1452. m_nCurrentRanking = 1;
  1453. if (m_nCurrentRanking < m_nHighestRanking[s_column])
  1454. m_nCurrentRanking = m_nHighestRanking[s_column];
  1455. debugf("Paging Up, m_nCurrentRanking = %d \n", m_nCurrentRanking);
  1456. TRef<IZoneSquad> psquad = FindSquadByRanking(s_column, m_nCurrentRanking);
  1457. if (psquad == NULL) // if we scrolled too fast and the high/low ranges are no longer valid
  1458. {
  1459. debugf("High Range was invalid, resetting it.\n");
  1460. ResetHighLowRanges();
  1461. m_nCurrentRanking = nOriginalCurrentRanking;
  1462. psquad = FindSquadByRanking(s_column, m_nCurrentRanking);
  1463. }
  1464. RequestPage(psquad);
  1465. return true;
  1466. }
  1467. bool OnButtonNext() // up arrow was pressed
  1468. {
  1469. UnselectSquad();
  1470. int nOriginalCurrentRanking = m_nCurrentRanking;
  1471. m_nCurrentRanking += (c_cSquadsShown-1);
  1472. if (m_nCurrentRanking > m_nLowestRanking[s_column])
  1473. m_nCurrentRanking = m_nLowestRanking[s_column];
  1474. debugf("Paging Down, m_nCurrentRanking = %d \n", m_nCurrentRanking);
  1475. TRef<IZoneSquad> psquad = FindSquadByRanking(s_column, m_nCurrentRanking);
  1476. if (psquad == NULL) // if we scrolled too fast and the high/low ranges are no longer valid
  1477. {
  1478. debugf("Low Range was invalid, resetting it.\n");
  1479. ResetHighLowRanges();
  1480. m_nCurrentRanking = nOriginalCurrentRanking;
  1481. psquad = FindSquadByRanking(s_column, m_nCurrentRanking);
  1482. }
  1483. RequestPage(psquad);
  1484. return true;
  1485. }
  1486. bool OnButtonZoneClub()
  1487. {
  1488. OnLeavingScreen();
  1489. #ifndef MARKCU1
  1490. GetWindow()->screen(ScreenIDZoneClubScreen);
  1491. #endif
  1492. return true;
  1493. }
  1494. bool OnButtonLeaderboard()
  1495. {
  1496. OnLeavingScreen();
  1497. #ifndef MARKCU1
  1498. if (s_pDudeXPlayer)
  1499. GetWindow()->LeaderBoardScreenForPlayer(s_pDudeXPlayer->GetName());
  1500. else
  1501. GetWindow()->LeaderBoardScreenForPlayer(s_pActivePlayer->GetName());
  1502. #endif
  1503. return true;
  1504. }
  1505. bool OnButtonPlayerProfile()
  1506. {
  1507. OnLeavingScreen();
  1508. #ifndef MARKCU1
  1509. if (s_pSelectedPlayer)
  1510. {
  1511. GetWindow()->CharInfoScreenForPlayer(s_pSelectedPlayer->GetID());
  1512. }
  1513. else
  1514. {
  1515. if (s_pDudeXPlayer && m_nTab == FILTER_DUDEX)
  1516. GetWindow()->CharInfoScreenForPlayer(s_pDudeXPlayer->GetID());
  1517. else
  1518. GetWindow()->CharInfoScreenForPlayer(s_pActivePlayer->GetID());
  1519. }
  1520. #endif
  1521. return true;
  1522. }
  1523. bool OnButtonReject()
  1524. {
  1525. if(s_pSelectedPlayer->IsPendingFor(*s_pSelectedSquad))
  1526. {
  1527. SEND_FOR_SELECTED_MEMBER(SQUAD_REJECT_JOIN_REQUEST);
  1528. s_pSelectedSquad->RejectPlayer(*s_pSelectedPlayer);
  1529. MessageBox("Player Rejected");
  1530. }
  1531. else
  1532. {
  1533. SEND_FOR_SELECTED_MEMBER(SQUAD_BOOT_MEMBER);
  1534. s_pSelectedSquad->BootPlayer(*s_pSelectedPlayer);
  1535. MessageBox("Player Booted");
  1536. }
  1537. RefreshScreen();
  1538. return true;
  1539. }
  1540. bool OnButtonAccept()
  1541. {
  1542. SEND_FOR_SELECTED_MEMBER(SQUAD_ACCEPT_JOIN_REQUEST);
  1543. s_pSelectedSquad->AddPlayer(*s_pSelectedPlayer, IZonePlayer::DSTAT_MEMBER);
  1544. RefreshScreen();
  1545. MessageBox("Player Accepted");
  1546. return true;
  1547. }
  1548. bool OnButtonCommission()
  1549. {
  1550. SEND_FOR_SELECTED_MEMBER(SQUAD_PROMOTE_TO_ASL);
  1551. s_pSelectedPlayer->SetPosition(*s_pSelectedSquad, IZonePlayer::POS_ASL);
  1552. RefreshScreen();
  1553. MessageBox("Player Commissioned");
  1554. return true;
  1555. }
  1556. bool OnButtonDemote()
  1557. {
  1558. SEND_FOR_SELECTED_MEMBER(SQUAD_DEMOTE_TO_MEMBER);
  1559. s_pSelectedPlayer->SetPosition(*s_pSelectedSquad, IZonePlayer::POS_MEMBER);
  1560. RefreshScreen();
  1561. MessageBox("Player Demoted");
  1562. return true;
  1563. }
  1564. bool OnButtonTransferControl()
  1565. {
  1566. SEND_FOR_SELECTED_MEMBER(SQUAD_TRANSFER_CONTROL);
  1567. s_pSelectedSquad->SetStatus(*s_pSelectedPlayer, IZonePlayer::DSTAT_LEADER);
  1568. RefreshScreen();
  1569. MessageBox("Ownership Transfered");
  1570. return true;
  1571. }
  1572. bool OnButtonRequestJoin()
  1573. {
  1574. SEND_FOR_ACTIVE_MEMBER(SQUAD_MAKE_JOIN_REQUEST);
  1575. s_pSelectedSquad->AddJoinRequest(*s_pActivePlayer);
  1576. RefreshScreen();
  1577. MessageBox("Request Issued");
  1578. return true;
  1579. }
  1580. bool OnButtonCancelRequest()
  1581. {
  1582. SEND_FOR_ACTIVE_MEMBER(SQUAD_CANCEL_JOIN_REQUEST);
  1583. s_pSelectedSquad->CancelJoinRequest(*s_pActivePlayer);
  1584. // remove squad from these tabs as needed
  1585. m_listSquads[FILTER_MY].Remove(s_pSelectedSquad);
  1586. if (s_pDudeXPlayer == s_pActivePlayer)
  1587. m_listSquads[FILTER_DUDEX].Remove(s_pSelectedSquad);
  1588. RefreshScreen();
  1589. MessageBox("Request Canceled");
  1590. return true;
  1591. }
  1592. bool OnButtonQuitSquad()
  1593. {
  1594. SEND_FOR_ACTIVE_MEMBER(SQUAD_QUIT);
  1595. s_pSelectedSquad->QuitPlayer(*s_pActivePlayer);
  1596. // remove squad from these tabs as needed
  1597. m_listSquads[FILTER_MY].Remove(s_pSelectedSquad);
  1598. if (s_pDudeXPlayer == s_pActivePlayer)
  1599. m_listSquads[FILTER_DUDEX].Remove(s_pSelectedSquad);
  1600. RefreshScreen();
  1601. MessageBox("Done");
  1602. return true;
  1603. }
  1604. bool OnButtonCreateSquad()
  1605. {
  1606. if (m_nTab == FILTER_DUDEX) // if dudex is selected, switch to "my" tab
  1607. {
  1608. OnButtonBarTabs(FILTER_MY);
  1609. }
  1610. else
  1611. if (m_nTab == FILTER_ALL)
  1612. {
  1613. // make room for the new squad
  1614. TRef<IZoneSquad> pdum;
  1615. if(m_listSquads[FILTER_ALL].GetCount() >= c_cSquadsShown) // if screen is full
  1616. {
  1617. // m_listSquads[FILTER_ALL].PopEnd(); // causes stack overflow
  1618. m_listSquads[FILTER_ALL].Remove(m_listSquads[FILTER_ALL].GetEnd());
  1619. }
  1620. }
  1621. TRef<IZoneSquad> psquad = CreateZoneSquad();
  1622. psquad->SetCreationID(m_nNextCreationID++);
  1623. psquad->SetName("Click Here to Enter Name");
  1624. psquad->SetDescription("Enter Description Here");
  1625. psquad->SetURL("Enter Squad Home Page Here");
  1626. psquad->SetInceptionDate("1/1/00");
  1627. assert(s_pActivePlayer);
  1628. psquad->AddPlayer(*s_pActivePlayer, IZonePlayer::DSTAT_LEADER);
  1629. AddSquadToScreen(psquad, true, m_nTab);
  1630. m_bSquadEditNameReset = true;
  1631. m_bSquadEditDescReset = true;
  1632. m_bSquadEditURLReset = true;
  1633. m_psquadBeingMade = psquad;
  1634. SelectSquad(*psquad);
  1635. return true;
  1636. }
  1637. bool OnButtonEditSquad()
  1638. {
  1639. // Make fields writable
  1640. //m_peditPaneSquadName->SetReadOnly(false); // Name not editable
  1641. m_peditPaneSquadDescription->SetHidden(false);
  1642. m_pstringDescription->SetValue("");
  1643. m_peditPaneSquadURL->SetReadOnly(false);
  1644. m_pbuttonApply->SetEnabled(true);
  1645. m_pbuttonCreateSquad->SetEnabled(false);
  1646. m_pbuttonQuitSquad->SetEnabled(false);
  1647. m_pcomboCiv->SetEnabled(true);
  1648. m_pbuttonApply->SetHidden(false);
  1649. m_pbuttonEditSquad->SetHidden(true);
  1650. GetWindow()->SetFocus(m_peditPaneSquadDescription);
  1651. return true;
  1652. }
  1653. bool OnSquadNameClick()
  1654. {
  1655. if (m_bSquadEditNameReset)
  1656. m_peditPaneSquadName->SetString("");
  1657. m_bSquadEditNameReset = false;
  1658. m_pbuttonApply->SetEnabled(true);
  1659. GetWindow()->SetFocus(m_peditPaneSquadName);
  1660. return true;
  1661. }
  1662. bool OnSquadDescriptionClick()
  1663. {
  1664. if (m_bSquadEditDescReset)
  1665. m_peditPaneSquadDescription->SetString("");
  1666. m_bSquadEditDescReset = false;
  1667. GetWindow()->SetFocus(m_peditPaneSquadDescription);
  1668. return true;
  1669. }
  1670. bool OnSquadURLClick() // This is not the Jump to URL function, see OnButtonURL()
  1671. {
  1672. if (m_bSquadEditURLReset)
  1673. m_peditPaneSquadURL->SetString("");
  1674. m_bSquadEditURLReset = false;
  1675. GetWindow()->SetFocus(m_peditPaneSquadURL);
  1676. return true;
  1677. }
  1678. bool OnFindClick()
  1679. {
  1680. GetWindow()->SetFocus(m_peditPaneFind);
  1681. return true;
  1682. }
  1683. bool OnButtonLog()
  1684. {
  1685. if (s_pSelectedSquad)
  1686. {
  1687. SEND_FOR_ACTIVE_MEMBER(SQUAD_LOG_REQ);
  1688. m_pHistoryDialog->SetHistory(s_pSelectedSquad->GetOwnershipLog());
  1689. GetWindow()->GetPopupContainer()->OpenPopup(m_pHistoryDialog, false);
  1690. }
  1691. return true;
  1692. }
  1693. bool OnButtonApply()
  1694. {
  1695. TRef<IKeyboardInput> p = GetWindow()->GetFocus();
  1696. if(p)
  1697. GetWindow()->RemoveFocus(p);
  1698. if(s_pSelectedSquad == m_psquadBeingMade // if creating (not editing)
  1699. && (m_bSquadEditNameReset ||
  1700. m_peditPaneSquadName->GetString().GetLength() == 0)
  1701. )
  1702. {
  1703. MessageBox("You must enter the \"squad name\".");
  1704. return true;
  1705. }
  1706. m_bSquadEditNameReset = false;
  1707. m_bSquadEditURLReset = false;
  1708. m_bSquadEditDescReset = false;
  1709. s_pSelectedSquad->SetName(m_peditPaneSquadName->GetString());
  1710. s_pSelectedSquad->SetURL(m_peditPaneSquadURL->GetString());
  1711. s_pSelectedSquad->SetDescription(m_peditPaneSquadDescription->GetString());
  1712. s_pSelectedSquad->SetCivID(m_pCivIds[m_pcomboCiv->GetSelection()]);
  1713. m_peditPaneSquadName->SetReadOnly();
  1714. m_peditPaneSquadDescription->SetHidden(true);
  1715. m_pstringDescription->SetValue(m_peditPaneSquadDescription->GetString());
  1716. m_peditPaneSquadURL->SetReadOnly();
  1717. if (s_pSelectedSquad == m_psquadBeingMade)
  1718. {
  1719. debugf("Sending SQUAD_CREATE: name: %s, descrip: %s, URL: %s", PCC(m_peditPaneSquadName->GetString()),
  1720. PCC(m_peditPaneSquadURL->GetString()),
  1721. PCC(m_peditPaneSquadDescription->GetString()));
  1722. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfm, C, SQUAD_CREATE)
  1723. FM_VAR_PARM(PCC(m_peditPaneSquadName->GetString()), CB_ZTS)
  1724. FM_VAR_PARM(PCC(m_peditPaneSquadDescription->GetString()), CB_ZTS)
  1725. FM_VAR_PARM(PCC(m_peditPaneSquadURL->GetString()), CB_ZTS)
  1726. END_PFM_CREATE
  1727. pfm->nClientSquadID = m_psquadBeingMade->GetCreationID();
  1728. pfm->civid = m_psquadBeingMade->GetCivID();
  1729. m_psquadBeingMade = NULL;
  1730. }
  1731. else
  1732. {
  1733. debugf("Sending SQUAD_EDIT; descrip: %s, URL: %s", PCC(m_peditPaneSquadURL->GetString()),
  1734. PCC(m_peditPaneSquadDescription->GetString()));
  1735. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfm, C, SQUAD_EDIT)
  1736. FM_VAR_PARM(PCC(m_peditPaneSquadDescription->GetString()), CB_ZTS)
  1737. FM_VAR_PARM(PCC(m_peditPaneSquadURL->GetString()), CB_ZTS)
  1738. END_PFM_CREATE
  1739. pfm->nSquadID = s_pSelectedSquad->GetID();
  1740. pfm->civid = s_pSelectedSquad->GetCivID();
  1741. }
  1742. trekClient.SendClubMessages();
  1743. RefreshScreen();
  1744. m_pbuttonApply->SetEnabled(false);
  1745. m_pcomboCiv->SetEnabled(false);
  1746. m_pbuttonApply->SetHidden(true);
  1747. m_pbuttonEditSquad->SetHidden(false);
  1748. return true;
  1749. }
  1750. bool OnButtonJumpURL() // not to be confused with OnSquadURLClick()
  1751. {
  1752. ShellExecute(NULL, NULL, m_peditPaneSquadURL->GetString(), NULL, NULL, SW_SHOWNORMAL);
  1753. return true;
  1754. }
  1755. bool OnButtonFindSquad()
  1756. {
  1757. if (m_peditPaneFind->GetString().GetLength() == 0)
  1758. return true;
  1759. m_listSquads[FILTER_ALL].SetEmpty();
  1760. if (m_nTab != FILTER_ALL)
  1761. {
  1762. OnButtonBarTabs(FILTER_ALL, true);
  1763. }
  1764. if (s_column != 1)
  1765. {
  1766. m_nCurrentRanking = -1; // we always set this to -1 when changing columns
  1767. m_psquadPrePage = NULL;
  1768. OnButtonBarSquads(1, true); // set sort by name
  1769. }
  1770. m_nBestSearchMatch = 99999999;
  1771. ResetHighLowRanges();
  1772. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmPage, C, SQUAD_PAGE_FIND)
  1773. FM_VAR_PARM(PCC(m_peditPaneFind->GetString()), CB_ZTS)
  1774. END_PFM_CREATE
  1775. debugf("Sending SQUAD_PAGE_FIND; %s\n", PCC(m_peditPaneFind->GetString()));
  1776. trekClient.SendClubMessages();
  1777. return true;
  1778. }
  1779. bool _OnButtonBarSquads(int nColumn)
  1780. {
  1781. return OnButtonBarSquads(nColumn);
  1782. }
  1783. /*-------------------------------------------------------------------------
  1784. * OnButtonBarSquads()
  1785. *-------------------------------------------------------------------------
  1786. * Purpose:
  1787. * User has requested a particular sort for column.
  1788. */
  1789. bool OnButtonBarSquads(int nColumn, bool bSkipPageRequest = false)
  1790. {
  1791. // if clicks on Ranking, do nothing
  1792. if (nColumn == 0 || nColumn == SSC_HOURS)
  1793. return true;
  1794. // do radio-button behavior
  1795. for (int i = 0; i < m_viColumns.GetCount(); i++)
  1796. {
  1797. if (i != nColumn) {
  1798. m_pbuttonbarSquadsHeader->SetChecked(i, false);
  1799. m_pbuttonbarSquadsHeader->SetChecked2(i, false);
  1800. }
  1801. }
  1802. /* if (m_pbuttonbarSquadsHeader->GetChecked(nColumn))
  1803. {
  1804. m_pbuttonbarSquadsHeader->SetChecked(nColumn, false);
  1805. m_pbuttonbarSquadsHeader->SetChecked2(nColumn, true);
  1806. } else
  1807. {
  1808. */
  1809. m_pbuttonbarSquadsHeader->SetChecked(nColumn, true);
  1810. m_pbuttonbarSquadsHeader->SetChecked2(nColumn, false);
  1811. // }
  1812. s_column = (SQUAD_SORT_COLUMN) nColumn;
  1813. if (m_nTab == FILTER_ALL)
  1814. {
  1815. if(!bSkipPageRequest)
  1816. RequestPage(s_pSelectedSquad, true);
  1817. }
  1818. //
  1819. // add this to the stack of sorting criteria as priority one;
  1820. // these are only used for "my" and dudex tabs
  1821. //
  1822. m_vuSorts.Remove((unsigned)nColumn); // remove it's previous priority
  1823. m_vuSorts.PushEnd(nColumn); // set as priority one
  1824. RefreshSquadsListBox();
  1825. return true;
  1826. }
  1827. bool _OnButtonBarTabs(int nColumn)
  1828. {
  1829. return OnButtonBarTabs(nColumn);
  1830. }
  1831. /*-------------------------------------------------------------------------
  1832. * OnButtonBarTabs()
  1833. *-------------------------------------------------------------------------
  1834. * Purpose:
  1835. * User has selected a tab...put it in the foreground.
  1836. */
  1837. bool OnButtonBarTabs(int nColumn, bool bSkipPageRequest = false)
  1838. {
  1839. if (m_nTab == nColumn)
  1840. return true;
  1841. // Disable DudeX column if Nobody is DudeX
  1842. if (s_pDudeXPlayer == NULL && nColumn == 2)
  1843. return true;
  1844. TRef<IZoneSquad> psquadPreRefresh = s_pSelectedSquad;
  1845. UnselectSquad();
  1846. m_nTab = nColumn;
  1847. RefreshSquadsListBox(); // this makes the m_nTab change legit
  1848. if(nColumn == FILTER_ALL) // "All" Tab was pressed
  1849. {
  1850. m_pscrollPaneSquads->SetHidden(true);
  1851. m_pbuttonNext->SetEnabled(true);
  1852. m_pbuttonPrev->SetEnabled(true);
  1853. m_pbuttonTop->SetEnabled(true);
  1854. //ResetHighLowRanges();
  1855. //m_nCurrentRanking = s_pSelectedSquad ? s_pSelectedSquad->GetRanking(s_column) : -1;
  1856. if(!bSkipPageRequest)
  1857. RequestPage(psquadPreRefresh ? psquadPreRefresh : m_psquadLastSelected, false, true);
  1858. }
  1859. else
  1860. if(nColumn == FILTER_MY) // "My" Tab was pressed
  1861. {
  1862. m_pscrollPaneSquads->SetHidden(false);
  1863. m_pbuttonNext->SetEnabled(false);
  1864. m_pbuttonPrev->SetEnabled(false);
  1865. m_pbuttonTop->SetEnabled(false);
  1866. if (psquadPreRefresh)
  1867. m_strSquadToBeSelected = psquadPreRefresh->GetName();
  1868. else
  1869. {
  1870. if (m_psquadLastSelected)
  1871. m_strSquadToBeSelected = m_psquadLastSelected->GetName();
  1872. else
  1873. m_strSquadToBeSelected= "";
  1874. }
  1875. DisplaySquadsInRangeForDudeX(FILTER_MY, s_pActivePlayer);
  1876. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmSquadMessage, C, SQUAD_NEXT_PAGE_MY)
  1877. END_PFM_CREATE
  1878. debugf("Sending SQUAD_NEXT_PAGE_MY\n");
  1879. trekClient.SendClubMessages();
  1880. }
  1881. else if(nColumn == FILTER_DUDEX) // DudeX Tab was pressed
  1882. {
  1883. m_pscrollPaneSquads->SetHidden(false);
  1884. m_pbuttonNext->SetEnabled(false);
  1885. m_pbuttonPrev->SetEnabled(false);
  1886. m_pbuttonTop->SetEnabled(false);
  1887. if (psquadPreRefresh)
  1888. m_strSquadToBeSelected = psquadPreRefresh->GetName();
  1889. else
  1890. {
  1891. if (m_psquadLastSelected)
  1892. m_strSquadToBeSelected = m_psquadLastSelected->GetName();
  1893. else
  1894. m_strSquadToBeSelected= "";
  1895. }
  1896. DisplaySquadsInRangeForDudeX(FILTER_DUDEX, s_pDudeXPlayer);
  1897. debugf("Sending SQUAD_NEXT_PAGE_DUDEX; member %d (%s)\n", s_pDudeXPlayer->GetID(), s_pDudeXPlayer->GetName());
  1898. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmSquadMessage, C, SQUAD_NEXT_PAGE_DUDEX)
  1899. END_PFM_CREATE
  1900. pfmSquadMessage->nMemberID = s_pDudeXPlayer->GetID();
  1901. trekClient.SendClubMessages();
  1902. }
  1903. // do radio-button behavior
  1904. for (int i = 0; i < m_viTabColumns.GetCount(); i++)
  1905. {
  1906. if (i != nColumn) {
  1907. m_ptabSquads->SetChecked(i, false);
  1908. m_ptabSquads->SetChecked2(i, false);
  1909. }
  1910. }
  1911. if (m_ptabSquads->GetChecked(nColumn))
  1912. {
  1913. m_ptabSquads->SetChecked(nColumn, false);
  1914. m_ptabSquads->SetChecked2(nColumn, true);
  1915. } else
  1916. {
  1917. m_ptabSquads->SetChecked(nColumn, true);
  1918. m_ptabSquads->SetChecked2(nColumn, false);
  1919. }
  1920. //
  1921. // Switch the game list filter of squads
  1922. //
  1923. m_filter = (FilterType)nColumn;
  1924. RefreshSquadsListBox();
  1925. return true;
  1926. }
  1927. /*-------------------------------------------------------------------------
  1928. * OnButtonBarPlayers()
  1929. *-------------------------------------------------------------------------
  1930. * Purpose:
  1931. * User has requested a particular sort. Give this column (nColumn) the
  1932. * highest priority for the sort.
  1933. */
  1934. bool OnButtonBarPlayers(int nColumn)
  1935. {
  1936. // do radio-button behavior
  1937. for (int i = 0; i < m_viPlayersColumns.GetCount(); i++)
  1938. {
  1939. if (i != nColumn) {
  1940. m_pbuttonbarPlayersHeader->SetChecked(i, false);
  1941. m_pbuttonbarPlayersHeader->SetChecked2(i, false);
  1942. }
  1943. }
  1944. /* if (m_pbuttonbarPlayersHeader->GetChecked(nColumn))
  1945. {
  1946. m_pbuttonbarPlayersHeader->SetChecked(nColumn, false);
  1947. m_pbuttonbarPlayersHeader->SetChecked2(nColumn, true);
  1948. } else
  1949. {
  1950. */
  1951. m_pbuttonbarPlayersHeader->SetChecked(nColumn, true);
  1952. m_pbuttonbarPlayersHeader->SetChecked2(nColumn, false);
  1953. // }
  1954. //
  1955. // add this to the stack of sorting criteria as priority one
  1956. //
  1957. m_vuPlayersSorts.Remove((unsigned)nColumn); // remove it's previous priority
  1958. m_vuPlayersSorts.PushEnd(nColumn); // set as priority one
  1959. RefreshPlayersListBox();
  1960. return true;
  1961. }
  1962. /*-------------------------------------------------------------------------
  1963. * IZoneSquadScreen::OnDoubleClickPlayer()
  1964. *-------------------------------------------------------------------------
  1965. * Event for when the active user double clicks on a person in the
  1966. * players list box
  1967. */
  1968. bool OnDoubleClickPlayer(/*IZonePlayer * pPlayer*/)
  1969. {
  1970. if (s_pSelectedPlayer==NULL)
  1971. return true;
  1972. s_pDudeXPlayer = s_pSelectedPlayer;//pPlayer;
  1973. m_pstringSquadTabDudeX->SetValue(s_pDudeXPlayer->GetName());
  1974. m_ptabSquads->SetHidden(FILTER_DUDEX, false);
  1975. if (m_nTab == FILTER_DUDEX)
  1976. {
  1977. DisplaySquadsInRangeForDudeX(FILTER_DUDEX, s_pDudeXPlayer);
  1978. debugf("Sending SQUAD_NEXT_PAGE_DUDEX; member %d (%s)\n", s_pActivePlayer->GetID(), s_pActivePlayer->GetName());
  1979. BEGIN_PFM_CREATE(trekClient.m_fmClub, pfmSquadMessage, C, SQUAD_NEXT_PAGE_DUDEX)
  1980. END_PFM_CREATE
  1981. pfmSquadMessage->nMemberID = s_pDudeXPlayer->GetID();
  1982. trekClient.SendClubMessages();
  1983. }
  1984. RefreshScreen();
  1985. return true;
  1986. }
  1987. /*-------------------------------------------------------------------------
  1988. * IZoneSquadScreen::AddSquadToScreen()
  1989. *-------------------------------------------------------------------------
  1990. * Purpose:
  1991. * Add a squad to the squad list box
  1992. *
  1993. */
  1994. void AddSquadToScreen(TRef<IZoneSquad> pSquad, bool bRefresh = true, int nTab = 0)
  1995. {
  1996. if(m_listSquads[nTab].Find(pSquad))
  1997. return;
  1998. m_listSquads[nTab].PushEnd(pSquad);
  1999. if(bRefresh)
  2000. RefreshScreen();
  2001. }
  2002. void UnselectSquad()
  2003. {
  2004. m_plistPaneSquads->SetSelection(NULL);
  2005. IZoneSquad * pNULL = NULL;
  2006. m_bSelectionNotFromSquadClick = true;
  2007. OnSquadSelected(*(pNULL));
  2008. }
  2009. /*-------------------------------------------------------------------------
  2010. * IZoneSquadScreen::DeleteSquad()
  2011. *-------------------------------------------------------------------------
  2012. * Purpose:
  2013. * Remove a squad from existence
  2014. *
  2015. */
  2016. void DeleteSquad(TRef<IZoneSquad> pSquad, bool bRefresh = true)
  2017. {
  2018. if (m_psquadLastSelected == pSquad)
  2019. m_psquadLastSelected = NULL;
  2020. pSquad->SetEmpty(); // remove all players from it
  2021. if (s_pSelectedSquad == pSquad)
  2022. {
  2023. UnselectSquad();
  2024. }
  2025. // remove from mother list
  2026. m_listAllSquads.Remove(pSquad);
  2027. // remove from screen list(s)
  2028. m_listSquads[FILTER_ALL].Remove(pSquad);
  2029. m_listSquads[FILTER_MY].Remove(pSquad);
  2030. m_listSquads[FILTER_DUDEX].Remove(pSquad);
  2031. if(bRefresh)
  2032. RefreshScreen();
  2033. }
  2034. /*-------------------------------------------------------------------------
  2035. * IZoneSquadScreen::IsSquadAssociatedWithPlayer()
  2036. *-------------------------------------------------------------------------
  2037. * Purpose:
  2038. * filter for tabs
  2039. *
  2040. * Returns:
  2041. * true iff squad is associated to player in any way
  2042. */
  2043. static bool IsSquadAssociatedWithPlayer(IZoneSquad* pSquad, IZonePlayer *pPlayer)
  2044. {
  2045. return pPlayer->GetStatus(*pSquad) != IZonePlayer::STAT_NO_ASSOCIATION;
  2046. }
  2047. /*-------------------------------------------------------------------------
  2048. * IZoneSquadScreen::IsSquadAssociatedWithActivePlayer()
  2049. *-------------------------------------------------------------------------
  2050. * Purpose:
  2051. * filter for My tab
  2052. *
  2053. * Returns:
  2054. * true iff this squad is not associated to user in any way?
  2055. */
  2056. static bool IsSquadAssociatedWithActivePlayer(ItemID pitem)
  2057. {
  2058. return IsSquadAssociatedWithPlayer((IZoneSquad*)pitem, s_pActivePlayer);
  2059. }
  2060. /*-------------------------------------------------------------------------
  2061. * IZoneSquadScreen::IsSquadAssociatedWithDudeX()
  2062. *-------------------------------------------------------------------------
  2063. * Purpose:
  2064. * filter for Dude X tab
  2065. *
  2066. * Returns:
  2067. * true iff this squad is not associated to tab's Dude X in any way?
  2068. */
  2069. static bool IsSquadAssociatedWithSelectedPlayer(ItemID pitem)
  2070. {
  2071. return IsSquadAssociatedWithPlayer((IZoneSquad*)pitem, s_pSelectedPlayer);
  2072. }
  2073. /* static bool ShouldSquadBeShown(ItemID pitem)
  2074. {
  2075. assert(g_pSquadScreen);
  2076. return g_pSquadScreen->m_ShouldSquadBeShown(pitem);
  2077. }
  2078. bool m_ShouldSquadBeShown(ItemID pitem)
  2079. {
  2080. if(m_nCurrentRanking==-1)
  2081. return false;
  2082. int ranking = ((IZoneSquad*)pitem)->GetRanking(s_column);
  2083. if (ranking != -1 && ranking >= m_nCurrentRanking && ranking < m_nCurrentRanking+c_cSquadsShown)
  2084. {
  2085. return true;
  2086. }
  2087. return false;
  2088. }
  2089. */
  2090. /*-------------------------------------------------------------------------
  2091. * IZoneSquadScreen::RefreshSquadsListBox()
  2092. *-------------------------------------------------------------------------
  2093. * Purpose:
  2094. * Redraw the listbox for squad
  2095. *
  2096. */
  2097. void RefreshSquadsListBox()
  2098. {
  2099. List *plist = new ListDelegate(&m_listSquads[m_nTab]);
  2100. // plist = new FilteredList<bool (*)(ItemID)>(plist, ShouldSquadBeShown);
  2101. /*
  2102. switch (m_filter)
  2103. {
  2104. case FILTER_MY:
  2105. plist = new FilteredList<bool (*)(ItemID)>(plist, IsSquadAssociatedWithActivePlayer);
  2106. break;
  2107. case FILTER_DUDEX:
  2108. plist = new FilteredList<bool (*)(ItemID)>(plist, IsSquadAssociatedWithSelectedPlayer);
  2109. break;
  2110. default: // FILTER_ALL is default
  2111. break;
  2112. }
  2113. */
  2114. plist = new SortedList<ItemIDCompareFunction>(plist, SquadRankingCompare);
  2115. if (m_nTab == FILTER_MY || m_nTab == FILTER_DUDEX)
  2116. {
  2117. for (int i = 0; i < m_vuSorts.GetCount(); i++)
  2118. {
  2119. switch (m_vuSorts[i])
  2120. {
  2121. case 1:
  2122. plist = new SortedList<ItemIDCompareFunction>(plist, SquadNameCompare);
  2123. break;
  2124. case 2:
  2125. plist = new SortedList<ItemIDCompareFunction>(plist, ScoreCompare);
  2126. break;
  2127. case 3:
  2128. plist = new SortedList<ItemIDCompareFunction>(plist, WinsCompare);
  2129. break;
  2130. case 4:
  2131. plist = new SortedList<ItemIDCompareFunction>(plist, LossesCompare);
  2132. break;
  2133. case 5:
  2134. plist = new SortedList<ItemIDCompareFunction>(plist, HoursCompare);
  2135. break;
  2136. }
  2137. }
  2138. m_plistPaneSquads->SetList(plist);
  2139. }
  2140. else
  2141. m_plistPaneSquads->SetList(plist);
  2142. }
  2143. /*-------------------------------------------------------------------------
  2144. * CPlayerscreen::RefreshPlayersListBox()
  2145. *-------------------------------------------------------------------------
  2146. * Purpose:
  2147. * Redraw the listbox for squad
  2148. *
  2149. */
  2150. void RefreshPlayersListBox()
  2151. {
  2152. if(!s_pSelectedSquad)
  2153. {
  2154. m_plistPanePlayers->SetList(new EmptyList);
  2155. return;
  2156. }
  2157. s_pSelectedSquad->AddPlayersToList(m_listPlayers);
  2158. List * plist = new ListDelegate(&m_listPlayers);
  2159. /* if (!m_fShowConquest)
  2160. plist = new FilteredList<bool (*)(ItemID)>(plist, IsNotConquest);
  2161. if (!m_fShowScoresCount)
  2162. plist = new FilteredList<bool (*)(ItemID)>(plist, IsNotScoresCount);
  2163. */
  2164. for (int i = 0; i < m_vuPlayersSorts.GetCount(); i++)
  2165. {
  2166. switch (m_vuPlayersSorts[i])
  2167. {
  2168. case 0:
  2169. plist = new SortedList<ItemIDCompareFunction>(plist, PlayerNameCompare);
  2170. break;
  2171. case 1:
  2172. plist = new SortedList<ItemIDCompareFunction>(plist, PlayerRankCompare);
  2173. break;
  2174. case 2:
  2175. plist = new SortedList<ItemIDCompareFunction>(plist, PlayerStatusCompare);
  2176. break;
  2177. case 3:
  2178. plist = new SortedList<ItemIDCompareFunction>(plist, PlayerLastDateCompare);
  2179. break;
  2180. }
  2181. }
  2182. m_plistPanePlayers->SetList(plist);
  2183. }
  2184. // how different are these strings?
  2185. unsigned CompareStrings(const char * sz1, const char * sz2, int cCharacters)
  2186. {
  2187. unsigned sum = 0;
  2188. for (int i = 0; i < cCharacters; ++i)
  2189. {
  2190. sum += abs(toupper(sz1[i]) - toupper(sz2[i])) + (cCharacters - i) * 256;
  2191. }
  2192. return sum;
  2193. }
  2194. /////////////////////////////////////////////////////////////////////////
  2195. int FillCombo(INameSpace* pns, ComboPane* pcombo, const char* szContentName)
  2196. {
  2197. IObjectList* plist;
  2198. CastTo(plist, pns->FindMember(szContentName));
  2199. plist->GetFirst();
  2200. int index = 0;
  2201. while (plist->GetCurrent() != NULL) {
  2202. pcombo->AddItem(GetString(plist->GetCurrent()), index);
  2203. plist->GetNext();
  2204. ++index;
  2205. }
  2206. return index;
  2207. }
  2208. /////////////////////////////////////////////////////////////////////////
  2209. int FillIntegerArray(INameSpace* pns, int * pInts, const char* szContentName)
  2210. {
  2211. IObjectList* plist;
  2212. CastTo(plist, pns->FindMember(szContentName));
  2213. plist->GetFirst();
  2214. int index = 0;
  2215. while (plist->GetCurrent() != NULL) {
  2216. pInts[index] = (int)GetNumber(plist->GetCurrent());
  2217. plist->GetNext();
  2218. ++index;
  2219. }
  2220. return index;
  2221. }
  2222. static char* CivID2String(CivID id)
  2223. {
  2224. char *szCivs[] = {
  2225. "ANY",
  2226. "Rix",
  2227. "Iron league",
  2228. "Belorian",
  2229. };
  2230. if (id < -1 || id > 3) return "Unknown";
  2231. return szCivs[id+1];
  2232. }
  2233. static bool SquadRankingCompare(ItemID pitem1, ItemID pitem2)
  2234. {
  2235. IZoneSquad* psquad1 = (IZoneSquad*)pitem1;
  2236. IZoneSquad* psquad2 = (IZoneSquad*)pitem2;
  2237. return psquad1->GetRanking(s_column) > psquad2->GetRanking(s_column);
  2238. }
  2239. static bool SquadNameCompare(ItemID pitem1, ItemID pitem2)
  2240. {
  2241. IZoneSquad* psquad1 = (IZoneSquad*)pitem1;
  2242. IZoneSquad* psquad2 = (IZoneSquad*)pitem2;
  2243. return _stricmp(psquad1->GetName(), psquad2->GetName()) > 0;
  2244. }
  2245. static bool ScoreCompare(ItemID pitem1, ItemID pitem2)
  2246. {
  2247. IZoneSquad* psquad1 = (IZoneSquad*)pitem1;
  2248. IZoneSquad* psquad2 = (IZoneSquad*)pitem2;
  2249. return psquad1->GetScore() < psquad2->GetScore();
  2250. }
  2251. static bool WinsCompare(ItemID pitem1, ItemID pitem2)
  2252. {
  2253. IZoneSquad* psquad1 = (IZoneSquad*)pitem1;
  2254. IZoneSquad* psquad2 = (IZoneSquad*)pitem2;
  2255. return psquad1->GetWins() < psquad2->GetWins();
  2256. }
  2257. static bool LossesCompare(ItemID pitem1, ItemID pitem2)
  2258. {
  2259. IZoneSquad* psquad1 = (IZoneSquad*)pitem1;
  2260. IZoneSquad* psquad2 = (IZoneSquad*)pitem2;
  2261. return psquad1->GetLosses() < psquad2->GetLosses();
  2262. }
  2263. static bool HoursCompare(ItemID pitem1, ItemID pitem2)
  2264. {
  2265. IZoneSquad* psquad1 = (IZoneSquad*)pitem1;
  2266. IZoneSquad* psquad2 = (IZoneSquad*)pitem2;
  2267. return s_pActivePlayer->GetHours(*psquad1) < s_pActivePlayer->GetHours(*psquad1);
  2268. }
  2269. static bool PlayerNameCompare(ItemID pitem1, ItemID pitem2)
  2270. {
  2271. IZonePlayer* pPlayer1 = (IZonePlayer*)pitem1;
  2272. IZonePlayer* pPlayer2 = (IZonePlayer*)pitem2;
  2273. return _stricmp(pPlayer1->GetName(), pPlayer2->GetName()) > 0;
  2274. }
  2275. static bool PlayerStatusCompare(ItemID pitem1, ItemID pitem2)
  2276. {
  2277. IZonePlayer* pPlayer1 = (IZonePlayer*)pitem1;
  2278. IZonePlayer* pPlayer2 = (IZonePlayer*)pitem2;
  2279. return pPlayer1->GetStatus(*s_pSelectedSquad) < pPlayer2->GetStatus(*s_pSelectedSquad);
  2280. }
  2281. static bool PlayerLastDateCompare(ItemID pitem1, ItemID pitem2)
  2282. {
  2283. if (!s_pSelectedSquad)
  2284. return false;
  2285. IZonePlayer* pPlayer1 = (IZonePlayer*)pitem1;
  2286. IZonePlayer* pPlayer2 = (IZonePlayer*)pitem2;
  2287. char * sz1 = pPlayer1->GetLastPlayedDate(*s_pSelectedSquad);
  2288. char * sz2 = pPlayer2->GetLastPlayedDate(*s_pSelectedSquad);
  2289. if (strlen(sz1) == 8 && strlen(sz2) == 8) // help ensure proper format
  2290. {
  2291. // Generate points for each day; a point is sort of like a day. It's not exactly equal to a
  2292. // day because there is no need to be exact. Besides being exact would be quite tricky (think about leap year).
  2293. unsigned n1 = (sz1[6]-48) * (10*366) + (sz1[7]-48) * 366 + (sz1[0]==' '?0:(sz1[0]-48)) * (10*32) + (sz1[1]-48) * 32 + (sz1[3]==' '?0:(sz1[3]-48)) * 11 + (sz1[4]-48);
  2294. unsigned n2 = (sz2[6]-48) * (10*366) + (sz2[7]-48) * 366 + (sz2[0]==' '?0:(sz2[0]-48)) * (10*32) + (sz2[1]-48) * 32 + (sz2[3]==' '?0:(sz2[3]-48)) * 11 + (sz2[4]-48);
  2295. return n1 > n2;
  2296. }
  2297. else return false;
  2298. }
  2299. static bool PlayerRankCompare(ItemID pitem1, ItemID pitem2)
  2300. {
  2301. IZonePlayer* pPlayer1 = (IZonePlayer*)pitem1;
  2302. IZonePlayer* pPlayer2 = (IZonePlayer*)pitem2;
  2303. return pPlayer1->GetRank() < pPlayer2->GetRank();
  2304. }
  2305. //
  2306. // Make these public for Painter classes
  2307. //
  2308. TRef<Image> GetIconImage_Owner() { return m_pimageOwner; }
  2309. TRef<Image> GetIconImage_ASL() { return m_pimageASL; }
  2310. TRef<Image> GetIconImage_Pending() { return m_pimagePending; }
  2311. TRef<Image> GetIconImage_Rejected() { return m_pimageRejected; }
  2312. TRef<Image> GetIconImage_Member() { return m_pimageMember; }
  2313. TRef<Image> GetIconImage_Booted() { return m_pimageBooted; }
  2314. TRef<Image> GetIconImage_Quit() { return m_pimageQuit; }
  2315. TRef<IZonePlayer> GetActivePlayer() { return s_pActivePlayer; }
  2316. TRef<IZoneSquad> GetSelectedSquad() { return s_pSelectedSquad; }
  2317. class SquadsItemPainter;
  2318. friend SquadsItemPainter;
  2319. //////////////////////////////////////////////////////////////////////////////
  2320. //
  2321. // SquadsItemPainter - within the Squads listbox
  2322. //
  2323. //////////////////////////////////////////////////////////////////////////////
  2324. class SquadsItemPainter : public ItemPainter
  2325. {
  2326. const TVector<int>& m_viColumns;
  2327. SquadsScreen * m_pSquadsScreen;
  2328. public:
  2329. SquadsItemPainter(const TVector<int>& viColumns, SquadsScreen * pMaker)
  2330. : m_viColumns(viColumns),
  2331. m_pSquadsScreen(pMaker)
  2332. {};
  2333. int GetXSize()
  2334. {
  2335. return m_viColumns[4];
  2336. }
  2337. int GetYSize()
  2338. {
  2339. return 14;
  2340. }
  2341. void Paint(ItemID pitemArg, Surface* psurface, bool bSelected, bool bFocus)
  2342. {
  2343. IZoneSquad* psquad = (IZoneSquad*)pitemArg;
  2344. char cbTemp[256];
  2345. if (bSelected)
  2346. {
  2347. //
  2348. // Draw selection bar
  2349. //
  2350. psurface->FillRect(
  2351. WinRect(0, 0, GetXSize(), GetYSize()),
  2352. m_pSquadsScreen->GetSquadSelectionBarColor());
  2353. // m_pSquadsScreen->OnSquadSelected(*psquad);
  2354. }
  2355. // TODO: make read in font
  2356. TRef<IEngineFont> pfont = TrekResources::SmallFont();
  2357. //
  2358. // Display Ranking
  2359. //
  2360. if(psquad->GetRanking(SquadsScreen::s_column) != -1 && m_pSquadsScreen->m_nTab == FILTER_ALL)
  2361. {
  2362. wsprintf(cbTemp, "%i", psquad->GetRanking(SquadsScreen::s_column));
  2363. psurface->DrawString(pfont, Color::White(), WinPoint(/*m_viColumns[-1] +*/ 2, 0), cbTemp);
  2364. }
  2365. //
  2366. // Display Name
  2367. //
  2368. WinRect rectClipOld = psurface->GetClipRect();
  2369. if (strcmp(PCC(psquad->GetName()), "Click Here to Enter Name") == 0)
  2370. wsprintf(cbTemp, "New Squad");
  2371. else
  2372. wsprintf(cbTemp, "%s", psquad->GetName());
  2373. psurface->SetClipRect(WinRect(WinPoint(m_viColumns[0] + 18, 0), WinPoint(m_viColumns[1], GetYSize()))); // clip name to fit in column
  2374. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[0] + 18, 0), cbTemp);
  2375. psurface->RestoreClipRect(rectClipOld);
  2376. //
  2377. // Display Score
  2378. //
  2379. wsprintf(cbTemp, "%i", psquad->GetScore());
  2380. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[1] + 2, 0), cbTemp);
  2381. //
  2382. // Display Wins
  2383. //
  2384. wsprintf(cbTemp, "%i", psquad->GetWins());
  2385. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[2] + 2, 0), cbTemp);
  2386. //
  2387. // Display Losses
  2388. //
  2389. wsprintf(cbTemp, "%i", psquad->GetLosses());
  2390. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[3] + 2, 0), cbTemp);
  2391. //
  2392. // Display Proper Icon
  2393. //
  2394. /*
  2395. switch (m_pSquadsScreen->GetActivePlayer()->GetStatus(*psquad))
  2396. {
  2397. case IZonePlayer::STAT_ACTIVE:
  2398. if (psquad->GetOwner() == m_pSquadsScreen->GetActivePlayer())
  2399. {
  2400. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_Owner()->GetSurface());
  2401. }
  2402. else if(m_pSquadsScreen->GetActivePlayer()->GetPosition(*psquad) == IZonePlayer::POS_ASL)
  2403. {
  2404. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_ASL()->GetSurface());
  2405. }
  2406. else // must be member
  2407. {
  2408. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_Member()->GetSurface());
  2409. }
  2410. break;
  2411. case IZonePlayer::STAT_PENDING:
  2412. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_Pending()->GetSurface());
  2413. break;
  2414. case IZonePlayer::STAT_REJECTED:
  2415. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_Rejected()->GetSurface());
  2416. break;
  2417. case IZonePlayer::STAT_BOOTED:
  2418. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_Booted()->GetSurface());
  2419. break;
  2420. case IZonePlayer::STAT_QUIT:
  2421. psurface->BitBlt(WinPoint(m_viColumns[1]-20, 1), m_pSquadsScreen->GetIconImage_Quit()->GetSurface());
  2422. break;
  2423. default:
  2424. assert(1); // User is not associated with the squad so shouldn't be drawn!
  2425. break;
  2426. }
  2427. */
  2428. //
  2429. // Display Hours
  2430. //
  2431. // sprintf(cbTemp, "%3.1f", m_pSquadsScreen->GetActivePlayer()->GetHours(*psquad));
  2432. // psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[4] + 2, 0), cbTemp);
  2433. }
  2434. };
  2435. /*-------------------------------------------------------------------------
  2436. * IZoneSquadScreen::RefreshSquadDetailsArea()
  2437. *-------------------------------------------------------------------------
  2438. * Purpose:
  2439. * Redraw the active squad's details-related stuff.
  2440. *
  2441. */
  2442. void RefreshSquadDetailsArea()
  2443. {
  2444. if(!s_pSelectedSquad)
  2445. {
  2446. m_peditPaneSquadName->SetString("");
  2447. m_peditPaneSquadDescription->SetString("");
  2448. m_peditPaneSquadURL->SetString("");
  2449. m_pstrpaneRanking->SetString("");
  2450. m_pstrpaneRank->SetString("");
  2451. m_pstrpaneWinsAndLosses->SetString("");
  2452. m_pstrpaneInceptionDate->SetString("");
  2453. m_pcomboCiv->SetSelection(0);
  2454. return;
  2455. }
  2456. //
  2457. // Refresh Edit Panes
  2458. //
  2459. m_peditPaneSquadName->SetString(s_pSelectedSquad->GetName());
  2460. m_peditPaneSquadDescription->SetString(s_pSelectedSquad->GetDescription());
  2461. if(m_peditPaneSquadDescription->IsHidden())
  2462. m_pstringDescription->SetValue(s_pSelectedSquad->GetDescription());
  2463. else
  2464. m_pstringDescription->SetValue("");
  2465. m_peditPaneSquadURL->SetString(s_pSelectedSquad->GetURL());
  2466. //
  2467. // Refresh String Panes
  2468. //
  2469. // if (s_pSelectedSquad->GetRanking(s_column) != -1)
  2470. // m_pstrpaneRanking->SetString(s_pSelectedSquad->GetRanking(s_column));
  2471. m_pstrpaneRank->SetString(s_pSelectedSquad->GetRank());
  2472. m_pstrpaneWinsAndLosses->SetString(ZString(s_pSelectedSquad->GetWins()) + "/" +
  2473. ZString(s_pSelectedSquad->GetLosses()));
  2474. m_pstrpaneInceptionDate->SetString(s_pSelectedSquad->GetInceptionDate());
  2475. for (int i = 0; i < m_cCivs; ++i)
  2476. if (m_pCivIds[i] == s_pSelectedSquad->GetCivID())
  2477. {
  2478. m_pcomboCiv->SetSelection(i);
  2479. }
  2480. }
  2481. /*-------------------------------------------------------------------------
  2482. * IZoneSquadScreen::SelectSquad()
  2483. *-------------------------------------------------------------------------
  2484. * Purpose:
  2485. * Call this to select a squad.
  2486. *
  2487. */
  2488. void SelectSquad(IZoneSquad & squad)
  2489. {
  2490. if (m_listSquads[m_nTab].Find(&squad))
  2491. {
  2492. m_bSelectionNotFromSquadClick = true;
  2493. m_plistPaneSquads->SetSelection(&squad);
  2494. }
  2495. }
  2496. /*-------------------------------------------------------------------------
  2497. * IZoneSquadScreen::SelectPlayer()
  2498. *-------------------------------------------------------------------------
  2499. * Purpose:
  2500. * Call this to select a Player.
  2501. *
  2502. */
  2503. void SelectPlayer(IZonePlayer & Player)
  2504. {
  2505. m_plistPanePlayers->SetSelection(&Player);
  2506. }
  2507. /*-------------------------------------------------------------------------
  2508. * IZoneSquadScreen::OnSquadSelected()
  2509. *-------------------------------------------------------------------------
  2510. * Purpose:
  2511. * Call this when a particular squad is selected.
  2512. *
  2513. */
  2514. void OnSquadSelected(IZoneSquad & squad)
  2515. {
  2516. if (!m_bSelectionNotFromSquadClick)
  2517. {
  2518. m_bSelectorNeedsAutoSet = false;
  2519. m_strSquadToBeSelected = "";
  2520. }
  2521. m_bSelectionNotFromSquadClick = false;
  2522. if(&squad != NULL)
  2523. m_psquadLastSelected = &squad;
  2524. if (s_pSelectedSquad == &squad) return;
  2525. s_pSelectedSquad = &squad; // note s_pSelectedSquad can be NULL
  2526. if (!s_pSelectedSquad)
  2527. m_pbuttonLog->SetEnabled(false);
  2528. else
  2529. m_pbuttonLog->SetEnabled(true);
  2530. if (s_pSelectedSquad == m_psquadBeingMade && s_pSelectedSquad != NULL)
  2531. {
  2532. // Make fields writable if just created...this is done like this because selection is delayed
  2533. m_peditPaneSquadName->SetReadOnly(false);
  2534. m_peditPaneSquadDescription->SetHidden(false);
  2535. m_pstringDescription->SetValue("");
  2536. m_peditPaneSquadURL->SetReadOnly(false);
  2537. m_pbuttonApply->SetEnabled(!m_bSquadEditNameReset);
  2538. m_pbuttonCreateSquad->SetEnabled(false);
  2539. m_pcomboCiv->SetEnabled(true);
  2540. m_pbuttonApply->SetHidden(false);
  2541. m_pbuttonEditSquad->SetHidden(true);
  2542. }
  2543. else
  2544. {
  2545. if (m_psquadBeingMade) // if user was making a squad, cancel that squad
  2546. {
  2547. TRef<IZoneSquad> psquadDead = m_psquadBeingMade;
  2548. m_psquadBeingMade = NULL;
  2549. DeleteSquad(psquadDead, false);
  2550. MessageBox("The squad you were creating was cancelled.\n\nThe Edit Profile Button becomes the SAVE Button during squad creation.\n\nTo complete squad creation, you must click on the SAVE button.");
  2551. }
  2552. m_peditPaneSquadName->SetReadOnly();
  2553. m_peditPaneSquadDescription->SetHidden(true);
  2554. m_pstringDescription->SetValue(m_peditPaneSquadDescription->GetString());
  2555. m_peditPaneSquadURL->SetReadOnly();
  2556. m_pbuttonApply->SetEnabled(false);
  2557. m_pbuttonCreateSquad->SetEnabled(true);
  2558. m_pcomboCiv->SetEnabled(false);
  2559. m_pbuttonApply->SetHidden(true);
  2560. m_pbuttonEditSquad->SetHidden(false);
  2561. if (s_pSelectedSquad)
  2562. {
  2563. SEND_FOR_ACTIVE_MEMBER(SQUAD_DETAILS_REQ);
  2564. }
  2565. }
  2566. m_listPlayers.SetEmpty();
  2567. s_pSelectedPlayer = NULL;
  2568. RefreshButtonStates();
  2569. // RefreshSquadsListBox();
  2570. RefreshPlayersListBox();
  2571. RefreshSquadDetailsArea();
  2572. }
  2573. /*-------------------------------------------------------------------------
  2574. * IZoneSquadScreen::PlayerSelectedEvent()
  2575. *-------------------------------------------------------------------------
  2576. * Purpose:
  2577. * Call this when a particular player is selected.
  2578. *
  2579. */
  2580. void OnPlayerSelected(IZonePlayer & player)
  2581. {
  2582. if (&player == s_pSelectedPlayer) return;
  2583. s_pSelectedPlayer = &player;
  2584. RefreshButtonStates();
  2585. }
  2586. class PlayersItemPainter;
  2587. friend class PlayersItemPainter;
  2588. //////////////////////////////////////////////////////////////////////////////
  2589. //
  2590. // PlayersItemPainter -- within the Players listbox
  2591. //
  2592. //////////////////////////////////////////////////////////////////////////////
  2593. class PlayersItemPainter : public ItemPainter
  2594. {
  2595. const TVector<int>& m_viColumns;
  2596. SquadsScreen * m_pSquadsScreen;
  2597. public:
  2598. PlayersItemPainter(const TVector<int>& viColumns, SquadsScreen * pMaker)
  2599. : m_viColumns(viColumns),
  2600. m_pSquadsScreen(pMaker)
  2601. {};
  2602. int GetXSize()
  2603. {
  2604. return m_viColumns[3];
  2605. }
  2606. int GetYSize()
  2607. {
  2608. return 14;
  2609. }
  2610. void Paint(ItemID pitemArg, Surface* psurface, bool bSelected, bool bFocus)
  2611. {
  2612. // if a squad isn't selected, then paint no players
  2613. if(!m_pSquadsScreen->GetSelectedSquad())
  2614. return;
  2615. IZonePlayer* pplayer = (IZonePlayer*)pitemArg;
  2616. IZonePlayer::DetailedStatus detailedstatus = pplayer->GetStatus(*(m_pSquadsScreen->GetSelectedSquad()));
  2617. // if this player isn't on the selected squad then don't draw him
  2618. if (detailedstatus == IZonePlayer::DSTAT_NO_ASSOCIATION ||
  2619. detailedstatus == IZonePlayer::DSTAT_UNKNOWN)
  2620. return;
  2621. char cbTemp[256];
  2622. if (bSelected)
  2623. {
  2624. //
  2625. // Draw selection bar
  2626. //
  2627. psurface->FillRect(
  2628. WinRect(0, 0, GetXSize(), GetYSize()),
  2629. m_pSquadsScreen->GetPlayerSelectionBarColor());
  2630. // m_pSquadsScreen->OnPlayerSelected(*pplayer);
  2631. }
  2632. // TODO: make read in
  2633. TRef<IEngineFont> pfont = TrekResources::SmallFont();
  2634. //
  2635. // Display Name
  2636. //
  2637. WinRect rectClipOld = psurface->GetClipRect();
  2638. psurface->SetClipRect(WinRect(WinPoint(2, 0), WinPoint(m_viColumns[0], GetYSize()))); // clip name to fit in column
  2639. wsprintf(cbTemp, "%s", pplayer->GetName());
  2640. psurface->DrawString(pfont, Color::White(), WinPoint(/*m_viColumns[-1] + */2, 0), cbTemp);
  2641. psurface->RestoreClipRect(rectClipOld);
  2642. //
  2643. // Display Rank
  2644. //
  2645. rectClipOld = psurface->GetClipRect();
  2646. psurface->SetClipRect(WinRect(WinPoint(m_viColumns[0] + 2, 0), WinPoint(m_viColumns[1], GetYSize()))); // clip rank to fit in column
  2647. CivID civid = s_pSelectedSquad ? s_pSelectedSquad->GetCivID() : -1;
  2648. wsprintf(cbTemp, "%s", PCC(trekClient.LookupRankName((RankID)pplayer->GetRank(), civid)));
  2649. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[0] + 2, 0), cbTemp);
  2650. psurface->RestoreClipRect(rectClipOld);
  2651. //
  2652. // Display Status
  2653. //
  2654. rectClipOld = psurface->GetClipRect();
  2655. psurface->SetClipRect(WinRect(WinPoint(m_viColumns[1] + 2, 0), WinPoint(m_viColumns[2], GetYSize()))); // clip status to fit in column
  2656. wsprintf(cbTemp, "%s", IZonePlayer::DetailedStatus2String(detailedstatus));
  2657. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[1] + 2, 0), cbTemp);
  2658. psurface->RestoreClipRect(rectClipOld);
  2659. //
  2660. // Display Last Date Played
  2661. //
  2662. if(s_pSelectedSquad)
  2663. {
  2664. wsprintf(cbTemp, "%s", pplayer->GetLastPlayedDate(*s_pSelectedSquad));
  2665. psurface->DrawString(pfont, Color::White(), WinPoint(m_viColumns[2] + 2, 0), cbTemp);
  2666. }
  2667. }
  2668. };
  2669. //////////////////////////////////////////////////////////////////////////////
  2670. //
  2671. // Screen Methods
  2672. //
  2673. //////////////////////////////////////////////////////////////////////////////
  2674. Pane* GetPane()
  2675. {
  2676. return m_ppane;
  2677. }
  2678. Color & GetPlayerSelectionBarColor()
  2679. {
  2680. return m_colorPlayerSelectionBar;
  2681. }
  2682. Color & GetSquadSelectionBarColor()
  2683. {
  2684. return m_colorSquadSelectionBar;
  2685. }
  2686. };
  2687. //////////////////////////////////////////////////////////////////////////////
  2688. //
  2689. // Constructor
  2690. //
  2691. //////////////////////////////////////////////////////////////////////////////
  2692. TRef<Screen> CreateSquadsScreen(Modeler* pmodeler, const char * szNameDudeX, int idZoneDudeX, const char * szSquad)
  2693. {
  2694. g_pSquadScreen = new SquadsScreen(pmodeler, szNameDudeX, idZoneDudeX, szSquad);
  2695. return g_pSquadScreen;
  2696. }
  2697. TRef<IZonePlayer> SquadsScreen::s_pActivePlayer; // points to the squad player that the interactive user controls
  2698. TRef<IZonePlayer> SquadsScreen::s_pSelectedPlayer;
  2699. TRef<IZonePlayer> SquadsScreen::s_pDudeXPlayer;
  2700. SQUAD_SORT_COLUMN SquadsScreen::s_column; // currently sorted column
  2701. TRef<IZoneSquad> SquadsScreen::s_pSelectedSquad;
  2702. SquadsScreen * g_pSquadScreen = NULL;
  2703. void ForwardSquadMessage(FEDMESSAGE * pSquadMessage)
  2704. {
  2705. if(g_pSquadScreen)
  2706. {
  2707. g_pSquadScreen->ForwardSquadMessage(pSquadMessage);
  2708. }
  2709. }