[Scummvm-git-logs] scummvm master -> 82dd4574b848ce583f0e99f44a6182047be98901

dreammaster paulfgilbert at gmail.com
Sun Feb 2 18:17:09 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
82dd4574b8 NUVIE: Enabling joystick code


Commit: 82dd4574b848ce583f0e99f44a6182047be98901
    https://github.com/scummvm/scummvm/commit/82dd4574b848ce583f0e99f44a6182047be98901
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-02-02T10:16:22-08:00

Commit Message:
NUVIE: Enabling joystick code

Note: Even though ScummVM has a EVENT_JOYAXIS_MOTION, at least
in the core sdl-events.cpp, it remaps the motion events to
mouse events without passing them to the engine. This needs to
be corrected.. maybe make an engine feature indicating the
engine wants joystick events unchanged

Changed paths:
  R engines/ultima/nuvie/menus/joystick_dialog.cpp
  R engines/ultima/nuvie/menus/joystick_dialog.h
    engines/ultima/module.mk
    engines/ultima/nuvie/core/events.cpp
    engines/ultima/nuvie/gui/gui.cpp
    engines/ultima/nuvie/gui/widgets/command_bar_new_ui.cpp
    engines/ultima/nuvie/gui/widgets/converse_gump.cpp
    engines/ultima/nuvie/gui/widgets/map_window.cpp
    engines/ultima/nuvie/keybinding/key_actions.cpp
    engines/ultima/nuvie/keybinding/keys.cpp
    engines/ultima/nuvie/keybinding/keys.h
    engines/ultima/nuvie/menus/game_menu_dialog.cpp
    engines/ultima/nuvie/menus/game_menu_dialog.h
    engines/ultima/nuvie/script/script_cutscene.cpp


diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index 5470c7e..1972b55 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -214,7 +214,6 @@ MODULE_OBJS := \
 	nuvie/menus/gameplay_dialog.o \
 	nuvie/menus/game_menu_dialog.o \
 	nuvie/menus/input_dialog.o \
-	nuvie/menus/joystick_dialog.o \
 	nuvie/menus/video_dialog.o \
 	nuvie/misc/sdl_compat.o \
 	nuvie/misc/iavl_tree.o \
diff --git a/engines/ultima/nuvie/core/events.cpp b/engines/ultima/nuvie/core/events.cpp
index 2d43d7e..5c0dfaf 100644
--- a/engines/ultima/nuvie/core/events.cpp
+++ b/engines/ultima/nuvie/core/events.cpp
@@ -2457,9 +2457,7 @@ void Events::gameMenuDialog() {
 		gamemenu_dialog = new GameMenuDialog(this);
 		gui->AddWidget(gamemenu_dialog);
 		gui->lock_input(gamemenu_dialog);
-#ifdef HAVE_JOYSTICK_SUPPORT
 		keybinder->set_enable_joy_repeat(false);
-#endif
 	} else
 		cancelAction();
 }
@@ -2485,9 +2483,7 @@ uint16 Events::callback(uint16 msg, CallBack *caller, void *data) {
 	case GAMEMENUDIALOG_CB_DELETE :
 		showingDialog = false;
 		gamemenu_dialog = NULL;
-#ifdef HAVE_JOYSTICK_SUPPORT
 		keybinder->set_enable_joy_repeat(true);
-#endif
 		return GUI_YUM;
 	}
 
diff --git a/engines/ultima/nuvie/gui/gui.cpp b/engines/ultima/nuvie/gui/gui.cpp
index c2625da..6dda003 100644
--- a/engines/ultima/nuvie/gui/gui.cpp
+++ b/engines/ultima/nuvie/gui/gui.cpp
@@ -26,10 +26,7 @@
 #include "ultima/nuvie/conf/configuration.h"
 #include "ultima/nuvie/gui/gui.h"
 #include "ultima/nuvie/gui/gui_types.h"
-
-#ifdef HAVE_JOYSTICK_SUPPORT
 #include "ultima/nuvie/keybinding/keys.h"
