Commit 553330c7 authored by mercury233's avatar mercury233

add reading single puzzle message

parent fdab949e
......@@ -623,7 +623,7 @@ bool Game::Initialize() {
btnLoadSinglePlay = env->addButton(rect<s32>(459, 301, 569, 326), tabSingle, BUTTON_LOAD_SINGLEPLAY, dataManager.GetSysString(1211));
btnSinglePlayCancel = env->addButton(rect<s32>(459, 331, 569, 356), tabSingle, BUTTON_CANCEL_SINGLEPLAY, dataManager.GetSysString(1210));
env->addStaticText(dataManager.GetSysString(1352), rect<s32>(360, 10, 550, 30), false, true, tabSingle);
stSinglePlayInfo = env->addStaticText(L"", rect<s32>(360, 40, 550, 280), false, true, tabSingle);
stSinglePlayInfo = env->addStaticText(L"", rect<s32>(360, 40, 560, 280), false, true, tabSingle);
//replay save
wReplaySave = env->addWindow(rect<s32>(510, 200, 820, 320), false, dataManager.GetSysString(1340));
wReplaySave->getCloseButton()->setVisible(false);
......@@ -898,6 +898,7 @@ void Game::RefreshReplay() {
}
void Game::RefreshSingleplay() {
lstSinglePlayList->clear();
stSinglePlayInfo->setText(L"");
FileSystem::TraversalDir(L"./single", [this](const wchar_t* name, bool isdir) {
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".lua", 4))
lstSinglePlayList->addItem(name);
......
......@@ -457,6 +457,55 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->SetStaticText(mainGame->stReplayInfo, 180, mainGame->guiFont, repinfo.c_str());
break;
}
case LISTBOX_SINGLEPLAY_LIST: {
int sel = mainGame->lstSinglePlayList->getSelected();
if(sel == -1)
break;
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel);
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
FILE *fp;
#ifdef _WIN32
fp = _wfopen(fname, L"rb");
#else
char filename[256];
BufferIO::EncodeUTF8(fname, filename);
fp = fopen(filename, "rb");
#endif
if(!fp) {
mainGame->stSinglePlayInfo->setText(L"");
break;
}
char linebuf[1024];
wchar_t wlinebuf[1024];
std::wstring message = L"";
bool in_message = false;
while(fgets(linebuf, 1024, fp)) {
if(!strnicmp(linebuf, "--[[message", 11)) {
size_t len = strlen(linebuf);
char* msgend = strrchr(linebuf, ']');
if(len <= 13) {
in_message = true;
continue;
} else if(len > 15 && msgend) {
*(msgend - 1) = '\0';
BufferIO::DecodeUTF8(linebuf + 12, wlinebuf);
message.append(wlinebuf);
break;
}
}
if(!strncmp(linebuf, "]]", 2)) {
in_message = false;
break;
}
if(in_message) {
BufferIO::DecodeUTF8(linebuf, wlinebuf);
message.append(wlinebuf);
}
}
mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str());
break;
}
case LISTBOX_BOT_LIST: {
int sel = mainGame->lstBotList->getSelected();
if(sel == -1)
......
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