OpenClonk
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::C4PlayerControlAssignmentSets ( )
default

◆ ~C4PlayerControlAssignmentSets()

C4PlayerControlAssignmentSets::~C4PlayerControlAssignmentSets ( )
default

Member Function Documentation

◆ Clear()

void C4PlayerControlAssignmentSets::Clear ( )

Definition at line 711 of file C4PlayerControl.cpp.

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

712 {
713  Sets.clear();
714 }
Here is the caller graph for this function:

◆ CompileFunc()

void C4PlayerControlAssignmentSets::CompileFunc ( StdCompiler pComp)

Definition at line 716 of file C4PlayerControl.cpp.

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

717 {
718  if (pComp->isSerializer() && pComp->isRegistry())
719  {
720  pComp->Default("ControlSets"); // special registry compiler: Clean out everything before
721  }
722  pComp->Value(mkNamingAdapt(clear_previous, "ClearPrevious", false));
724 }
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:699
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:

◆ CreateEmptySetByTemplate()

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::CreateEmptySetByTemplate ( const C4PlayerControlAssignmentSet template_set)

Definition at line 820 of file C4PlayerControl.cpp.

References C4PlayerControlAssignmentSet::InitEmptyFromTemplate().

821 {
822  Sets.emplace_back();
823  Sets.back().InitEmptyFromTemplate(template_set);
824  return &Sets.back();
825 }
Here is the call graph for this function:

◆ GetDefaultSet()

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetDefaultSet ( )

Definition at line 793 of file C4PlayerControl.cpp.

Referenced by C4Player::InitControl(), and C4StartupPlrPropertiesDlg::OnClrChangeRight().

794 {
795  // default set is first defined control set
796  if (Sets.empty()) return nullptr; // nothing defined :(
797  return &Sets.front();
798 }
Here is the caller graph for this function:

◆ GetSetByIndex()

C4PlayerControlAssignmentSet * C4PlayerControlAssignmentSets::GetSetByIndex ( int32_t  index)

Definition at line 810 of file C4PlayerControl.cpp.

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

811 {
812  // bounds check
813  if (index < 0 || index >= (int32_t)Sets.size()) return nullptr;
814  // return indexed set
815  AssignmentSetList::iterator i = Sets.begin();
816  while (index--) ++i;
817  return &*i;
818 }
Here is the caller graph for this function:

◆ GetSetByName()

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

Definition at line 785 of file C4PlayerControl.cpp.

References WildcardMatch().

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

786 {
787  for (auto & Set : Sets)
788  if (WildcardMatch(szName, Set.GetName()))
789  return &Set;
790  return nullptr;
791 }
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:

◆ GetSetCount()

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:

◆ GetSetIndex()

int32_t C4PlayerControlAssignmentSets::GetSetIndex ( const C4PlayerControlAssignmentSet set) const

Definition at line 800 of file C4PlayerControl.cpp.

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

801 {
802  // find set in list; return index
803  int32_t index = 0;
804  for (AssignmentSetList::const_iterator i = Sets.begin(); i != Sets.end(); ++i,++index)
805  if (&*i == set)
806  return index;
807  return -1; // not found
808 }
Here is the caller graph for this function:

◆ MergeFrom()

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

Definition at line 731 of file C4PlayerControl.cpp.

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

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

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

◆ operator==()

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

Definition at line 726 of file C4PlayerControl.cpp.

727 {
728  return Sets == cmp.Sets && clear_previous == cmp.clear_previous;
729 }

◆ RemoveSetByName()

void C4PlayerControlAssignmentSets::RemoveSetByName ( const char *  set_name)

Definition at line 827 of file C4PlayerControl.cpp.

References SEqual().

828 {
829  for (AssignmentSetList::iterator i = Sets.begin(); i != Sets.end(); ++i)
830  if (SEqual(set_name, (*i).GetName()))
831  {
832  Sets.erase(i);
833  return;
834  }
835 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
Here is the call graph for this function:

◆ ResolveRefs()

bool C4PlayerControlAssignmentSets::ResolveRefs ( C4PlayerControlDefs pControlDefs)

Definition at line 772 of file C4PlayerControl.cpp.

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

773 {
774  for (auto & Set : Sets)
775  if (!Set.ResolveRefs(pDefs)) return false;
776  return true;
777 }
Here is the caller graph for this function:

◆ SortAssignments()

void C4PlayerControlAssignmentSets::SortAssignments ( )

Definition at line 779 of file C4PlayerControl.cpp.

780 {
781  for (auto & Set : Sets)
782  Set.SortAssignments();
783 }

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