-#endif
 
 namespace Ultima {
 namespace Nuvie {
@@ -265,18 +262,19 @@ GUI_status GUI:: HandleEvent(Common::Event *event) {
 			}
 		}
 	} else if (!block_input) {
-#ifdef HAVE_JOYSTICK_SUPPORT
-		if (event->type >= SDL_JOYAXISMOTION && event->type <= SDL_JOYBUTTONUP) {
-			event->key.keysym.sym = Game::get_game()->get_keybinder()->get_key_from_joy_events(event);
-			if (event->key.keysym.sym == Common::KEYCODE_INVALID) { // isn't mapped, is in deadzone, or axis didn't return to center before moving again
+		if (event->type == Common::EVENT_JOYAXIS_MOTION ||
+				event->type == Common::EVENT_JOYBUTTON_DOWN ||
+				event->type == Common::EVENT_JOYBUTTON_UP) {
+			event->kbd.keycode = Game::get_game()->get_keybinder()->get_key_from_joy_events(event);
+			if (event->kbd.keycode == Common::KEYCODE_INVALID) { // isn't mapped, is in deadzone, or axis didn't return to center before moving again
 				HandleStatus(status);
 				CleanupDeletedWidgets(status != GUI_QUIT);
 				return status; // pretend nothing happened
 			}
-			event->type = SDL_KEYDOWN;
-			event->key.keysym.mod = Common::KBD_NONE;
+			event->type = Common::EVENT_KEYDOWN;
+			event->kbd.flags = 0;
 		}
-#endif
+
 		switch (event->type) {
 		/* SDL_QUIT events quit the GUI */
 		// case SDL_QUIT:
diff --git a/engines/ultima/nuvie/gui/widgets/command_bar_new_ui.cpp b/engines/ultima/nuvie/gui/widgets/command_bar_new_ui.cpp
index 9c555a5..6e60c65 100644
--- a/engines/ultima/nuvie/gui/widgets/command_bar_new_ui.cpp
+++ b/engines/ultima/nuvie/gui/widgets/command_bar_new_ui.cpp
@@ -149,9 +149,7 @@ GUI_status CommandBarNewUI::MouseDown(int x, int y, Shared::MouseButton button)
 			if (pos < num_icons) {
 				cur_pos = pos;
 				hit((sint8)cur_pos);
-#ifdef HAVE_JOYSTICK_SUPPORT
 				Game::get_game()->get_keybinder()->set_enable_joy_repeat(true);
-#endif
 				Hide();
 			}
 		}
@@ -211,17 +209,13 @@ GUI_status CommandBarNewUI::KeyDown(const Common::KeyState &key) {
 	case DO_ACTION_KEY:
 		if (cur_pos < num_icons) {
 			hit((sint8)cur_pos);
-#ifdef HAVE_JOYSTICK_SUPPORT
 			keybinder->set_enable_joy_repeat(true);
-#endif
 			Hide();
 		}
 		break;
 	case CANCEL_ACTION_KEY:
 	case NEW_COMMAND_BAR_KEY:
-#ifdef HAVE_JOYSTICK_SUPPORT
 		keybinder->set_enable_joy_repeat(true);
-#endif
 		Hide();
 		break;
 
diff --git a/engines/ultima/nuvie/gui/widgets/converse_gump.cpp b/engines/ultima/nuvie/gui/widgets/converse_gump.cpp
index c49e30a..9cfc796 100644
--- a/engines/ultima/nuvie/gui/widgets/converse_gump.cpp
+++ b/engines/ultima/nuvie/gui/widgets/converse_gump.cpp
@@ -137,9 +137,7 @@ ConverseGump::~ConverseGump() {
 
 void ConverseGump::set_talking(bool state, Actor *actor) {
 	if (state == true) {
-#ifdef HAVE_JOYSTICK_SUPPORT
 		Game::get_game()->get_keybinder()->set_enable_joy_repeat(false);
-#endif
 		found_break_char = true;
 		conv_keywords.clear();
 		permitted_input_keywords.clear();
@@ -173,9 +171,7 @@ void ConverseGump::set_talking(bool state, Actor *actor) {
 
 		cursor_position = 0;
 	} else {
-#ifdef HAVE_JOYSTICK_SUPPORT
 		Game::get_game()->get_keybinder()->set_enable_joy_repeat(true);
-#endif
 	}
 
 	MsgScroll::set_talking(state);
diff --git a/engines/ultima/nuvie/gui/widgets/map_window.cpp b/engines/ultima/nuvie/gui/widgets/map_window.cpp
index 1796fd9..37520f4 100644
--- a/engines/ultima/nuvie/gui/widgets/map_window.cpp
+++ b/engines/ultima/nuvie/gui/widgets/map_window.cpp
@@ -670,27 +670,20 @@ void MapWindow::update() {
 		} else
 			walking = false;
 	}
-#ifdef HAVE_JOYSTICK_SUPPORT // repeat axis or hat when walking or wizard_eye_mode
+
 	KeyBinder *keybinder = game->get_keybinder();
-	if (keybinder->get_joystick() && keybinder->is_joy_repeat_enabled() && (event->get_mode() == MOVE_MODE || is_wizard_eye_mode())
-	        && keybinder->get_next_joy_repeat_time() < clock->get_ticks())
-// !game->user_paused(), !game->get_view_manager()->gumps_are_active() - I don't think these are needed but may need them later
-	{
-		Common::KeyCode key;
-		if (keybinder->is_hat_repeating())
-			key = keybinder->get_key_from_joy_hat_button(SDL_JoystickGetHat(keybinder->get_joystick(), 0));
-		else
-			key = keybinder->get_key_from_joy_walk_axes();
+	if (keybinder->is_joy_repeat_enabled() && (event->get_mode() == MOVE_MODE || is_wizard_eye_mode())
+	        && keybinder->get_next_joy_repeat_time() < clock->get_ticks()) {
+		Common::KeyCode key = keybinder->get_key_from_joy_walk_axes();
 		if (key != Common::KEYCODE_INVALID) {
 			Common::Event sdl_event;
-			sdl_event.type = SDL_KEYDOWN;
-			sdl_event.key.keysym.sym = key;
-			sdl_event.key.keysym.mod = Common::KBD_NONE;
+			sdl_event.type = Common::EVENT_KEYDOWN;
+			sdl_event.kbd.keycode = key;
+			sdl_event.kbd.flags = 0;
 			if (GUI::get_gui()->HandleEvent(&sdl_event) == GUI_PASS)
 				event->handleEvent(&sdl_event);
 		}
 	}
-#endif
 }
 
 // moved from updateBlacking() so you don't have to update all blacking (SB-X)
diff --git a/engines/ultima/nuvie/keybinding/key_actions.cpp b/engines/ultima/nuvie/keybinding/key_actions.cpp
index fbc7d11..0314b52 100644
--- a/engines/ultima/nuvie/keybinding/key_actions.cpp
+++ b/engines/ultima/nuvie/keybinding/key_actions.cpp
@@ -162,9 +162,7 @@ void ActionSelectNewCommandBar(int const *params) {
 
 	cb->grab_focus();
 	cb->Show();
-#ifdef HAVE_JOYSTICK_SUPPORT
 	GAME->get_keybinder()->set_enable_joy_repeat(false);
-#endif
 }
 
 void ActionDollGump(int const *params) {
diff --git a/engines/ultima/nuvie/keybinding/keys.cpp b/engines/ultima/nuvie/keybinding/keys.cpp
index d9b0fe5..712b44c 100644
--- a/engines/ultima/nuvie/keybinding/keys.cpp
+++ b/engines/ultima/nuvie/keybinding/keys.cpp
@@ -281,26 +281,10 @@ KeyBinder::KeyBinder(Configuration *config) {
 	LoadGameSpecificKeys(); // won't load if file isn't found
 	LoadFromPatch(); // won't load if file isn't found
 
-#ifdef HAVE_JOYSTICK_SUPPORT
-	joystick = NULL;
-	Std::string enable_joystick_str;
-	config->value("config/joystick/enable_joystick", enable_joystick_str, "no");
-
-	if (enable_joystick_str == "no")
-		enable_joystick =  -1;
-#if SDL_VERSION_ATLEAST(2,0,0)
-	else if (enable_joystick_str == "auto")
-		init_joystick(127);
-#endif
-	else
-		init_joystick(clamp(atoi(enable_joystick_str.c_str()), 0, 9));
-
 	int config_int;
 	uint16 max_delay = 10000; // 10 seconds but means no repeat
-	uint16 max_deadzone = 32766; // one less than highest possible
 	config->value("config/joystick/repeat_hat", repeat_hat, false);
 
-
 	config->value("config/joystick/repeat_delay", config_int, 50);
 	joy_repeat_delay = config_int < max_delay ? config_int : max_delay;
 	if (joy_repeat_delay == max_delay)
@@ -308,54 +292,39 @@ KeyBinder::KeyBinder(Configuration *config) {
 	else
 		joy_repeat_enabled = true;
 
-// AXES_PAIR1
+	Common::fill(_joyAxisPositions, _joyAxisPositions + 8, 0);
+
+	// AXES_PAIR1
 	config->value("config/joystick/axes_pair1/x_axis", config_int, 0);
 	x_axis = config_int < 255 ? config_int : 255;
 	config->value("config/joystick/axes_pair1/y_axis", config_int, 1);
 	y_axis = config_int < 255 ? config_int : 255;
-	config->value("config/joystick/axes_pair1/x_deadzone", config_int, 8000);
-	x_axis_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
-	config->value("config/joystick/axes_pair1/y_deadzone", config_int, 8000);
-	y_axis_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
 	config->value("config/joystick/axes_pair1/delay", config_int, 110);
 	pair1_delay = config_int < max_delay ? config_int : max_delay;
-// AXES_PAIR2
+	// AXES_PAIR2
 	config->value("config/joystick/axes_pair2/x_axis", config_int, 3);
 	x_axis2 = config_int < 255 ? config_int : 255;
 	config->value("config/joystick/axes_pair2/y_axis", config_int, 2);
 	y_axis2 = config_int < 255 ? config_int : 255;
-	config->value("config/joystick/axes_pair2/x_deadzone", config_int, 8000);
-	x_axis2_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
-	config->value("config/joystick/axes_pair2/y_deadzone", config_int, 8000);
-	y_axis2_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
 	config->value("config/joystick/axes_pair2/delay", config_int, 110);
 	pair2_delay = config_int < max_delay ? config_int : max_delay;
-// AXES_PAIR3
+	// AXES_PAIR3
 	config->value("config/joystick/axes_pair3/x_axis", config_int, 4);
 	x_axis3 = config_int < 255 ? config_int : 255;
 	config->value("config/joystick/axes_pair3/y_axis", config_int, 5);
 	y_axis3 = config_int < 255 ? config_int : 255;
-	config->value("config/joystick/axes_pair3/x_deadzone", config_int, 8000);
-	x_axis3_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
-	config->value("config/joystick/axes_pair3/y_deadzone", config_int, 8000);
-	y_axis3_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
 	config->value("config/joystick/axes_pair3/delay", config_int, 110);
 	pair3_delay = config_int < max_delay ? config_int : max_delay;
-// AXES_PAIR4
+	// AXES_PAIR4
 	config->value("config/joystick/axes_pair4/x_axis", config_int, 6);
 	x_axis4 = config_int < 255 ? config_int : 255;
 	config->value("config/joystick/axes_pair4/y_axis", config_int, 7);
 	y_axis4 = config_int < 255 ? config_int : 255;
-	config->value("config/joystick/axes_pair4/x_deadzone", config_int, 8000);
-	x_axis4_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
-	config->value("config/joystick/axes_pair4/y_deadzone", config_int, 8000);
-	y_axis4_deadzone = config_int < max_deadzone ? config_int : max_deadzone;
 	config->value("config/joystick/axes_pair4/delay", config_int, 110);
 	pair4_delay = config_int < max_delay ? config_int : max_delay;
 
 	next_axes_pair_update = next_axes_pair2_update = next_axes_pair3_update = 0;
 	next_axes_pair4_update = next_joy_repeat_time = 0;
-#endif
 }
 
 KeyBinder::~KeyBinder() {
@@ -705,8 +674,6 @@ void KeyBinder::FillParseMaps() {
 		_actions[NuvieActions[i].s] = &(NuvieActions[i]);
 }
 
-#ifdef HAVE_JOYSTICK_SUPPORT
-
 uint8 KeyBinder::get_axis(uint8 index) {
 	switch (index) {
 	case 0:
@@ -764,41 +731,11 @@ joy_axes_pairs KeyBinder::get_axes_pair(int axis) {
 		return UNHANDLED_AXES_PAIR;
 }
 
-uint16 KeyBinder::get_x_axis_deadzone(joy_axes_pairs axes_pair) {
-	switch (axes_pair) {
-	case AXES_PAIR1:
-		return x_axis_deadzone;
-	case AXES_PAIR2:
-		return x_axis2_deadzone;
-	case AXES_PAIR3:
-		return x_axis3_deadzone;
-	case AXES_PAIR4:
-		return x_axis4_deadzone;
-	default:
-		return 0; // shouldn't happen
-	}
-}
-
-uint16 KeyBinder::get_y_axis_deadzone(joy_axes_pairs axes_pair) {
-	switch (axes_pair) {
-	case AXES_PAIR1:
-		return y_axis_deadzone;
-	case AXES_PAIR2:
-		return y_axis2_deadzone;
-	case AXES_PAIR3:
-		return y_axis3_deadzone;
-	case AXES_PAIR4:
-		return y_axis4_deadzone;
-	default:
-		return 0; // shouldn't happen
-	}
-}
-
 Common::KeyCode KeyBinder::get_key_from_joy_axis_motion(int axis, bool repeating) {
 	joy_axes_pairs axes_pair =  get_axes_pair(axis);
-
-	if (axes_pair == UNHANDLED_AXES_PAIR) // joystick NULL check doesn't seem to be needed - It is also checked before tring to repeat
+	if (axes_pair == UNHANDLED_AXES_PAIR)
 		return Common::KEYCODE_INVALID;
+
 	sint8 xoff = 0;
 	sint8 yoff = 0;
 	int xaxis, yaxis;
@@ -824,10 +761,10 @@ Common::KeyCode KeyBinder::get_key_from_joy_axis_motion(int axis, bool repeating
 		return Common::KEYCODE_INVALID; // shouldn't happen
 	}
 
-	if (xaxis != 255 && abs(SDL_JoystickGetAxis(joystick, xaxis)) > get_x_axis_deadzone(axes_pair))
-		xoff = (SDL_JoystickGetAxis(joystick, xaxis) < 0 ? -1 : 1);
-	if (yaxis != 255 && abs(SDL_JoystickGetAxis(joystick, yaxis)) > get_y_axis_deadzone(axes_pair))
-		yoff = (SDL_JoystickGetAxis(joystick, yaxis) < 0 ? -1 : 1);
+	if (xaxis != 255 && _joyAxisPositions[xaxis] != 0)
+		xoff = _joyAxisPositions[xaxis] < 0 ? -1 : 1;
+	if (yaxis != 255 && _joyAxisPositions[yaxis] != 0)
+		yoff = _joyAxisPositions[yaxis] < 0 ? -1 : 1;
 
 	uint8 dir = get_direction_code(xoff, yoff);
 	if (axes_pair == AXES_PAIR1) {
@@ -996,93 +933,17 @@ Common::KeyCode KeyBinder::get_key_from_joy_button(uint8 button) {
 	}
 }
 
-Common::KeyCode KeyBinder::get_key_from_joy_hat(SDL_JoyHatEvent jhat) {
-//	if(jhat.which == 0) // only handling one jhat for now and some devices don't start at 0
-	return get_key_from_joy_hat_button(jhat.value);
-//	else
-//		return Common::KEYCODE_INVALID; // unhandled hat
-}
-
-Common::KeyCode KeyBinder::get_key_from_joy_hat_button(uint8 hat_button) {
-	if (repeat_hat)
-		next_joy_repeat_time = SDL_GetTicks() + joy_repeat_delay;
-	switch (hat_button) {
-	case SDL_HAT_UP:
-		return JOY_HAT_UP;
-	case SDL_HAT_DOWN:
-		return JOY_HAT_DOWN;
-	case SDL_HAT_LEFT:
-		return JOY_HAT_LEFT;
-	case SDL_HAT_RIGHT:
-		return JOY_HAT_RIGHT;
-	case SDL_HAT_RIGHTUP:
-		return JOY_HAT_RIGHTUP;
-	case SDL_HAT_RIGHTDOWN:
-		return JOY_HAT_RIGHTDOWN;
-	case SDL_HAT_LEFTUP:
-		return JOY_HAT_LEFTUP;
-	case SDL_HAT_LEFTDOWN:
-		return JOY_HAT_LEFTDOWN;
-	default:
-		return Common::KEYCODE_INVALID; // center or unhandled position
-	}
-}
-
 Common::KeyCode KeyBinder::get_key_from_joy_events(Common::Event *event) {
-	if (event->type == SDL_JOYBUTTONUP)
-		return get_key_from_joy_button(event->jbutton.button);
-	else if (event->type == SDL_JOYHATMOTION)
-		return get_key_from_joy_hat(event->jhat);
-	else if (event->type == SDL_JOYAXISMOTION)
-		return get_key_from_joy_axis_motion(event->jaxis.axis, false);
-	else
+	if (event->type == Common::EVENT_JOYBUTTON_UP) {
+		return get_key_from_joy_button(event->joystick.button);
+	} else if (event->type == Common::EVENT_JOYAXIS_MOTION && event->joystick.axis < 8) {
+		_joyAxisPositions[event->joystick.axis] = event->joystick.position;
+		return get_key_from_joy_axis_motion(event->joystick.axis, false);
+	} else {
 		return Common::KEYCODE_INVALID;
-}
-
-void KeyBinder::init_joystick(sint8 joy_num) {
-	enable_joystick = joy_num;
-	if (joystick) {
-		SDL_JoystickClose(joystick);
-		joystick = NULL;
-		if (enable_joystick == - 1)
-			SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
-	}
-	enable_joystick = joy_num;
-
-	if (enable_joystick > - 1) {
-		int joystick_index = (int)enable_joystick;
-		SDL_InitSubSystem(SDL_INIT_JOYSTICK);
-
-		if (SDL_NumJoysticks() > 0) {
-			for (int i = 0; i < SDL_NumJoysticks(); i++)
-				fprintf(stdout, "Joystick %i is %s.\n", i, SDL_JoystickNameForIndex(i));
-#if SDL_VERSION_ATLEAST(2,0,0)
-//can use SDL_GameControllerGetAttached(SDL_GameController* gamecontroller) when we implement SDL2
-			if (enable_joystick == 127) { // autodetect - seems to always pick joystick 0 but there is some possiblity that SDL couldn't open it
-				for (int i = 0; joystick == NULL && i < SDL_NumJoysticks(); i++) {
-					joystick_index = i;
-					joystick = SDL_JoystickOpen(i);
-				}
-			} else
-#endif
-				joystick = SDL_JoystickOpen(joystick_index);
-		}
-		if (joystick == NULL) {
-			if (enable_joystick == 127 || SDL_NumJoysticks() == 0)
-				fprintf(stderr, "Couldn't find any joysticks.\n");
-			else
-				fprintf(stderr, "Joysticks number %d was not found.\n", joystick_index);
-			SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
-		} else {
-			fprintf(stdout, "Using joystick #%u, \"%s\". It has %u axes, %u %s, and %u buttons.\n", joystick_index, SDL_JoystickNameForIndex(joystick_index),
-			        SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick), SDL_JoystickNumHats(joystick) == 1 ? "hat" : "hats", SDL_JoystickNumButtons(joystick));
-			SDL_JoystickEventState(SDL_ENABLE);
-		}
 	}
 }
 
-#endif /* HAVE_JOYSTICK_SUPPORT */
-
 char get_ascii_char_from_keysym(Common::KeyState keysym) {
 	char ascii = 0;
 	if (keysym.keycode < 128) {
diff --git a/engines/ultima/nuvie/keybinding/keys.h b/engines/ultima/nuvie/keybinding/keys.h
index a99e324..f57822e 100644
--- a/engines/ultima/nuvie/keybinding/keys.h
+++ b/engines/ultima/nuvie/keybinding/keys.h
@@ -30,14 +30,13 @@
 #include "common/events.h"
 #include "common/hash-str.h"
 
-#ifdef HAVE_JOYSTICK_SUPPORT
-typedef enum { AXES_PAIR1, AXES_PAIR2, AXES_PAIR3, AXES_PAIR4, UNHANDLED_AXES_PAIR } joy_axes_pairs;
-#endif
-
-
 namespace Ultima {
 namespace Nuvie {
 
+enum joy_axes_pairs {
+	AXES_PAIR1, AXES_PAIR2, AXES_PAIR3, AXES_PAIR4, UNHANDLED_AXES_PAIR
+};
+
 struct str_int_pair {
 	const char *str;
 	int  num;
@@ -68,19 +67,15 @@ private:
 	Std::vector<Std::string> _cheatHelp;
 	ParseKeyMap _keys;
 	ParseActionMap _actions;
+	int16 _joyAxisPositions[8];
 
-
-#ifdef HAVE_JOYSTICK_SUPPORT
-	SDL_Joystick *joystick;
 	bool repeat_hat, joy_repeat_enabled; // repeat hat instead of axis when hat is found
 	uint32 next_axes_pair_update, next_axes_pair2_update, next_axes_pair3_update,
-	       next_axes_pair4_update, next_joy_repeat_time;
-	uint16 pair1_delay, pair2_delay, pair3_delay, pair4_delay, joy_repeat_delay, x_axis_deadzone,
-	       y_axis_deadzone, x_axis2_deadzone, y_axis2_deadzone, x_axis3_deadzone, y_axis3_deadzone,
-	       x_axis4_deadzone, y_axis4_deadzone;
+		next_axes_pair4_update, next_joy_repeat_time;
+	uint16 pair1_delay, pair2_delay, pair3_delay, pair4_delay, joy_repeat_delay;
 	uint8 x_axis, y_axis, x_axis2, y_axis2, x_axis3, y_axis3, x_axis4, y_axis4;
 	sint8 enable_joystick;
-#endif
+
 	void LoadFromFileInternal(const char *filename);
 public:
 	KeyBinder(Configuration *config);
@@ -111,7 +106,7 @@ public:
 	bool handle_always_available_keys(ActionType a);
 
 	void ShowKeys() const;
-#ifdef HAVE_JOYSTICK_SUPPORT
+
 	uint8 get_axis(uint8 index);
 	void set_axis(uint8 index, uint8 value);
 	Common::KeyCode get_key_from_joy_walk_axes() {
@@ -121,9 +116,7 @@ public:
 	Common::KeyCode get_key_from_joy_hat_button(uint8 hat_button);
 	Common::KeyCode get_key_from_joy_events(Common::Event *event);
 	void init_joystick(sint8 joy_num);
-	SDL_Joystick *get_joystick() {
-		return joystick;
-	}
+//	SDL_Joystick *get_joystick() { return joystick; }
 	uint32 get_next_joy_repeat_time() {
 		return next_joy_repeat_time;
 	}
@@ -146,19 +139,14 @@ public:
 	void set_enable_joystick(bool val) {
 		enable_joystick = val;
 	}
-#endif
 
 private:
 	void ParseText(char *text, int len);
 	void ParseLine(char *line);
 	void FillParseMaps();
-#ifdef HAVE_JOYSTICK_SUPPORT
+
 	joy_axes_pairs get_axes_pair(int axis);
-	uint16 get_x_axis_deadzone(joy_axes_pairs axes_pair);
-	uint16 get_y_axis_deadzone(joy_axes_pairs axes_pair);
 	Common::KeyCode get_key_from_joy_button(uint8 button);
-	Common::KeyCode get_key_from_joy_hat(SDL_JoyHatEvent);
-#endif
 };
 
 } // End of namespace Nuvie
diff --git a/engines/ultima/nuvie/menus/game_menu_dialog.cpp b/engines/ultima/nuvie/menus/game_menu_dialog.cpp
index 2473a20..efccfb7 100644
--- a/engines/ultima/nuvie/menus/game_menu_dialog.cpp
+++ b/engines/ultima/nuvie/menus/game_menu_dialog.cpp
@@ -41,14 +41,7 @@ namespace Ultima {
 namespace Nuvie {
 
 #define GMD_WIDTH 150
-
-#ifdef HAVE_JOYSTICK_SUPPORT
-#include "JoystickDialog.h"
-
-#define GMD_HEIGHT 148 // 13 bigger
-#else
 #define GMD_HEIGHT 135
-#endif
 
 GameMenuDialog::GameMenuDialog(CallBack *callback)
 	: GUI_Dialog(Game::get_game()->get_game_x_offset() + (Game::get_game()->get_game_width() - GMD_WIDTH) / 2,
@@ -84,11 +77,6 @@ bool GameMenuDialog::init() {
 	input_button = new GUI_Button(this, buttonX, buttonY += row_h, width, height, "Input Options", gui->get_font(), BUTTON_TEXTALIGN_CENTER, 0, this, 0);
 	AddWidget(input_button);
 	button_index[++last_index] = input_button;
-#ifdef HAVE_JOYSTICK_SUPPORT
-	joystick_button = new GUI_Button(this, buttonX, buttonY += row_h, width, height, "Joystick Options", gui->get_font(), BUTTON_TEXTALIGN_CENTER, 0, this, 0);
-	AddWidget(joystick_button);
-	button_index[++last_index] = joystick_button;
-#endif
 	gameplay_button = new GUI_Button(this, buttonX, buttonY += row_h, width, height, "Gameplay Options", gui->get_font(), BUTTON_TEXTALIGN_CENTER, 0, this, 0);
 	AddWidget(gameplay_button);
 	button_index[++last_index] = gameplay_button;
@@ -176,13 +164,6 @@ GUI_status GameMenuDialog::callback(uint16 msg, GUI_CallBack *caller, void *data
 		input_dialog = (GUI_Widget *) new InputDialog(this);
 		GUI::get_gui()->AddWidget(input_dialog);
 		gui->lock_input(input_dialog);
-#ifdef HAVE_JOYSTICK_SUPPORT
-	} else if (caller == joystick_button) {
-		GUI_Widget *joystick_dialog;
-		joystick_dialog = (GUI_Widget *) new JoystickDialog(this);
-		GUI::get_gui()->AddWidget(joystick_dialog);
-		gui->lock_input(joystick_dialog);
-#endif
 	} else if (caller == gameplay_button) {
 		GUI_Widget *gameplay_dialog;
 		gameplay_dialog = (GUI_Widget *) new GameplayDialog(this);
diff --git a/engines/ultima/nuvie/menus/game_menu_dialog.h b/engines/ultima/nuvie/menus/game_menu_dialog.h
index 5da919d..83734f9 100644
--- a/engines/ultima/nuvie/menus/game_menu_dialog.h
+++ b/engines/ultima/nuvie/menus/game_menu_dialog.h
@@ -42,12 +42,7 @@ protected:
 	CallBack *callback_object;
 	GUI_Button *load_button, *save_button, *video_button, *audio_button, *input_button,
 		*gameplay_button, *cheats_button, *continue_button, *quit_button;
-#ifdef HAVE_JOYSTICK_SUPPORT
-	GUI_Button *joystick_button;
-	GUI_Button *button_index[10]; // needs to be one bigger
-#else
 	GUI_Button *button_index[9]; // add to here when you add a button. Keep buttons in order by height
-#endif
 public:
 	GameMenuDialog(CallBack *callback);
 	~GameMenuDialog();
diff --git a/engines/ultima/nuvie/menus/joystick_dialog.cpp b/engines/ultima/nuvie/menus/joystick_dialog.cpp
deleted file mode 100644
index f06a613..0000000
--- a/engines/ultima/nuvie/menus/joystick_dialog.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifdef HAVE_JOYSTICK_SUPPORT
-
-#include "ultima/nuvie/core/nuvie_defs.h"
-#include "ultima/nuvie/gui/gui.h"
-#include "ultima/nuvie/gui/gui_types.h"
-#include "ultima/nuvie/gui/gui_button.h"
-#include "ultima/nuvie/gui/gui_text.h"
-#include "ultima/nuvie/gui/gui_text_toggle_button.h"
-#include "ultima/nuvie/gui/gui_callback.h"
-#include "ultima/nuvie/gui/gui_area.h"
-
-#include "ultima/nuvie/gui/gui_dialog.h"
-#include "JoystickDialog.h"
-#include "ultima/nuvie/conf/configuration.h"
-#include "ultima/nuvie/keybinding/keys.h"
-
-namespace Ultima {
-namespace Nuvie {
-
-#define JD_WIDTH 244
-#define JD_HEIGHT 127
-
-JoystickDialog::JoystickDialog(GUI_CallBack *callback)
-	: GUI_Dialog(Game::get_game()->get_game_x_offset() + (Game::get_game()->get_game_width() - JD_WIDTH) / 2,
-	             Game::get_game()->get_game_y_offset() + (Game::get_game()->get_game_height() - JD_HEIGHT) / 2,
-	             JD_WIDTH, JD_HEIGHT, 244, 216, 131, GUI_DIALOG_UNMOVABLE) {
-	callback_object = callback;
-	init();
-	grab_focus();
-}
-
-bool JoystickDialog::init() {
-	int height = 12;
-	int buttonX[] = { 128, 142, 183};
-	int textX[] = { 9, 115, 170 };
-	int textY = 11;
-	int buttonY = 9;
-	uint8 sub_h = 4;
-	uint8 row_h = 13;
-	uint8 axis_w = 40;
-	b_index_num = -1;
-	last_index = 0;
-//	uint8 yesno_width = 32;
-
-	GUI_Widget *widget;
-	GUI_Font *font = GUI::get_gui()->get_font();
-
-
-
-//	Configuration *config = Game::get_game()->get_config();
-	KeyBinder *kb = Game::get_game()->get_keybinder();
-
-	uint8 enable_selection; /*index*/;
-	char enable_buff[11], axis_buff[4];
-
-	if (kb->get_enable_joystick() == -1)
-		enable_selection = 4;
-#if SDL_VERSION_ATLEAST(2,0,0) // haven't considered this in the saving loop
-	else if (kb->get_enable_joystick() == 127) {
-		enable_selection = 5;
-		sprintf(enable_buff, "%s", "auto detect");
-	}
-#endif
-	else if (kb->get_enable_joystick() < 4)
-		enable_selection = kb->get_enable_joystick();
-	else {
-		enable_selection = 5;
-		sprintf(enable_buff, "Joystick %i", kb->get_enable_joystick());
-	}
-
-// enable_button
-	widget = (GUI_Widget *) new GUI_Text(textX[0], textY, 0, 0, 0, "Enable joystick:", font);
-	AddWidget(widget);
-	const char *const enabled_text[] = { "Joystick 0", "Joystick 1", "Joystick 2", "joystick 3", "Disabled", enable_buff };
-	enable_button = new GUI_TextToggleButton(this, buttonX[1], buttonY, 93, height, enabled_text, enable_selection == 5 ? 6 : 5, enable_selection, font, BUTTON_TEXTALIGN_CENTER, this, 0);
-	AddWidget(enable_button);
-	button_index[last_index] = enable_button;
-// hat_repeating_b
-	widget = (GUI_Widget *) new GUI_Text(textX[0], textY += row_h, 0, 0, 0, "Repeat when held:", font);
-	AddWidget(widget);
-	const char *const hat_repeating_text[] = { "axes pair 1", "hat" };
-	hat_repeating_b = new GUI_TextToggleButton(this, buttonX[1], buttonY += row_h, 93, height, hat_repeating_text, 2, kb->is_hat_repeating(), font, BUTTON_TEXTALIGN_CENTER, this, 0);
-	AddWidget(hat_repeating_b);
-	button_index[last_index += 1] = hat_repeating_b;
-// Axes Pairs
-	int str_i = 0; // used in loop
-	const char *axis_text[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "none", "" };
-	const char *const axes_str[] = { "Axes pair 1:", "Axes pair 2:", "Axes pair 3:", "Axes pair 4:" };
-	for (int i = 0; i < 8; i++) {
-		if (i % 2 == 0) { // pairs text
-			widget = (GUI_Widget *) new GUI_Text(textX[0], textY += row_h, 0, 0, 0, axes_str[str_i++], font);
-			AddWidget(widget);
-		} // x and y text
-		widget = (GUI_Widget *) new GUI_Text(i % 2 ? textX[2] : textX[1], textY += i % 2 ? 0 : sub_h, 0, 0, 0, i % 2 ? "Y:" : "X:", font);
-		AddWidget(widget);
-		// x and y  button
-		uint8 index = get_axis_index(kb->get_axis(i));
-		if (index == 11) {
-			sprintf(axis_buff, "%i", kb->get_axis(i));
-			axis_text[11] = axis_buff;
-		}
-		axes_index[i] = new GUI_TextToggleButton(this, i % 2 ? buttonX[2] : buttonX[0], buttonY += i % 2 ? 0 : row_h + sub_h, axis_w, height, axis_text, index == 11 ? 12 : 11, index, font, BUTTON_TEXTALIGN_CENTER, this, 0);
-		AddWidget(axes_index[i]);
-		button_index[last_index += 1] = axes_index[i];
-	}
-// cancel_button
-	cancel_button = new GUI_Button(this, 59, JD_HEIGHT - 20, 54, height, "Cancel", font, BUTTON_TEXTALIGN_CENTER, 0, this, 0);
-	AddWidget(cancel_button);
-	button_index[last_index += 1] = cancel_button;
-// save_button
-	save_button = new GUI_Button(this, 124, JD_HEIGHT - 20, 60, height, "Save", font, BUTTON_TEXTALIGN_CENTER, 0, this, 0);
-	AddWidget(save_button);
-	button_index[last_index += 1] = save_button;
-
-	return true;
-}
-
-JoystickDialog::~JoystickDialog() {
-}
-
-uint8 JoystickDialog::get_axis_index(uint8 axis) {
-	if (axis == 255)
-		return 10;
-	else if (axis <= 9)
-		return axis;
-	else
-		return 11;
-}
-
-GUI_status JoystickDialog::close_dialog() {
-	Delete(); // mark dialog as deleted. it will be freed by the GUI object
-	callback_object->callback(0, this, this);
-	return GUI_YUM;
-}
-
-GUI_status JoystickDialog::KeyDown(const Common::KeyState &key) {
-	KeyBinder *keybinder = Game::get_game()->get_keybinder();
-	ActionType a = keybinder->get_ActionType(key);
-
-	switch (keybinder->GetActionKeyType(a)) {
-	case NORTH_KEY:
-		if (b_index_num > 2) {
-			button_index[b_index_num]->set_highlighted(false);
-			if (b_index_num == last_index)
-				b_index_num = b_index_num - 3;
-			else
-				b_index_num = b_index_num - 2;
-			button_index[b_index_num]->set_highlighted(true);
-			break;
-		} // else fall through
-	case WEST_KEY:
-		if (b_index_num != -1)
-			button_index[b_index_num]->set_highlighted(false);
-
-		if (b_index_num <= 0)
-			b_index_num = last_index;
-		else
-			b_index_num = b_index_num - 1;
-		button_index[b_index_num]->set_highlighted(true);
-		break;
-	case SOUTH_KEY:
-		if (b_index_num > 1 && b_index_num != last_index) {
-			button_index[b_index_num]->set_highlighted(false);
-			b_index_num += 2;
-			if (b_index_num > last_index)
-				b_index_num = 0;
-			button_index[b_index_num]->set_highlighted(true);
-			break;
-		} // else fall through
-	case EAST_KEY:
-		if (b_index_num != -1)
-			button_index[b_index_num]->set_highlighted(false);
-
-		if (b_index_num == last_index)
-			b_index_num = 0;
-		else
-			b_index_num += 1;
-		button_index[b_index_num]->set_highlighted(true);
-		break;
-	case DO_ACTION_KEY:
-		if (b_index_num != -1) return button_index[b_index_num]->Activate_button();
-		break;
-	case CANCEL_ACTION_KEY:
-		return close_dialog();
-	default:
-		keybinder->handle_always_available_keys(a);
-		break;
-	}
-	return GUI_YUM;
-}
-
-GUI_status JoystickDialog::callback(uint16 msg, GUI_CallBack *caller, void *data) {
-	if (caller == cancel_button) {
-		return close_dialog();
-	} else if (caller == save_button) {
-		Configuration *config = Game::get_game()->get_config();
-		KeyBinder *kb = Game::get_game()->get_keybinder();
-// enable joystick
-		uint8 enabled_setting;
-		if (enable_button->GetSelection() == 5)
-			enabled_setting = kb->get_enable_joystick();
-		else if (enable_button->GetSelection() == 4) {
-			enabled_setting = 255;
-			config->set("config/joystick/enable_joystick", "no");
-		} else {
-			enabled_setting = enable_button->GetSelection();
-			config->set("config/joystick/enable_joystick", enabled_setting);
-		}
-		kb->init_joystick(enabled_setting == 255 ? -1 : enabled_setting); // will close and NULL joystick and open again if enabled
-// hat repeating
-		kb->set_hat_repeating(hat_repeating_b->GetSelection() == 1);
-		config->set("config/joystick/repeat_hat", hat_repeating_b->GetSelection() == 1 ? "yes" : "no");
-// Axes Pairs
-		Std::string axes_str[] = { "axes_pair1/x_axis", "axes_pair1/y_axis", "axes_pair2/x_axis", "axes_pair2/y_axis",
-		                           "axes_pair3/x_axis", "axes_pair3/y_axis", "axes_pair4/x_axis", "axes_pair4/y_axis"
-		                         };
-		for (int i = 0; i < 8; i++) {
-			uint8 val = axes_index[i]->GetSelection();
-			if (val != kb->get_axis(i) && val != 11 && (val != 10 || kb->get_axis(i) != 255)) {
-				val = val == 10 ? 255 : val;
-				config->set("config/joystick/" + axes_str[i], val);
-				kb->set_axis(i, val);
-			}
-		}
-
-		config->write();
-		return close_dialog();
-	}
-
-	return GUI_PASS;
-}
-
-} // End of namespace Nuvie
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/nuvie/menus/joystick_dialog.h b/engines/ultima/nuvie/menus/joystick_dialog.h
deleted file mode 100644
index 350bd1a..0000000
--- a/engines/ultima/nuvie/menus/joystick_dialog.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * 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
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef NUVIE_MENUS_JOYSTICK_DIALOG_H
-#define NUVIE_MENUS_JOYSTICK_DIALOG_H
-#ifdef HAVE_JOYSTICK_SUPPORT
-
-#include "ultima/nuvie/gui/gui_dialog.h"
-
-namespace Ultima {
-namespace Nuvie {
-
-class GUI;
-class GUI_CallBack;
-class GUI_Button;
-class GUI_TextToggleButton;
-
-class JoystickDialog : public GUI_Dialog {
-protected:
-	uint8 last_index;
-	sint8 b_index_num;
-	GUI_CallBack *callback_object;
-	GUI_Button *save_button, *cancel_button;
-	GUI_TextToggleButton *enable_button, *hat_repeating_b, *axes_index[8];
-	GUI_Button *button_index[12]; // add to here when you add a button. Keep buttons in order by height
-	uint8 get_axis_index(uint8 axis);
-
-public:
-	JoystickDialog(GUI_CallBack *callback);
-	~JoystickDialog();
-	bool init();
-
-	GUI_status close_dialog();
-	GUI_status KeyDown(const Common::KeyState &key);
-	GUI_status callback(uint16 msg, GUI_CallBack *caller, void *data);
-};
-#endif /* HAVE_JOYSTICK_SUPPORT */
-
-} // End of namespace Nuvie
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/nuvie/script/script_cutscene.cpp b/engines/ultima/nuvie/script/script_cutscene.cpp
index fe1be8f..d672ae5 100644
--- a/engines/ultima/nuvie/script/script_cutscene.cpp
+++ b/engines/ultima/nuvie/script/script_cutscene.cpp
@@ -999,15 +999,19 @@ static int nscript_input_poll(lua_State *L) {
 	while (Events::get()->pollEvent(event)) {
 		//FIXME do something here.
 		KeyBinder *keybinder = Game::get_game()->get_keybinder();
-#ifdef HAVE_JOYSTICK_SUPPORT
-		if (event.type >= SDL_JOYAXISMOTION && event.type <= SDL_JOYBUTTONUP) {
-			event.key.keysym.sym = keybinder->get_key_from_joy_events(&event);
-			if (event.key.keysym.sym == Common::KEYCODE_INVALID) // make sure button isn't mapped or is in deadzone
+
+		if (event.type == Common::EVENT_JOYAXIS_MOTION ||
+				event.type == Common::EVENT_JOYBUTTON_DOWN ||
+				event.type == Common::EVENT_JOYBUTTON_UP) {
+			event.kbd.flags = 0;
+			event.kbd.keycode = keybinder->get_key_from_joy_events(&event);
+			if (event.kbd.keycode == Common::KEYCODE_INVALID)
+				// button isn't mapped or was in deadzone
 				return 0; // pretend nothing happened
-			event.type = SDL_KEYDOWN;
-			event.key.keysym.mod = Common::KBD_NONE;
+
+			event.type = Common::EVENT_KEYDOWN;
 		}
-#endif
+
 		if (event.type == Common::EVENT_KEYDOWN) {
 			Common::KeyState key = event.kbd;
 




More information about the Scummvm-git-logs mailing list