Skip to content

Commit

Permalink
Added ability to pathfind when long touching with a finger and the op…
Browse files Browse the repository at this point in the history
…tion to toggle it in the "iOS" options.

It will show a little animation on releasing the finger when the path is clear and "BLOCKED" when Exult can't find a path there.
It could use an improvement to show the animation *while* the finger is touching but that would require a timer in the SDL_MOUSEBUTTONDOWN event in exult.cc.
  • Loading branch information
DominusExult committed Oct 10, 2016
1 parent 84c7732 commit 939dfd5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
12 changes: 12 additions & 0 deletions exult.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,10 @@ static void Handle_event(
case SDL_MOUSEBUTTONDOWN: {
if (dont_move_mode)
break;
#ifdef __IPHONEOS__
uint32 curtime = SDL_GetTicks();
last_b1down_click = curtime;
#endif
#ifdef UNDER_CE
if (gkeyboard->handle_event(&event))
break;
Expand Down Expand Up @@ -1661,6 +1665,14 @@ static void Handle_event(
if (!dragging || !dragged)
last_b1_click = curtime;

#ifdef __IPHONEOS__
if (gwin->get_touch_pathfind() && !click_handled && (curtime - last_b1down_click > 500) && avatar_can_act && gwin->main_actor_can_act_charmed() && !(gump = gump_man->find_gump(x, y, false))) {
gwin->start_actor_along_path(x, y, Mouse::mouse->avatar_speed);
dragging = dragged = false;
break;
}
#endif

if (!click_handled && avatar_can_act &&
left_down_x - 1 <= x && x <= left_down_x + 1 &&
left_down_y - 1 <= y && y <= left_down_y + 1) {
Expand Down
4 changes: 4 additions & 0 deletions exult.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ extern int Get_click(
bool rotate_colors = false // If the palette colors should rotate.
);

#ifdef __IPHONEOS__
static int last_b1down_click;
#endif

/*
* Make a screenshot of the current screen display
*/
Expand Down
16 changes: 14 additions & 2 deletions gamewin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ Game_window::Game_window(
}
config->set("config/iphoneos/dpad_location", str, false);
config->value("config/shortcutbar/use_shortcutbar", str, "translucent");
config->value("config/iphoneos/touch_pathfind", str, "yes");
touch_pathfind = str == "yes";
config->set("config/iphoneos/touch_pathfind", touch_pathfind ? "yes" : "no", false);
#else
config->value("config/shortcutbar/use_shortcutbar", str, "no");
#endif
Expand Down Expand Up @@ -1919,10 +1922,19 @@ void Game_window::start_actor_along_path(
int liftpixels = 4 * lift; // Figure abs. tile.
Tile_coord dest(get_scrolltx() + (winx + liftpixels) / c_tilesize,
get_scrollty() + (winy + liftpixels) / c_tilesize, lift);
if (!main_actor->walk_path_to_tile(dest, speed))
if (!main_actor->walk_path_to_tile(dest, speed)) {
cout << "Couldn't find path for Avatar." << endl;
else
#ifdef __IPHONEOS__
if (touch_pathfind)
Mouse::mouse->flash_shape(Mouse::blocked);
#endif
} else {
#ifdef __IPHONEOS__
if (touch_pathfind)
get_effects()->add_effect(new Sprites_effect(18, dest, 0, 0, 0, 0));
#endif
main_actor->get_followers();
}
}

/*
Expand Down
7 changes: 7 additions & 0 deletions gamewin.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Game_window {
//iphoneOS Options
bool item_menu;
int dpad_location;
bool touch_pathfind;
#endif
// Private methods:
void set_scrolls(Tile_coord cent);
Expand Down Expand Up @@ -331,6 +332,12 @@ class Game_window {
inline int get_dpad_location() {
return dpad_location;
}
bool get_touch_pathfind() const {
return touch_pathfind;
}
void set_touch_pathfind(bool s) {
touch_pathfind = s;
}
#endif
/*
* Game components:
Expand Down
10 changes: 10 additions & 0 deletions gumps/iphoneOptions_gump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void iphoneOptions_gump::toggle(Gump_button *btn, int state) {
item_menu = state;
else if (btn == buttons[id_dpad_location])
dpad_location = state;
else if (btn == buttons[id_touch_pathfind])
touch_pathfind = state;
}

void iphoneOptions_gump::build_buttons() {
Expand All @@ -135,6 +137,8 @@ void iphoneOptions_gump::build_buttons() {
buttons[id_dpad_location] = new iphoneTextToggle(this, dpad_text, colx[4], rowy[1],
59, dpad_location, num_dpad_texts);

buttons[id_touch_pathfind] = new iphoneEnabledToggle(this, colx[4], rowy[2],
59, touch_pathfind);
// Ok
buttons[id_ok] = new iphoneOptions_button(this, oktext, colx[0], rowy[12]);
// Cancel
Expand All @@ -145,6 +149,7 @@ void iphoneOptions_gump::load_settings() {
//string yn;
item_menu = gwin->get_item_menu();
dpad_location = gwin->get_dpad_location();
touch_pathfind = gwin->get_touch_pathfind();
}

iphoneOptions_gump::iphoneOptions_gump()
Expand Down Expand Up @@ -172,6 +177,10 @@ void iphoneOptions_gump::save_settings() {
gwin->set_dpad_location(dpad_location);
config->set("config/iphoneos/dpad_location", dpad_texts[dpad_location], false);

gwin->set_touch_pathfind(touch_pathfind != 0);
config->set("config/iphoneos/touch_pathfind",
touch_pathfind ? "yes" : "no", false);

config->write_back();

touchui->onDpadLocationChanged();
Expand All @@ -186,6 +195,7 @@ void iphoneOptions_gump::paint() {
Image_window8 *iwin = gwin->get_win();
font->paint_text(iwin->get_ib8(), "Item helper menu:", x + colx[0], y + rowy[0] + 1);
font->paint_text(iwin->get_ib8(), "D-Pad screen location:", x + colx[0], y + rowy[1] + 1);
font->paint_text(iwin->get_ib8(), "Long touch pathfind:", x + colx[0], y + rowy[2] + 1);

gwin->set_painted();
}
Expand Down
2 changes: 2 additions & 0 deletions gumps/iphoneOptions_gump.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ class iphoneOptions_gump : public Modal_gump {
private:
bool item_menu;
int dpad_location;
bool touch_pathfind;

enum button_ids {
id_first = 0,
id_ok = id_first,
id_cancel,
id_item_menu,
id_dpad_location,
id_touch_pathfind,
id_count
};
Gump_button *buttons[id_count];
Expand Down

0 comments on commit 939dfd5

Please sign in to comment.