OpenClonk
C4PlayerControlAssignmentSet Class Reference

#include <C4PlayerControl.h>

Public Types

enum  MergeMode { MM_Normal , MM_LowPrio , MM_Inherit , MM_ConfigOverload }
 

Public Member Functions

 C4PlayerControlAssignmentSet ()=default
 
 ~C4PlayerControlAssignmentSet ()=default
 
void InitEmptyFromTemplate (const C4PlayerControlAssignmentSet &template_set)
 
void CompileFunc (StdCompiler *pComp)
 
bool ResolveRefs (C4PlayerControlDefs *pControlDefs)
 
void SortAssignments ()
 
void MergeFrom (const C4PlayerControlAssignmentSet &Src, MergeMode merge_mode)
 
C4PlayerControlAssignmentCreateAssignmentForControl (const char *control_name)
 
void RemoveAssignmentByControlName (const char *control_name)
 
const char * GetName () const
 
const char * GetGUIName () const
 
bool IsWildcardName () const
 
C4PlayerControlAssignmentGetAssignmentByIndex (int32_t index)
 
C4PlayerControlAssignmentGetAssignmentByControlName (const char *szControlName)
 
C4PlayerControlAssignmentGetAssignmentByControl (int32_t control)
 
void GetAssignmentsByKey (const C4PlayerControlDefs &rDefs, const C4KeyCodeEx &key, bool fHoldKeysOnly, C4PlayerControlAssignmentPVec *pOutVec, const C4PlayerControlRecentKeyList &DownKeys, const C4PlayerControlRecentKeyList &RecentKeys) const
 
void GetTriggerKeys (const C4PlayerControlDefs &rDefs, C4KeyCodeExVec *pRegularKeys, C4KeyCodeExVec *pHoldKeys) const
 
bool operator== (const C4PlayerControlAssignmentSet &cmp) const
 
C4Facet GetPicture () const
 
bool HasKeyboard () const
 
bool HasMouse () const
 
bool HasGamepad () const
 
int32_t GetLayoutOrder () const
 
bool IsMouseControlAssigned (int32_t mouseevent) const
 

Detailed Description

Definition at line 231 of file C4PlayerControl.h.

Member Enumeration Documentation

◆ MergeMode

Constructor & Destructor Documentation

◆ C4PlayerControlAssignmentSet()

C4PlayerControlAssignmentSet::C4PlayerControlAssignmentSet ( )
default

◆ ~C4PlayerControlAssignmentSet()

C4PlayerControlAssignmentSet::~C4PlayerControlAssignmentSet ( )
default

Member Function Documentation

◆ CompileFunc()

void C4PlayerControlAssignmentSet::CompileFunc ( StdCompiler pComp)

Definition at line 490 of file C4PlayerControl.cpp.

491 {
492  if (!pComp->Name("ControlSet")) { pComp->NameEnd(); pComp->excNotFound("ControlSet"); }
493  pComp->Value(mkNamingAdapt(mkParAdapt(sName, StdCompiler::RCT_All), "Name", "None")); // can't do RCT_Idtf because of wildcards
494  pComp->Value(mkNamingAdapt(mkParAdapt(sGUIName, StdCompiler::RCT_All), "GUIName", "undefined"));
495  pComp->Value(mkNamingAdapt(mkParAdapt(sParentSetName, StdCompiler::RCT_Idtf), "Parent", ""));
496  pComp->Value(mkNamingAdapt(has_keyboard, "Keyboard", true));
497  pComp->Value(mkNamingAdapt(has_mouse, "Mouse", true));
498  pComp->Value(mkNamingAdapt(has_gamepad, "Gamepad", false));
499  pComp->Value(mkSTLContainerAdapt(Assignments, StdCompiler::SEP_NONE));
500  pComp->NameEnd();
501 }
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:713
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:78
void excNotFound(const char *szMessage,...)
Definition: StdCompiler.h:233
virtual bool Name(const char *szName)
Definition: StdCompiler.h:77

