-
-
Save xyx0no646/5521bf6c61ee54db5bd1343b2c364bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ncbind/ncbind.hpp" | |
#include "CharacterSet.h" | |
#include <SDL.h> | |
/** | |
* 同期モードで動くYesNoDialogプラグイン | |
* Licenced by CC0 | |
* Created by http://twitter.com/xyx0no646 | |
* | |
* usage: | |
* KrkrUIAlert.askYesNo("テスト","これはテストですね"); | |
*/ | |
class KrkrUIAlert { | |
public: | |
static tjs_int askYesNo(TJS::tTJSString tTitle,TJS::tTJSString tMessage) | |
{ | |
const SDL_MessageBoxButtonData buttons[] = { | |
{ /* .flags, .buttonid, .text */ 0, 0, "いいえ" }, | |
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "はい" }, | |
}; | |
const SDL_MessageBoxColorScheme colorScheme = { | |
{ /* .colors (.r, .g, .b) */ | |
/* [SDL_MESSAGEBOX_COLOR_BACKGROUND] */ | |
{ 255, 0, 0 }, | |
/* [SDL_MESSAGEBOX_COLOR_TEXT] */ | |
{ 0, 255, 0 }, | |
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BORDER] */ | |
{ 255, 255, 0 }, | |
/* [SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND] */ | |
{ 0, 0, 255 }, | |
/* [SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED] */ | |
{ 255, 0, 255 } | |
} | |
}; | |
std::string title; | |
TVPUtf16ToUtf8( title, tTJSString(tTitle).AsStdString() ); | |
std::string message; | |
TVPUtf16ToUtf8( message, tTJSString(tMessage).AsStdString()); | |
const SDL_MessageBoxData messageboxdata = { | |
SDL_MESSAGEBOX_INFORMATION, /* .flags */ | |
NULL, /* .window */ | |
title.c_str(), /* .title */ | |
message.c_str(), /* .message */ | |
SDL_arraysize(buttons), /* .numbuttons */ | |
buttons, /* .buttons */ | |
&colorScheme /* .colorScheme */ | |
}; | |
int buttonid; | |
if (SDL_ShowMessageBox(&messageboxdata, &buttonid) < 0) { | |
SDL_Log("メッセージボックスの表示に失敗した"); | |
return 1; | |
} | |
if (buttonid == -1) { | |
SDL_Log("選択されなかった"); | |
} else { | |
SDL_Log("%sが選択された", buttons[buttonid].text); | |
} | |
return buttonid; | |
} | |
}; | |
NCB_REGISTER_CLASS(KrkrUIAlert) { | |
NCB_CONSTRUCTOR(()); | |
NCB_METHOD(askYesNo); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment