Skip to content

Instantly share code, notes, and snippets.

@xyx0no646
Last active August 10, 2021 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyx0no646/5521bf6c61ee54db5bd1343b2c364bcf to your computer and use it in GitHub Desktop.
Save xyx0no646/5521bf6c61ee54db5bd1343b2c364bcf to your computer and use it in GitHub Desktop.
#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