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 ()=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

Constructor & Destructor Documentation

C4PlayerControlAssignmentSet::C4PlayerControlAssignmentSet ( )
default
C4PlayerControlAssignmentSet::~C4PlayerControlAssignmentSet ( )
default

Member Function Documentation

void C4PlayerControlAssignmentSet::CompileFunc ( StdCompiler pComp)

Definition at line 492 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().

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

Here is the call graph for this function:

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

Definition at line 567 of file C4PlayerControl.cpp.

568 {
569  Assignments.emplace_back();
570  Assignments.back().SetControlName(control_name);
571  return &Assignments.back();
572 }
C4PlayerControlAssignment * C4PlayerControlAssignmentSet::GetAssignmentByControl ( int32_t  control)

Definition at line 620 of file C4PlayerControl.cpp.

References C4PlayerControlAssignment::CTM_Release.

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

Definition at line 610 of file C4PlayerControl.cpp.

References C4PlayerControlAssignment::CTM_Release, and SEqual().

Referenced by C4PlayerControlAssignment::ResolveRefs().

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

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

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

Definition at line 637 of file C4PlayerControl.cpp.

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

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

Here is the call graph for this function:

const char* C4PlayerControlAssignmentSet::GetGUIName ( ) const
inline

Definition at line 258 of file C4PlayerControl.h.

References StdStrBuf::getData().

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

Here is the call graph for this function:

int32_t C4PlayerControlAssignmentSet::GetLayoutOrder ( ) const
inline

Definition at line 274 of file C4PlayerControl.h.

Referenced by C4ViewportList::SortViewportsByPlayerControl().

274 { 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 257 of file C4PlayerControl.h.

References StdStrBuf::getData().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4Facet C4PlayerControlAssignmentSet::GetPicture ( ) const

Definition at line 694 of file C4PlayerControl.cpp.

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

Referenced by C4Viewport::DrawPlayerStartup().

695 {
696  // get image to be drawn to represent this control set
697  // picture per set not implemented yet. So just default to out standard images
699 // if (HasMouse()) return ::GraphicsResource.fctMouse; // might be useful again with changing control sets
701  return C4Facet();
702 }
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:93

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

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

Referenced by C4PlayerControl::RegisterKeyset().

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

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

273 { return has_gamepad; }

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::HasKeyboard ( ) const
inline

Definition at line 271 of file C4PlayerControl.h.

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

271 { return has_keyboard; }

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::HasMouse ( ) const
inline

Definition at line 272 of file C4PlayerControl.h.

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

272 { return has_mouse; }

Here is the caller graph for this function:

void C4PlayerControlAssignmentSet::InitEmptyFromTemplate ( const C4PlayerControlAssignmentSet template_set)

Definition at line 481 of file C4PlayerControl.cpp.

References StdStrBuf::Copy().

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

Here is the call graph for this function:

bool C4PlayerControlAssignmentSet::IsMouseControlAssigned ( int32_t  mouseevent) const

Definition at line 704 of file C4PlayerControl.cpp.

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

705 {
706  // TODO
707  return true;
708 }

Here is the caller graph for this function:

bool C4PlayerControlAssignmentSet::IsWildcardName ( ) const
inline

Definition at line 259 of file C4PlayerControl.h.

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

259 { return IsWildcardString(sName.getData()); }
const char * getData() const
Definition: StdBuf.h:442
bool IsWildcardString(const char *szString)
Definition: StdFile.cpp:366

Here is the call graph for this function:

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

Definition at line 507 of file C4PlayerControl.cpp.

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

Referenced by C4PlayerControlAssignmentSets::MergeFrom().

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

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

632 {
633  return Assignments == cmp.Assignments
634  && sName == cmp.sName;
635 }
void C4PlayerControlAssignmentSet::RemoveAssignmentByControlName ( const char *  control_name)

Definition at line 574 of file C4PlayerControl.cpp.

References SEqual().

575 {
576  for (C4PlayerControlAssignmentVec::iterator i = Assignments.begin(); i != Assignments.end(); ++i)
577  if (SEqual((*i).GetControlName(), control_name))
578  {
579  Assignments.erase(i);
580  return;
581  }
582 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

Here is the call graph for this function:

bool C4PlayerControlAssignmentSet::ResolveRefs ( C4PlayerControlDefs pControlDefs)

Definition at line 584 of file C4PlayerControl.cpp.

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

Definition at line 597 of file C4PlayerControl.cpp.

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

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