Cloudsave support
This commit is contained in:
@@ -293,7 +293,7 @@ static const char * const _subdirs[] = {
|
||||
"game" PATHSEP,
|
||||
"game" PATHSEP "library" PATHSEP,
|
||||
#ifdef __ANDROID__
|
||||
"../../../../../../Pictures/",
|
||||
"screenshot" PATHSEP,
|
||||
#else
|
||||
"screenshot" PATHSEP,
|
||||
#endif
|
||||
|
||||
@@ -35,12 +35,16 @@
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
#ifdef __ANDROID__
|
||||
#include <SDL_android.h>
|
||||
#endif
|
||||
|
||||
SaveLoadDialogMode _saveload_mode;
|
||||
LoadCheckData _load_check_data; ///< Data loaded from save during SL_LOAD_CHECK.
|
||||
|
||||
static bool _fios_path_changed;
|
||||
static bool _savegame_sort_dirty;
|
||||
static const char *NETWORK_SAVE_FILENAME = "network-save.sav";
|
||||
|
||||
|
||||
/**
|
||||
@@ -285,6 +289,7 @@ public:
|
||||
this->FinishInitNested(0);
|
||||
|
||||
this->LowerWidget(WID_SL_DRIVES_DIRECTORIES_LIST);
|
||||
if (mode == SLD_SAVE_GAME) this->SetWidgetLoweredState(WID_SL_SAVE_NETWORK_BUTTON, _settings_client.gui.save_to_network);
|
||||
|
||||
/* pause is only used in single-player, non-editor mode, non-menu mode. It
|
||||
* will be unpaused in the WE_DESTROY event handler. */
|
||||
@@ -627,6 +632,32 @@ public:
|
||||
/* Note, this is also called via the OSK; and we need to lower the button. */
|
||||
this->HandleButtonClick(WID_SL_SAVE_GAME);
|
||||
break;
|
||||
|
||||
case WID_SL_SAVE_NETWORK_BUTTON:
|
||||
_settings_client.gui.save_to_network = !_settings_client.gui.save_to_network;
|
||||
this->SetWidgetLoweredState(WID_SL_SAVE_NETWORK_BUTTON, _settings_client.gui.save_to_network);
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case WID_SL_LOAD_NETWORK_BUTTON: {
|
||||
char savePath[PATH_MAX];
|
||||
FiosMakeSavegameName(savePath, NETWORK_SAVE_FILENAME, sizeof(savePath));
|
||||
#ifdef __ANDROID__
|
||||
if (!SDL_ANDROID_CloudLoad(savePath, NULL, "OpenTTD")) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
_load_check_data.Clear();
|
||||
SaveOrLoadResult res = SaveOrLoad(savePath, SL_LOAD_CHECK, SAVE_DIR, false);
|
||||
if (res == SL_OK && !_load_check_data.HasErrors()) {
|
||||
strecpy(_file_to_saveload.name, savePath, lastof(_file_to_saveload.name));
|
||||
strecpy(_file_to_saveload.title, "", lastof(_file_to_saveload.title));
|
||||
if (!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
|
||||
_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,9 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "safeguards.h"
|
||||
#ifdef __ANDROID__
|
||||
#include <SDL_android.h>
|
||||
#endif
|
||||
|
||||
void CallLandscapeTick();
|
||||
void IncreaseDate();
|
||||
@@ -81,6 +84,8 @@ bool HandleBootstrap();
|
||||
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
|
||||
extern void ShowOSErrorBox(const char *buf, bool system);
|
||||
extern char *_config_file;
|
||||
const char *NETWORK_SAVE_SCREENSHOT_FILE = "OpenTTD-network-save";
|
||||
const char *NETWORK_SAVE_SCREENSHOT_FILE_PNG = "OpenTTD-network-save.png";
|
||||
|
||||
/**
|
||||
* Error handling for fatal user errors.
|
||||
@@ -1161,6 +1166,23 @@ void SwitchToMode(SwitchMode new_mode)
|
||||
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
|
||||
} else {
|
||||
DeleteWindowById(WC_SAVELOAD, 0);
|
||||
#ifdef __ANDROID__
|
||||
if (_settings_client.gui.save_to_network) {
|
||||
char screenshotFile[PATH_MAX] = "";
|
||||
const char* lastPart = strrchr(_file_to_saveload.name, PATHSEPCHAR);
|
||||
if (!lastPart) {
|
||||
lastPart = _file_to_saveload.name;
|
||||
} else {
|
||||
lastPart++;
|
||||
}
|
||||
MakeScreenshot(SC_VIEWPORT, NETWORK_SAVE_SCREENSHOT_FILE);
|
||||
FioFindFullPath(screenshotFile, sizeof(screenshotFile), SCREENSHOT_DIR, NETWORK_SAVE_SCREENSHOT_FILE_PNG);
|
||||
int ret = SDL_ANDROID_CloudSave(_file_to_saveload.name, lastPart, "OpenTTD", lastPart, screenshotFile, _date);
|
||||
if (_settings_client.gui.save_to_network == 2) {
|
||||
_settings_client.gui.save_to_network = ret ? 1 : 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -871,7 +871,7 @@ bool MakeScreenshot(ScreenshotType t, const char *name)
|
||||
|
||||
if (ret) {
|
||||
SetDParamStr(0, _screenshot_name);
|
||||
ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
|
||||
//ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING); // No need for message when we're doing cloudsave
|
||||
} else {
|
||||
ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static const char *_locale_units = "imperial|metric|si";
|
||||
static const char *_town_names = "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovak|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan";
|
||||
static const char *_climates = "temperate|arctic|tropic|toyland";
|
||||
static const char *_autosave_interval = "off|monthly|quarterly|half year|yearly";
|
||||
static const char *_save_to_network = "ask|enabled|disabled";
|
||||
static const char *_save_to_network = "disabled|enabled|ask";
|
||||
static const char *_roadsides = "left|right";
|
||||
static const char *_savegame_date = "long|short|iso";
|
||||
#ifdef ENABLE_NETWORK
|
||||
@@ -178,7 +178,7 @@ cat = SC_BASIC
|
||||
var = gui.save_to_network
|
||||
type = SLE_UINT8
|
||||
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
|
||||
def = 0
|
||||
def = 2
|
||||
max = 2
|
||||
full = _save_to_network
|
||||
cat = SC_BASIC
|
||||
|
||||
Reference in New Issue
Block a user