forked from Mirrors/openclonk
implement DefaultDisabled for PlayerControls (#206)
parent
a776d99f68
commit
e8aaa703fc
|
@ -644,6 +644,17 @@ bool C4PlayerControl::CSync::SetControlDisabled(int32_t iControl, int32_t iVal)
|
|||
return true;
|
||||
}
|
||||
|
||||
void C4PlayerControl::CSync::InitDefaults(const C4PlayerControlDefs &ControlDefs)
|
||||
{
|
||||
const C4PlayerControlDef *def;
|
||||
int32_t i=0;
|
||||
while (def = ControlDefs.GetControlByIndex(i))
|
||||
{
|
||||
if (def->IsDefaultDisabled()) SetControlDisabled(i, true);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void C4PlayerControl::CSync::Clear()
|
||||
{
|
||||
ControlDownStates.clear();
|
||||
|
@ -662,10 +673,18 @@ bool C4PlayerControl::CSync::operator ==(const CSync &cmp) const
|
|||
&& ControlDisableStates == cmp.ControlDisableStates;
|
||||
}
|
||||
|
||||
void C4PlayerControl::Init()
|
||||
{
|
||||
// defaultdisabled controls
|
||||
Sync.InitDefaults(ControlDefs);
|
||||
}
|
||||
|
||||
void C4PlayerControl::CompileFunc(StdCompiler *pComp)
|
||||
{
|
||||
// compile sync values only
|
||||
pComp->Value(mkNamingAdapt(Sync, "PlayerControl", CSync()));
|
||||
CSync DefaultSync;
|
||||
DefaultSync.InitDefaults(ControlDefs);
|
||||
pComp->Value(mkNamingAdapt(Sync, "PlayerControl", DefaultSync));
|
||||
}
|
||||
|
||||
bool C4PlayerControl::ProcessKeyEvent(const C4KeyCodeEx &pressed_key, const C4KeyCodeEx &matched_key, bool fUp, const C4KeyEventData &rKeyExtraData)
|
||||
|
|
|
@ -66,6 +66,7 @@ class C4PlayerControlDef
|
|||
bool IsGlobal() const { return fGlobal; }
|
||||
int32_t GetRepeatDelay() const { return iRepeatDelay; }
|
||||
int32_t GetInitialRepeatDelay() const { return iInitialRepeatDelay; }
|
||||
bool IsDefaultDisabled() const { return fDefaultDisabled; }
|
||||
|
||||
//C4PlayerControlDef &operator =(const C4PlayerControlDef &src);
|
||||
bool operator ==(const C4PlayerControlDef &cmp) const;
|
||||
|
@ -314,6 +315,7 @@ class C4PlayerControl
|
|||
void SetControlDownState(int32_t iControl, const C4KeyEventData &rDownState, int32_t iDownFrame, bool fDownByUser);
|
||||
bool SetControlDisabled(int32_t iControl, int32_t iVal);
|
||||
|
||||
void InitDefaults(const C4PlayerControlDefs &ControlDefs);
|
||||
void Clear();
|
||||
void CompileFunc(StdCompiler *pComp);
|
||||
bool operator ==(const CSync &cmp) const;
|
||||
|
@ -340,6 +342,11 @@ class C4PlayerControl
|
|||
~C4PlayerControl() { Clear(); }
|
||||
void Clear();
|
||||
|
||||
// first-time init call after player join
|
||||
// not called again after control set change/savegame resume
|
||||
// does DefaultDisabled controls
|
||||
void Init();
|
||||
|
||||
void CompileFunc(StdCompiler *pComp);
|
||||
|
||||
void RegisterKeyset(int32_t iPlr, C4PlayerControlAssignmentSet *pKeyset); // register all keys into Game.KeyboardInput creating KeyBindings
|
||||
|
@ -361,6 +368,7 @@ class C4PlayerControl
|
|||
bool SetControlDisabled(int ctrl, bool is_disabled) { return Sync.SetControlDisabled(ctrl, is_disabled); }
|
||||
bool IsControlDisabled(int ctrl) const { return Sync.IsControlDisabled(ctrl); }
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -339,6 +339,9 @@ bool C4Player::Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientNa
|
|||
// Init control method before scenario init, because script callbacks may need to know it!
|
||||
InitControl();
|
||||
|
||||
// defaultdisabled controls
|
||||
Control.Init();
|
||||
|
||||
// Special: Script players may skip scenario initialization altogether, and just desire a single callback to all objects
|
||||
// of a given ID
|
||||
if (!pInfo->IsScenarioInitDesired())
|
||||
|
|
Loading…
Reference in New Issue