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

#include <C4PlayerControl.h>

Public Member Functions

 C4PlayerControlAssignmentSets ()=default
 
 ~C4PlayerControlAssignmentSets ()=default
 
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 279 of file C4PlayerControl.h.

Constructor & Destructor Documentation

C4PlayerControlAssignmentSets::C4PlayerControlAssignmentSets ( )
default
C4PlayerControlAssignmentSets::~C4PlayerControlAssignmentSets ( )
default

Member Function Documentation

void C4PlayerControlAssignmentSets::Clear ( )

Definition at line 713 of file C4PlayerControl.cpp.

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

714 {
715  Sets.clear();
716 }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSets::CompileFunc ( StdCompiler pComp)

Definition at line 718 of file C4PlayerControl.cpp.

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

719 {
720  if (pComp->isSerializer() && pComp->isRegistry())
721  {
722  pComp->Default("ControlSets"); // special registry compiler: Clean out everything before
723  }
724  pComp->Value(mkNamingAdapt(clear_previous, "ClearPrevious", false));
726 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
bool isSerializer()
Definition: StdCompiler.h:54
void Value(const T &rStruct)
Definition: StdCompiler.h:161
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:681
virtual bool Default(const char *szName)
Definition: StdCompiler.h:88
virtual bool isRegistry()
Definition: StdCompiler.h:65

Here is the call graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::CreateEmptySetByTemplate ( const C4PlayerControlAssignmentSet template_set)

Definition at line 822 of file C4PlayerControl.cpp.

Referenced by MergeFrom().

823 {
824  Sets.emplace_back();
825  Sets.back().InitEmptyFromTemplate(template_set);
826  return &Sets.back();
827 }

Here is the caller graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetDefaultSet ( )

Definition at line 795 of file C4PlayerControl.cpp.

Referenced by C4Player::InitControl().

796 {
797  // default set is first defined control set
798  if (Sets.empty()) return nullptr; // nothing defined :(
799  return &Sets.front();
800 }

Here is the caller graph for this function:

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetSetByIndex ( int32_t  index)

Definition at line 812 of file C4PlayerControl.cpp.

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

813 {
814  // bounds check
815  if (index < 0 || index >= (int32_t)Sets.size()) return nullptr;
816  // return indexed set
817  AssignmentSetList::iterator i = Sets.begin();
818  while (index--) ++i;
819  return &*i;
820 }

Here is the caller graph for this function:

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

Definition at line 787 of file C4PlayerControl.cpp.

References WildcardMatch().

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

788 {
789  for (auto & Set : Sets)
790  if (WildcardMatch(szName, Set.GetName()))
791  return &Set;
792  return nullptr;
793 }
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:374

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 305 of file C4PlayerControl.h.

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

305 { return Sets.size(); }

Here is the caller graph for this function:

int32_t C4PlayerControlAssignmentSets::GetSetIndex ( const C4PlayerControlAssignmentSet set) const

Definition at line 802 of file C4PlayerControl.cpp.

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

803 {
804  // find set in list; return index
805  int32_t index = 0;
806  for (AssignmentSetList::const_iterator i = Sets.begin(); i != Sets.end(); ++i,++index)
807  if (&*i == set)
808  return index;
809  return -1; // not found
810 }

Here is the caller graph for this function:

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

Definition at line 733 of file C4PlayerControl.cpp.

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

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

734 {
735  // if source set is flagged to clear previous, do this!
736  if (Src.clear_previous) Sets.clear();
737  // take over all assignments in known sets and new sets defined in Src
738  for (const auto & SrcSet : Src.Sets)
739  {
740  // overwrite if def of same name existed if it's not low priority anyway
741  bool fIsWildcardSet = SrcSet.IsWildcardName();
742  if (!fIsWildcardSet)
743  {
744  C4PlayerControlAssignmentSet *pPrevSet = GetSetByName(SrcSet.GetName());
745  if (!pPrevSet && merge_mode == C4PlayerControlAssignmentSet::MM_Inherit)
746  {
747  // inherited sets must go through merge procedure to set inherited links
748  pPrevSet = CreateEmptySetByTemplate(SrcSet);
749  }
750  if (pPrevSet)
751  {
752  pPrevSet->MergeFrom(SrcSet, merge_mode);
753  }
754  else
755  {
756  // new def: Append a copy
757  Sets.push_back(SrcSet);
758  }
759  }
760  else
761  {
762  // source is a wildcard: Merge with all matching sets
763  for (auto & DstSet : Sets)
764  {
765  if (WildcardMatch(SrcSet.GetName(), DstSet.GetName()))
766  {
767  DstSet.MergeFrom(SrcSet, merge_mode);
768  }
769  }
770  }
771  }
772 }
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:374

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 728 of file C4PlayerControl.cpp.

729 {
730  return Sets == cmp.Sets && clear_previous == cmp.clear_previous;
731 }
void C4PlayerControlAssignmentSets::RemoveSetByName ( const char *  set_name)

Definition at line 829 of file C4PlayerControl.cpp.

References SEqual().

830 {
831  for (AssignmentSetList::iterator i = Sets.begin(); i != Sets.end(); ++i)
832  if (SEqual(set_name, (*i).GetName()))
833  {
834  Sets.erase(i);
835  return;
836  }
837 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

Here is the call graph for this function:

bool C4PlayerControlAssignmentSets::ResolveRefs ( C4PlayerControlDefs pControlDefs)

Definition at line 774 of file C4PlayerControl.cpp.

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

775 {
776  for (auto & Set : Sets)
777  if (!Set.ResolveRefs(pDefs)) return false;
778  return true;
779 }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSets::SortAssignments ( )

Definition at line 781 of file C4PlayerControl.cpp.

Referenced by C4Game::InitGame().

782 {
783  for (auto & Set : Sets)
784  Set.SortAssignments();
785 }

Here is the caller graph for this function:


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