OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4PlayerControlAssignmentSets Class Reference

#include <C4PlayerControl.h>

Public Member Functions

 C4PlayerControlAssignmentSets ()
 
 ~C4PlayerControlAssignmentSets ()
 
void Clear ()
 
void CompileFunc (StdCompiler *pComp)
 
bool operator== (const C4PlayerControlAssignmentSets &cmp) const
 
bool ResolveRefs (C4PlayerControlDefs *pControlDefs)
 
void SortAssignments ()
 
void MergeFrom (const C4PlayerControlAssignmentSets &Src, C4PlayerControlAssignmentSet::MergeMode merge_mode)
 
C4PlayerControlAssignmentSetCreateEmptySetByTemplate (const C4PlayerControlAssignmentSet &template_set)
 
void RemoveSetByName (const char *set_name)
 
C4PlayerControlAssignmentSetGetSetByName (const char *szName)
 
C4PlayerControlAssignmentSetGetDefaultSet ()
 
int32_t GetSetIndex (const C4PlayerControlAssignmentSet *set) const
 
C4PlayerControlAssignmentSetGetSetByIndex (int32_t index)
 
size_t GetSetCount () const
 

Detailed Description

Definition at line 284 of file C4PlayerControl.h.

Constructor & Destructor Documentation

C4PlayerControlAssignmentSets::C4PlayerControlAssignmentSets ( )
inline

Definition at line 292 of file C4PlayerControl.h.

292 : clear_previous(false) {}
C4PlayerControlAssignmentSets::~C4PlayerControlAssignmentSets ( )
inline

Definition at line 293 of file C4PlayerControl.h.

293 {}

Member Function Documentation

void C4PlayerControlAssignmentSets::Clear ( )

Definition at line 727 of file C4PlayerControl.cpp.

Referenced by C4Game::Clear(), C4PlayerControlFile::Clear(), C4Game::InitPlayerControlSettings(), C4Game::InitPlayerControlUserSettings(), and C4ConfigControls::ResetKeys().

728 {
729  Sets.clear();
730 }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSets::CompileFunc ( StdCompiler pComp)

Definition at line 732 of file C4PlayerControl.cpp.

References StdCompiler::Default(), StdCompiler::isRegistry(), StdCompiler::isSerializer(), mkNamingAdapt(), mkSTLContainerAdapt(), StdCompiler::SEP_NONE, and StdCompiler::Value().

