1
0
mirror of https://github.com/blawar/ooot.git synced 2024-06-28 07:24:04 +00:00

implemented language setting in config.json

This commit is contained in:
Blake Warner 2022-04-06 21:04:42 -04:00
parent 2277fb7a1e
commit 455e16dcf4
17 changed files with 136 additions and 96 deletions

View File

@ -5,9 +5,20 @@
struct OcarinaStaff;
typedef enum { TEXTBOX_ICON_TRIANGLE, TEXTBOX_ICON_SQUARE, TEXTBOX_ICON_ARROW } TextBoxIcon;
enum TextBoxIcon
{
TEXTBOX_ICON_TRIANGLE,
TEXTBOX_ICON_SQUARE,
TEXTBOX_ICON_ARROW
};
typedef enum { LANGUAGE_ENG, LANGUAGE_GER, LANGUAGE_FRA, LANGUAGE_MAX } Language;
enum Language
{
LANGUAGE_ENG,
LANGUAGE_GER,
LANGUAGE_FRA,
LANGUAGE_MAX
};
// TODO get these properties from the textures themselves
#define FONT_CHAR_TEX_WIDTH 16

View File

@ -352,6 +352,7 @@ namespace oot::save
/* 0x1406 */ u16 minigameScore; // "yabusame_total"
/* 0x1408 */ char unk_1408[0x0001];
/* 0x1409 */ u8 language; // NTSC 0: Japanese; 1: English | PAL 0: English; 1: German; 2: French
/* 0x1409 */ u8 saveLanguage; // NTSC 0: Japanese; 1: English | PAL 0: English; 1: German; 2: French
/* 0x140A */ u8 audioSetting;
/* 0x140B */ char unk_140B[0x0001];
/* 0x140C */ u8 zTargetSetting; // 0: Switch; 1: Hold

View File

@ -3334,16 +3334,9 @@ void Message_SetTables(void) {
}
}
static u8 g_currentLanguage = 0;
u8 Get_Language()
{
return gSaveContext.language;
}
void Set_Language(u8 language_id)
{
g_currentLanguage = gSaveContext.language = language_id % LANGUAGE_MAX;
gSaveContext.language = language_id % LANGUAGE_MAX;
Message_SetTables();
}

View File

