Skip to content

Commit

Permalink
Merge pull request #24 from rsn8887/master
Browse files Browse the repository at this point in the history
Implement touch controls, improve button mapping
  • Loading branch information
lantus360 authored Jul 14, 2019
2 parents 51b59d6 + b98644e commit 347dced
Show file tree
Hide file tree
Showing 15 changed files with 669 additions and 235 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ add_executable(devilutionx
SourceX/DiabloUI/selgame.cpp
SourceX/DiabloUI/selhero.cpp
SourceX/DiabloUI/title.cpp
SourceX/main.cpp)
SourceX/main.cpp
touch/touch.cpp)

target_include_directories(devilution PUBLIC Source SourceS)
target_include_directories(devilutionx PRIVATE
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,34 @@
- Extract contents of diablo-nx.zip release into SDMC:\switch\diablo-nx
- Copy DIABDAT.MPQ from original Diablo game disc or GOG version.
- Launch diablo-nx.nro
- *Note:* If using SX OS, hold R on any installed game and launch it.
- *Note:* Hold R on any installed game and launch it. Do not use photo-album to launch. If you use photo-album, the homebrew only has very little memory available, and the touch keyboard doesn't work. This is true for all homebrew, not just Diablo-NX.
- Enjoy :)

### Controls
### Joycon Controls

- Left Analog : Move Hero
- Right Analog : Simulate Mouse
- B : Attack nearby enemies, talk to towns people and merchants. Pickup & Drop items in inventory.
- B : Attack nearby enemies, talk to towns people and merchants. Pickup & Drop items in inventory. OK in Menu
- Y : Pickup gold, potions & equipment from ground, open chests and doors that are nearby. Use item when in inventory (read books etc.).
- X : Cast Spell, Previous Menu
- A : Inventory
- R : Character
- X : Cast Spell
- A : Select Spell, Cancel in Menu
- R : Inventory
- L : Character
- ZR : Drink Mana Potion
- ZL : Drink Heal Potion
- Left Analog Click : Quest Log
- Right Analog Click : Left mouse click
- Minus : Automap
- Plus : Game Menu, Skip Intro

### Touch Controls

- Single finger drag : move the mouse pointer (pointer jumps to finger)
- Single short tap : left mouse click
- Single short tap while holding a second finger down : right mouse click
- Dual finger drag : drag'n'drop (left mouse button is held down)
- Three finger drag : drag'n'drop (right mouse button is held down)

### Notes

There are lots of bugs. Check issues on the code repo.
Expand Down Expand Up @@ -53,7 +62,8 @@ There are lots of bugs. Check issues on the code repo.
### Credits
- Reverse engineered by GalaXyHaXz in 2018
- Switch Port by MVG in 2019
- Controller code by Jacob Fliss
- Control Improvements and bug fixes for Switch Port by [rsn8887](https://github.com/rsn8887) in 2019
- Controller code by [Jacob Fliss](https://github.com/erfg12)
- RetroArch team for the Switch mman.h file
- [sanctuary](https://github.com/sanctuary) - extensively documenting Diablo's game engine
- [BWAPI Team](https://github.com/bwapi) - providing library API to work with Storm
Expand Down
16 changes: 6 additions & 10 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer)
else
uMsg = WM_DIABLOADGAME;

inmainmenu = false;
run_game_loop(uMsg);
NetClose();

Expand Down Expand Up @@ -464,9 +463,10 @@ void diablo_parse_flags(char *args)
case 'w':
debug_mode_key_w = 1;
break;
//case 'x': // JAKE: Removed for spell casting
// fullscreen = FALSE;
// break;
case 'x':
fullscreen = 0;
break;
}
#endif
}
}
Expand Down Expand Up @@ -1420,12 +1420,8 @@ void PressChar(int vkey)
// JAKE: Spacebar used to go back, now Z goes back.
if (pcurs >= CURSOR_FIRSTITEM && invflag)
DropItemBeforeTrig();
ticks = GetTickCount();
if (ticks - castwait < 300 || ticks - talkwait < 600) { // prevent double spell cast
return;
}
castwait = ticks;
if (!invflag && !talkflag && !inmainmenu && stextflag == 0 && !qtextflag) // prevent "spell not rdy" speech
//castwait = ticks;
if (!invflag && !talkflag)
RightMouseDown();
PressEscKey();
return;
Expand Down
1 change: 0 additions & 1 deletion Source/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ void mainmenu_loop()
BOOL done;
int menu;

inmainmenu = true; // JAKE: Let the controller know we're in the main menu
done = FALSE;
mainmenu_refresh_music();

Expand Down
1 change: 0 additions & 1 deletion Source/plrctrls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ int hsr[3] = { 0, 0, 0 }; // hot spell row counts
DWORD talkwait;
DWORD talktick;
DWORD castwait;
bool inmainmenu = false;

// 0 = not near, >0 = distance related player 1 coordinates
coords checkNearbyObjs(int x, int y, int diff)
Expand Down
2 changes: 0 additions & 2 deletions Source/plrctrls.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ extern DWORD talkwait;
extern DWORD talktick;
extern DWORD castwait;

extern bool inmainmenu;

#define INV_TOP 240;
#define INV_LEFT 350;
#define INV_HEIGHT 320;
Expand Down
25 changes: 11 additions & 14 deletions SourceX/DiabloUI/diabloui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,26 +220,23 @@ bool UiFocusNavigation(SDL_Event *event)
{
if (event->type == SDL_QUIT)
exit(0);
if (event->type == SDL_JOYBUTTONDOWN) {
if (event->jbutton.which == 0) {
if (event->jbutton.button == 0) {

if (event->type == SDL_CONTROLLERBUTTONDOWN) {
if (event->cbutton.which == 0) {
switch (event->cbutton.button) {
case SDL_CONTROLLER_BUTTON_A:
UiFocusNavigationSelect();
return true;
}
}

if (event->jbutton.which == 0) {
if (event->jbutton.button == 13){
case SDL_CONTROLLER_BUTTON_B:
UiFocusNavigationEsc();
return true;
case SDL_CONTROLLER_BUTTON_DPAD_UP:
UiFocus(SelectedItem - 1, UiItemsWraps);
return true;
}
}

if (event->jbutton.which == 0) {
if (event->jbutton.button == 15){
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
UiFocus(SelectedItem + 1, UiItemsWraps);
return true;
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions SourceX/DiabloUI/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ void UiMainMenuSelect(int value)

void mainmenu_Esc()
{
#ifdef SWITCH
return;
#else
UiMainMenuSelect(MAINMENU_EXIT_DIABLO);
#endif
}

void mainmenu_Load(char *name, void(*fnSound)(char *file))
Expand Down
1 change: 1 addition & 0 deletions SourceX/DiabloUI/title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ BOOL UiTitleDialog(int a1)

while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_CONTROLLERBUTTONDOWN:
case SDL_KEYDOWN: /* To match the original uncomment this
if (event.key.keysym.sym == SDLK_UP
|| event.key.keysym.sym == SDLK_UP
Expand Down
3 changes: 2 additions & 1 deletion SourceX/miniwin/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,13 @@ HWND CreateWindowExA(
HINSTANCE hInstance,
LPVOID lpParam)
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) <= -1) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) <= -1) {
SDL_Log(SDL_GetError());
return NULL;
}

SDL_JoystickOpen(0);
SDL_GameControllerOpen(0);

int upscale = 1;
DvlIntSetting("upscale", &upscale);
Expand Down
Loading

0 comments on commit 347dced

Please sign in to comment.