Add support for hidden scenarios.

If C4S.Head.Secret is set and mission access to the scenario has not been gained, it is hidden in the scenario selection list.
shapetextures
Sven Eberhardt 2015-09-24 23:51:16 -04:00
parent ec1b34d3c1
commit 88167a03a8
5 changed files with 14 additions and 1 deletions

View File

@ -70,6 +70,11 @@
<col>String</col>
<col>The scenario will only load if the player gained this password in another scenario. See script function <funclink>GainMissionAccess</funclink>().</col>
</row>
<row>
<col>Secret</col>
<col>bool</col>
<col>If true and MissionAccess is set, the scenario is invisible in the scenario selection list if the player does not have the required password access.</col>
</row>
<row>
<col>ForcedFairCrew</col>
<col>Integer</col>

View File

@ -667,6 +667,8 @@ bool C4ScenarioListLoader::Scenario::LoadCustomPre(C4Group &rGrp)
if (!rGrp.LoadEntryString(C4CFN_ScenarioCore, &sFileContents)) return false;
if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkParAdapt(C4S, false), sFileContents, (rGrp.GetFullName() + DirSep C4CFN_ScenarioCore).getData()))
return false;
// Mission access
fNoMissionAccess = (C4S.Head.MissionAccess[0] && !SIsModule(Config.General.MissionAccess, C4S.Head.MissionAccess));
// Localized parameter definitions. needed for achievements and parameter input boxes.
// Only show them for "real" scenarios
if (!C4S.Head.SaveGame && !C4S.Head.Replay)
@ -767,7 +769,7 @@ bool C4ScenarioListLoader::Scenario::CanOpen(StdStrBuf &sErrOut)
C4StartupScenSelDlg *pDlg = C4StartupScenSelDlg::pInstance;
if (!pDlg) return false;
// check mission access
if (C4S.Head.MissionAccess[0] && !SIsModule(Config.General.MissionAccess, C4S.Head.MissionAccess))
if (!HasMissionAccess())
{
sErrOut.Copy(LoadResStr("IDS_PRC_NOMISSIONACCESS"));
return false;
@ -1595,6 +1597,7 @@ void C4StartupScenSelDlg::UpdateList()
// add what has been loaded
for (C4ScenarioListLoader::Entry *pEnt = pScenLoader->GetFirstEntry(); pEnt; pEnt = pEnt->GetNext())
{
if (pEnt->IsHidden()) continue; // no UI entry at all for hidden items
ScenListItem *pEntItem = new ScenListItem(pScenSelList, pEnt);
if (pEnt == pOldSelection) pScenSelList->SelectEntry(pEntItem, false);
}

View File

@ -92,6 +92,7 @@ public:
virtual bool CanOpen(StdStrBuf &sError) { return true; } // whether item can be started/opened (e.g. mission access, unregistered)
virtual bool IsGrayed() { return false; } // additional condition for graying out - notice unreg folders are grayed but can still be opened
virtual bool IsHidden() { return false; } // condition for hiding element completely
virtual bool HasMissionAccess() const { return true; }
virtual bool HasUnregisteredAccess() const { return false; }
virtual StdStrBuf GetOpenText() = 0; // get open button text
@ -129,6 +130,7 @@ public:
virtual bool CanOpen(StdStrBuf &sError); // check mission access, player count, etc.
virtual bool IsGrayed() { return false; } // additional option for graying out
virtual bool IsHidden() { return C4S.Head.Secret && !HasMissionAccess(); } // condition for hiding element completely
virtual bool HasMissionAccess() const { return !fNoMissionAccess; }; // check mission access only
virtual StdStrBuf GetOpenText(); // get open button text
virtual StdStrBuf GetOpenTooltip();

View File

@ -152,6 +152,7 @@ void C4SHead::Default()
Origin.Clear();
Icon=18;
*Title = *Loader = *Font = *Engine = *MissionAccess = '\0';
Secret = false;
C4XVer[0] = C4XVer[1] = 0;
Difficulty = RandomSeed = 0;
SaveGame = Replay = NoInitialize = false;
@ -186,6 +187,7 @@ void C4SHead::CompileFunc(StdCompiler *pComp, bool fSection)
{
pComp->Value(mkNamingAdapt(mkStringAdaptMA(Engine), "Engine", ""));
pComp->Value(mkNamingAdapt(mkStringAdaptMA(MissionAccess), "MissionAccess", ""));
pComp->Value(mkNamingAdapt(Secret, "Secret", false));
pComp->Value(mkNamingAdapt(NetworkGame, "NetworkGame", false));
pComp->Value(mkNamingAdapt(NetworkRuntimeJoin, "NetworkRuntimeJoin", false));
pComp->Value(mkNamingAdapt(mkStrValAdapt(mkParAdapt(Origin, StdCompiler::RCT_All), C4InVal::VAL_SubPathFilename), "Origin", StdCopyStrBuf()));

View File

@ -72,6 +72,7 @@ public:
int32_t RandomSeed;
char Engine[C4MaxTitle+1]; // Relative filename of engine to be used for this scenario
char MissionAccess[C4MaxTitle+1];
bool Secret; // if true, scenario is invisible if MissionAccess has not been granted
bool NetworkGame;
bool NetworkRuntimeJoin;
StdCopyStrBuf Origin; // original oath and filename to scenario (for records and savegames)