mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
Wii U: Use own virtual keyboard
This commit is contained in:
parent
9f2eeca117
commit
071c6f68d5
12 changed files with 108 additions and 240 deletions
|
@ -83,7 +83,7 @@ SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) \
|
||||
$(foreach dir,$(SHADERS),$(notdir $(wildcard $(dir)/*.gsh)))
|
||||
|
||||
export LD := $(CXX)
|
||||
export LD := $(CC)
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
|
36
src/Entity.c
36
src/Entity.c
|
@ -799,10 +799,6 @@ static void LocalPlayers_OnNewMap(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static struct LocalPlayer* LocalPlayer_Get(int deviceIndex) {
|
||||
return &LocalPlayer_Instances[Game_MapState(deviceIndex)];
|
||||
}
|
||||
|
||||
static cc_bool LocalPlayer_IsSolidCollide(BlockID b) { return Blocks.Collide[b] == COLLIDE_SOLID; }
|
||||
static void LocalPlayer_DoRespawn(struct LocalPlayer* p) {
|
||||
struct LocationUpdate update;
|
||||
|
@ -851,7 +847,7 @@ static void LocalPlayer_DoRespawn(struct LocalPlayer* p) {
|
|||
}
|
||||
|
||||
static cc_bool LocalPlayer_HandleRespawn(int key, struct InputDevice* device) {
|
||||
struct LocalPlayer* p = LocalPlayer_Get(device->index);
|
||||
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
|
||||
if (p->Hacks.CanRespawn) {
|
||||
LocalPlayer_DoRespawn(p);
|
||||
return true;
|
||||
|
@ -863,7 +859,7 @@ static cc_bool LocalPlayer_HandleRespawn(int key, struct InputDevice* device) {
|
|||
}
|
||||
|
||||
static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) {
|
||||
struct LocalPlayer* p = LocalPlayer_Get(device->index);
|
||||
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
|
||||
if (p->Hacks.CanRespawn) {
|
||||
|
||||
if (!p->Hacks.CanNoclip && !p->Base.OnGround) {
|
||||
|
@ -889,7 +885,7 @@ static cc_bool LocalPlayer_HandleSetSpawn(int key, struct InputDevice* device) {
|
|||
}
|
||||
|
||||
static cc_bool LocalPlayer_HandleFly(int key, struct InputDevice* device) {
|
||||
struct LocalPlayer* p = LocalPlayer_Get(device->index);
|
||||
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
|
||||
|
||||
if (p->Hacks.CanFly && p->Hacks.Enabled) {
|
||||
HacksComp_SetFlying(&p->Hacks, !p->Hacks.Flying);
|
||||
|
@ -902,7 +898,7 @@ static cc_bool LocalPlayer_HandleFly(int key, struct InputDevice* device) {
|
|||
}
|
||||
|
||||
static cc_bool LocalPlayer_HandleNoclip(int key, struct InputDevice* device) {
|
||||
struct LocalPlayer* p = LocalPlayer_Get(device->index);
|
||||
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
|
||||
p->Hacks._noclipping = true;
|
||||
|
||||
if (p->Hacks.CanNoclip && p->Hacks.Enabled) {
|
||||
|
@ -919,7 +915,7 @@ static cc_bool LocalPlayer_HandleNoclip(int key, struct InputDevice* device) {
|
|||
}
|
||||
|
||||
static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) {
|
||||
struct LocalPlayer* p = LocalPlayer_Get(device->index);
|
||||
struct LocalPlayer* p = &LocalPlayer_Instances[device->mappedIndex];
|
||||
struct HacksComp* hacks = &p->Hacks;
|
||||
struct PhysicsComp* physics = &p->Physics;
|
||||
int maxJumps;
|
||||
|
@ -939,7 +935,7 @@ static cc_bool LocalPlayer_HandleJump(int key, struct InputDevice* device) {
|
|||
|
||||
|
||||
static cc_bool LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks;
|
||||
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
|
||||
cc_bool touch = device->type == INPUT_DEVICE_TOUCH;
|
||||
|
||||
hacks->HalfSpeeding = (!touch || !hacks->HalfSpeeding) && hacks->Enabled;
|
||||
|
@ -947,7 +943,7 @@ static cc_bool LocalPlayer_TriggerHalfSpeed(int key, struct InputDevice* device)
|
|||
}
|
||||
|
||||
static cc_bool LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks;
|
||||
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
|
||||
cc_bool touch = device->type == INPUT_DEVICE_TOUCH;
|
||||
|
||||
hacks->Speeding = (!touch || !hacks->Speeding) && hacks->Enabled;
|
||||
|
@ -955,47 +951,47 @@ static cc_bool LocalPlayer_TriggerSpeed(int key, struct InputDevice* device) {
|
|||
}
|
||||
|
||||
static void LocalPlayer_ReleaseHalfSpeed(int key, struct InputDevice* device) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks;
|
||||
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
|
||||
if (device->type != INPUT_DEVICE_TOUCH) hacks->HalfSpeeding = false;
|
||||
}
|
||||
|
||||
static void LocalPlayer_ReleaseSpeed(int key, struct InputDevice* device) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks;
|
||||
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
|
||||
if (device->type != INPUT_DEVICE_TOUCH) hacks->Speeding = false;
|
||||
}
|
||||
|
||||
|
||||
static cc_bool LocalPlayer_TriggerFlyUp(int key, struct InputDevice* device) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks;
|
||||
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
|
||||
hacks->FlyingUp = true;
|
||||
return hacks->CanFly && hacks->Enabled;
|
||||
}
|
||||
|
||||
static cc_bool LocalPlayer_TriggerFlyDown(int key, struct InputDevice* device) {
|
||||
struct HacksComp* hacks = &LocalPlayer_Get(device->index)->Hacks;
|
||||
struct HacksComp* hacks = &LocalPlayer_Instances[device->mappedIndex].Hacks;
|
||||
hacks->FlyingDown = true;
|
||||
return hacks->CanFly && hacks->Enabled;
|
||||
}
|
||||
|
||||
static void LocalPlayer_ReleaseFlyUp(int key, struct InputDevice* device) {
|
||||
LocalPlayer_Get(device->index)->Hacks.FlyingUp = false;
|
||||
LocalPlayer_Instances[device->mappedIndex].Hacks.FlyingUp = false;
|
||||
}
|
||||
|
||||
static void LocalPlayer_ReleaseFlyDown(int key, struct InputDevice* device) {
|
||||
LocalPlayer_Get(device->index)->Hacks.FlyingDown = false;
|
||||
LocalPlayer_Instances[device->mappedIndex].Hacks.FlyingDown = false;
|
||||
}
|
||||
|
||||
|
||||
static cc_bool LocalPlayer_TriggerJump(int key, struct InputDevice* device) {
|
||||
LocalPlayer_Get(device->index)->Physics.Jumping = true;
|
||||
LocalPlayer_Instances[device->mappedIndex].Physics.Jumping = true;
|
||||
return true;
|
||||
}
|
||||
static void LocalPlayer_ReleaseJump(int key, struct InputDevice* device) {
|
||||
LocalPlayer_Get(device->index)->Physics.Jumping = false;
|
||||
LocalPlayer_Instances[device->mappedIndex].Physics.Jumping = false;
|
||||
}
|
||||
|
||||
static void LocalPlayer_ReleaseNoclip(int key, struct InputDevice* device) {
|
||||
LocalPlayer_Get(device->index)->Hacks._noclipping = false;
|
||||
LocalPlayer_Instances[device->mappedIndex].Hacks._noclipping = false;
|
||||
}
|
||||
|
||||
static void LocalPlayer_HookBinds(void) {
|
||||
|
|
|
@ -284,7 +284,7 @@ static cc_bool TouchDevice_IsPressed(struct InputDevice* device, int key) {
|
|||
}
|
||||
|
||||
struct InputDevice NormDevice = {
|
||||
INPUT_DEVICE_NORMAL, 0,
|
||||
INPUT_DEVICE_NORMAL, 0, 0,
|
||||
NormDevice_IsPressed,
|
||||
/* General buttons */
|
||||
CCKEY_UP, CCKEY_DOWN, CCKEY_LEFT, CCKEY_RIGHT,
|
||||
|
@ -298,7 +298,7 @@ struct InputDevice NormDevice = {
|
|||
"key-%c", KeyBind_Defaults, KeyBind_Mappings
|
||||
};
|
||||
static const struct InputDevice padDevice = {
|
||||
INPUT_DEVICE_GAMEPAD, 0,
|
||||
INPUT_DEVICE_GAMEPAD, 0, 0,
|
||||
PadDevice_IsPressed,
|
||||
/* General buttons */
|
||||
CCPAD_UP, CCPAD_DOWN, CCPAD_LEFT, CCPAD_RIGHT,
|
||||
|
@ -312,7 +312,7 @@ static const struct InputDevice padDevice = {
|
|||
"pad-%c", NULL, NULL
|
||||
};
|
||||
struct InputDevice TouchDevice = {
|
||||
INPUT_DEVICE_TOUCH, 0,
|
||||
INPUT_DEVICE_TOUCH, 0, 0,
|
||||
TouchDevice_IsPressed
|
||||
};
|
||||
|
||||
|
@ -523,6 +523,7 @@ struct GamepadDevice Gamepad_Devices[INPUT_MAX_GAMEPADS];
|
|||
|
||||
static void Gamepad_Apply(int port, int btn, cc_bool was, int pressed) {
|
||||
struct InputDevice* device = &Gamepad_Devices[port].base;
|
||||
device->mappedIndex = Game_MapState(device->rawIndex);
|
||||
|
||||
if (pressed) {
|
||||
Event_RaiseInput(&InputEvents.Down, btn + GAMEPAD_BEG_BTN, was, device);
|
||||
|
@ -588,7 +589,7 @@ int Gamepad_Connect(long deviceID, const struct BindMapping_* defaults) {
|
|||
if (Gamepad_Devices[i].deviceID != 0) continue;
|
||||
|
||||
Mem_Copy(&Gamepad_Devices[i].base, &padDevice, sizeof(struct InputDevice));
|
||||
Gamepad_Devices[i].base.index = i;
|
||||
Gamepad_Devices[i].base.rawIndex = i;
|
||||
Gamepad_Devices[i].base.currentBinds = padBind_Mappings[i];
|
||||
Gamepad_Devices[i].base.defaultBinds = defaults;
|
||||
Gamepad_Devices[i].deviceID = deviceID;
|
||||
|
|
|
@ -96,7 +96,9 @@ struct BindMapping_;
|
|||
typedef cc_bool (*InputDevice_IsPressed)(struct InputDevice* device, int key);
|
||||
|
||||
struct InputDevice {
|
||||
int type, index; /* Device type and index (e.g. controller port) */
|
||||
int type;
|
||||
int rawIndex; /* Device index (i.e virtual controller port number) */
|
||||
int mappedIndex; /* Device index after calling Game_MapState */
|
||||
InputDevice_IsPressed IsPressed;
|
||||
int upButton, downButton, leftButton, rightButton;
|
||||
int enterButton1, enterButton2;
|
||||
|
@ -202,7 +204,7 @@ void Gamepad_SetButton(int port, int btn, int pressed);
|
|||
void Gamepad_SetAxis(int port, int axis, float x, float y, float delta);
|
||||
void Gamepad_Tick(float delta);
|
||||
|
||||
#define INPUT_MAX_GAMEPADS 4
|
||||
#define INPUT_MAX_GAMEPADS 5
|
||||
#define GAMEPAD_BEG_BTN CCPAD_1
|
||||
#define GAMEPAD_BTN_COUNT (INPUT_COUNT - GAMEPAD_BEG_BTN)
|
||||
|
||||
|
|
|
@ -893,47 +893,40 @@ static void OnInputUp(void* obj, int key, cc_bool was, struct InputDevice* devic
|
|||
}
|
||||
}
|
||||
|
||||
static int moveFlags[INPUT_MAX_GAMEPADS];
|
||||
static int moveFlags[MAX_LOCAL_PLAYERS];
|
||||
|
||||
static cc_bool Player_TriggerLeft(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] |= FACE_BIT_XMIN;
|
||||
moveFlags[device->mappedIndex] |= FACE_BIT_XMIN;
|
||||
return Gui.InputGrab == NULL;
|
||||
}
|
||||
static cc_bool Player_TriggerRight(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] |= FACE_BIT_XMAX;
|
||||
moveFlags[device->mappedIndex] |= FACE_BIT_XMAX;
|
||||
return Gui.InputGrab == NULL;
|
||||
}
|
||||
static cc_bool Player_TriggerUp(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] |= FACE_BIT_YMIN;
|
||||
moveFlags[device->mappedIndex] |= FACE_BIT_YMIN;
|
||||
return Gui.InputGrab == NULL;
|
||||
}
|
||||
static cc_bool Player_TriggerDown(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] |= FACE_BIT_YMAX;
|
||||
moveFlags[device->mappedIndex] |= FACE_BIT_YMAX;
|
||||
return Gui.InputGrab == NULL;
|
||||
}
|
||||
|
||||
static void Player_ReleaseLeft(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] &= ~FACE_BIT_XMIN;
|
||||
moveFlags[device->mappedIndex] &= ~FACE_BIT_XMIN;
|
||||
}
|
||||
static void Player_ReleaseRight(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] &= ~FACE_BIT_XMAX;
|
||||
moveFlags[device->mappedIndex] &= ~FACE_BIT_XMAX;
|
||||
}
|
||||
static void Player_ReleaseUp(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] &= ~FACE_BIT_YMIN;
|
||||
moveFlags[device->mappedIndex] &= ~FACE_BIT_YMIN;
|
||||
}
|
||||
static void Player_ReleaseDown(int key, struct InputDevice* device) {
|
||||
moveFlags[device->index] &= ~FACE_BIT_YMAX;
|
||||
moveFlags[device->mappedIndex] &= ~FACE_BIT_YMAX;
|
||||
}
|
||||
|
||||
static void PlayerInputNormal(struct LocalPlayer* p, float* xMoving, float* zMoving) {
|
||||
int flags = 0, port;
|
||||
|
||||
if (Game_NumStates == 1) {
|
||||
for (port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
||||
flags |= moveFlags[port];
|
||||
} else {
|
||||
flags = moveFlags[p->index];
|
||||
}
|
||||
int flags = moveFlags[p->index];
|
||||
|
||||
if (flags & FACE_BIT_YMIN) *zMoving -= 1;
|
||||
if (flags & FACE_BIT_YMAX) *zMoving += 1;
|
||||
|
|
|
@ -181,18 +181,22 @@ static void VirtualKeyboard_CalcPosition(int* x, int* y, int width, int height)
|
|||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------Input handling------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void VirtualKeyboard_Scroll(int xDelta, int yDelta) {
|
||||
static void VirtualKeyboard_Clamp(void) {
|
||||
int perRow = kb->cellsPerRow, numRows = kb->numRows;
|
||||
if (kb_curX < 0) kb_curX = 0;
|
||||
|
||||
kb_curX += xDelta;
|
||||
if (kb_curX < 0) kb_curX += perRow;
|
||||
if (kb_curX >= perRow) kb_curX -= perRow;
|
||||
|
||||
kb_curY += yDelta;
|
||||
if (kb_curY < 0) kb_curY += numRows;
|
||||
if (kb_curY >= numRows) kb_curY -= numRows;
|
||||
}
|
||||
|
||||
static void VirtualKeyboard_Scroll(int xDelta, int yDelta) {
|
||||
if (kb_curX < 0) kb_curX = 0;
|
||||
|
||||
kb_curX += xDelta;
|
||||
kb_curY += yDelta;
|
||||
|
||||
VirtualKeyboard_Clamp();
|
||||
KB_MarkDirty();
|
||||
}
|
||||
|
||||
|
@ -279,6 +283,23 @@ static void VirtualKeyboard_PadAxis(void* obj, int port, int axis, float x, floa
|
|||
if (ySteps) VirtualKeyboard_Scroll(0, ySteps > 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
static void VirtualKeyboard_PointerDown(void* obj, int idx) {
|
||||
int width = VirtualKeyboard_Width();
|
||||
int height = VirtualKeyboard_Height();
|
||||
int kbX, kbY;
|
||||
VirtualKeyboard_CalcPosition(&kbX, &kbY, Window_Main.Width, Window_Main.Height);
|
||||
|
||||
int x = Pointers[idx].x, y = Pointers[idx].y;
|
||||
if (x < kbX || y < kbY || x >= kbX + width || y >= kbY + height) return;
|
||||
|
||||
kb_curX = (x - kbX) / KB_TILE_SIZE;
|
||||
kb_curY = (y - kbY) / KB_TILE_SIZE;
|
||||
if (kb_curX >= kb->cellsPerRow) kb_curX = kb->cellsPerRow - 1;
|
||||
|
||||
VirtualKeyboard_Clamp();
|
||||
VirtualKeyboard_ClickSelected();
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------2D mode----------------------------------------------------------*
|
||||
|
@ -358,7 +379,7 @@ static void VirtualKeyboard_Display3D(void) {
|
|||
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
||||
Gfx_BindTexture(kb_texture.ID);
|
||||
|
||||
struct VertexTextured* data = Gfx_LockDynamicVb(kb_vb, VERTEX_FORMAT_TEXTURED, 4);
|
||||
struct VertexTextured* data = (struct VertexTextured*)Gfx_LockDynamicVb(kb_vb, VERTEX_FORMAT_TEXTURED, 4);
|
||||
struct VertexTextured** ptr = &data;
|
||||
Gfx_Make2DQuad(&kb_texture, PACKEDCOL_WHITE, ptr);
|
||||
Gfx_UnlockDynamicVb(kb_vb);
|
||||
|
@ -373,6 +394,7 @@ static void VirtualKeyboard_Hook(void) {
|
|||
/* the virtual keyboard in the first place gets mistakenly processed */
|
||||
kb_needsHook = false;
|
||||
Event_Register_(&ControllerEvents.AxisUpdate, NULL, VirtualKeyboard_PadAxis);
|
||||
Event_Register_(&PointerEvents.Down, NULL, VirtualKeyboard_PointerDown);
|
||||
}
|
||||
|
||||
static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher) {
|
||||
|
@ -419,6 +441,7 @@ static void VirtualKeyboard_Close(void) {
|
|||
VirtualKeyboard_Close3D();
|
||||
|
||||
Event_Unregister_(&ControllerEvents.AxisUpdate, NULL, VirtualKeyboard_PadAxis);
|
||||
Event_Unregister_(&PointerEvents.Down, NULL, VirtualKeyboard_PointerDown);
|
||||
Window_Main.SoftKeyboardFocus = false;
|
||||
|
||||
KB_MarkDirty = NULL;
|
||||
|
|
|
@ -287,7 +287,7 @@ void Gamepads_Process(float delta) {
|
|||
maple_device_t* cont;
|
||||
cont_state_t* state;
|
||||
|
||||
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
cont = maple_enum_type(i, MAPLE_FUNC_CONTROLLER);
|
||||
if (!cont) return;
|
||||
|
|
|
@ -110,7 +110,7 @@ void Window_RequestClose(void) {
|
|||
/*########################################################################################################################*
|
||||
*---------------------------------------------GameCube controller processing----------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static PADStatus gc_pads[INPUT_MAX_GAMEPADS];
|
||||
static PADStatus gc_pads[PAD_CHANMAX];
|
||||
|
||||
#define PAD_AXIS_SCALE 8.0f
|
||||
static void ProcessPAD_Joystick(int port, int axis, int x, int y, float delta) {
|
||||
|
@ -139,8 +139,8 @@ static void ProcessPAD_Buttons(int port, int mods) {
|
|||
Gamepad_SetButton(port, CCPAD_DOWN, mods & PAD_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
static void ProcessPADInput(int i, float delta) {
|
||||
PADStatus pads[4];
|
||||
static void ProcessPADInput(PADStatus* pad, int i, float delta) {
|
||||
PADStatus pads[PAD_CHANMAX];
|
||||
PAD_Read(pads);
|
||||
int error = pads[i].err;
|
||||
|
||||
|
@ -158,6 +158,16 @@ static void ProcessPADInput(int i, float delta) {
|
|||
ProcessPAD_Joystick(port, PAD_AXIS_RIGHT, gc_pads[i].substickX, gc_pads[i].substickY, delta);
|
||||
}
|
||||
|
||||
static void ProcessPADInputs(float delta) {
|
||||
PADStatus pads[PAD_CHANMAX];
|
||||
PAD_Read(pads);
|
||||
|
||||
for (int i = 0; i < PAD_CHANMAX; i++)
|
||||
{
|
||||
ProcessPADInput(&pads[i], i, delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------Kebyaord processing----------------------------------------------------*
|
||||
|
@ -448,18 +458,15 @@ static void ProcessWPADInput(int i, float delta) {
|
|||
}
|
||||
|
||||
void Gamepads_Process(float delta) {
|
||||
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ProcessWPADInput(i, delta);
|
||||
ProcessPADInput( i, delta);
|
||||
}
|
||||
ProcessPADInputs(delta);
|
||||
}
|
||||
#else
|
||||
void Gamepads_Process(float delta) {
|
||||
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||
{
|
||||
ProcessPADInput(i, delta);
|
||||
}
|
||||
ProcessPADInputs(delta);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ static void ProcessAnalogInput(int port, joypad_inputs_t* inputs, float delta) {
|
|||
void Gamepads_Process(float delta) {
|
||||
joypad_poll();
|
||||
|
||||
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||
for (int i = 0; i < JOYPAD_PORT_COUNT; i++)
|
||||
{
|
||||
if (!joypad_is_connected(i)) continue;
|
||||
joypad_inputs_t inputs = joypad_get_inputs(i);
|
||||
|
|
|
@ -246,7 +246,7 @@ static void ProcessPadInput(int port, float delta, struct padButtonStatus* pad)
|
|||
HandleJoystick(port, PAD_AXIS_RIGHT, pad->rjoy_h - 0x80, pad->rjoy_v - 0x80, delta);
|
||||
}
|
||||
|
||||
static cc_bool setMode[INPUT_MAX_GAMEPADS];
|
||||
static cc_bool setMode[2];
|
||||
static void ProcessPad(int i, float delta) {
|
||||
struct padButtonStatus pad;
|
||||
int state = padGetState(i, 0);
|
||||
|
|
|
@ -323,7 +323,7 @@ static void ProcessPadInput(int port, float delta, padData* pad) {
|
|||
|
||||
void Gamepads_Process(float delta) {
|
||||
ioPadGetInfo(&pad_info);
|
||||
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||
for (int i = 0; i < MAX_PORT_NUM; i++)
|
||||
{
|
||||
if (!pad_info.status[i]) continue;
|
||||
ioPadGetData(i, &pad_data);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "Core.h"
|
||||
#if defined CC_BUILD_WIIU
|
||||
extern "C" {
|
||||
#include "Window.h"
|
||||
#include "Platform.h"
|
||||
#include "Input.h"
|
||||
|
@ -13,7 +12,7 @@ extern "C" {
|
|||
#include "Graphics.h"
|
||||
#include "Launcher.h"
|
||||
#include "LBackend.h"
|
||||
}
|
||||
#include "VirtualKeyboard.h"
|
||||
#include <coreinit/memheap.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/memfrmheap.h>
|
||||
|
@ -29,21 +28,13 @@ extern "C" {
|
|||
#include <gx2/mem.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <coreinit/memdefaultheap.h>
|
||||
#include <nn/swkbd.h>
|
||||
|
||||
static cc_bool launcherMode;
|
||||
static cc_bool keyboardOpen;
|
||||
struct _DisplayData DisplayInfo;
|
||||
struct cc_window WindowInfo;
|
||||
struct cc_window Window_Alt;
|
||||
cc_bool launcherTop;
|
||||
|
||||
|
||||
|
||||
static void OnscreenKeyboard_Update(void);
|
||||
static void OnscreenKeyboard_DrawTV(void);
|
||||
static void OnscreenKeyboard_DrawDRC(void);
|
||||
|
||||
static void LoadTVDimensions(void) {
|
||||
switch(GX2GetSystemTVScanMode())
|
||||
{
|
||||
|
@ -98,7 +89,7 @@ void Window_Init(void) {
|
|||
DisplayInfo.ContentOffsetX = 10;
|
||||
DisplayInfo.ContentOffsetY = 10;
|
||||
|
||||
Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE;
|
||||
Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL;
|
||||
Input_SetTouchMode(true);
|
||||
|
||||
Window_Alt.Width = 854;
|
||||
|
@ -163,7 +154,6 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; }
|
|||
*-------------------------------------------------------Gamepads----------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static VPADStatus vpadStatus;
|
||||
static bool kpad_valid[4];
|
||||
static KPADStatus kpads[4];
|
||||
|
||||
void Gamepads_Init(void) {
|
||||
|
@ -240,26 +230,28 @@ static void ProcessProButtons(int port, int mods) {
|
|||
}
|
||||
|
||||
static void ProcessKPAD(float delta, int i) {
|
||||
kpad_valid[i] = false;
|
||||
int res = KPADRead((WPADChan)(WPAD_CHAN_0 + i), &kpads[i], 1);
|
||||
|
||||
int res = KPADRead(WPAD_CHAN_0 + i, &kpads[i], 1);
|
||||
int port;
|
||||
if (res != KPAD_ERROR_OK) return;
|
||||
kpad_valid[i] = true;
|
||||
|
||||
switch (kpads[i].extensionType)
|
||||
{
|
||||
case WPAD_EXT_CLASSIC:
|
||||
ProcessClassicButtons(i, kpads[i].classic.hold | kpads[i].classic.trigger);
|
||||
port = Gamepad_Connect(0xC1 + i, PadBind_Defaults);
|
||||
ProcessClassicButtons(port, kpads[i].classic.hold | kpads[i].classic.trigger);
|
||||
break;
|
||||
case WPAD_EXT_PRO_CONTROLLER:
|
||||
ProcessProButtons( i, kpads[i].pro.hold | kpads[i].pro.trigger);
|
||||
port = Gamepad_Connect(0xC110 + i, PadBind_Defaults);
|
||||
ProcessProButtons(port, kpads[i].pro.hold | kpads[i].pro.trigger);
|
||||
break;
|
||||
case WPAD_EXT_NUNCHUK:
|
||||
ProcessKPadButtons(i, kpads[i].hold | kpads[i].trigger);
|
||||
ProcessNunchuckButtons(i, kpads[i].nunchuk.hold | kpads[i].nunchuk.trigger);
|
||||
port = Gamepad_Connect(0xCC + i, PadBind_Defaults);
|
||||
ProcessKPadButtons(port, kpads[i].hold | kpads[i].trigger);
|
||||
ProcessNunchuckButtons(port, kpads[i].nunchuk.hold | kpads[i].nunchuk.trigger);
|
||||
break;
|
||||
default:
|
||||
ProcessKPadButtons(i, kpads[i].hold | kpads[i].trigger);
|
||||
port = Gamepad_Connect(0x11 + i, PadBind_Defaults);
|
||||
ProcessKPadButtons(port, kpads[i].hold | kpads[i].trigger);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -318,13 +310,14 @@ static void ProcessVPAD(float delta) {
|
|||
VPADReadError error = VPAD_READ_SUCCESS;
|
||||
VPADRead(VPAD_CHAN_0, &vpadStatus, 1, &error);
|
||||
if (error != VPAD_READ_SUCCESS) return;
|
||||
int port = Gamepad_Connect(0xDC, PadBind_Defaults);
|
||||
|
||||
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &vpadStatus.tpNormal, &vpadStatus.tpNormal);
|
||||
ProcessVpadButtons(0, vpadStatus.hold);
|
||||
ProcessVpadButtons(port, vpadStatus.hold);
|
||||
ProcessVpadTouch(&vpadStatus.tpNormal);
|
||||
|
||||
ProcessVpadStick(0, PAD_AXIS_LEFT, vpadStatus.leftStick.x, vpadStatus.leftStick.y, delta);
|
||||
ProcessVpadStick(0, PAD_AXIS_RIGHT, vpadStatus.rightStick.x, vpadStatus.rightStick.y, delta);
|
||||
ProcessVpadStick(port, PAD_AXIS_LEFT, vpadStatus.leftStick.x, vpadStatus.leftStick.y, delta);
|
||||
ProcessVpadStick(port, PAD_AXIS_RIGHT, vpadStatus.rightStick.x, vpadStatus.rightStick.y, delta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -332,8 +325,6 @@ void Gamepads_Process(float delta) {
|
|||
ProcessVPAD(delta);
|
||||
for (int i = 0; i < 4; i++)
|
||||
ProcessKPAD(delta, i);
|
||||
|
||||
if (keyboardOpen) OnscreenKeyboard_Update();
|
||||
}
|
||||
|
||||
|
||||
|
@ -395,7 +386,6 @@ static void DrawTV(void) {
|
|||
WHBGfxBeginRenderTV();
|
||||
WHBGfxClearColor(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
DrawLauncher();
|
||||
if (keyboardOpen) OnscreenKeyboard_DrawTV();
|
||||
WHBGfxFinishRenderTV();
|
||||
}
|
||||
|
||||
|
@ -403,7 +393,6 @@ static void DrawDRC(void) {
|
|||
WHBGfxBeginRenderDRC();
|
||||
WHBGfxClearColor(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
DrawLauncher();
|
||||
if (keyboardOpen) OnscreenKeyboard_DrawDRC();
|
||||
WHBGfxFinishRenderDRC();
|
||||
}
|
||||
|
||||
|
@ -461,159 +450,16 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
|||
/*########################################################################################################################*
|
||||
*----------------------------------------------------Onscreen keyboard----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static FSClient* fs_client;
|
||||
static nn::swkbd::CreateArg create_arg;
|
||||
static nn::swkbd::AppearArg appear_arg;
|
||||
|
||||
static char kb_buffer[512];
|
||||
static cc_string kb_str = String_FromArray(kb_buffer);
|
||||
#define UNI_STR_LENGTH 64
|
||||
|
||||
static int UniString_Length(const char16_t* raw) {
|
||||
int length = 0;
|
||||
while (length < UInt16_MaxValue && *raw) { raw++; length++; }
|
||||
return length;
|
||||
}
|
||||
|
||||
static void UniString_WriteConst(const char* src, char16_t* dst) {
|
||||
while (*src) { *dst++ = *src++; }
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
static void UniString_WriteString(const cc_string* src, char16_t* dst) {
|
||||
for (int i = 0; i < src->length && i < UNI_STR_LENGTH; i++)
|
||||
{
|
||||
*dst++ = Convert_CP437ToUnicode(src->buffer[i]);
|
||||
}
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
static void OnscreenKeyboard_ProcessDown(int key, struct InputDevice* device) { }
|
||||
|
||||
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) {
|
||||
if (keyboardOpen) OnscreenKeyboard_Close();
|
||||
char16_t hint[UNI_STR_LENGTH + 1] = { 0 };
|
||||
char16_t initial[UNI_STR_LENGTH + 1] = { 0 };
|
||||
int mode = args->type & 0xFF;
|
||||
|
||||
kb_str.length = 0;
|
||||
keyboardOpen = true;
|
||||
Window_Main.SoftKeyboardFocus = true;
|
||||
Input.DownHook = OnscreenKeyboard_ProcessDown;
|
||||
|
||||
fs_client = (FSClient *)MEMAllocFromDefaultHeap(sizeof(FSClient));
|
||||
FSAddClient(fs_client, FS_ERROR_FLAG_NONE);
|
||||
|
||||
create_arg.regionType = nn::swkbd::RegionType::Europe;
|
||||
create_arg.workMemory = MEMAllocFromDefaultHeap(nn::swkbd::GetWorkMemorySize(0));
|
||||
create_arg.fsClient = fs_client;
|
||||
|
||||
if (!nn::swkbd::Create(create_arg)) {
|
||||
Platform_LogConst("nn::swkbd::Create failed");
|
||||
return;
|
||||
}
|
||||
nn::swkbd::MuteAllSound(false);
|
||||
|
||||
nn::swkbd::ConfigArg* cfg = &appear_arg.keyboardArg.configArg;
|
||||
cfg->languageType = nn::swkbd::LanguageType::English;
|
||||
cfg->okString = args->type & KEYBOARD_FLAG_SEND ? u"Send" : u"OK";
|
||||
|
||||
if (mode == KEYBOARD_TYPE_INTEGER) {
|
||||
cfg->keyboardMode = nn::swkbd::KeyboardMode::Numpad;
|
||||
cfg->numpadCharLeft = '-';
|
||||
cfg->numpadCharRight = 0;
|
||||
} else if (mode == KEYBOARD_TYPE_NUMBER) {
|
||||
cfg->keyboardMode = nn::swkbd::KeyboardMode::Numpad;
|
||||
cfg->numpadCharLeft = '-';
|
||||
cfg->numpadCharRight = '.';
|
||||
} else {
|
||||
cfg->keyboardMode = nn::swkbd::KeyboardMode::Full;
|
||||
}
|
||||
|
||||
nn::swkbd::InputFormArg* ipt = &appear_arg.inputFormArg;
|
||||
UniString_WriteConst(args->placeholder, hint);
|
||||
UniString_WriteString(args->text, initial);
|
||||
ipt->hintText = hint;
|
||||
ipt->initialText = initial;
|
||||
ipt->maxTextLength = UNI_STR_LENGTH;
|
||||
|
||||
if (mode == KEYBOARD_TYPE_PASSWORD)
|
||||
ipt->passwordMode = nn::swkbd::PasswordMode::Hide;
|
||||
else
|
||||
ipt->passwordMode = nn::swkbd::PasswordMode::Clear;
|
||||
|
||||
if (!nn::swkbd::AppearInputForm(appear_arg)) {
|
||||
Platform_LogConst("nn::swkbd::AppearInputForm failed");
|
||||
return;
|
||||
}
|
||||
if (Input.Sources & INPUT_SOURCE_NORMAL) return;
|
||||
VirtualKeyboard_Open(args, launcherMode);
|
||||
}
|
||||
|
||||
static void ProcessKeyboardInput(void) {
|
||||
char tmpBuffer[NATIVE_STR_LEN];
|
||||
cc_string tmp = String_FromArray(tmpBuffer);
|
||||
|
||||
const char16_t* str = nn::swkbd::GetInputFormString();
|
||||
if (!str) return;
|
||||
String_AppendUtf16(&tmp, str, UniString_Length(str));
|
||||
|
||||
if (String_Equals(&tmp, &kb_str)) return;
|
||||
String_Copy(&kb_str, &tmp);
|
||||
Event_RaiseString(&InputEvents.TextChanged, &tmp);
|
||||
void OnscreenKeyboard_SetText(const cc_string* text) {
|
||||
VirtualKeyboard_SetText(text);
|
||||
}
|
||||
|
||||
static void OnscreenKeyboard_Update(void) {
|
||||
nn::swkbd::ControllerInfo controllerInfo;
|
||||
controllerInfo.vpad = &vpadStatus;
|
||||
controllerInfo.kpad[0] = kpad_valid[0] ? &kpads[0] : nullptr;
|
||||
controllerInfo.kpad[1] = kpad_valid[1] ? &kpads[1] : nullptr;
|
||||
controllerInfo.kpad[2] = kpad_valid[2] ? &kpads[2] : nullptr;
|
||||
controllerInfo.kpad[3] = kpad_valid[3] ? &kpads[3] : nullptr;
|
||||
nn::swkbd::Calc(controllerInfo);
|
||||
|
||||
if (nn::swkbd::IsNeedCalcSubThreadFont()) {
|
||||
nn::swkbd::CalcSubThreadFont();
|
||||
}
|
||||
|
||||
if (nn::swkbd::IsNeedCalcSubThreadPredict()) {
|
||||
nn::swkbd::CalcSubThreadPredict();
|
||||
}
|
||||
ProcessKeyboardInput();
|
||||
|
||||
if (nn::swkbd::IsDecideOkButton(nullptr)) {
|
||||
Input_SetPressed(CCKEY_ENTER);
|
||||
Input_SetReleased(CCKEY_ENTER);
|
||||
OnscreenKeyboard_Close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (nn::swkbd::IsDecideCancelButton(nullptr)) {
|
||||
OnscreenKeyboard_Close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void OnscreenKeyboard_DrawTV(void) {
|
||||
nn::swkbd::DrawTV();
|
||||
}
|
||||
|
||||
static void OnscreenKeyboard_DrawDRC(void) {
|
||||
nn::swkbd::DrawDRC();
|
||||
}
|
||||
|
||||
|
||||
void OnscreenKeyboard_SetText(const cc_string* text) { }
|
||||
|
||||
void OnscreenKeyboard_Close(void) {
|
||||
if (!keyboardOpen) return;
|
||||
keyboardOpen = false;
|
||||
Window_Main.SoftKeyboardFocus = false;
|
||||
Input.DownHook = NULL;
|
||||
|
||||
nn::swkbd::DisappearInputForm();
|
||||
nn::swkbd::Destroy();
|
||||
MEMFreeToDefaultHeap(create_arg.workMemory);
|
||||
|
||||
FSDelClient(fs_client, FS_ERROR_FLAG_NONE);
|
||||
MEMFreeToDefaultHeap(fs_client);
|
||||
void OnscreenKeyboard_Close(void) {
|
||||
VirtualKeyboard_Close();
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue