- transitioned the local input handler.

There wasn't anything EDuke32-specific in there - nearly everything mapped perfectly to JFDuke.
This commit is contained in:
Christoph Oelckers 2020-07-15 19:48:04 +02:00
parent a0cd407632
commit ea6c74d0e6
15 changed files with 244 additions and 190 deletions

View file

@ -155,6 +155,7 @@ const char *KeyNames[NUM_KEYS] =
FKeyBindings Bindings;
FKeyBindings DoubleBindings;
FKeyBindings AutomapBindings;
FKeyBindings ShiftBindings;
static unsigned int DClickTime[NUM_KEYS];
static FixedBitArray<NUM_KEYS> DClicked;

View file

@ -87,7 +87,7 @@ public:
extern FKeyBindings Bindings;
extern FKeyBindings DoubleBindings;
extern FKeyBindings AutomapBindings;
extern FKeyBindings MenuBindings;
extern FKeyBindings ShiftBindings;
bool C_DoKey (event_t *ev, FKeyBindings *binds, FKeyBindings *doublebinds);

View file

@ -277,6 +277,8 @@ void FKeyboard::PostKeyEvent(int key, INTBOOL down, bool foreground)
}
ev.data1 = key;
ev.data2 = Convert[key];
ev.data3 = 0;
if (CheckKey(DIK_LSHIFT) || CheckKey(DIK_RSHIFT)) ev.data3 |= 1;
D_PostEvent(&ev);
}

View file

@ -49,15 +49,16 @@
bool G_Responder (event_t *ev)
{
FKeyBindings* binds = &Bindings;
switch (ev->type)
{
case EV_KeyDown:
if (C_DoKey (ev, &Bindings, &DoubleBindings))
if (C_DoKey (ev, binds, &DoubleBindings))
return true;
break;
case EV_KeyUp:
C_DoKey (ev, &Bindings, &DoubleBindings);
C_DoKey (ev, binds, &DoubleBindings);
break;
#if 0

View file

@ -1101,7 +1101,7 @@ bool CheckCheatmode(bool printmsg)
void updatePauseStatus()
{
bool GUICapture = System_WantGuiCapture();
if (M_Active() || GUICapture)
if ( GUICapture)
{
paused = 1;
}

View file

@ -178,13 +178,6 @@ CUSTOM_CVARD(Int, hud_size, 9, CVAR_ARCHIVE | CVAR_NOINITCALL, "Defines the HUD
}
}
CUSTOM_CVARD(Int, hud_scale, 100, CVAR_ARCHIVE | CVAR_NOINITCALL, "changes the hud scale")
{
if (self < 35) self = 35;
else if (self > 100) self = 100;
else gi->set_hud_scale(self);
}
// This is to allow flattening the overly complicated HUD configuration to one single value and keep the complexity safely inside the HUD code.
bool G_ChangeHudLayout(int direction)
{
@ -211,6 +204,37 @@ bool G_ChangeHudLayout(int direction)
return false;
}
CCMD(sizeup)
{
if (G_ChangeHudLayout(1)) gi->PlayHudSound();
}
CCMD(sizedown)
{
if (G_ChangeHudLayout(-1)) gi->PlayHudSound();
}
CUSTOM_CVARD(Int, hud_scale, 100, CVAR_ARCHIVE | CVAR_NOINITCALL, "changes the hud scale")
{
if (self < 36) self = 36;
else if (self > 100) self = 100;
else gi->set_hud_scale(self);
}
CCMD(scaleup)
{
int oldscale = hud_scale;
hud_scale = hud_scale + 4;
if (hud_scale != oldscale) gi->PlayHudSound();
}
CCMD(scaledown)
{
int oldscale = hud_scale;
hud_scale = hud_scale - 4;
if (hud_scale != oldscale) gi->PlayHudSound();
}
int hud_statusbarrange; // will be set by the game's configuration setup.
CUSTOM_CVARD(Int, hud_custom, 0, CVAR_ARCHIVE|CVAR_NOINITCALL, "change the custom hud") // this has no backing implementation, it seems to be solely for scripted HUDs.
{

View file

@ -58,6 +58,8 @@ struct GameInterface
virtual bool validate_hud(int) { return true; }
virtual void set_hud_layout(int size) = 0;
virtual void set_hud_scale(int size) {}
virtual bool automapActive() { return false; }
virtual void PlayHudSound() {}
virtual FString statFPS() { return "FPS display not available"; }
virtual GameStats getStats() { return {}; }
virtual void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) {}

View file

@ -43,6 +43,8 @@ struct GameInterface : ::GameInterface
bool validate_hud(int) override;
void set_hud_layout(int size) override;
void set_hud_scale(int size) override;
void PlayHudSound() override;
bool automapActive() override;
FString statFPS() override;
GameStats getStats() override;
void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override;

View file

@ -229,5 +229,6 @@ void newgame(MapRecord* mi, int sk);
void startnewgame(MapRecord* map, int skill);
void setlocalplayerinput(player_struct *pp);
void PlayerColorChanged(void);
void nonsharedkeys(void);
END_DUKE_NS

View file

@ -51,7 +51,6 @@ extern int32_t tempwallptr;
void G_BackToMenu(void);
void G_HandleLocalKeys(void);
void G_UpdatePlayerFromMenu(void);

View file

@ -915,6 +915,11 @@ void setupbackdrop()
}
}
bool GameInterface::automapActive()
{
return ud.overhead_on != 0;
}
END_DUKE_NS

