OpenClonk
C4PlayerControlDefs Class Reference

#include <C4PlayerControl.h>

Collaboration diagram for C4PlayerControlDefs:
[legend]

Classes

struct  CInternalCons
 

Public Member Functions

void UpdateInternalCons ()
 
 C4PlayerControlDefs ()=default
 
 ~C4PlayerControlDefs ()=default
 
void Clear ()
 
void CompileFunc (StdCompiler *pComp)
 
void MergeFrom (const C4PlayerControlDefs &Src)
 
void FinalInit ()
 
const C4PlayerControlDefGetControlByIndex (int32_t idx) const
 
int32_t GetControlIndexByIdentifier (const char *szIdentifier) const
 
size_t GetCount () const
 
bool operator== (const C4PlayerControlDefs &cmp) const
 

Public Attributes

struct C4PlayerControlDefs::CInternalCons InternalCons
 

Detailed Description

Definition at line 96 of file C4PlayerControl.h.

Constructor & Destructor Documentation

◆ C4PlayerControlDefs()

C4PlayerControlDefs::C4PlayerControlDefs ( )
default

◆ ~C4PlayerControlDefs()

C4PlayerControlDefs::~C4PlayerControlDefs ( )
default

Member Function Documentation

◆ Clear()

void C4PlayerControlDefs::Clear ( )

Definition at line 114 of file C4PlayerControl.cpp.

115 {
116  clear_previous = false;
117  Defs.clear();
119 }

References UpdateInternalCons().

Referenced by C4PlayerControlFile::Clear(), and C4Game::Clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4PlayerControlDefs::CompileFunc ( StdCompiler pComp)

Definition at line 121 of file C4PlayerControl.cpp.

122 {
123  pComp->Value(mkNamingAdapt(clear_previous, "ClearPrevious", false));
125  if (pComp->isDeserializer()) UpdateInternalCons();
126 }
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:713
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References StdCompiler::isDeserializer(), mkNamingAdapt(), mkSTLContainerAdapt(), StdCompiler::SEP_NONE, UpdateInternalCons(), and StdCompiler::Value().

Here is the call graph for this function:

◆ FinalInit()

void C4PlayerControlDefs::FinalInit ( )

Definition at line 165 of file C4PlayerControl.cpp.

166 {
167  // Assume all defs have been loaded
168  // Register scritp constants
169  for (DefVecImpl::const_iterator i = Defs.begin(); i != Defs.end(); ++i)
170  {
171  const char *szIdtf = (*i).GetIdentifier();
172  if (szIdtf && *szIdtf && !SEqual(szIdtf, "None"))
173  {
174  ::ScriptEngine.RegisterGlobalConstant(FormatString("CON_%s", szIdtf).getData(), C4VInt(i-Defs.begin()));
175  }
176  }
177 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4Value C4VInt(int32_t i)
Definition: C4Value.h:239
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
Definition: C4Aul.cpp:123

References C4VInt(), FormatString(), C4AulScriptEngine::RegisterGlobalConstant(), ScriptEngine, and SEqual().

Here is the call graph for this function:

◆ GetControlByIndex()

const C4PlayerControlDef * C4PlayerControlDefs::GetControlByIndex ( int32_t  idx) const

Definition at line 150 of file C4PlayerControl.cpp.

151 {
152  // safe index
153  if (idx<0 || idx>=int32_t(Defs.size())) return nullptr;
154  return &(Defs[idx]);
155 }

Referenced by C4PlayerControlAssignmentSet::GetAssignmentsByKey(), C4PlayerControlAssignment::GetGUIDesc(), C4PlayerControlAssignment::GetGUIName(), C4PlayerControlAssignmentSet::GetTriggerKeys(), and C4PlayerControl::CSync::InitDefaults().

Here is the caller graph for this function:

◆ GetControlIndexByIdentifier()

int32_t C4PlayerControlDefs::GetControlIndexByIdentifier ( const char *  szIdentifier) const

Definition at line 157 of file C4PlayerControl.cpp.

158 {
159  for (DefVecImpl::const_iterator i = Defs.begin(); i != Defs.end(); ++i)
160  if (SEqual((*i).GetIdentifier(), szIdentifier))
161  return i-Defs.begin();
162  return CON_None;
163 }
@ CON_None

References CON_None, and SEqual().

Referenced by MergeFrom(), C4PlayerControlAssignment::ResolveRefs(), and UpdateInternalCons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCount()

size_t C4PlayerControlDefs::GetCount ( ) const
inline

Definition at line 124 of file C4PlayerControl.h.

124 { return Defs.size(); }

◆ MergeFrom()

void C4PlayerControlDefs::MergeFrom ( const C4PlayerControlDefs Src)

Definition at line 128 of file C4PlayerControl.cpp.

129 {
130  // Clear previous defs if specified in merge set
131  if (Src.clear_previous) Defs.clear();
132  // copy all defs from source file; overwrite defs of same name if found
133  for (const auto & SrcDef : Src.Defs)
134  {
135  // overwrite if def of same name existed
136  int32_t iPrevIdx = GetControlIndexByIdentifier(SrcDef.GetIdentifier());
137  if (iPrevIdx != CON_None)
138  {
139  Defs[iPrevIdx] = SrcDef;
140  }
141  else
142  {
143  // new def: Append a copy
144  Defs.push_back(SrcDef);
145  }
146  }
148 }
int32_t GetControlIndexByIdentifier(const char *szIdentifier) const

References CON_None, GetControlIndexByIdentifier(), and UpdateInternalCons().

Referenced by C4Game::LoadAdditionalSystemGroup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==()

bool C4PlayerControlDefs::operator== ( const C4PlayerControlDefs cmp) const
inline

Definition at line 126 of file C4PlayerControl.h.

126 { return Defs == cmp.Defs && clear_previous == cmp.clear_previous; }

◆ UpdateInternalCons()

void C4PlayerControlDefs::UpdateInternalCons ( )

Definition at line 105 of file C4PlayerControl.cpp.

References C4PlayerControlDefs::CInternalCons::CON_CursorPos, C4PlayerControlDefs::CInternalCons::CON_ObjectMenuCancel, C4PlayerControlDefs::CInternalCons::CON_ObjectMenuOK, C4PlayerControlDefs::CInternalCons::CON_ObjectMenuOKAll, C4PlayerControlDefs::CInternalCons::CON_ObjectMenuSelect, GetControlIndexByIdentifier(), and InternalCons.

Referenced by Clear(), CompileFunc(), and MergeFrom().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ InternalCons


The documentation for this class was generated from the following files: