Browse Source

Load and save all ini values the same way (#1260)

pull/1265/head
Anders Jenbo 5 years ago committed by GitHub
parent
commit
f2140688e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      Source/diablo.cpp
  2. 37
      Source/diablo.h
  3. 17
      Source/items.cpp
  4. 2
      Source/pack.h
  5. 4
      SourceX/DiabloUI/selgame.cpp
  6. 2
      SourceX/controls/controller_motion.cpp
  7. 13
      SourceX/controls/game_controls.cpp
  8. 2
      SourceX/controls/game_controls.h
  9. 2
      SourceX/controls/modifier_hints.cpp
  10. 10
      SourceX/controls/touch.cpp
  11. 10
      SourceX/display.cpp

50
Source/diablo.cpp

@ -73,14 +73,14 @@ bool gbFriendlyMode = true;
/** Specifies players will still damage other players in non-PvP mode. */
bool gbFriendlyFire;
/** Default quick messages */
const char *const spszMsgTbl[4] = {
const char *const spszMsgTbl[] = {
"I need help! Come Here!",
"Follow me.",
"Here's something for you.",
"Now you DIE!"
};
/** INI files variable names for quick message keys */
const char *const spszMsgHotKeyTbl[4] = { "F9", "F10", "F11", "F12" };
const char *const spszMsgHotKeyTbl[] = { "F9", "F10", "F11", "F12" };
/** To know if these things have been done when we get to the diablo_deinit() function */
BOOL was_archives_init = false;
@ -395,6 +395,10 @@ BOOL StartGame(BOOL bNewGame, BOOL bSinglePlayer)
*/
static void SaveOptions()
{
setIniInt("Diablo", "Intro", sgOptions.Diablo.bInto);
setIniInt("Hellfire", "Intro", sgOptions.Hellfire.bInto);
setIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem);
setIniInt("Audio", "Sound Volume", sgOptions.Audio.nSoundVolume);
setIniInt("Audio", "Music Volume", sgOptions.Audio.nMusicVolume);
setIniInt("Audio", "Walking Sound", sgOptions.Audio.bWalkingSound);
@ -439,6 +443,17 @@ static void SaveOptions()
setIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress);
setIniInt("Network", "Port", sgOptions.Network.nPort);
setIniValue("Network", "Previous Host", sgOptions.Network.szPreviousHost);
for (int i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++)
setIniValue("NetMsg", spszMsgHotKeyTbl[i], sgOptions.Chat.szHotKeyMsgs[i]);
setIniValue("Controller", "Mapping", sgOptions.Controller.szMapping);
setIniInt("Controller", "Swap Shoulder Button Mode", sgOptions.Controller.bSwapShoulderButtonMode);
setIniInt("Controller", "Dpad Hotkeys", sgOptions.Controller.bDpadHotkeys);
#ifdef __vita__
setIniInt("Controller", "Enable Rear Touchpad", sgOptions.Controller.bRearTouch);
#endif
}
/**
@ -446,6 +461,10 @@ static void SaveOptions()
*/
static void LoadOptions()
{
sgOptions.Diablo.bInto = getIniBool("Diablo", "Intro", true);
sgOptions.Hellfire.bInto = getIniBool("Hellfire", "Intro", true);
getIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem, sizeof(sgOptions.Hellfire.szItem), "");
sgOptions.Audio.nSoundVolume = getIniInt("Audio", "Sound Volume", VOLUME_MAX);
sgOptions.Audio.nMusicVolume = getIniInt("Audio", "Music Volume", VOLUME_MAX);
sgOptions.Audio.bWalkingSound = getIniBool("Audio", "Walking Sound", true);
@ -495,6 +514,17 @@ static void LoadOptions()
getIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress, sizeof(sgOptions.Network.szBindAddress), "0.0.0.0");
sgOptions.Network.nPort = getIniInt("Network", "Port", 6112);
getIniValue("Network", "Previous Host", sgOptions.Network.szPreviousHost, sizeof(sgOptions.Network.szPreviousHost), "");
for (int i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++)
getIniValue("NetMsg", spszMsgHotKeyTbl[i], sgOptions.Chat.szHotKeyMsgs[i], MAX_SEND_STR_LEN, spszMsgTbl[i]);
getIniValue("Controller", "Mapping", sgOptions.Controller.szMapping, sizeof(sgOptions.Controller.szMapping), "");
sgOptions.Controller.bSwapShoulderButtonMode = getIniBool("Controller", "Swap Shoulder Button Mode", false);
sgOptions.Controller.bDpadHotkeys = getIniBool("Controller", "Dpad Hotkeys", false);
#ifdef __vita__
sgOptions.Controller.bRearTouch = getIniBool("Controller", "Enable Rear Touchpad", true);
#endif
}
static void diablo_init_screen()
@ -549,13 +579,13 @@ static void diablo_splash()
play_movie("gendata\\logo.smk", TRUE);
if (gbIsHellfire && getIniBool("Hellfire", "Intro", true)) {
if (gbIsHellfire && sgOptions.Hellfire.bInto) {
play_movie("gendata\\Hellfire.smk", TRUE);
setIniValue("Hellfire", "Intro", "0");
sgOptions.Hellfire.bInto = false;
}
if (!gbIsHellfire && !gbIsSpawn && getIniBool("Diablo", "Intro", true)) {
if (!gbIsHellfire && !gbIsSpawn && sgOptions.Diablo.bInto) {
play_movie("gendata\\diablo1.smk", TRUE);
setIniValue("Diablo", "Intro", "0");
sgOptions.Diablo.bInto = false;
}
UiTitleDialog();
@ -847,19 +877,13 @@ void diablo_pause_game()
static void diablo_hotkey_msg(DWORD dwMsg)
{
char szMsg[MAX_SEND_STR_LEN];
if (!gbIsMultiplayer) {
return;
}
assert(dwMsg < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]));
if (!getIniValue("NetMsg", spszMsgHotKeyTbl[dwMsg], szMsg, MAX_SEND_STR_LEN)) {
snprintf(szMsg, MAX_SEND_STR_LEN, "%s", spszMsgTbl[dwMsg]);
setIniValue("NetMsg", spszMsgHotKeyTbl[dwMsg], szMsg);
}
NetSendCmdString(-1, szMsg);
NetSendCmdString(-1, sgOptions.Chat.szHotKeyMsgs[dwMsg]);
}
static BOOL PressSysKey(int wParam)