View file

@ -39,6 +39,193 @@ source as it is released.
BEGIN_DUKE_NS
//---------------------------------------------------------------------------
//
// handles UI side input not handled via CCMDs or CVARs.
// Most of what's in here needs to be offloaded to CCMDs
//
//---------------------------------------------------------------------------
void nonsharedkeys(void)
{
static int nonsharedtimer;
short i, ch, weapon;
int j;
if (ud.recstat == 2)
{
ControlInfo noshareinfo;
CONTROL_GetInput(&noshareinfo);
}
if (System_WantGuiCapture())
return;
if (!ALT_IS_PRESSED && ud.overhead_on == 0)
{
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))
{
buttonMap.ClearButton(gamefunc_Enlarge_Screen);
if (!SHIFTS_IS_PRESSED)
{
if (G_ChangeHudLayout(1))
{
S_PlaySound(isRR() ? 341 : THUD, CHAN_AUTO, CHANF_UI);
}
}
else
{
hud_scale = hud_scale + 4;
}
}
if (buttonMap.ButtonDown(gamefunc_Shrink_Screen))
{
buttonMap.ClearButton(gamefunc_Shrink_Screen);
if (!SHIFTS_IS_PRESSED)
{
if (G_ChangeHudLayout(-1))
{
S_PlaySound(isRR() ? 341 : THUD, CHAN_AUTO, CHANF_UI);
}
}
else
{
hud_scale = hud_scale - 4;
}
}
}
if (buttonMap.ButtonDown(gamefunc_See_Coop_View) && (ud.coop || ud.recstat == 2))
{
buttonMap.ClearButton(gamefunc_See_Coop_View);
screenpeek = connectpoint2[screenpeek];
if (screenpeek == -1) screenpeek = 0;
}
if ((ud.multimode > 1) && buttonMap.ButtonDown(gamefunc_Show_Opponents_Weapon))
{
buttonMap.ClearButton(gamefunc_Show_Opponents_Weapon);
ud.showweapons = 1 - ud.showweapons;
cl_showweapon = ud.showweapons;
FTA(QUOTE_WEAPON_MODE_OFF - ud.showweapons, &ps[screenpeek]);
}
if (buttonMap.ButtonDown(gamefunc_Toggle_Crosshair))
{
buttonMap.ClearButton(gamefunc_Toggle_Crosshair);
cl_crosshair = !cl_crosshair;
FTA(QUOTE_CROSSHAIR_OFF - cl_crosshair, &ps[screenpeek]);
}
if (ud.overhead_on && buttonMap.ButtonDown(gamefunc_Map_Follow_Mode))
{
buttonMap.ClearButton(gamefunc_Map_Follow_Mode);
ud.scrollmode = 1 - ud.scrollmode;
if (ud.scrollmode)
{
ud.folx = ps[screenpeek].oposx;
ud.foly = ps[screenpeek].oposy;
ud.fola = ps[screenpeek].getoang();
}
FTA(QUOTE_MAP_FOLLOW_OFF + ud.scrollmode, &ps[myconnectindex]);
}
// Fixme: This really should be done via CCMD, not via hard coded key checks - but that needs alternative Shift and Alt bindings.
if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED)
{
int taunt = 0;
// NOTE: sc_F1 .. sc_F10 are contiguous. sc_F11 is not sc_F10+1.
for (int j = sc_F1; j <= sc_F10; j++)
if (inputState.UnboundKeyPressed(j))
{
inputState.ClearKeyStatus(j);
taunt = j - sc_F1 + 1;
break;
}
if (taunt)
{
if (SHIFTS_IS_PRESSED)
{
Printf(PRINT_NOTIFY, *CombatMacros[taunt - 1]);
//Net_SendTaunt(taunt);
return;
}
if (startrts(taunt, 1))
{
//Net_SendRTS(taunt);
return;
}
}
}
if (!ALT_IS_PRESSED && !SHIFTS_IS_PRESSED)
{
if (buttonMap.ButtonDown(gamefunc_Third_Person_View))
{
buttonMap.ClearButton(gamefunc_Third_Person_View);
if (!isRRRA() || (!ps[myconnectindex].OnMotorcycle && !ps[myconnectindex].OnBoat))
{
if (ps[myconnectindex].over_shoulder_on)
ps[myconnectindex].over_shoulder_on = 0;
else
{
ps[myconnectindex].over_shoulder_on = 1;
cameradist = 0;
cameraclock = (int)totalclock;
}
FTA(QUOTE_VIEW_MODE_OFF + ps[myconnectindex].over_shoulder_on, &ps[myconnectindex]);
}
}
if (ud.overhead_on != 0)
{
int j = (int)totalclock - nonsharedtimer;
nonsharedtimer += j;
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))
ps[myconnectindex].zoom += mulscale6(j, max(ps[myconnectindex].zoom, 256));
if (buttonMap.ButtonDown(gamefunc_Shrink_Screen))
ps[myconnectindex].zoom -= mulscale6(j, max(ps[myconnectindex].zoom, 256));
ps[myconnectindex].zoom = clamp(ps[myconnectindex].zoom, 48, 2048);
}
}
#if 0 // ESC is blocked by the menu, this function is not particularly useful anyway.
if (inputState.GetKeyStatus(sc_Escape) && ud.overhead_on && ps[myconnectindex].newowner == -1)
{
inputState.ClearKeyStatus(sc_Escape);
ud.last_overhead = ud.overhead_on;
ud.overhead_on = 0;
ud.scrollmode = 0;
}
#endif
if (buttonMap.ButtonDown(gamefunc_Map))
{
buttonMap.ClearButton(gamefunc_Map);
if (ud.last_overhead != ud.overhead_on && ud.last_overhead)
{
ud.overhead_on = ud.last_overhead;
ud.last_overhead = 0;
}
else
{
ud.overhead_on++;
if (ud.overhead_on == 3) ud.overhead_on = 0;
ud.last_overhead = ud.overhead_on;
}
}
}
//---------------------------------------------------------------------------
//
// handles all HUD related input, i.e. inventory item selection and activation plus weapon selection.