References StdCompiler::excNotFound(), mkNamingAdapt(), mkParAdapt(), mkSTLContainerAdapt(), StdCompiler::Name(), StdCompiler::NameEnd(), StdCompiler::RCT_All, StdCompiler::RCT_Idtf, StdCompiler::SEP_NONE, and StdCompiler::Value().

Here is the call graph for this function:

◆ CreateAssignmentForControl()

C4PlayerControlAssignment * C4PlayerControlAssignmentSet::CreateAssignmentForControl ( const char *  control_name)

Definition at line 565 of file C4PlayerControl.cpp.

566 {
567  Assignments.emplace_back();
568  Assignments.back().SetControlName(control_name);
569  return &Assignments.back();
570 }

◆ GetAssignmentByControl()

C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByControl ( int32_t  control)

Definition at line 618 of file C4PlayerControl.cpp.

619 {
620  // TODO: Might want to stuff this into a vector indexed by control for faster lookup
621  for (auto & Assignment : Assignments)
622  if (Assignment.GetControl() == control)
623  // We don't like release keys... (2do)
624  if (!(Assignment.GetTriggerMode() & C4PlayerControlAssignment::CTM_Release))
625  return &Assignment;
626  return nullptr;
627 }

References C4PlayerControlAssignment::CTM_Release.

◆ GetAssignmentByControlName()

C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByControlName ( const char *  szControlName)

Definition at line 608 of file C4PlayerControl.cpp.

609 {
610  for (auto & Assignment : Assignments)
611  if (SEqual(Assignment.GetControlName(), szControlName))
612  // We don't like release keys... (2do)
613  if (!(Assignment.GetTriggerMode() & C4PlayerControlAssignment::CTM_Release))
614  return &Assignment;
615  return nullptr;
616 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

References C4PlayerControlAssignment::CTM_Release, and SEqual().

Referenced by C4PlayerControlAssignment::ResolveRefs().

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

◆ GetAssignmentByIndex()

C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByIndex ( int32_t  index)

Definition at line 602 of file C4PlayerControl.cpp.

603 {
604  if (index<0 || index>=int32_t(Assignments.size())) return nullptr;
605  return &Assignments[index];
606 }

◆ GetAssignmentsByKey()

void C4PlayerControlAssignmentSet::GetAssignmentsByKey ( const C4PlayerControlDefs rDefs,
const C4KeyCodeEx key,
bool  fHoldKeysOnly,
C4PlayerControlAssignmentPVec pOutVec,
const C4PlayerControlRecentKeyList DownKeys,
const C4PlayerControlRecentKeyList RecentKeys 
) const

Definition at line 635 of file C4PlayerControl.cpp.

636 {
637  assert(pOutVec);
638  // primary match by TriggerKey (todo: Might use a hash map here if matching speed becomes an issue due to large control sets)
639  for (const auto & rAssignment : Assignments)
640  {
641  const C4KeyCodeEx &rAssignmentTriggerKey = rAssignment.GetTriggerKey();
642  if (!(rAssignmentTriggerKey.Key == key.Key)) continue;
643  // special: hold-keys-only ignore shift, because shift state might have been release during hold
644  if (!fHoldKeysOnly) if (rAssignmentTriggerKey.dwShift != key.dwShift) continue;
645  // check linked control def
646  const C4PlayerControlDef *pCtrl = rDefs.GetControlByIndex(rAssignment.GetControl());
647  if (!pCtrl) continue;
648  // only want hold keys?
649  if (fHoldKeysOnly)
650  {
651  // a hold/release-trigger key is not a real hold key, even if the underlying control is
652  if (!pCtrl->IsHoldKey() || (rAssignment.GetTriggerMode() & (C4PlayerControlAssignment::CTM_Hold | C4PlayerControlAssignment::CTM_Release))) continue;
653  }
654  else if (rAssignment.HasCombo())
655  {
656  // hold-only events match the trigger key only (i.e., Release-events are generated as soon as the trigger key goes up)
657  // other events must match either the sequence or the down-key-combination
658  if (!rAssignment.IsComboMatched(DownKeys, RecentKeys)) continue;
659  }
660  // we got match! Store it
661  pOutVec->push_back(&rAssignment);
662  }
663 }
bool IsHoldKey() const
const C4PlayerControlDef * GetControlByIndex(int32_t idx) const
C4KeyCode Key

References C4PlayerControlAssignment::CTM_Hold, C4PlayerControlAssignment::CTM_Release, C4KeyCodeEx::dwShift, C4PlayerControlDefs::GetControlByIndex(), C4PlayerControlDef::IsHoldKey(), and C4KeyCodeEx::Key.

Here is the call graph for this function:

◆ GetGUIName()

const char* C4PlayerControlAssignmentSet::GetGUIName ( ) const
inline

Definition at line 257 of file C4PlayerControl.h.

257 { return sGUIName.getData(); }
const char * getData() const
Definition: StdBuf.h:442

References StdStrBuf::getData().

Here is the call graph for this function:

◆ GetLayoutOrder()

int32_t C4PlayerControlAssignmentSet::GetLayoutOrder ( ) const
inline

Definition at line 273 of file C4PlayerControl.h.

273 { return 0; } // returns position on keyboard (increasing from left to right) for viewport sorting

Referenced by C4ViewportList::SortViewportsByPlayerControl().

Here is the caller graph for this function:

◆ GetName()

const char* C4PlayerControlAssignmentSet::GetName ( ) const
inline

Definition at line 256 of file C4PlayerControl.h.

256 { return sName.getData(); }

References StdStrBuf::getData().

Referenced by C4ControlPlayerAction::InitPlayerControl(), C4StartupPlrPropertiesDlg::OnCtrlChangeLeft(), C4StartupPlrPropertiesDlg::OnCtrlChangeRight(), and C4PlayerControlAssignment::ResolveRefs().

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

◆ GetPicture()

C4Facet C4PlayerControlAssignmentSet::GetPicture ( ) const

Definition at line 692 of file C4PlayerControl.cpp.

693 {
694  // get image to be drawn to represent this control set
695  // picture per set not implemented yet. So just default to out standard images
697 // if (HasMouse()) return ::GraphicsResource.fctMouse; // might be useful again with changing control sets
699  return C4Facet();
700 }
C4Game Game
Definition: C4Globals.cpp:52
C4GraphicsResource GraphicsResource
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
Definition: C4Facet.cpp:59
C4PlayerControlAssignmentSets PlayerControlUserAssignmentSets
Definition: C4Game.h:93
int32_t GetSetIndex(const C4PlayerControlAssignmentSet *set) const

References C4GraphicsResource::fctGamepad, C4GraphicsResource::fctKeyboard, Game, C4Facet::GetPhase(), C4PlayerControlAssignmentSets::GetSetIndex(), GraphicsResource, HasGamepad(), HasKeyboard(), and C4Game::PlayerControlUserAssignmentSets.

Here is the call graph for this function:

◆ GetTriggerKeys()

void C4PlayerControlAssignmentSet::GetTriggerKeys ( const C4PlayerControlDefs rDefs,
C4KeyCodeExVec pRegularKeys,
C4KeyCodeExVec pHoldKeys 
) const

Definition at line 665 of file C4PlayerControl.cpp.

666 {
667  // put all trigger keys of keyset into output vectors
668  // first all hold keys
669  for (const auto & rAssignment : Assignments)
670  {
671  const C4PlayerControlDef *pDef = rDefs.GetControlByIndex(rAssignment.GetControl());
672  if (pDef && pDef->IsHoldKey())
673  {
674  const C4KeyCodeEx &rKey = rAssignment.GetTriggerKey();
675  if (std::find(pHoldKeys->begin(), pHoldKeys->end(), rKey) == pHoldKeys->end()) pHoldKeys->push_back(rKey);
676  }
677  }
678  // then all regular keys that aren't in the hold keys list yet
679  for (const auto & rAssignment : Assignments)
680  {
681  const C4PlayerControlDef *pDef = rDefs.GetControlByIndex(rAssignment.GetControl());
682  if (pDef && !pDef->IsHoldKey())
683  {
684  const C4KeyCodeEx &rKey = rAssignment.GetTriggerKey();
685  if (std::find(pHoldKeys->begin(), pHoldKeys->end(), rKey) == pHoldKeys->end())
686  if (std::find(pRegularKeys->begin(), pRegularKeys->end(), rKey) == pRegularKeys->end())
687  pRegularKeys->push_back(rKey);
688  }
689  }
690 }

References C4PlayerControlDefs::GetControlByIndex(), and C4PlayerControlDef::IsHoldKey().

Referenced by C4PlayerControl::RegisterKeyset().

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

◆ HasGamepad()

bool C4PlayerControlAssignmentSet::HasGamepad ( ) const
inline

Definition at line 272 of file C4PlayerControl.h.

272 { return has_gamepad; }

Referenced by C4Player::Execute(), GetPicture(), C4Player::InitControl(), C4ControlPlayerAction::InitPlayerControl(), and C4StartupPlrPropertiesDlg::UserClose().

Here is the caller graph for this function:

◆ HasKeyboard()

bool C4PlayerControlAssignmentSet::HasKeyboard ( ) const
inline

Definition at line 270 of file C4PlayerControl.h.

270 { return has_keyboard; }

Referenced by GetPicture(), and C4ControlPlayerAction::InitPlayerControl().

Here is the caller graph for this function:

◆ HasMouse()

bool C4PlayerControlAssignmentSet::HasMouse ( ) const
inline

Definition at line 271 of file C4PlayerControl.h.

271 { return has_mouse; }

Referenced by C4Player::InitControl(), and C4ControlPlayerAction::InitPlayerControl().

Here is the caller graph for this function:

◆ InitEmptyFromTemplate()

void C4PlayerControlAssignmentSet::InitEmptyFromTemplate ( const C4PlayerControlAssignmentSet template_set)

Definition at line 479 of file C4PlayerControl.cpp.

480 {
481  // copy all fields except assignments
482  sName.Copy(template_set.sName);
483  sGUIName.Copy(template_set.sGUIName);
484  sParentSetName.Copy(template_set.sParentSetName);
485  has_keyboard = template_set.has_keyboard;
486  has_mouse = template_set.has_mouse;
487  has_gamepad = template_set.has_gamepad;
488 }
void Copy()
Definition: StdBuf.h:467

References StdStrBuf::Copy().

Here is the call graph for this function:

◆ IsMouseControlAssigned()

bool C4PlayerControlAssignmentSet::IsMouseControlAssigned ( int32_t  mouseevent) const

Definition at line 702 of file C4PlayerControl.cpp.

703 {
704  // TODO
705  return true;
706 }

Referenced by C4MouseControl::DoMoveInput(), and C4MouseControl::Move().

Here is the caller graph for this function:

◆ IsWildcardName()

bool C4PlayerControlAssignmentSet::IsWildcardName ( ) const
inline

Definition at line 258 of file C4PlayerControl.h.

258 { return IsWildcardString(sName.getData()); }
bool IsWildcardString(const char *szString)
Definition: StdFile.cpp:363

References StdStrBuf::getData(), and IsWildcardString().

Here is the call graph for this function:

◆ MergeFrom()

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

Definition at line 505 of file C4PlayerControl.cpp.

506 {
507  // take over all assignments defined in Src
508  for (const auto & SrcAssignment : Src.Assignments)
509  {
510  bool fIsReleaseKey = !!(SrcAssignment.GetTriggerMode() & C4PlayerControlAssignment::CTM_Release);
511  // overwrite same def and release key state
512  if (merge_mode != MM_LowPrio && SrcAssignment.IsOverrideAssignments())
513  {
514  // high priority override control clears all previous (very inefficient method...might as well recreate the whole list)
515  bool any_remaining = true;
516  while (any_remaining)
517  {
518  any_remaining = false;
519  for (C4PlayerControlAssignmentVec::iterator j = Assignments.begin(); j != Assignments.end(); ++j)
520  if (SEqual((*j).GetControlName(), SrcAssignment.GetControlName()))
521  {
522  bool fSelfIsReleaseKey = !!((*j).GetTriggerMode() & C4PlayerControlAssignment::CTM_Release);
523  if (fSelfIsReleaseKey == fIsReleaseKey)
524  {
525  Assignments.erase(j);
526  any_remaining = true;
527  break;
528  }
529  }
530  }
531  }
532  else if (merge_mode == MM_LowPrio || merge_mode == MM_ConfigOverload)
533  {
534  // if this is low priority, another override control kills this
535  bool any_override = false;
536  for (auto & Assignment : Assignments)
537  if (SEqual(Assignment.GetControlName(), SrcAssignment.GetControlName()))
538  {
539  bool fSelfIsReleaseKey = !!(Assignment.GetTriggerMode() & C4PlayerControlAssignment::CTM_Release);
540  if (fSelfIsReleaseKey == fIsReleaseKey)
541  {
542  any_override = true;
543  // config overloads just change the key of the inherited assignment
544  if (merge_mode == MM_ConfigOverload)
545  {
546  Assignment.CopyKeyFrom(SrcAssignment);
547  Assignment.SetInherited(false);
548  }
549  break;
550  }
551  }
552  if (any_override) continue;
553  }
554  // new def: Append a copy
555  Assignments.push_back(SrcAssignment);
556  // inherited marker
557  if (merge_mode == MM_Inherit)
558  {
559  Assignments.back().SetInherited(true);
560  Assignments.back().SetInheritedAssignment(&SrcAssignment);
561  }
562  }
563 }

References C4PlayerControlAssignment::CTM_Release, MM_ConfigOverload, MM_Inherit, MM_LowPrio, and SEqual().

Referenced by C4PlayerControlAssignmentSets::MergeFrom().

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

◆ operator==()

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

Definition at line 629 of file C4PlayerControl.cpp.

630 {
631  return Assignments == cmp.Assignments
632  && sName == cmp.sName;
633 }

◆ RemoveAssignmentByControlName()

void C4PlayerControlAssignmentSet::RemoveAssignmentByControlName ( const char *  control_name)

Definition at line 572 of file C4PlayerControl.cpp.

573 {
574  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
575  if (SEqual((*i).GetControlName(), control_name))
576  {
577  Assignments.erase(i);
578  return;
579  }
580 }

References SEqual().

Here is the call graph for this function:

◆ ResolveRefs()

bool C4PlayerControlAssignmentSet::ResolveRefs ( C4PlayerControlDefs pControlDefs)

Definition at line 582 of file C4PlayerControl.cpp.

583 {
584  // reset all resolved flags to allow re-resolve after overloads
585  for (auto & Assignment : Assignments)
586  Assignment.ResetRefsResolved();
587  // resolve in order; ignore already resolved because they might have been resolved by cross reference
588  for (auto & Assignment : Assignments)
589  if (!Assignment.IsRefsResolved())
590  if (!Assignment.ResolveRefs(this, pDefs))
591  return false;
592  return true;
593 }

◆ SortAssignments()

void C4PlayerControlAssignmentSet::SortAssignments ( )

Definition at line 595 of file C4PlayerControl.cpp.

596 {
597  // final init: sort assignments by priority
598  // note this screws up sorting for config dialog
599  std::sort(Assignments.begin(), Assignments.end());
600 }

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