bool C4MainMenu::ActivateNewPlayer(int32_t iPlayer) { // league or replay game if (Game.Parameters.isLeague() || Game.C4S.Head.Replay) return false; // Max player limit if (::Players.GetCount() >= Game.Parameters.MaxPlayers) return false; // Menu symbol/init if (GfxR->fctPlayerClr.Surface) GfxR->fctPlayerClr.Surface->SetClr(0xff); InitRefSym(GfxR->fctPlayerClr, LoadResStr("IDS_MENU_NOPLRFILES"), iPlayer); for (DirectoryIterator iter(Config.General.UserDataPath); *iter; ++iter) if (WildcardMatch("*.ocp", *iter)) { char szFilename[_MAX_PATH+1], szCommand[_MAX_PATH+30+1]; SCopy(*iter, szFilename, _MAX_PATH); if (DirectoryExists(szFilename)) continue; if (::Players.FileInUse(szFilename)) continue; // Open group C4Group hGroup; if (!hGroup.Open(szFilename)) continue; // Load player info C4PlayerInfoCore C4P; if (!C4P.Load(hGroup)) { hGroup.Close(); continue; } // Close group hGroup.Close(); // Add player item sprintf(szCommand, "JoinPlayer:%s", szFilename); StdStrBuf sItemText; sItemText.Format(LoadResStr("IDS_MENU_NEWPLAYER"), C4P.PrefName); C4FacetSurface fctSymbol; // Add menu item Add(sItemText.getData(), fctSymbol, szCommand); // Reset symbol facet (menu holds on to the surface) fctSymbol.Default(); } // Alignment SetAlignment(C4MN_Align_Left | C4MN_Align_Bottom); // Go back to options menu on close SetCloseCommand("ActivateMenu:Main"); return true; }
bool C4ObjectMenu::DoRefillInternal(bool &rfRefilled) { // Variables C4FacetSurface fctSymbol; C4Object *pObj; char szCaption[256+1],szCommand[256+1],szCommand2[256+1]; int32_t iCount; C4Def *pDef; C4IDList ListItems; C4Object *pTarget; C4Facet fctTarget; // Refill switch (Identification) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_Activate: // Clear items ClearItems(); // Refill target if (!(pTarget=RefillObject)) return false; { // Add target contents items C4ObjectListIterator iter(pTarget->Contents); while ((pObj = iter.GetNext(&iCount))) { pDef = pObj->Def; if (pDef->NoGet) continue; // Prefer fully constructed objects if (~pObj->OCF & OCF_FullCon) { // easy way: only if first concat check matches // this doesn't catch all possibilities, but that will rarely matter C4Object *pObj2=pTarget->Contents.Find(pDef, ANY_OWNER, OCF_FullCon); if (pObj2) if (pObj2->CanConcatPictureWith(pObj)) pObj = pObj2; } // Caption sprintf(szCaption,LoadResStr("IDS_MENU_ACTIVATE"),(const char *) pObj->GetName()); // Picture fctSymbol.Set(fctSymbol.Surface, 0,0,C4SymbolSize,C4SymbolSize); pObj->Picture2Facet(fctSymbol); // Commands sprintf(szCommand,"SetCommand(\"Activate\",Object(%d))&&ExecuteCommand()",pObj->Number); sprintf(szCommand2,"SetCommand(\"Activate\",nil,%d,0,Object(%d),%s)&&ExecuteCommand()",pTarget->Contents.ObjectCount(pDef->id),pTarget->Number,pDef->id.ToString()); // Add menu item Add(szCaption,fctSymbol,szCommand,iCount,pObj,"",pDef->id,szCommand2,true,pObj->GetValue(pTarget, NO_OWNER)); // facet taken over (arrg!) fctSymbol.Default(); } } break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_Get: case C4MN_Contents: // Clear items ClearItems(); // Refill target if (!(pTarget = RefillObject)) return false; { // Add target contents items C4ObjectListIterator iter(pTarget->Contents); while ((pObj = iter.GetNext(&iCount))) { pDef = pObj->Def; if (pDef->NoGet) continue; // Prefer fully constructed objects if (~pObj->OCF & OCF_FullCon) { // easy way: only if first concat check matches // this doesn't catch all possibilities, but that will rarely matter C4Object *pObj2 = pTarget->Contents.Find(pDef, ANY_OWNER, OCF_FullCon); if (pObj2) if (pObj2->CanConcatPictureWith(pObj)) pObj = pObj2; } // Determine whether to get or activate bool fGet = true; if (!(pObj->OCF & OCF_Carryable)) fGet = false; // not a carryable item if (Identification == C4MN_Contents) { if (Object && !!Object->Call(PSF_RejectCollection, &C4AulParSet(pObj->Def, pObj))) fGet = false; // collection rejected } if (!(pTarget->OCF & OCF_Entrance)) fGet = true; // target object has no entrance: cannot activate - force get // Caption sprintf(szCaption, LoadResStr(fGet ? "IDS_MENU_GET" : "IDS_MENU_ACTIVATE"), (const char *)pObj->GetName()); // Picture fctSymbol.Set(fctSymbol.Surface, 0, 0, C4SymbolSize, C4SymbolSize); pObj->Picture2Facet(fctSymbol); // Primary command: get/activate single object sprintf(szCommand, "SetCommand(\"%s\", Object(%d)) && ExecuteCommand()", fGet ? "Get" : "Activate", pObj->Number); // Secondary command: get/activate all objects of the chosen type szCommand2[0] = 0; int32_t iAllCount; if ((iAllCount = pTarget->Contents.ObjectCount(pDef->id)) > 1) sprintf(szCommand2, "SetCommand(\"%s\", nil, %d,0, Object(%d), %s) && ExecuteCommand()", fGet ? "Get" : "Activate", iAllCount, pTarget->Number, pDef->id.ToString()); // Add menu item (with object) Add(szCaption, fctSymbol, szCommand, iCount, pObj, "", pDef->id, szCommand2); fctSymbol.Default(); } } break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - default: // Not an internal menu return true; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } // Successfull internal refill rfRefilled = true; return true; }
bool C4MainMenu::DoRefillInternal(bool &rfRefilled) { // Variables C4FacetSurface fctSymbol; C4Player *pPlayer; C4IDList ListItems; C4Facet fctTarget; bool fWasEmpty = !GetItemCount(); // Refill switch (Identification) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_Hostility: { // Clear items ClearItems(); // Refill player if (!(pPlayer = ::Players.Get(Player))) return false; // Refill items C4Player *pPlr; int32_t iIndex; for (iIndex=0; (pPlr = ::Players.GetByIndex(iIndex)); iIndex++) // Ignore player self and invisible if (pPlr != pPlayer) if (!pPlr->IsInvisible()) { // Symbol fctSymbol.Create(C4SymbolSize,C4SymbolSize); pPlayer->DrawHostility(fctSymbol,iIndex); // Message StdStrBuf sMsg; bool isFriendly = pPlayer->Hostility.find(pPlr) == pPlayer->Hostility.end(); if (isFriendly) sMsg.Format(LoadResStr("IDS_MENU_ATTACK"),pPlr->GetName()); else sMsg.Format(LoadResStr("IDS_MENU_NOATTACK"),pPlr->GetName()); // Command char szCommand[1000]; sprintf(szCommand,"SetHostility:%i",pPlr->Number); // Info caption char szInfoCaption[C4MaxTitle+1],szFriendly[50],szNot[30]=""; SCopy(LoadResStr(isFriendly ? "IDS_MENU_ATTACKHOSTILE" : "IDS_MENU_ATTACKFRIENDLY"),szFriendly); if (!isFriendly) SCopy(LoadResStr("IDS_MENU_ATTACKNOT"),szNot); sprintf(szInfoCaption,LoadResStr("IDS_MENU_ATTACKINFO"),pPlr->GetName(),szFriendly,szNot); if (iIndex==pPlayer->Number) SCopy(LoadResStr("IDS_MENU_ATTACKSELF"),szInfoCaption); // Add item Add(sMsg.getData(),fctSymbol,szCommand,C4MN_Item_NoCount,NULL,szInfoCaption); fctSymbol.Default(); } break; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_TeamSelection: case C4MN_TeamSwitch: { // Clear items ClearItems(); // add all teams as menu items // 2do: Icon C4Team *pTeam; int32_t i=0; bool fAddNewTeam=Game.Teams.IsAutoGenerateTeams(); for (;;) { pTeam = Game.Teams.GetTeamByIndex(i); if (pTeam) { // next regular team ++i; // do not add a new team if an empty team exists if (!pTeam->GetPlayerCount()) fAddNewTeam = false; } else if (fAddNewTeam) { // join new team fAddNewTeam = false; } else { // all teams done break; } // create team symbol: Icon spec if specified; otherwise flag for empty and crew for nonempty team fctSymbol.Create(C4SymbolSize,C4SymbolSize); const char *szIconSpec = pTeam ? pTeam->GetIconSpec() : NULL; bool fHasIcon = false; if (szIconSpec && *szIconSpec) { fHasIcon = Game.DrawTextSpecImage(fctSymbol, szIconSpec, NULL, pTeam->GetColor()); } if (!fHasIcon) { if (pTeam && pTeam->GetPlayerCount()) ::GraphicsResource.fctCrewClr.DrawClr(fctSymbol, true, pTeam->GetColor()); else C4GUI::Icon::GetIconFacet(C4GUI::Ico_Team).Draw(fctSymbol, true); } StdStrBuf sTeamName; if (pTeam) { sTeamName.Take(pTeam->GetNameWithParticipants()); } else sTeamName.Ref(LoadResStr("IDS_PRC_NEWTEAM")); const char *szOperation = (Identification == C4MN_TeamSwitch) ? "TeamSwitch" : "TeamSel"; Add(sTeamName.getData(), fctSymbol,FormatString("%s:%d", szOperation, pTeam ? pTeam->GetID() : TEAMID_New).getData(), C4MN_Item_NoCount,NULL,FormatString(LoadResStr("IDS_MSG_JOINTEAM"), sTeamName.getData()).getData(), C4ID(pTeam ? pTeam->GetID() : 0)); fctSymbol.Default(); } break; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case C4MN_Observer: // observer menu { // Clear items ClearItems(); // Check validity C4Viewport *pVP = ::Viewports.GetViewport(NO_OWNER); if (!pVP) return false; int32_t iInitialSelection = 0; // Add free view AddRefSym(LoadResStr("IDS_MSG_FREEVIEW"), C4GUI::Icon::GetIconFacet(C4GUI::Ico_Star), "Observe:Free", C4MN_Item_NoCount, NULL, LoadResStr("IDS_MSG_FREELYSCROLLAROUNDTHEMAP")); // Add players C4Player *pPlr; int32_t iIndex; for (iIndex=0; (pPlr = ::Players.GetByIndex(iIndex)); iIndex++) { // Ignore invisible if (!pPlr->IsInvisible()) { // Symbol fctSymbol.Create(C4SymbolSize,C4SymbolSize); ::GraphicsResource.fctPlayerClr.DrawClr(fctSymbol, true, pPlr->ColorDw); // Message StdStrBuf sMsg; DWORD dwClr = pPlr->ColorDw; sMsg.Format("<c %x>%s</c>", (unsigned int)C4GUI::MakeColorReadableOnBlack(dwClr), pPlr->GetName()); // Command StdStrBuf sCommand; sCommand.Format("Observe:%d", (int)pPlr->Number); // Info caption StdStrBuf sInfo; sInfo.Format(LoadResStr("IDS_TEXT_FOLLOWVIEWOFPLAYER"), pPlr->GetName()); // Add item Add(sMsg.getData(),fctSymbol,sCommand.getData(),C4MN_Item_NoCount,NULL,sInfo.getData()); fctSymbol.Default(); // check if this is the currently selected player if (pVP->GetPlayer() == pPlr->Number) iInitialSelection = GetItemCount()-1; } // Initial selection on followed player if (fWasEmpty) SetSelection(iInitialSelection, false, true); } } break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - default: // No internal refill needed return true; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } // Successfull internal refill rfRefilled = true; return true; }