733 {
734  if (pComp->isSerializer() && pComp->isRegistry())
735  {
736  pComp->Default("ControlSets"); // special registry compiler: Clean out everything before
737  }
738  pComp->Value(mkNamingAdapt(clear_previous, "ClearPrevious", false));
740 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
bool isSerializer()
Definition: StdCompiler.h:64
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:679
virtual bool Default(const char *szName)
Definition: StdCompiler.h:98
virtual bool isRegistry()
Definition: StdCompiler.h:75

Here is the call graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::CreateEmptySetByTemplate ( const C4PlayerControlAssignmentSet template_set)

Definition at line 838 of file C4PlayerControl.cpp.

Referenced by MergeFrom().

839 {
840  Sets.push_back(C4PlayerControlAssignmentSet());
841  Sets.back().InitEmptyFromTemplate(template_set);
842  return &Sets.back();
843 }

Here is the caller graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetDefaultSet ( )

Definition at line 811 of file C4PlayerControl.cpp.

Referenced by C4Player::InitControl().

812 {
813  // default set is first defined control set
814  if (Sets.empty()) return nullptr; // nothing defined :(
815  return &Sets.front();
816 }

Here is the caller graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetSetByIndex ( int32_t  index)

Definition at line 828 of file C4PlayerControl.cpp.

Referenced by C4StartupPlrPropertiesDlg::OnCtrlChangeLeft(), and C4StartupPlrPropertiesDlg::OnCtrlChangeRight().

829 {
830  // bounds check
831  if (index < 0 || index >= (int32_t)Sets.size()) return nullptr;
832  // return indexed set
833  AssignmentSetList::iterator i = Sets.begin();
834  while (index--) ++i;
835  return &*i;
836 }

Here is the caller graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetSetByName ( const char *  szName)

Definition at line 803 of file C4PlayerControl.cpp.

References WildcardMatch().

Referenced by C4Player::InitControl(), MergeFrom(), C4StartupPlrPropertiesDlg::OnCtrlChangeLeft(), and C4StartupPlrPropertiesDlg::OnCtrlChangeRight().

804 {
805  for (AssignmentSetList::iterator i = Sets.begin(); i != Sets.end(); ++i)
806  if (WildcardMatch(szName, (*i).GetName()))
807  return &*i;
808  return nullptr;
809 }
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384

Here is the call graph for this function:

Here is the caller graph for this function:

size_t C4PlayerControlAssignmentSets::GetSetCount ( ) const
inline

Definition at line 310 of file C4PlayerControl.h.

Referenced by C4StartupPlrPropertiesDlg::OnCtrlChangeLeft(), and C4StartupPlrPropertiesDlg::OnCtrlChangeRight().

310 { return Sets.size(); }

Here is the caller graph for this function:

int32_t C4PlayerControlAssignmentSets::GetSetIndex ( const C4PlayerControlAssignmentSet set) const

Definition at line 818 of file C4PlayerControl.cpp.

Referenced by C4PlayerControlAssignmentSet::GetPicture(), C4StartupPlrPropertiesDlg::OnCtrlChangeLeft(), and C4StartupPlrPropertiesDlg::OnCtrlChangeRight().

819 {
820  // find set in list; return index
821  int32_t index = 0;
822  for (AssignmentSetList::const_iterator i = Sets.begin(); i != Sets.end(); ++i,++index)
823  if (&*i == set)
824  return index;
825  return -1; // not found
826 }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSets::MergeFrom ( const C4PlayerControlAssignmentSets Src,
C4PlayerControlAssignmentSet::MergeMode  merge_mode 
)

Definition at line 747 of file C4PlayerControl.cpp.

References CreateEmptySetByTemplate(), C4PlayerControlAssignmentSet::GetName(), GetSetByName(), C4PlayerControlAssignmentSet::IsWildcardName(), C4PlayerControlAssignmentSet::MergeFrom(), C4PlayerControlAssignmentSet::MM_Inherit, and WildcardMatch().

Referenced by C4Game::InitPlayerControlSettings(), C4Game::InitPlayerControlUserSettings(), and C4Game::LoadAdditionalSystemGroup().

748 {
749  // if source set is flagged to clear previous, do this!
750  if (Src.clear_previous) Sets.clear();
751  // take over all assignments in known sets and new sets defined in Src
752  for (AssignmentSetList::const_iterator i = Src.Sets.begin(); i != Src.Sets.end(); ++i)
753  {
754  const C4PlayerControlAssignmentSet &SrcSet = *i;
755  // overwrite if def of same name existed if it's not low priority anyway
756  bool fIsWildcardSet = SrcSet.IsWildcardName();
757  if (!fIsWildcardSet)
758  {
759  C4PlayerControlAssignmentSet *pPrevSet = GetSetByName(SrcSet.GetName());
760  if (!pPrevSet && merge_mode == C4PlayerControlAssignmentSet::MM_Inherit)
761  {
762  // inherited sets must go through merge procedure to set inherited links
763  pPrevSet = CreateEmptySetByTemplate(SrcSet);
764  }
765  if (pPrevSet)
766  {
767  pPrevSet->MergeFrom(SrcSet, merge_mode);
768  }
769  else
770  {
771  // new def: Append a copy
772  Sets.push_back(SrcSet);
773  }
774  }
775  else
776  {
777  // source is a wildcard: Merge with all matching sets
778  for (AssignmentSetList::iterator j = Sets.begin(); j != Sets.end(); ++j)
779  {
780  C4PlayerControlAssignmentSet &DstSet = *j;
781  if (WildcardMatch(SrcSet.GetName(), DstSet.GetName()))
782  {
783  DstSet.MergeFrom(SrcSet, merge_mode);
784  }
785  }
786  }
787  }
788 }
const char * GetName() const
C4PlayerControlAssignmentSet * GetSetByName(const char *szName)
void MergeFrom(const C4PlayerControlAssignmentSet &Src, MergeMode merge_mode)
C4PlayerControlAssignmentSet * CreateEmptySetByTemplate(const C4PlayerControlAssignmentSet &template_set)
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSets::operator== ( const C4PlayerControlAssignmentSets cmp) const

Definition at line 742 of file C4PlayerControl.cpp.

743 {
744  return Sets == cmp.Sets && clear_previous == cmp.clear_previous;
745 }
void C4PlayerControlAssignmentSets::RemoveSetByName ( const char *  set_name)

Definition at line 845 of file C4PlayerControl.cpp.

References SEqual().

846 {
847  for (AssignmentSetList::iterator i = Sets.begin(); i != Sets.end(); ++i)
848  if (SEqual(set_name, (*i).GetName()))
849  {
850  Sets.erase(i);
851  return;
852  }
853 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97

Here is the call graph for this function:

bool C4PlayerControlAssignmentSets::ResolveRefs ( C4PlayerControlDefs pControlDefs)

Definition at line 790 of file C4PlayerControl.cpp.

Referenced by C4Game::InitPlayerControlSettings(), C4Game::InitPlayerControlUserSettings(), C4Game::LoadAdditionalSystemGroup(), and C4Game::OnKeyboardLayoutChanged().

791 {
792  for (AssignmentSetList::iterator i = Sets.begin(); i != Sets.end(); ++i)
793  if (!(*i).ResolveRefs(pDefs)) return false;
794  return true;
795 }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSets::SortAssignments ( )

Definition at line 797 of file C4PlayerControl.cpp.

Referenced by C4Game::InitGame().

798 {
799  for (AssignmentSetList::iterator i = Sets.begin(); i != Sets.end(); ++i)
800  (*i).SortAssignments();
801 }

Here is the caller graph for this function:


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