Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch control optimisation [iOS, Android] #207

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ $ mv app /Applications/Fallout
### Android

> **NOTE**: Fallout was designed with mouse in mind. There are many controls that require precise cursor positioning, which is not possible with fingers. Current control scheme resembles trackpad usage:
> - One finger moves mouse cursor around.

> - One finger tap moves mouse cursor to the tapped position and does left mouse click. (new!)
> - One finger drag moves mouse cursor around. The finger doesn't have to be at the cursor position, but anywhere on the screen. This is useful for accurate selection of dialogue options, and precise aiming during combat.
> - Tap one finger for left mouse click.
> - Tap two fingers for right mouse click (switches mouse cursor mode).
> - Move two fingers to scroll current view (map view, worldmap view, inventory scrollers).
> - Tap with three fingers to simulate a left mouse button click at the cursor's current location without moving it. This is ideal for accurately selecting dialogue options or executing precise attacks during combat.

> **NOTE**: To activate UI buttons, you need to double-tap on them.



> **NOTE**: From Android standpoint release and debug builds are different apps. Both apps require their own copy of game assets and have their own savegames. This is intentional. As a gamer just stick with release version and check for updates.

Expand Down
4 changes: 2 additions & 2 deletions src/movie_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void _nfPkDecomp(unsigned char* buf, unsigned char* a2, int a3, int a4, i

static constexpr uint16_t loadUInt16LE(const uint8_t* b);
static constexpr uint32_t loadUInt32LE(const uint8_t* b);
static uint8_t getOffset(uint16_t v);
static int getOffset(uint16_t v);

// 0x51EBD8
static int dword_51EBD8 = 0;
Expand Down Expand Up @@ -2802,7 +2802,7 @@ constexpr uint32_t loadUInt32LE(const uint8_t* b)
return (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0];
}

uint8_t getOffset(uint16_t v)
int getOffset(uint16_t v)
{
return static_cast<int8_t>(v & 0xFF) + dword_51F018[v >> 8];
}
Expand Down
33 changes: 28 additions & 5 deletions src/plib/gnw/mouse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ void mouse_hide()
}

// 0x4B4DD8
// New version of mouse_info for touch devices
void mouse_info()
{
if (!have_mouse) {
Expand All @@ -434,11 +435,18 @@ void mouse_info()
static int prevy;

switch (gesture.type) {
case kTap:
case kTap:
if (gesture.numberOfTouches == 1) {
mouse_simulate_input(0, 0, MOUSE_STATE_LEFT_BUTTON_DOWN);
// Save current cursor position
int current_x, current_y;
mouse_get_position(&current_x, &current_y);

// Simulate moving the cursor (move) to a new position
mouse_simulate_input(gesture.x - current_x, gesture.y - current_y, MOUSE_STATE_LEFT_BUTTON_DOWN);
} else if (gesture.numberOfTouches == 2) {
mouse_simulate_input(0, 0, MOUSE_STATE_RIGHT_BUTTON_DOWN);
} else if (gesture.numberOfTouches == 3) {
mouse_simulate_input(0, 0, MOUSE_STATE_LEFT_BUTTON_DOWN);
}
break;
case kLongPress:
Expand Down Expand Up @@ -497,7 +505,6 @@ void mouse_info()
y = 0;
}

// Adjust for mouse senstivity.
x = (int)(x * mouse_sensitivity);
y = (int)(y * mouse_sensitivity);

Expand All @@ -515,8 +522,6 @@ void mouse_info()

mouse_simulate_input(x, y, buttons);

// TODO: Move to `_mouse_simulate_input`.
// TODO: Record wheel event in VCR.
gMouseWheelX = mouseData.wheelX;
gMouseWheelY = mouseData.wheelY;

Expand All @@ -526,6 +531,7 @@ void mouse_info()
}
}


// 0x4B4ECC
void mouse_simulate_input(int delta_x, int delta_y, int buttons)
{
Expand Down Expand Up @@ -649,6 +655,22 @@ bool mouse_in(int left, int top, int right, int bottom)
}

// 0x4B51C0
// Expanding cursor hot Size for touch devices
bool mouse_click_in(int left, int top, int right, int bottom)
{
int expand = 10; // Extend active area by 10 pixels (set as needed)

if (!have_mouse) {
return false;
}

return (mouse_hoty + mouse_y >= top - expand) &&
(mouse_hotx + mouse_x <= right + expand) &&
(mouse_hotx + mouse_x >= left - expand) &&
(mouse_hoty + mouse_y <= bottom + expand);
}

/*
bool mouse_click_in(int left, int top, int right, int bottom)
{
if (!have_mouse) {
Expand All @@ -660,6 +682,7 @@ bool mouse_click_in(int left, int top, int right, int bottom)
&& mouse_hotx + mouse_x >= left
&& mouse_hoty + mouse_y <= bottom;
}
*/

// 0x4B522C
void mouse_get_rect(Rect* rect)
Expand Down