Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions platforms/ios/AppPlatform_iOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AppPlatform_iOS : public AppPlatform

// Also add these to allow saving options.
bool hasFileSystemAccess() override;

void showMessageModal(const MessageModal& msg) override;
private:
Logger* m_pLogger;
SoundSystem* m_pSoundSystem;
Expand Down
29 changes: 29 additions & 0 deletions platforms/ios/AppPlatform_iOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,32 @@

return [assetPath UTF8String];
}

void AppPlatform_iOS::showMessageModal(const MessageModal& msg)
{
NSString *title;
switch(msg.type)
{
case MessageModal::TYPE_ERROR:
title = @"Error";
break;
default:
LOG_W("Unhandled MessageModal type");
// fall through
case MessageModal::TYPE_INFO:
title = @"Info";
break;
}

// this doesn't block the thread, it should
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:[NSString stringWithCString:msg.text.c_str()
encoding:[NSString defaultCStringEncoding]]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil
];
[alert show];
[alert release];
}
24 changes: 24 additions & 0 deletions platforms/sdl/sdl2/base/AppPlatform_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,27 @@ bool AppPlatform_sdl2::GetMouseButtonState(const SDL_Event& event)

return result;
}

// this segfaults on wsl, why?
void AppPlatform_sdl2::showMessageModal(const MessageModal& msg)
{
const char *title;
Uint32 flags = 0;

switch (msg.type)
{
case MessageModal::TYPE_ERROR:
title = "Error";
flags = SDL_MESSAGEBOX_ERROR;
break;
default:
LOG_W("Unhandled MessageModal type");
// fall through
case MessageModal::TYPE_INFO:
title = "Info";
flags = SDL_MESSAGEBOX_INFORMATION;
break;
}

SDL_ShowSimpleMessageBox(flags, title, msg.text.c_str(), nullptr);
}
2 changes: 2 additions & 0 deletions platforms/sdl/sdl2/base/AppPlatform_sdl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class AppPlatform_sdl2 : public AppPlatform_sdl
void gameControllerAdded(int32_t index);
void gameControllerRemoved(int32_t index);

void showMessageModal(const MessageModal& msg) override;

public:
static bool GetMouseButtonState(const SDL_Event& event);

Expand Down
23 changes: 23 additions & 0 deletions platforms/windows/AppPlatform_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,26 @@ Keyboard::KeyState AppPlatform_win32::GetKeyState(UINT iMsg)
return Keyboard::KeyState::DOWN;
}
}

void AppPlatform_win32::showMessageModal(const MessageModal& msg)
{
const char *title;
uint32_t flags = 0;

switch (msg.type)
{
case MessageModal::TYPE_ERROR:
title = "Error";
flags = MB_ICONERROR;
break;
default:
LOG_W("Unhandled MessageModal type");
// fall through
case MessageModal::TYPE_INFO:
title = "Info";
flags = MB_ICONINFORMATION;
break;
}

MessageBoxA(NULL, msg.text.c_str(), title, flags);
}
2 changes: 2 additions & 0 deletions platforms/windows/AppPlatform_win32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class AppPlatform_win32 : public AppPlatform
static bool GetMouseButtonState(UINT iMsg, WPARAM wParam);
static Keyboard::KeyState GetKeyState(UINT iMsg);

void showMessageModal(const MessageModal& msg) override;

private:
HICON m_cursor;

Expand Down
19 changes: 19 additions & 0 deletions source/client/app/AppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,22 @@ void AppPlatform::beginProfileDataWrite(unsigned int playerId)
void AppPlatform::endProfileDataWrite(unsigned int playerId)
{
}

void AppPlatform::showMessageModal(const MessageModal& msg)
{
FILE *stream;
switch(msg.type)
{
case MessageModal::TYPE_ERROR:
stream = stderr;
break;
default:
LOG_W("Unhandled MessageModal type");
// fall through
case MessageModal::TYPE_INFO:
stream = stdout;
break;
}

fputs(msg.text.c_str(), stream);
}
21 changes: 21 additions & 0 deletions source/client/app/AppPlatform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@
#define C_HOME_PATH "/games/com.mojang/"
#define C_MAX_LOCAL_PLAYERS 4

struct MessageModal
{
enum Type
{
TYPE_INFO,
TYPE_ERROR
};

Type type;
std::string text;

MessageModal(Type type, const std::string& text)
: type(type)
, text(text)
{
}
};


class GameControllerHandler;
class AppPlatformListener;

Expand Down Expand Up @@ -135,6 +154,8 @@ class AppPlatform
virtual void beginProfileDataWrite(unsigned int playerId);
virtual void endProfileDataWrite(unsigned int playerId);

virtual void showMessageModal(const MessageModal& msg);

public:
ListenerMap m_listeners;
std::string m_externalStorageDir;
Expand Down
3 changes: 3 additions & 0 deletions source/client/gui/screens/CreditsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ void CreditsScreen::_initCreditsText()
{
m_credits.push_back("Failed to load credits.txt");
}

// for testing only, should not make it into master, remove if found
AppPlatform::singleton()->showMessageModal(MessageModal(MessageModal::TYPE_INFO, "death"));
}

void CreditsScreen::init()
Expand Down