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

#include <C4PlayerControl.h>

Public Types

enum  MergeMode { MM_Normal, MM_LowPrio, MM_Inherit, MM_ConfigOverload }
 

Public Member Functions

 C4PlayerControlAssignmentSet ()
 
 ~C4PlayerControlAssignmentSet ()
 
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 236 of file C4PlayerControl.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

C4PlayerControlAssignmentSet::C4PlayerControlAssignmentSet ( )
inline

Definition at line 248 of file C4PlayerControl.h.

248 : parent_set(nullptr), has_keyboard(true), has_mouse(true), has_gamepad(false) {}
C4PlayerControlAssignmentSet::~C4PlayerControlAssignmentSet ( )
inline

Definition at line 249 of file C4PlayerControl.h.

249 {}

Member Function Documentation

void C4PlayerControlAssignmentSet::CompileFunc ( StdCompiler pComp)

Definition at line 502 of file C4PlayerControl.cpp.

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

503 {
504  if (!pComp->Name("ControlSet")) { pComp->NameEnd(); pComp->excNotFound("ControlSet"); }
505  pComp->Value(mkNamingAdapt(mkParAdapt(sName, StdCompiler::RCT_All), "Name", "None")); // can't do RCT_Idtf because of wildcards
506  pComp->Value(mkNamingAdapt(mkParAdapt(sGUIName, StdCompiler::RCT_All), "GUIName", "undefined"));
507  pComp->Value(mkNamingAdapt(mkParAdapt(sParentSetName, StdCompiler::RCT_Idtf), "Parent", ""));
508  pComp->Value(mkNamingAdapt(has_keyboard, "Keyboard", true));
509  pComp->Value(mkNamingAdapt(has_mouse, "Mouse", true));
510  pComp->Value(mkNamingAdapt(has_gamepad, "Gamepad", false));
511  pComp->Value(mkSTLContainerAdapt(Assignments, StdCompiler::SEP_NONE));
512  pComp->NameEnd();
513 }
virtual bool Name(const char *szName)
Definition: StdCompiler.h:87
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void excNotFound(const char *szMessage,...)
Definition: StdCompiler.h:243
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:679
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:88

Here is the call graph for this function:

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

Definition at line 578 of file C4PlayerControl.cpp.

579 {
580  Assignments.push_back(C4PlayerControlAssignment());
581  Assignments.back().SetControlName(control_name);
582  return &Assignments.back();
583 }
C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByControl ( int32_t  control)

Definition at line 631 of file C4PlayerControl.cpp.

References C4PlayerControlAssignment::CTM_Release.

632 {
633  // TODO: Might want to stuff this into a vector indexed by control for faster lookup
634  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
635  if ((*i).GetControl() == control)
636  // We don't like release keys... (2do)
637  if (!((*i).GetTriggerMode() & C4PlayerControlAssignment::CTM_Release))
638  return &*i;
639  return nullptr;
640 }
C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByControlName ( const char *  szControlName)

Definition at line 621 of file C4PlayerControl.cpp.

References C4PlayerControlAssignment::CTM_Release, and SEqual().

Referenced by C4PlayerControlAssignment::ResolveRefs().

622 {
623  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
624  if (SEqual((*i).GetControlName(), szControlName))
625  // We don't like release keys... (2do)
626  if (!((*i).GetTriggerMode() & C4PlayerControlAssignment::CTM_Release))
627  return &*i;
628  return nullptr;
629 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97

Here is the call graph for this function:

Here is the caller graph for this function:

C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByIndex ( int32_t  index)

Definition at line 615 of file C4PlayerControl.cpp.

616 {
617  if (index<0 || index>=int32_t(Assignments.size())) return nullptr;
618  return &Assignments[index];
619 }
void C4PlayerControlAssignmentSet::GetAssignmentsByKey ( const C4PlayerControlDefs rDefs,
const C4KeyCodeEx key,
bool  fHoldKeysOnly,
C4PlayerControlAssignmentPVec pOutVec,
const C4PlayerControlRecentKeyList DownKeys,
const C4PlayerControlRecentKeyList RecentKeys 
) const

Definition at line 648 of file C4PlayerControl.cpp.

References C4PlayerControlAssignment::CTM_Hold, C4PlayerControlAssignment::CTM_Release, C4KeyCodeEx::dwShift, C4PlayerControlAssignment::GetControl(), C4PlayerControlDefs::GetControlByIndex(), C4PlayerControlAssignment::GetTriggerKey(), C4PlayerControlAssignment::GetTriggerMode(), C4PlayerControlAssignment::HasCombo(), C4PlayerControlAssignment::IsComboMatched(), C4PlayerControlDef::IsHoldKey(), and C4KeyCodeEx::Key.

649 {
650  assert(pOutVec);
651  // primary match by TriggerKey (todo: Might use a hash map here if matching speed becomes an issue due to large control sets)
652  for (C4PlayerControlAssignmentVec::const_iterator i = Assignments.begin(); i != Assignments.end(); ++i)
653  {
654  const C4PlayerControlAssignment &rAssignment = *i;
655  const C4KeyCodeEx &rAssignmentTriggerKey = rAssignment.GetTriggerKey();
656  if (!(rAssignmentTriggerKey.Key == key.Key)) continue;
657  // special: hold-keys-only ignore shift, because shift state might have been release during hold
658  if (!fHoldKeysOnly) if (rAssignmentTriggerKey.dwShift != key.dwShift) continue;
659  // check linked control def
660  const C4PlayerControlDef *pCtrl = rDefs.GetControlByIndex(rAssignment.GetControl());
661  if (!pCtrl) continue;
662  // only want hold keys?
663  if (fHoldKeysOnly)
664  {
665  // a hold/release-trigger key is not a real hold key, even if the underlying control is
667  }
668  else if (rAssignment.HasCombo())
669  {
670  // hold-only events match the trigger key only (i.e., Release-events are generated as soon as the trigger key goes up)
671  // other events must match either the sequence or the down-key-combination
672  if (!rAssignment.IsComboMatched(DownKeys, RecentKeys)) continue;
673  }
674  // we got match! Store it
675  pOutVec->push_back(&rAssignment);
676  }
677 }
const C4PlayerControlDef * GetControlByIndex(int32_t idx) const
const C4KeyCodeEx & GetTriggerKey() const
bool IsHoldKey() const
C4KeyCode Key
bool IsComboMatched(const C4PlayerControlRecentKeyList &DownKeys, const C4PlayerControlRecentKeyList &RecentKeys) const
int32_t GetTriggerMode() const
int32_t GetControl() const

Here is the call graph for this function:

const char* C4PlayerControlAssignmentSet::GetGUIName ( ) const
inline

Definition at line 263 of file C4PlayerControl.h.

References StdStrBuf::getData().

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

Here is the call graph for this function:

int32_t C4PlayerControlAssignmentSet::GetLayoutOrder ( ) const
inline

Definition at line 279 of file C4PlayerControl.h.

Referenced by C4ViewportList::SortViewportsByPlayerControl().

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

Here is the caller graph for this function:

const char* C4PlayerControlAssignmentSet::GetName ( ) const
inline

Definition at line 262 of file C4PlayerControl.h.

References StdStrBuf::getData().

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

262 { return sName.getData(); }
const char * getData() const
Definition: StdBuf.h:450

Here is the call graph for this function:

Here is the caller graph for this function:

C4Facet C4PlayerControlAssignmentSet::GetPicture ( ) const

Definition at line 708 of file C4PlayerControl.cpp.

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

Referenced by C4Viewport::DrawPlayerStartup().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 679 of file C4PlayerControl.cpp.

References C4PlayerControlAssignment::GetControl(), C4PlayerControlDefs::GetControlByIndex(), C4PlayerControlAssignment::GetTriggerKey(), and C4PlayerControlDef::IsHoldKey().

Referenced by C4PlayerControl::RegisterKeyset().

680 {
681  // put all trigger keys of keyset into output vectors
682  // first all hold keys
683  for (C4PlayerControlAssignmentVec::const_iterator i = Assignments.begin(); i != Assignments.end(); ++i)
684  {
685  const C4PlayerControlAssignment &rAssignment = *i;
686  const C4PlayerControlDef *pDef = rDefs.GetControlByIndex(rAssignment.GetControl());
687  if (pDef && pDef->IsHoldKey())
688  {
689  const C4KeyCodeEx &rKey = rAssignment.GetTriggerKey();
690  if (std::find(pHoldKeys->begin(), pHoldKeys->end(), rKey) == pHoldKeys->end()) pHoldKeys->push_back(rKey);
691  }
692  }
693  // then all regular keys that aren't in the hold keys list yet
694  for (C4PlayerControlAssignmentVec::const_iterator i = Assignments.begin(); i != Assignments.end(); ++i)
695  {
696  const C4PlayerControlAssignment &rAssignment = *i;
697  const C4PlayerControlDef *pDef = rDefs.GetControlByIndex(rAssignment.GetControl());
698  if (pDef && !pDef->IsHoldKey())
699  {
700  const C4KeyCodeEx &rKey = rAssignment.GetTriggerKey();
701  if (std::find(pHoldKeys->begin(), pHoldKeys->end(), rKey) == pHoldKeys->end())
702  if (std::find(pRegularKeys->begin(), pRegularKeys->end(), rKey) == pRegularKeys->end())
703  pRegularKeys->push_back(rKey);
704  }
705  }
706 }
const C4PlayerControlDef * GetControlByIndex(int32_t idx) const
const C4KeyCodeEx & GetTriggerKey() const
bool IsHoldKey() const
int32_t GetControl() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::HasGamepad ( ) const
inline

Definition at line 278 of file C4PlayerControl.h.

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

278 { return has_gamepad; }

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::HasKeyboard ( ) const
inline

Definition at line 276 of file C4PlayerControl.h.

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

276 { return has_keyboard; }

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::HasMouse ( ) const
inline

Definition at line 277 of file C4PlayerControl.h.

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

277 { return has_mouse; }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSet::InitEmptyFromTemplate ( const C4PlayerControlAssignmentSet template_set)

Definition at line 491 of file C4PlayerControl.cpp.

References StdStrBuf::Copy().

492 {
493  // copy all fields except assignments
494  sName.Copy(template_set.sName);
495  sGUIName.Copy(template_set.sGUIName);
496  sParentSetName.Copy(template_set.sParentSetName);
497  has_keyboard = template_set.has_keyboard;
498  has_mouse = template_set.has_mouse;
499  has_gamepad = template_set.has_gamepad;
500 }
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

bool C4PlayerControlAssignmentSet::IsMouseControlAssigned ( int32_t  mouseevent) const

Definition at line 718 of file C4PlayerControl.cpp.

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

719 {
720  // TODO
721  return true;
722 }

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::IsWildcardName ( ) const
inline

Definition at line 264 of file C4PlayerControl.h.

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

Referenced by C4PlayerControlAssignmentSets::MergeFrom().

264 { return IsWildcardString(sName.getData()); }
const char * getData() const
Definition: StdBuf.h:450
bool IsWildcardString(const char *szString)
Definition: StdFile.cpp:376

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 517 of file C4PlayerControl.cpp.

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

Referenced by C4PlayerControlAssignmentSets::MergeFrom().

518 {
519  // take over all assignments defined in Src
520  for (C4PlayerControlAssignmentVec::const_iterator i = Src.Assignments.begin(); i != Src.Assignments.end(); ++i)
521  {
522  const C4PlayerControlAssignment &SrcAssignment = *i;
523  bool fIsReleaseKey = !!(SrcAssignment.GetTriggerMode() & C4PlayerControlAssignment::CTM_Release);
524  // overwrite same def and release key state
525  if (merge_mode != MM_LowPrio && SrcAssignment.IsOverrideAssignments())
526  {
527  // high priority override control clears all previous (very inefficient method...might as well recreate the whole list)
528  bool any_remaining = true;
529  while (any_remaining)
530  {
531  any_remaining = false;
532  for (C4PlayerControlAssignmentVec::iterator j = Assignments.begin(); j != Assignments.end(); ++j)
533  if (SEqual((*j).GetControlName(), SrcAssignment.GetControlName()))
534  {
535  bool fSelfIsReleaseKey = !!((*j).GetTriggerMode() & C4PlayerControlAssignment::CTM_Release);
536  if (fSelfIsReleaseKey == fIsReleaseKey)
537  {
538  Assignments.erase(j);
539  any_remaining = true;
540  break;
541  }
542  }
543  }
544  }
545  else if (merge_mode == MM_LowPrio || merge_mode == MM_ConfigOverload)
546  {
547  // if this is low priority, another override control kills this
548  bool any_override = false;
549  for (C4PlayerControlAssignmentVec::iterator j = Assignments.begin(); j != Assignments.end(); ++j)
550  if (SEqual((*j).GetControlName(), SrcAssignment.GetControlName()))
551  {
552  bool fSelfIsReleaseKey = !!((*j).GetTriggerMode() & C4PlayerControlAssignment::CTM_Release);
553  if (fSelfIsReleaseKey == fIsReleaseKey)
554  {
555  any_override = true;
556  // config overloads just change the key of the inherited assignment
557  if (merge_mode == MM_ConfigOverload)
558  {
559  (*j).CopyKeyFrom(SrcAssignment);
560  (*j).SetInherited(false);
561  }
562  break;
563  }
564  }
565  if (any_override) continue;
566  }
567  // new def: Append a copy
568  Assignments.push_back(SrcAssignment);
569  // inherited marker
570  if (merge_mode == MM_Inherit)
571  {
572  Assignments.back().SetInherited(true);
573  Assignments.back().SetInheritedAssignment(&SrcAssignment);
574  }
575  }
576 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
const char * GetControlName() const
int32_t GetTriggerMode() const
bool IsOverrideAssignments() const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 642 of file C4PlayerControl.cpp.

643 {
644  return Assignments == cmp.Assignments
645  && sName == cmp.sName;
646 }
void C4PlayerControlAssignmentSet::RemoveAssignmentByControlName ( const char *  control_name)

Definition at line 585 of file C4PlayerControl.cpp.

References SEqual().

586 {
587  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
588  if (SEqual((*i).GetControlName(), control_name))
589  {
590  Assignments.erase(i);
591  return;
592  }
593 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97

Here is the call graph for this function:

bool C4PlayerControlAssignmentSet::ResolveRefs ( C4PlayerControlDefs pControlDefs)

Definition at line 595 of file C4PlayerControl.cpp.

596 {
597  // reset all resolved flags to allow re-resolve after overloads
598  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
599  (*i).ResetRefsResolved();
600  // resolve in order; ignore already resolved because they might have been resolved by cross reference
601  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
602  if (!(*i).IsRefsResolved())
603  if (!(*i).ResolveRefs(this, pDefs))
604  return false;
605  return true;
606 }
void C4PlayerControlAssignmentSet::SortAssignments ( )

Definition at line 608 of file C4PlayerControl.cpp.

609 {
610  // final init: sort assignments by priority
611  // note this screws up sorting for config dialog
612  std::sort(Assignments.begin(), Assignments.end());
613 }

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