Commit fdab949e authored by mercury233's avatar mercury233 Committed by GitHub

add switch for prefer expansion script (#2169)

parent ca6f8e9c
#include "data_manager.h"
#include "game.h"
#include <stdio.h>
namespace ygo {
......@@ -311,12 +312,20 @@ int DataManager::CardReader(int code, void* pData) {
return 0;
}
byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
char exname[256] = "./expansions";
strcat(exname, script_name + 1);//default script name: ./script/c%d.lua
if(ScriptReader(exname, slen))
// default script name: ./script/c%d.lua
char first[256];
char second[256];
if(mainGame->gameConf.prefer_expansion_script) {
sprintf(first, "expansions/%s", script_name + 2);
sprintf(second, "%s", script_name + 2);
} else {
sprintf(first, "%s", script_name + 2);
sprintf(second, "expansions/%s", script_name + 2);
}
if(ScriptReader(first, slen))
return scriptBuffer;
else
return ScriptReader(script_name, slen);
return ScriptReader(second, slen);
}
byte* DataManager::ScriptReader(const char* script_name, int* slen) {
FILE *fp;
......
......@@ -1828,6 +1828,11 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
break;
}
case CHECKBOX_PREFER_EXPANSION: {
mainGame->gameConf.prefer_expansion_script = mainGame->chkPreferExpansionScript->isChecked() ? 1 : 0;
return true;
break;
}
}
break;
}
......
......@@ -294,6 +294,9 @@ bool Game::Initialize() {
chkMultiKeywords = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_MULTI_KEYWORDS, dataManager.GetSysString(1378));
chkMultiKeywords->setChecked(gameConf.search_multiple_keywords > 0);
posY += 30;
chkPreferExpansionScript = env->addCheckBox(false, rect<s32>(posX, posY, posX + 260, posY + 25), tabSystem, CHECKBOX_PREFER_EXPANSION, dataManager.GetSysString(1379));
chkPreferExpansionScript->setChecked(gameConf.prefer_expansion_script != 0);
posY += 30;
chkEnableSound = env->addCheckBox(gameConf.enable_sound, rect<s32>(posX, posY, posX + 120, posY + 25), tabSystem, -1, dataManager.GetSysString(1279));
chkEnableSound->setChecked(gameConf.enable_sound);
scrSoundVolume = env->addScrollBar(true, rect<s32>(posX + 126, posY + 4, posX + 260, posY + 21), tabSystem, SCROLL_VOLUME);
......@@ -981,6 +984,7 @@ void Game::LoadConfig() {
gameConf.enable_bot_mode = 0;
gameConf.quick_animation = 0;
gameConf.auto_save_replay = 0;
gameConf.prefer_expansion_script = 0;
gameConf.enable_sound = true;
gameConf.sound_volume = 0.5;
gameConf.enable_music = true;
......@@ -1054,6 +1058,8 @@ void Game::LoadConfig() {
gameConf.quick_animation = atoi(valbuf);
} else if(!strcmp(strbuf, "auto_save_replay")) {
gameConf.auto_save_replay = atoi(valbuf);
} else if(!strcmp(strbuf, "prefer_expansion_script")) {
gameConf.prefer_expansion_script = atoi(valbuf);
#ifdef YGOPRO_USE_IRRKLANG
} else if(!strcmp(strbuf, "enable_sound")) {
gameConf.enable_sound = atoi(valbuf) > 0;
......@@ -1130,6 +1136,7 @@ void Game::SaveConfig() {
fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode);
fprintf(fp, "quick_animation = %d\n", gameConf.quick_animation);
fprintf(fp, "auto_save_replay = %d\n", (chkAutoSaveReplay->isChecked() ? 1 : 0));
fprintf(fp, "prefer_expansion_script = %d\n", gameConf.prefer_expansion_script);
#ifdef YGOPRO_USE_IRRKLANG
fprintf(fp, "enable_sound = %d\n", (chkEnableSound->isChecked() ? 1 : 0));
fprintf(fp, "enable_music = %d\n", (chkEnableMusic->isChecked() ? 1 : 0));
......
......@@ -45,6 +45,7 @@ struct Config {
int enable_bot_mode;
int quick_animation;
int auto_save_replay;
int prefer_expansion_script;
bool enable_sound;
bool enable_music;
double sound_volume;
......@@ -248,6 +249,7 @@ public:
irr::gui::IGUICheckBox* chkIgnoreDeckChanges;
irr::gui::IGUICheckBox* chkAutoSearch;
irr::gui::IGUICheckBox* chkMultiKeywords;
irr::gui::IGUICheckBox* chkPreferExpansionScript;
irr::gui::IGUICheckBox* chkEnableSound;
irr::gui::IGUICheckBox* chkEnableMusic;
irr::gui::IGUIScrollBar* scrSoundVolume;
......@@ -626,6 +628,7 @@ extern Game* mainGame;
#define BUTTON_CANCEL_SINGLEPLAY 352
#define CHECKBOX_AUTO_SEARCH 360
#define CHECKBOX_MULTI_KEYWORDS 372
#define CHECKBOX_PREFER_EXPANSION 373
#define CHECKBOX_ENABLE_SOUND 361
#define CHECKBOX_ENABLE_MUSIC 362
#define SCROLL_VOLUME 363
......
......@@ -399,6 +399,7 @@
!system 1373 名称↓
!system 1374 连接标记
!system 1378 使用多个关键词搜索卡片
!system 1379 启用扩展卡包调试模式
!system 1380 人机模式
!system 1381 残局模式
!system 1382 人机信息:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment