2012-06-03 16:11:22 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
|
|
|
|
|
|
|
This file is part of EDuke32.
|
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2012-06-03 16:11:22 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2019-10-25 22:32:49 +00:00
|
|
|
#include "gamecontrol.h"
|
2012-06-03 16:11:22 +00:00
|
|
|
#include "keyboard.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "joystick.h"
|
|
|
|
#include "control.h"
|
|
|
|
#include "input.h"
|
2019-10-28 06:00:31 +00:00
|
|
|
#include "inputstate.h"
|
2012-06-03 16:11:22 +00:00
|
|
|
|
2019-10-28 17:32:05 +00:00
|
|
|
char typebuf[TYPEBUFSIZE];
|
|
|
|
|
2019-09-21 20:53:00 +00:00
|
|
|
|
2019-12-01 09:31:44 +00:00
|
|
|
bool mouseInactiveConditional(bool condition)
|
|
|
|
{
|
|
|
|
return condition;
|
|
|
|
}
|
2019-09-21 20:53:00 +00:00
|
|
|
|
2012-06-03 16:11:22 +00:00
|
|
|
int32_t I_CheckAllInput(void)
|
|
|
|
{
|
2019-08-13 09:15:49 +00:00
|
|
|
return
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.keyBufferWaiting()
|
2019-11-04 00:01:54 +00:00
|
|
|
|| inputState.MouseGetButtons()
|
2019-10-28 17:32:05 +00:00
|
|
|
|| JOYSTICK_GetButtons();
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
void I_ClearAllInput(void)
|
|
|
|
{
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.keyFlushChars();
|
|
|
|
inputState.ClearKeysDown();
|
2019-11-04 00:01:54 +00:00
|
|
|
inputState.MouseClearAllButtonss();
|
2012-06-03 16:11:22 +00:00
|
|
|
JOYSTICK_ClearAllButtons();
|
2019-11-04 22:01:50 +00:00
|
|
|
buttonMap.ResetButtonStates();
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-16 00:20:52 +00:00
|
|
|
int32_t I_TextSubmit(void)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2019-08-13 09:15:49 +00:00
|
|
|
return
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.GetKeyStatus(sc_Enter)
|
|
|
|
|| inputState.GetKeyStatus(sc_kpad_Enter)
|
2019-12-01 09:31:44 +00:00
|
|
|
|| mouseInactiveConditional(inputState.MouseGetButtons()&LEFT_MOUSE)
|
2019-10-28 17:32:05 +00:00
|
|
|
|| (JOYSTICK_GetGameControllerButtons()&(1<<GAMECONTROLLER_BUTTON_A));
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2014-06-16 23:15:49 +00:00
|
|
|
|
2019-08-16 00:20:52 +00:00
|
|
|
void I_TextSubmitClear(void)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.keyFlushChars();
|
|
|
|
inputState.ClearKeyStatus(sc_kpad_Enter);
|
|
|
|
inputState.ClearKeyStatus(sc_Enter);
|
2019-11-04 00:01:54 +00:00
|
|
|
inputState.MouseClearButton(LEFT_MOUSE);
|
2019-08-14 16:11:55 +00:00
|
|
|
JOYSTICK_ClearGameControllerButton(1<<GAMECONTROLLER_BUTTON_A);
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2014-06-16 23:15:49 +00:00
|
|
|
|
2019-08-16 00:20:52 +00:00
|
|
|
int32_t I_AdvanceTrigger(void)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
I_TextSubmit()
|
2019-11-03 23:53:55 +00:00
|
|
|
|| inputState.GetKeyStatus(sc_Space);
|
2019-08-16 00:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void I_AdvanceTriggerClear(void)
|
|
|
|
{
|
|
|
|
I_TextSubmitClear();
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.ClearKeyStatus(sc_Space);
|
2019-08-16 00:20:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 23:15:49 +00:00
|
|
|
int32_t I_ReturnTrigger(void)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2019-08-13 09:15:49 +00:00
|
|
|
return
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.GetKeyStatus(sc_Escape)
|
2019-11-04 00:01:54 +00:00
|
|
|
|| (inputState.MouseGetButtons()&RIGHT_MOUSE)
|
2019-10-28 17:32:05 +00:00
|
|
|
|| (JOYSTICK_GetGameControllerButtons()&(1<<GAMECONTROLLER_BUTTON_B));
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2014-06-16 23:15:49 +00:00
|
|
|
|
|
|
|
void I_ReturnTriggerClear(void)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.keyFlushChars();
|
|
|
|
inputState.ClearKeyStatus(sc_Escape);
|
2019-11-04 00:01:54 +00:00
|
|
|
inputState.MouseClearButton(RIGHT_MOUSE);
|
2019-08-14 16:11:55 +00:00
|
|
|
JOYSTICK_ClearGameControllerButton(1<<GAMECONTROLLER_BUTTON_B);
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2014-06-16 23:15:49 +00:00
|
|
|
|
2019-08-07 19:12:07 +00:00
|
|
|
int32_t I_GeneralTrigger(void)
|
|
|
|
{
|
2019-08-13 09:15:49 +00:00
|
|
|
return
|
|
|
|
I_AdvanceTrigger()
|
|
|
|
|| I_ReturnTrigger()
|
2019-11-04 22:01:50 +00:00
|
|
|
|| buttonMap.ButtonDown(gamefunc_Open)
|
2019-12-01 09:31:44 +00:00
|
|
|
|| mouseInactiveConditional(buttonMap.ButtonDown(gamefunc_Fire))
|
2019-11-04 22:01:50 +00:00
|
|
|
|| buttonMap.ButtonDown(gamefunc_Crouch)
|
2019-10-28 17:32:05 +00:00
|
|
|
|| (JOYSTICK_GetGameControllerButtons()&(1<<GAMECONTROLLER_BUTTON_START));
|
2019-08-07 19:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void I_GeneralTriggerClear(void)
|
|
|
|
{
|
|
|
|
I_AdvanceTriggerClear();
|
|
|
|
I_ReturnTriggerClear();
|
2019-11-04 22:01:50 +00:00
|
|
|
buttonMap.ClearButton(gamefunc_Open);
|
|
|
|
buttonMap.ClearButton(gamefunc_Fire);
|
|
|
|
buttonMap.ClearButton(gamefunc_Crouch);
|
2019-08-13 09:15:49 +00:00
|
|
|
JOYSTICK_ClearGameControllerButton(1<<GAMECONTROLLER_BUTTON_START);
|
2019-08-07 19:12:07 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 23:15:49 +00:00
|
|
|
|
|
|
|
int32_t I_EscapeTrigger(void)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2019-08-13 09:15:49 +00:00
|
|
|
return
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.GetKeyStatus(sc_Escape)
|
2019-10-28 17:32:05 +00:00
|
|
|
|| (JOYSTICK_GetGameControllerButtons()&(1<<GAMECONTROLLER_BUTTON_START));
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2014-06-16 23:15:49 +00:00
|
|
|
|
|
|
|
void I_EscapeTriggerClear(void)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2019-11-03 23:53:55 +00:00
|
|
|
inputState.keyFlushChars();
|
|
|
|
inputState.ClearKeyStatus(sc_Escape);
|
2019-08-13 09:15:49 +00:00
|
|
|
JOYSTICK_ClearGameControllerButton(1<<GAMECONTROLLER_BUTTON_START);
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 23:15:49 +00:00
|
|
|
|
2014-05-31 12:26:41 +00:00
|
|
|
int32_t I_EnterText(char *t, int32_t maxlength, int32_t flags)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
|
|
|
char ch;
|
2019-10-28 17:32:05 +00:00
|
|
|
int32_t inputloc = strlen(typebuf);
|
2012-06-03 16:11:22 +00:00
|
|
|
|
2019-11-03 23:53:55 +00:00
|
|
|
while ((ch = inputState.keyGetChar()) != 0)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
|
|
|
if (ch == asc_BackSpace)
|
|
|
|
{
|
|
|
|
if (inputloc > 0)
|
|
|
|
{
|
|
|
|
inputloc--;
|
|
|
|
*(t+inputloc) = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ch == asc_Enter)
|
|
|
|
{
|
|
|
|
I_AdvanceTriggerClear();
|
2014-05-31 12:26:41 +00:00
|
|
|
return 1;
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
else if (ch == asc_Escape)
|
|
|
|
{
|
|
|
|
I_ReturnTriggerClear();
|
2014-05-31 12:26:41 +00:00
|
|
|
return -1;
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2014-05-31 12:26:41 +00:00
|
|
|
else if (ch >= 32 && inputloc < maxlength && ch < 127)
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2014-05-31 12:26:41 +00:00
|
|
|
if (!(flags & INPUT_NUMERIC) || (ch >= '0' && ch <= '9'))
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
|
|
|
// JBF 20040508: so we can have numeric only if we want
|
|
|
|
*(t+inputloc) = ch;
|
|
|
|
*(t+inputloc+1) = 0;
|
|
|
|
inputloc++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-16 00:20:52 +00:00
|
|
|
if (I_TextSubmit())
|
2019-08-14 03:04:04 +00:00
|
|
|
{
|
2019-08-16 00:20:52 +00:00
|
|
|
I_TextSubmitClear();
|
2019-08-14 03:04:04 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-05-31 12:26:41 +00:00
|
|
|
if (I_ReturnTrigger())
|
2012-06-03 16:11:22 +00:00
|
|
|
{
|
2014-05-31 12:26:41 +00:00
|
|
|
I_ReturnTriggerClear();
|
|
|
|
return -1;
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 12:26:41 +00:00
|
|
|
return 0;
|
2012-06-03 16:11:22 +00:00
|
|
|
}
|
2019-09-21 20:53:00 +00:00
|
|
|
|