View file

@ -346,6 +346,11 @@ void GameInterface::set_hud_layout(int layout)
}
}
void GameInterface::PlayHudSound()
{
S_PlaySound(isRR() ? 341 : THUD, CHAN_AUTO, CHANF_UI);
}
void GameInterface::set_hud_scale(int scale)
{
ud.statusbarscale = clamp(scale, 36, 100);

View file

@ -67,7 +67,7 @@ struct user_defs
int m_respawn_items, m_respawn_monsters, m_respawn_inventory, m_recstat, m_monsters_off, detail;
int m_ffire, ffire, m_player_skill, multimode;
int player_skill, m_marker, marker, mouseflip;
int statusbarmode, althud, ShowOpponentWeapons;
int statusbarmode, althud;
MapRecord* nextLevel;
};

View file

@ -72,7 +72,6 @@ int32_t g_Shareware = 0;
int32_t tempwallptr;
int32_t actor_tog;
static int32_t nonsharedtimer;
weaponhit hittype[MAXSPRITES];
ActorInfo actorinfo[MAXTILES];
player_struct ps[MAXPLAYERS];
@ -102,179 +101,6 @@ void G_InitTimer(int32_t ticspersec)
void G_HandleLocalKeys(void)
{
// CONTROL_ProcessBinds();
if (ud.recstat == 2)
{
ControlInfo noshareinfo;
CONTROL_GetInput(&noshareinfo);
}
if (!ALT_IS_PRESSED && ud.overhead_on == 0 && (ps[myconnectindex].gm & MODE_TYPE) == 0)
{
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))
{
buttonMap.ClearButton(gamefunc_Enlarge_Screen);
if (!SHIFTS_IS_PRESSED)
{
if (G_ChangeHudLayout(1))
{
S_PlaySound(isRR() ? 341 : THUD, CHAN_AUTO, CHANF_UI);
}
}
else
{
hud_scale = hud_scale + 4;
}
}
if (buttonMap.ButtonDown(gamefunc_Shrink_Screen))
{
buttonMap.ClearButton(gamefunc_Shrink_Screen);
if (!SHIFTS_IS_PRESSED)
{
if (G_ChangeHudLayout(-1))
{
S_PlaySound(isRR() ? 341 : THUD, CHAN_AUTO, CHANF_UI);
}
}
else
{
hud_scale = hud_scale - 4;
}
}
}
if ((ps[myconnectindex].gm&(MODE_MENU|MODE_TYPE)) || System_WantGuiCapture())
return;
if (buttonMap.ButtonDown(gamefunc_See_Coop_View) && (ud.coop || ud.recstat == 2))
{
buttonMap.ClearButton(gamefunc_See_Coop_View);
screenpeek = connectpoint2[screenpeek];
if (screenpeek == -1) screenpeek = 0;
}
if ((ud.multimode > 1) && buttonMap.ButtonDown(gamefunc_Show_Opponents_Weapon))
{
buttonMap.ClearButton(gamefunc_Show_Opponents_Weapon);
ud.ShowOpponentWeapons = ud.showweapons = 1-ud.showweapons;
FTA(QUOTE_WEAPON_MODE_OFF-ud.showweapons,&ps[screenpeek]);
}
if (buttonMap.ButtonDown(gamefunc_Toggle_Crosshair))
{
buttonMap.ClearButton(gamefunc_Toggle_Crosshair);
cl_crosshair = !cl_crosshair;
FTA(QUOTE_CROSSHAIR_OFF-cl_crosshair,&ps[screenpeek]);
}
if (ud.overhead_on && buttonMap.ButtonDown(gamefunc_Map_Follow_Mode))
{
buttonMap.ClearButton(gamefunc_Map_Follow_Mode);
ud.scrollmode = 1-ud.scrollmode;
if (ud.scrollmode)
{
ud.folx = ps[screenpeek].oposx;
ud.foly = ps[screenpeek].oposy;
ud.fola = fix16_to_int(ps[screenpeek].oq16ang);
}
FTA(QUOTE_MAP_FOLLOW_OFF+ud.scrollmode,&ps[myconnectindex]);
}
if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED || WIN_IS_PRESSED)
{
int ridiculeNum = 0;
// NOTE: sc_F1 .. sc_F10 are contiguous. sc_F11 is not sc_F10+1.
for (bssize_t j=sc_F1; j<=sc_F10; j++)
if (inputState.UnboundKeyPressed(j))
{
inputState.ClearKeyStatus(j);
ridiculeNum = j - sc_F1 + 1;
break;
}
if (ridiculeNum)
{
if (SHIFTS_IS_PRESSED)
{
Printf(PRINT_NOTIFY, *CombatMacros[ridiculeNum-1]);
//Net_SendTaunt(ridiculeNum);
return;
}
// Not SHIFT -- that is, either some ALT or WIN.
if (startrts(ridiculeNum, 1))
{
//Net_SendRTS(ridiculeNum);
return;
}
}
}
else
{
if (buttonMap.ButtonDown(gamefunc_Third_Person_View))
{
buttonMap.ClearButton(gamefunc_Third_Person_View);
if (!isRRRA() || (!ps[myconnectindex].OnMotorcycle && !ps[myconnectindex].OnBoat))
{
ps[myconnectindex].over_shoulder_on = !ps[myconnectindex].over_shoulder_on;
cameradist = 0;
cameraclock = (int32_t) totalclock;
FTA(QUOTE_VIEW_MODE_OFF + ps[myconnectindex].over_shoulder_on, &ps[myconnectindex]);
}
}
if (ud.overhead_on != 0)
{
int const timerOffset = ((int) totalclock - nonsharedtimer);
nonsharedtimer += timerOffset;
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))
ps[myconnectindex].zoom += mulscale6(timerOffset, max<int>(ps[myconnectindex].zoom, 256));
if (buttonMap.ButtonDown(gamefunc_Shrink_Screen))
ps[myconnectindex].zoom -= mulscale6(timerOffset, max<int>(ps[myconnectindex].zoom, 256));
ps[myconnectindex].zoom = clamp(ps[myconnectindex].zoom, 48, 2048);
}
}
#if 0 // fixme: We should not query Esc here, this needs to be done differently
if (I_EscapeTrigger() && ud.overhead_on && ps[myconnectindex].newowner == -1)
{
I_EscapeTriggerClear();
ud.last_overhead = ud.overhead_on;
ud.overhead_on = 0;
ud.scrollmode = 0;
}
#endif
if (buttonMap.ButtonDown(gamefunc_Map))
{
buttonMap.ClearButton(gamefunc_Map);
if (ud.last_overhead != ud.overhead_on && ud.last_overhead)
{
ud.overhead_on = ud.last_overhead;
ud.last_overhead = 0;
}
else
{
ud.overhead_on++;
if (ud.overhead_on == 3) ud.overhead_on = 0;
ud.last_overhead = ud.overhead_on;
}
}
}
static int parsedefinitions_game(scriptfile *, int);
@ -430,7 +256,6 @@ int GameInterface::app_main()
checkcommandline();
ps[0].aim_mode = 1;
ud.ShowOpponentWeapons = 0;
ud.camerasprite = -1;
ud.camera_time = 0;//4;
@ -556,7 +381,7 @@ MAIN_LOOP_RESTART:
}
}
ud.showweapons = ud.ShowOpponentWeapons;
ud.showweapons = cl_showweapon;
setlocalplayerinput(&ps[myconnectindex]);
PlayerColorChanged();
inputState.ClearAllInput();
@ -572,7 +397,7 @@ MAIN_LOOP_RESTART:
//Net_GetPackets();
G_HandleLocalKeys();
nonsharedkeys();
C_RunDelayedCommands();