Messagebox fix

This commit is contained in:
Mathew Velasquez 2016-12-15 02:08:23 -05:00
parent 99d0c2888a
commit d47a2241ee
4 changed files with 57 additions and 37 deletions

View file

@ -23,10 +23,12 @@ RB_METHOD(oneshotMsgBox)
RB_UNUSED_PARAM; RB_UNUSED_PARAM;
int type; int type;
const char *body; VALUE body;
const char *title = 0; VALUE title = Qnil;
rb_get_args(argc, argv, "iz|z", &type, &body, &title RB_ARG_END); rb_get_args(argc, argv, "iS|S", &type, &body, &title RB_ARG_END);
return rb_bool_new(shState->oneshot().msgbox(type, body, title)); std::string bodyStr = std::string(RSTRING_PTR(body), RSTRING_LEN(body));
std::string titleStr = (title == Qnil) ? "" : std::string(RSTRING_PTR(title), RSTRING_LEN(title));
return rb_bool_new(shState->oneshot().msgbox(type, bodyStr.c_str(), titleStr.c_str()));
} }
RB_METHOD(oneshotResetObscured) RB_METHOD(oneshotResetObscured)

View file

@ -66,7 +66,7 @@ win32 {
PKGCONFIG += sigc++-2.0 pixman-1 zlib \ PKGCONFIG += sigc++-2.0 pixman-1 zlib \
sdl2 SDL2_image SDL2_ttf openal SDL_sound vorbisfile freetype2 sdl2 SDL2_image SDL2_ttf openal SDL_sound vorbisfile freetype2
LIBS += -lphysfs -lsecur32 LIBS += -lphysfs -lsecur32 -lwinmm
release { release {
RC_FILE = assets/resources.rc RC_FILE = assets/resources.rc

View file

@ -1,40 +1,40 @@
module EdText module EdText
def self.blue_understand def self.blue_understand
Oneshot.msgbox Oneshot::Msg::YESNO, tr("Do you understand what this means?") self.msgbox(Oneshot::Msg::YESNO, tr("Do you understand what this means?"))
end end
def self.info(text) def self.info(text)
if(Graphics.fullscreen == true) # TODO tr text
Graphics.fullscreen = false self.msgbox(Oneshot::Msg::INFO, text)
$console = false
end
sleep 0.2
Graphics.update
text.gsub!("\\p", $game_oneshot.player_name)
Oneshot.msgbox Oneshot::Msg::INFO, tr(text)
Graphics.frame_reset
end end
def self.yesno(text) def self.yesno(text)
if(Graphics.fullscreen == true) # TODO tr text
Graphics.fullscreen = false self.msgbox(Oneshot::Msg::YESNO, text)
$console = false
end
sleep 0.2
Graphics.update
text.gsub!("\\p", $game_oneshot.player_name)
result = Oneshot.msgbox Oneshot::Msg::YESNO, tr(text)
Graphics.frame_reset
return result
end end
def self.err(text) def self.err(text)
if(Graphics.fullscreen == true) # TODO tr text
Graphics.fullscreen = false self.msgbox(Oneshot::Msg::ERR, text)
$console = false end
end
sleep 0.2 def self.msgbox(type, text)
Graphics.update if Graphics.fullscreen
text.gsub!("\\p", $game_oneshot.player_name) Graphics.fullscreen = false
result = Oneshot.msgbox Oneshot::Msg::ERR, tr(text) $console = false
Graphics.frame_reset sleep 0.2
return result end
result = nil
thread = Thread.new do
result = Oneshot.msgbox(type, text
.gsub(/\s+\n\s+/, " ")
.gsub("\\p", $game_oneshot.player_name) +
" " * 10)
# HACK: Fuck
end
while thread.alive?
Graphics.update
end
result
end end
end end

View file

@ -15,6 +15,7 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define SECURITY_WIN32 #define SECURITY_WIN32
#include <windows.h> #include <windows.h>
#include <mmsystem.h>
#include <security.h> #include <security.h>
#include <shlobj.h> #include <shlobj.h>
#include <SDL2/SDL_syswm.h> #include <SDL2/SDL_syswm.h>
@ -637,7 +638,7 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
{ {
if (!title) if (!title)
title = ""; title = "";
#if defined OS_W32 #if 0
//Get native window handle //Get native window handle
SDL_SysWMinfo wminfo; SDL_SysWMinfo wminfo;
SDL_version version; SDL_version version;
@ -667,7 +668,7 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
//Create message box //Create message box
WCHAR *wbody = w32_toWide(body); WCHAR *wbody = w32_toWide(body);
WCHAR *wtitle = w32_toWide(title); WCHAR *wtitle = w32_toWide(title);
int result = MessageBoxW(hwnd, wbody, wtitle, flags); int result = MessageBoxW(N, wbody, wtitle, flags);
delete [] title; delete [] title;
delete [] body; delete [] body;
@ -698,19 +699,32 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
data.colorScheme = 0; data.colorScheme = 0;
data.title = title; data.title = title;
data.message = body; data.message = body;
#ifdef OS_W32
DWORD sound;
#endif
//Set type //Set type
switch (type) switch (type)
{ {
case MSG_INFO: case MSG_INFO:
case MSG_YESNO: case MSG_YESNO:
default:
data.flags = SDL_MESSAGEBOX_INFORMATION; data.flags = SDL_MESSAGEBOX_INFORMATION;
#ifdef OS_W32
sound = SND_ALIAS_SYSTEMQUESTION;
#endif
break; break;
case MSG_WARN: case MSG_WARN:
data.flags = SDL_MESSAGEBOX_WARNING; data.flags = SDL_MESSAGEBOX_WARNING;
#ifdef OS_W32
sound = SND_ALIAS_SYSTEMEXCLAMATION;
#endif
break; break;
case MSG_ERR: case MSG_ERR:
data.flags = SDL_MESSAGEBOX_WARNING; data.flags = SDL_MESSAGEBOX_WARNING;
#ifdef OS_W32
sound = SND_ALIAS_SYSTEMASTERISK;
#endif
break; break;
} }
@ -720,6 +734,7 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
case MSG_INFO: case MSG_INFO:
case MSG_WARN: case MSG_WARN:
case MSG_ERR: case MSG_ERR:
default:
data.numbuttons = 1; data.numbuttons = 1;
data.buttons = buttonsOk; data.buttons = buttonsOk;
break; break;
@ -730,6 +745,9 @@ bool Oneshot::msgbox(int type, const char *body, const char *title)
} }
//Show messagebox //Show messagebox
#ifdef OS_W32
PlaySoundW((LPCWSTR)sound, NULL, SND_ALIAS_ID | SND_ASYNC);
#endif
int button; int button;
SDL_ShowMessageBox(&data, &button); SDL_ShowMessageBox(&data, &button);
return button ? true : false; return button ? true : false;