37
Source/diablo.h

@ -6,6 +6,7 @@
#ifndef __DIABLO_H__
#define __DIABLO_H__
#include "pack.h"
#ifdef _DEBUG
#include "monstdat.h"
#endif
@ -23,6 +24,18 @@ extern "C" {
#define DEFAULT_HEIGHT 480
#endif
typedef struct DiabloOptions {
/** @brief Play game intro video on startup. */
bool bInto;
} DiabloOptions;
typedef struct HellfireOptions {
/** @brief Play game intro video on startup. */
bool bInto;
/** @brief Corner stone of the world item. */
char szItem[sizeof(PkItemStruct) * 2 + 1];
} HellfireOptions;
typedef struct AudioOptions {
/** @brief Movie and SFX volume. */
Sint32 nSoundVolume;
@ -102,18 +115,42 @@ typedef struct GameplayOptions {
bool bShowMonsterType;
} GameplayOptions;
typedef struct ControllerOptions {
/** @brief SDL Controller mapping, see SDL_GameControllerDB. */
char szMapping[1024];
/** @brief Use dpad for spell hotkeys without holding "start" */
bool bDpadHotkeys;
/** @brief Shoulder gamepad shoulder buttons act as potions by default */
bool bSwapShoulderButtonMode;
#ifdef __vita__
/** @brief Enable input via rear touchpad */
bool bRearTouch;
#endif
} ControllerOptions;
typedef struct NetworkOptions {
/** @brief Optionally bind to a specific network interface. */
char szBindAddress[129];
/** @brief Most recently entered Hostname in join dialog. */
char szPreviousHost[129];
/** @brief What network port to use. */
Uint16 nPort;
} NetworkOptions;
typedef struct ChatOptions {
/** @brief Quick chat messages. */
char szHotKeyMsgs[4][MAX_SEND_STR_LEN];
} ChatOptions;
typedef struct Options {
DiabloOptions Diablo;
HellfireOptions Hellfire;
AudioOptions Audio;
GameplayOptions Gameplay;
GraphicsOptions Graphics;
ControllerOptions Controller;
NetworkOptions Network;
ChatOptions Chat;
} Options;
extern SDL_Window *ghMainWnd;

17
Source/items.cpp

@ -5,7 +5,6 @@
*/
#include <algorithm>
#include "all.h"
#include "../3rdParty/Storm/Source/storm.h"
DEVILUTION_BEGIN_NAMESPACE
@ -2974,7 +2973,6 @@ void RecreateEar(int ii, WORD ic, int iseed, int Id, int dur, int mdur, int ch,
void items_427A72()
{
PkItemStruct id;
char hexId[sizeof(PkItemStruct) * 2 + 1];
BYTE *buffer;
if (CornerStone.activated) {
@ -2982,12 +2980,10 @@ void items_427A72()
PackItem(&id, &CornerStone.item);
buffer = (BYTE *)&id;
for (int i = 0; i < sizeof(PkItemStruct); i++) {
sprintf(&hexId[i * 2], "%02X", buffer[i]);
sprintf(&sgOptions.Hellfire.szItem[i * 2], "%02X", buffer[i]);
}
setIniValue("Hellfire", "SItem", hexId, sizeof(hexId));
} else {
setIniValue("Hellfire", "SItem", "", 1);
sgOptions.Hellfire.szItem[0] = '\0';
}
}
}
@ -3011,8 +3007,6 @@ void hex2bin(const char *src, int bytes, char *target)
void items_427ABA(int x, int y)
{
PkItemStruct PkSItem;
char hexPkSItem[sizeof(PkItemStruct) * 2 + 1];
BYTE *buffer;
if (CornerStone.activated || x == 0 || y == 0) {
return;
@ -3031,13 +3025,10 @@ void items_427ABA(int x, int y)
dItem[x][y] = 0;
}
if (!getIniValue("Hellfire", "SItem", hexPkSItem, sizeof(hexPkSItem)))
return;
if (strlen(hexPkSItem) < sizeof(PkItemStruct) * 2)
if (strlen(sgOptions.Hellfire.szItem) < sizeof(PkItemStruct) * 2)
return;
hex2bin(hexPkSItem, sizeof(PkItemStruct), (char *)&PkSItem);
hex2bin(sgOptions.Hellfire.szItem, sizeof(PkItemStruct), (char *)&PkSItem);
int ii = AllocateItem();

2
Source/pack.h

@ -6,6 +6,8 @@
#ifndef __PACK_H__
#define __PACK_H__
#include "items.h"
DEVILUTION_BEGIN_NAMESPACE
#ifdef __cplusplus

4
SourceX/DiabloUI/selgame.cpp

@ -69,7 +69,7 @@ void selgame_GameSelection_Init()
return;
}
getIniValue("Phone Book", "Entry1", selgame_Ip, 128);
strcpy(selgame_Ip, sgOptions.Network.szPreviousHost);
selgame_FreeVectors();
@ -423,7 +423,7 @@ static bool IsGameCompatible(GameData *data)
void selgame_Password_Select(int value)
{
if (selgame_selectedGame) {
setIniValue("Phone Book", "Entry1", selgame_Ip);
strcpy(sgOptions.Network.szPreviousHost, selgame_Ip);
if (SNetJoinGame(selgame_selectedGame, selgame_Ip, selgame_Password, NULL, NULL, gdwPlayerId)) {
if (!IsGameCompatible(m_client_info->initdata)) {
selgame_GameSelection_Select(1);

2
SourceX/controls/controller_motion.cpp

@ -17,7 +17,7 @@ namespace {
// SELECT + D-Pad to simulate right stick movement.
bool SimulateRightStickWithDpad(const SDL_Event &event, ControllerButtonEvent ctrl_event)
{
if (dpad_hotkeys)
if (sgOptions.Controller.bDpadHotkeys)
return false;
static bool simulating = false;
if (ctrl_event.button == ControllerButton_BUTTON_BACK) {

13
SourceX/controls/game_controls.cpp

@ -15,11 +15,6 @@ namespace dvl {
bool start_modifier_active = false;
bool select_modifier_active = false;
/** Gamepad dpad acts as hotkeys without holding "start" */
bool dpad_hotkeys = false;
/** Shoulder gamepad buttons act as potions by default */
bool switch_potions_and_clicks = false;
namespace {
DWORD translate_controller_button_to_key(ControllerButton controller_button)
@ -124,14 +119,14 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
if (!in_game_menu) {
switch (ctrl_event.button) {
case ControllerButton_BUTTON_LEFTSHOULDER:
if ((select_modifier_active && !switch_potions_and_clicks) || (switch_potions_and_clicks && !select_modifier_active) ) {
if ((select_modifier_active && !sgOptions.Controller.bSwapShoulderButtonMode) || (sgOptions.Controller.bSwapShoulderButtonMode && !select_modifier_active)) {
if (!IsAutomapActive())
*action = GameActionSendMouseClick{ GameActionSendMouseClick::LEFT, ctrl_event.up };
return true;
}
break;
case ControllerButton_BUTTON_RIGHTSHOULDER:
if ((select_modifier_active && !switch_potions_and_clicks) || (switch_potions_and_clicks && !select_modifier_active) ) {
if ((select_modifier_active && !sgOptions.Controller.bSwapShoulderButtonMode) || (sgOptions.Controller.bSwapShoulderButtonMode && !select_modifier_active)) {
if (!IsAutomapActive())
*action = GameActionSendMouseClick{ GameActionSendMouseClick::RIGHT, ctrl_event.up };
return true;
@ -161,7 +156,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
default:
break;
}
if (dpad_hotkeys) {
if (sgOptions.Controller.bDpadHotkeys) {
switch (ctrl_event.button) {
case ControllerButton_BUTTON_DPAD_UP:
if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK))
@ -352,7 +347,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam
AxisDirection GetMoveDirection()
{
return controller.GetLeftStickOrDpadDirection(/*allow_dpad=*/!dpad_hotkeys);
return controller.GetLeftStickOrDpadDirection(/*allow_dpad=*/!sgOptions.Controller.bDpadHotkeys);
}
} // namespace dvl

2
SourceX/controls/game_controls.h

@ -75,7 +75,5 @@ AxisDirection GetMoveDirection();
extern bool start_modifier_active;
extern bool select_modifier_active;
extern bool dpad_hotkeys;
extern bool switch_potions_and_clicks;
} // namespace dvl

2
SourceX/controls/modifier_hints.cpp

@ -122,7 +122,7 @@ void DrawSelectModifierMenu(CelOutputBuffer out)
{
if (!select_modifier_active)
return;
if (dpad_hotkeys)
if (sgOptions.Controller.bDpadHotkeys)
{
static const CircleMenuHint kDpad(/*is_dpad=*/true, /*top=*/"F6", /*right=*/"F8", /*bottom=*/"F7", /*left=*/"F5");
DrawCircleMenuHint(out, kDpad, PANEL_LEFT + kCircleMarginX, PANEL_TOP - kCirclesTop);

10
SourceX/controls/touch.cpp

@ -4,11 +4,6 @@
#include "../../defs.h"
#include <math.h>
#ifdef __vita__
#include "../3rdParty/Storm/Source/storm.h"
static bool back_touch = false;
#endif
static int visible_width;
static int visible_height;
static int x_borderwidth;
@ -93,9 +88,6 @@ static void init_touch(void)
visible_width = (current.h * dvl::gnScreenWidth) / dvl::gnScreenHeight;
x_borderwidth = (current.w - visible_width) / 2;
y_borderwidth = (current.h - visible_height) / 2;
#ifdef __vita__
back_touch = dvl::getIniBool("controls", "enable_second_touchscreen", true);
#endif
}
static void preprocess_events(SDL_Event *event)
@ -114,7 +106,7 @@ static void preprocess_events(SDL_Event *event)
SDL_TouchID port = event->tfinger.touchId;
if (port != 0) {
#ifdef __vita__
if (back_touch) {
if (dvl::sgOptions.Controller.bRearTouch) {
switch (event->type) {
case SDL_FINGERDOWN:
preprocess_back_finger_down(event);

10
SourceX/display.cpp

@ -132,17 +132,11 @@ bool SpawnWindow(const char *lpWindowName)
}
#ifndef USE_SDL1
char mapping[1024];
memset(mapping, 0, 1024);
getIniValue("controls", "sdl2_controller_mapping", mapping, 1024);
if (mapping[0] != '\0') {
SDL_GameControllerAddMapping(mapping);
if (sgOptions.Controller.szMapping[0] != '\0') {
SDL_GameControllerAddMapping(sgOptions.Controller.szMapping);
}
#endif
dpad_hotkeys = getIniBool("controls", "dpad_hotkeys");
switch_potions_and_clicks = getIniBool("controls", "switch_potions_and_clicks");
#ifdef USE_SDL1
SDL_EnableUNICODE(1);
#endif

Loading…
Cancel
Save