Jeck - Language is now a per-profile option settable in the options menu. Also, game no longer crashes when no language files are present.
This commit is contained in:
@@ -23,7 +23,6 @@ public:
|
||||
enum {
|
||||
//Global settings
|
||||
ACTIVE_PROFILE,
|
||||
LANG,
|
||||
DIFFICULTY_MODE_UNLOCKED,
|
||||
MOMIR_MODE_UNLOCKED,
|
||||
EVILTWIN_MODE_UNLOCKED,
|
||||
@@ -31,6 +30,7 @@ public:
|
||||
LAST_GLOBAL = RANDOMDECK_MODE_UNLOCKED,
|
||||
//Values /must/ match ordering in optionNames, or everything loads wrong.
|
||||
//Profile settings
|
||||
LANG,
|
||||
ACTIVE_THEME,
|
||||
ACTIVE_MODE,
|
||||
MUSICVOLUME,
|
||||
|
||||
@@ -43,7 +43,7 @@ class GameStateMenu: public GameState, public JGuiListener
|
||||
void setLang(int id);
|
||||
string getLang(string s);
|
||||
void loadLangMenu();
|
||||
|
||||
bool langChoices;
|
||||
public:
|
||||
GameStateMenu(GameApp* parent);
|
||||
virtual ~GameStateMenu();
|
||||
|
||||
@@ -408,11 +408,28 @@ class OptionSelect:public OptionItem{
|
||||
size_t prior_value;
|
||||
};
|
||||
|
||||
class OptionLanguage: public OptionSelect{
|
||||
public:
|
||||
OptionLanguage(string _displayValue);
|
||||
|
||||
virtual void addSelection(string s) {addSelection(s,s);};
|
||||
virtual void addSelection(string s,string show);
|
||||
virtual void initSelections();
|
||||
virtual void confirmChange(bool confirmed);
|
||||
virtual void Reload();
|
||||
virtual bool Visible();
|
||||
virtual bool Selectable();
|
||||
virtual void setData();
|
||||
protected:
|
||||
vector<string> actual_data;
|
||||
};
|
||||
|
||||
|
||||
class OptionDirectory:public OptionSelect{
|
||||
public:
|
||||
virtual void Reload();
|
||||
OptionDirectory(string _root, int _id, string _displayValue);
|
||||
private:
|
||||
protected:
|
||||
string root;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
const char * Options::optionNames[] = {
|
||||
//Global options
|
||||
"Profile",
|
||||
"Lang",
|
||||
"prx_handler",
|
||||
"prx_rimom",
|
||||
"prx_eviltwin",
|
||||
"prx_rnddeck",
|
||||
//Options set on a per-profile basis
|
||||
"Lang",
|
||||
"Theme",
|
||||
"Mode",
|
||||
"musicVolume",
|
||||
|
||||
@@ -73,6 +73,7 @@ GameStateMenu::GameStateMenu(GameApp* parent): GameState(parent)
|
||||
yW = 55;
|
||||
mVolume = 0;
|
||||
scroller = NULL;
|
||||
langChoices = false;
|
||||
}
|
||||
|
||||
GameStateMenu::~GameStateMenu() {}
|
||||
@@ -303,6 +304,7 @@ void GameStateMenu::loadLangMenu(){
|
||||
file.close();
|
||||
}
|
||||
if (lang.size()){
|
||||
langChoices = true;
|
||||
string filen = mDit->d_name;
|
||||
langs.push_back(filen.substr(0,filen.size()-4));
|
||||
subMenuController->Add(langs.size(),lang.c_str());
|
||||
@@ -319,7 +321,12 @@ void GameStateMenu::Update(float dt)
|
||||
if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR)) {
|
||||
if (!subMenuController) loadLangMenu();
|
||||
}
|
||||
subMenuController->Update(dt);
|
||||
if(!langChoices){
|
||||
currentState = MENU_STATE_MAJOR_LOADING_CARDS;
|
||||
SAFE_DELETE(subMenuController);
|
||||
}
|
||||
else
|
||||
subMenuController->Update(dt);
|
||||
break;
|
||||
case MENU_STATE_MAJOR_LOADING_CARDS :
|
||||
if (mReadConf){
|
||||
|
||||
@@ -46,6 +46,9 @@ void GameStateOptions::Start()
|
||||
|
||||
optionsList = NEW WGuiList("Game");
|
||||
optionsList->Add(NEW WGuiHeader("Interface Options"));
|
||||
WDecoConfirm * cLang = NEW WDecoConfirm(this,NEW OptionLanguage("Language"));
|
||||
cLang->confirm = "Use this Language";
|
||||
optionsList->Add(cLang);
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::CLOSEDHAND,"Closed hand",1,1,0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::HANDDIRECTION,"Hand direction",1,1,0)));
|
||||
optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::MANADISPLAY,"Mana display",2,1,0)));
|
||||
@@ -120,6 +123,8 @@ void GameStateOptions::Update(float dt)
|
||||
}
|
||||
if(mReload){
|
||||
options.reloadProfile(true);
|
||||
Translator::EndInstance();
|
||||
Translator::GetInstance()->init();
|
||||
optionsTabs->Reload();
|
||||
mReload = false;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,91 @@ void OptionProfile::confirmChange(bool confirmed){
|
||||
}
|
||||
return;
|
||||
}
|
||||
//OptionLanguage
|
||||
OptionLanguage::OptionLanguage(string _displayValue) : OptionSelect(Options::LANG,_displayValue)
|
||||
{
|
||||
Reload();
|
||||
initSelections();
|
||||
};
|
||||
|
||||
void OptionLanguage::setData(){
|
||||
if(id == INVALID_OPTION) return;
|
||||
|
||||
if (value < selections.size()){
|
||||
options[id] = GameOption(actual_data[value]);
|
||||
Translator::EndInstance();
|
||||
Translator::GetInstance()->init();
|
||||
}
|
||||
}
|
||||
void OptionLanguage::confirmChange(bool confirmed){
|
||||
if(!confirmed)
|
||||
value = prior_value;
|
||||
else{
|
||||
setData();
|
||||
if(Changed()){
|
||||
options[id] = GameOption(actual_data[value]);
|
||||
Translator::EndInstance();
|
||||
Translator::GetInstance()->init();
|
||||
}
|
||||
prior_value = value;
|
||||
}
|
||||
}
|
||||
void OptionLanguage::Reload(){
|
||||
struct dirent *mDit;
|
||||
DIR *mDip;
|
||||
|
||||
mDip = opendir("Res/lang");
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
string filename = "Res/lang/";
|
||||
filename += mDit->d_name;
|
||||
std::ifstream file(filename.c_str());
|
||||
string s;
|
||||
string lang;
|
||||
if(file){
|
||||
if(std::getline(file,s)){
|
||||
if (!s.size()){
|
||||
lang = "";
|
||||
}else{
|
||||
if (s[s.size()-1] == '\r')
|
||||
s.erase(s.size()-1); //Handle DOS files
|
||||
size_t found = s.find("#LANG:");
|
||||
if (found != 0) lang = "";
|
||||
else lang = s.substr(6);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
if (lang.size()){
|
||||
string filen = mDit->d_name;
|
||||
addSelection(filen.substr(0,filen.size()-4),lang);
|
||||
}
|
||||
}
|
||||
closedir(mDip);
|
||||
initSelections();
|
||||
}
|
||||
void OptionLanguage::addSelection(string s,string show){
|
||||
selections.push_back(show);
|
||||
actual_data.push_back(s);
|
||||
}
|
||||
void OptionLanguage::initSelections(){
|
||||
//Find currently active bit in the list.
|
||||
for(size_t i=0;i<actual_data.size();i++){
|
||||
if(actual_data[i] == options[id].str)
|
||||
value = i;
|
||||
}
|
||||
}
|
||||
bool OptionLanguage::Visible(){
|
||||
if(selections.size() > 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool OptionLanguage::Selectable(){
|
||||
if(selections.size() > 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
//OptionDirectory
|
||||
void OptionDirectory::Reload(){
|
||||
DIR *mDip;
|
||||
|
||||
Reference in New Issue
Block a user