@ -4722,23 +4722,6 @@ void Interface_Update(GlobalContext* globalCtx)
s16 alpha;
s16 alpha1;
u16 action;
Input* debugInput = &globalCtx->state.input[2];
if(CHECK_BTN_ALL(debugInput->press.button, BTN_DLEFT))
{
Set_Language(LANGUAGE_ENG);
osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language);
}
else if(CHECK_BTN_ALL(debugInput->press.button, BTN_DUP))
{
Set_Language(LANGUAGE_GER);
osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language);
}
else if(CHECK_BTN_ALL(debugInput->press.button, BTN_DRIGHT))
{
Set_Language(LANGUAGE_FRA);
osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language);
}
if((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0))
{

View File

@ -21,8 +21,6 @@
oot::save::Context gSaveContext;
void Set_Language(u8 language_id);
namespace oot::save
{
// these are the main substructs of save context.
@ -594,9 +592,6 @@ namespace oot::save
if(!isValidMagic())
{
osSyncPrintf("SRAM Destruction!!!!!!\n"); // "SRAM destruction! ! ! ! ! !"
#ifdef USE_SAVE_LANGUAGE
Set_Language(sramCtx->readBuff[SRAM_HEADER_LANGUAGE]);
#endif
memcpy(header.magic, sZeldaMagic + 3, sizeof(sZeldaMagic) - 3);
header.language = slot.language;
save();
@ -605,13 +600,8 @@ namespace oot::save
slot.audioSetting = header.sound & 3;
slot.zTargetSetting = header.ztarget & 1;
#ifdef USE_SAVE_LANGUAGE
Set_Language(sramCtx->readBuff[SRAM_HEADER_LANGUAGE]);
#endif
if(slot.language >= LANGUAGE_MAX)
{
Set_Language(LANGUAGE_ENG);
header.language = slot.language;
save();
}
@ -794,7 +784,7 @@ namespace oot::save
s.minigameState = this->minigameState;
s.minigameScore = this->minigameScore;
memcpy(s.unk_1408, this->unk_1408, sizeof(unk_1408));
s.language = this->language;
s.language = this->saveLanguage;
s.audioSetting = this->audioSetting;
memcpy(s.unk_140B, this->unk_140B, sizeof(unk_140B));
s.zTargetSetting = this->zTargetSetting;
@ -930,7 +920,7 @@ namespace oot::save
this->minigameState = s.minigameState;
this->minigameScore = s.minigameScore;
memcpy(this->unk_1408, s.unk_1408, sizeof(unk_1408));
this->language = s.language;
this->saveLanguage = s.language;
this->audioSetting = s.audioSetting;
memcpy(this->unk_140B, s.unk_140B, sizeof(unk_140B));
this->zTargetSetting = s.zTargetSetting;
@ -964,7 +954,6 @@ namespace oot::save
void Context::init()
{
u8 currentLanguage = 0; // Get_Language(); TODO FIX
Slot emptySlot;
memset(&emptySlot, 0, sizeof(emptySlot));
load(emptySlot);
@ -979,6 +968,6 @@ namespace oot::save
dogIsLost = true;
nextTransition = 0xFF;
unk_13EE = 50;
language = currentLanguage;
language = oot::config().game().language();
}
} // namespace oot::save

View File

@ -32,9 +32,6 @@
#include "def/z_vr_box_draw.h"
#include "def/z_play.h" // FORCE
void Set_Language(u8 language_id);
u8 Get_Language();
extern u16 gSramSlotOffsets[];
static s16 sUnused = 106;

View File

@ -347,12 +347,12 @@ namespace oot::hid
return value * (oot::config().controls().mouseyInvert() ? -1 : 1) * oot::config().controls().mouseyScaler();
}
bool Controller::updateRebind(int input)
bool Controller::updateRebind(hid::Button input)
{
return false;
}
void Controller::processKey(int input)
void Controller::processKey(hid::Button input)
{
if(input > 0xFFFF)
{
@ -386,7 +386,7 @@ namespace oot::hid
}
}
void Controller::processKeyDown(int input)
void Controller::processKeyDown(hid::Button input)
{
switch(input)
{
@ -417,10 +417,13 @@ namespace oot::hid
case Button::CENTER_CAMERA:
oot::state.center_camera = true;
break;
case LANGUAGE_TOGGLE:
config().game().setLanguage((Language)((int)config().game().language() + 1));
break;
}
}
void Controller::processKeyUp(int input)
void Controller::processKeyUp(hid::Button input)
{
switch(input)
{
@ -479,7 +482,7 @@ namespace oot::hid
namespace controller
{
const char* getInputName(Button input)
const char* getInputName(hid::Button input)
{
switch(input)
{
@ -517,6 +520,8 @@ namespace oot::hid
return "DEBUG_MENU";
case Button::FAST_FORWARD:
return "FAST_FORWARD";
case Button::LANGUAGE_TOGGLE:
return "LANGUAGE_TOGGLE";
case Button::CENTER_CAMERA:
return "CENTER_CAMERA";
case Button::CURRENT_ACTION:
@ -583,6 +588,8 @@ namespace oot::hid
return Button::DEBUG_MENU;
if(input == "FAST_FORWARD")
return Button::FAST_FORWARD;
if(input == "LANGUAGE_TOGGLE")
return Button::LANGUAGE_TOGGLE;
if(input == "OCARINA")
return Button::OCARINA;
if(input == "HOOKSHOT")

View File

@ -4,7 +4,7 @@
namespace oot::hid
{
enum Button
enum Button : s64
{
EMPTY_BUTTON = 0,
CONT_A = 0x8000,
@ -36,23 +36,24 @@ namespace oot::hid
L_CBUTTONS = CONT_C,
R_CBUTTONS = CONT_F,
D_CBUTTONS = CONT_D,
STICK_X_LEFT = 1 << 16,
STICK_X_RIGHT = 1 << 17,
STICK_X_DOWN = 1 << 19,
STICK_X_UP = 1 << 18,
WALK_BUTTON = 1 << 20,
DEBUG_MENU = 1 << 21,
OCARINA = 1 << 22,
HOOKSHOT = 1 << 23,
BOW_ARROW = 1 << 24,
LENS_OF_TRUTH = 1 << 25,
BOOTS_TOGGLE = 1 << 26,
SWORD_TOGGLE = 1 << 27,
SHIELD_TOGGLE = 1 << 28,
TUNIC_TOGGLE = 1 << 29,
FAST_FORWARD = 1 << 30,
CENTER_CAMERA = 1 << 31,
CURRENT_ACTION = 1 << 32
STICK_X_LEFT = 1ULL << 16,
STICK_X_RIGHT = 1ULL << 17,
STICK_X_DOWN = 1ULL << 19,
STICK_X_UP = 1ULL << 18,
WALK_BUTTON = 1ULL << 20,
DEBUG_MENU = 1ULL << 21,
OCARINA = 1ULL << 22,
HOOKSHOT = 1ULL << 23,
BOW_ARROW = 1ULL << 24,
LENS_OF_TRUTH = 1ULL << 25,
BOOTS_TOGGLE = 1ULL << 26,
SWORD_TOGGLE = 1ULL << 27,
SHIELD_TOGGLE = 1ULL << 28,
TUNIC_TOGGLE = 1ULL << 29,
FAST_FORWARD = 1ULL << 30,
CENTER_CAMERA = 1ULL << 31,
CURRENT_ACTION = 1ULL << 32,
LANGUAGE_TOGGLE = 1ULL << 33
};
class State
@ -127,10 +128,10 @@ namespace oot::hid
virtual void ResetMotorPack();
virtual void SendMotorVib(int level);
virtual bool updateRebind(int input);
virtual void processKey(int input);
virtual void processKeyUp(int input);
virtual void processKeyDown(int input);
virtual bool updateRebind(hid::Button input);
virtual void processKey(hid::Button input);
virtual void processKeyUp(hid::Button input);
virtual void processKeyDown(hid::Button input);
protected:
virtual void vibrate();
@ -152,7 +153,7 @@ namespace oot::hid
namespace controller
{
const char* getInputName(Button input);
const char* getInputName(hid::Button input);
Button getInputValue(const std::string& input);
}
} // namespace oot::hid

View File

@ -41,7 +41,7 @@ namespace oot::hid
return *m_controllers[index];
}
bool Driver::updateRebind(int input)
bool Driver::updateRebind(hid::Button input)
{
bool result = 0;
for (auto& controller : m_controllers)
@ -75,7 +75,7 @@ namespace oot::hid
}
}
Controllers::Controllers() : m_rebindInput(0)
Controllers::Controllers() : m_rebindInput(Button::EMPTY_BUTTON)
{
#if defined(_MSC_VER)
if(oot::config().controls().useXInput() && !oot::config().controls().enableGyro())
@ -125,7 +125,7 @@ namespace oot::hid
if (result)
{
m_rebindInput = 0;
m_rebindInput = Button::EMPTY_BUTTON;
}
}
else
@ -158,7 +158,7 @@ namespace oot::hid
}
}
void Controllers::rebind(int input)
void Controllers::rebind(hid::Button input)
{
m_rebindInput = input;
}

View File

@ -15,7 +15,7 @@ namespace oot::hid
virtual const u64 size() const;
virtual Controller& controller(const u64 index);
virtual void update();
virtual bool updateRebind(int input);
virtual bool updateRebind(hid::Button input);
virtual void scan(class Controllers* controllers);
virtual void resetBindings();
virtual bool defaultOnly()
@ -41,7 +41,7 @@ namespace oot::hid
void update();
void scan();
bool isRebindMode() const;
void rebind(int input);
void rebind(hid::Button input);
void resetBindings();
std::vector<class Driver*>& drivers()
{
@ -50,7 +50,7 @@ namespace oot::hid
protected:
std::vector<class Driver*> m_drivers;
int m_rebindInput;
Button m_rebindInput;
};
Controllers& controllers();

View File

@ -110,6 +110,7 @@ namespace oot::hid
m_keyBindings[SDL_SCANCODE_F5] = Button::DEBUG_MENU;
m_keyBindings[SDL_SCANCODE_G] = Button::FAST_FORWARD;
m_keyBindings[SDL_SCANCODE_F9] = Button::LANGUAGE_TOGGLE;
m_mouseBindings[SDL_BUTTON_LEFT] = Button::B_BUTTON;
m_mouseBindings[SDL_BUTTON_RIGHT] = Button::CENTER_CAMERA;
@ -288,7 +289,7 @@ namespace oot::hid
this->state().has_mouse = true;
}
bool canRebind(SDL_Scancode scancode, int input)
bool canRebind(SDL_Scancode scancode, hid::Button input)
{
if(m_keyBindings.count(scancode) == 0)
{
@ -309,7 +310,7 @@ namespace oot::hid
return count != 1;
}
bool updateRebind(int input) override
bool updateRebind(hid::Button input) override
{
int count = 0;
auto state = SDL_GetKeyboardState(&count);

View File

@ -284,7 +284,7 @@ namespace oot::hid
return convertToByte(value, g_rstickY_peak);
}
bool canRebind(SDL_GameControllerButton button, int input)
bool canRebind(SDL_GameControllerButton button, hid::Button input)
{
if(m_keyBindings.count(button) == 0)
{
@ -319,7 +319,7 @@ namespace oot::hid
return count != 1;
}
bool updateRebind(int input) override
bool updateRebind(hid::Button input) override
{
u8 state[SDL_CONTROLLER_BUTTON_MAX];

View File

@ -318,7 +318,7 @@ namespace oot::hid
resetBindingsImpl();
}
bool canRebind(XInputButtons button, int input)
bool canRebind(XInputButtons button, hid::Button input)
{
if(m_keyBindings.count(button) == 0)
{
@ -353,7 +353,7 @@ namespace oot::hid
return count != 1;
}
bool updateRebind(int input) override
bool updateRebind(hid::Button input) override
{
u8 state[MAX_BUTTONS];
XINPUT_STATE xstate;

View File

@ -16,6 +16,39 @@
#define CONFIG_JSON_FILE "config.json"
#endif
void Set_Language(u8 language_id);
std::string languageGetString(Language id)
{
switch(id)
{
case LANGUAGE_ENG:
return "en";
case LANGUAGE_FRA:
return "fr";
case LANGUAGE_GER:
return "de";
}
return "en";
}
Language languageGetId(const std::string& s)
{
if(s == "en")
{
return LANGUAGE_ENG;
}
else if(s == "fr")
{
return LANGUAGE_FRA;
}
else if(s == "de")
{
return LANGUAGE_GER;
}
return LANGUAGE_ENG;
}
namespace oot
{
static Options* g_options = nullptr;
@ -132,9 +165,11 @@ namespace oot
json::setBool(container, "recordTas", recordTas(), allocator);
json::setBool(container, "forceMouse", forceMouse(), allocator);
json::setBool(container, "enableExtendedOptionsMenu", enableExtendedOptionsMenu(), allocator);
json::setBool(container, "enablDebugLevelSelect", enablDebugLevelSelect(), allocator);
u64 m_pauseExitInputClearFrames;
u64 m_textScrollSpeed;
json::setBool(container, "enableDebugLevelSelect", enablDebugLevelSelect(), allocator);
json::setU64(container, "pauseExitInputClearFrames", pauseExitInputClearFrames(), allocator);
json::setU64(container, "textScrollSpeed", textScrollSpeed(), allocator);
json::set(container, "language", languageGetString(language()), allocator);
doc.AddMember(rapidjson::Value("game", allocator), container, allocator);
@ -154,10 +189,23 @@ namespace oot
json::getBool(container, "recordTas", recordTas());
json::getBool(container, "forceMouse", forceMouse());
json::getBool(container, "enableExtendedOptionsMenu", enableExtendedOptionsMenu());
json::getBool(container, "enablDebugLevelSelect", enablDebugLevelSelect());
json::getBool(container, "enableDebugLevelSelect", enablDebugLevelSelect());
json::getU64(container, "pauseExitInputClearFrames", pauseExitInputClearFrames());
json::getU64(container, "textScrollSpeed", textScrollSpeed());
std::string lang;
json::get(container, "language", lang);
setLanguage(languageGetId(lang));
}
}
void Game::setLanguage(Language id)
{
m_language = (Language)(id % LANGUAGE_MAX);
Set_Language(id);
}
const bool Game::mirror() const
{
if(!m_mirror)

View File

@ -3,6 +3,7 @@
#include <map>
#include "json.h"
#include "port/controller/controller.h"
#include "include/z64message.h"
namespace oot
{
@ -336,6 +337,13 @@ namespace oot
return m_textScrollSpeed;
}
const Language& language() const
{
return m_language;
}
void setLanguage(Language id);
protected:
bool m_graphicsEnabled = true;
bool m_audioEnabled = true;
@ -348,6 +356,7 @@ namespace oot
bool m_enablDebugLevelSelect = false;
u64 m_pauseExitInputClearFrames = 2;
u64 m_textScrollSpeed = 1;
Language m_language = LANGUAGE_ENG;
};
class Base

View File

@ -3,7 +3,7 @@
namespace oot
{
Player::Player() : m_rebindInput(0)
Player::Player() : m_rebindInput(hid::Button::EMPTY_BUTTON)
{
}
@ -44,12 +44,12 @@ namespace oot
if (result)
{
m_rebindInput = -10;
m_rebindInput = (hid::Button)-10;
}
}
else if (m_rebindInput < 0)
else if ((s64)m_rebindInput < 0)
{
m_rebindInput++;
m_rebindInput = (hid::Button)((s64)m_rebindInput + 1);
}
else
{
@ -68,7 +68,7 @@ namespace oot
m_controller.resolveInputs();
}
void Player::rebind(int input)
void Player::rebind(hid::Button input)
{
m_rebindInput = input;
}

View File

@ -25,14 +25,14 @@ namespace oot
return m_controller;
}
void rebind(int input);
void rebind(hid::Button input);
bool isRebindMode() const;
void SendMotorEvent(short time, short level, u8 decay = 0);
protected:
std::vector<std::shared_ptr<hid::Controller> > m_controllers;
hid::Controller m_controller;
int m_rebindInput;
hid::Button m_rebindInput;
};
} // namespace oot