Skip to content

Commit

Permalink
Android: Fix "Show folder name" setting for unsupported games
Browse files Browse the repository at this point in the history
Make localization simpler by merging some strings
  • Loading branch information
Ghabry committed Jan 20, 2025
1 parent cc4975a commit 305a1ea
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,14 @@ Java_org_easyrpg_player_game_1browser_GameScanner_findGames(JNIEnv *env, jclass,
std::string root_path = FileFinder::GetFullFilesystemPath(root);
bool game_in_main_dir = false;
if (ge_list.size() == 1) {
if (ge_list[0].type == FileFinder::ProjectType::Supported &&
root_path == FileFinder::GetFullFilesystemPath(ge_list[0].fs)) {
game_in_main_dir = true;
}
if (root_path == FileFinder::GetFullFilesystemPath(ge_list[0].fs)) {
game_in_main_dir = true;
}
}

for (size_t i = 0; i < ge_list.size(); ++i) {
auto& ge = ge_list[i];
auto& fs = ge.fs;

// If game is unsupported, create a Game object with only directory name as title and project type id and continue early
if (ge.type > FileFinder::ProjectType::Supported) {
jobject jgame_object = env->NewObject(jgame_class, jgame_constructor_unsupported, (int)ge.type);

// Use the directory name as the title
auto dir = jstring_to_string(env, jmain_dir_name);
jstring jtitle = env->NewStringUTF(dir.c_str());
jmethodID jset_title_method = env->GetMethodID(jgame_class, "setTitle", "(Ljava/lang/String;)V");
env->CallVoidMethod(jgame_object, jset_title_method, jtitle);

env->SetObjectArrayElement(jgame_array, i, jgame_object);
continue;
}
auto& fs = ge.fs;

std::string full_path = FileFinder::GetFullFilesystemPath(fs);
std::string game_dir_name;
Expand All @@ -239,6 +224,19 @@ Java_org_easyrpg_player_game_1browser_GameScanner_findGames(JNIEnv *env, jclass,
game_dir_name = std::get<1>(FileFinder::GetPathAndFilename(fs.GetFullPath()));
}

// If game is unsupported, create a Game object with only directory name as title and project type id and continue early
if (ge.type > FileFinder::ProjectType::Supported) {
jobject jgame_object = env->NewObject(jgame_class, jgame_constructor_unsupported, (int)ge.type);

// Use the directory name as the title
jstring jfolder = env->NewStringUTF(game_dir_name.c_str());
jmethodID jset_folder_name_method = env->GetMethodID(jgame_class, "setGameFolderName", "(Ljava/lang/String;)V");
env->CallVoidMethod(jgame_object, jset_folder_name_method, jfolder);

env->SetObjectArrayElement(jgame_array, i, jgame_object);
continue;
}

std::string save_path;
if (!fs.IsFeatureSupported(Filesystem::Feature::Write)) {
// Is an archive and needs a redirected save path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

public class Game implements Comparable<Game> {
final static char escapeCode = '\u0001';
final static String cacheVersion = "1";
/** The title shown in the Game Browser */
private String title;
private String title = "";
/** Bytes of the title string in an unspecified encoding */
private byte[] titleRaw = null;
/** Human readable version of the game directory. Shown in the game browser
* when the specific setting is enabled.
*/
private String gameFolderName;
private String gameFolderName = "";
/** Path to the game folder (forwarded via --project-path */
private final String gameFolderPath;
/** Relative path to the save directory, made absolute by launchGame (forwarded via --save-path) */
Expand All @@ -39,9 +38,8 @@ public class Game implements Comparable<Game> {
private ProjectType projectType = ProjectType.UNKNOWN;

public Game(int projectTypeId) {
this.gameFolderPath = "";
this.gameFolderName = "";
this.projectType = ProjectType.getProjectType(projectTypeId);
this.gameFolderPath = "";
}

public Game(String gameFolderPath, String saveFolder, byte[] titleScreen, int projectTypeId) {
Expand All @@ -66,7 +64,7 @@ public String getDisplayTitle() {
return customTitle;
}

if (SettingsManager.getGameBrowserLabelMode() == 0) {
if (SettingsManager.getGameBrowserLabelMode() == 0 && !getTitle().isEmpty()) {
return getTitle();
} else {
return gameFolderName;
Expand Down Expand Up @@ -193,39 +191,39 @@ public String toString() {
public static Game fromCacheEntry(Context context, String cache) {
String[] entries = cache.split(String.valueOf(escapeCode));

if (entries.length != 8 || !entries[0].equals(cacheVersion)) {
if (entries.length != 7) {
return null;
}

int parsedProjectType = Integer.parseInt(entries[7]);
int parsedProjectType = Integer.parseInt(entries[6]);
if (parsedProjectType > ProjectType.SUPPORTED.ordinal()) {
// Unsupported game
Game g = new Game(parsedProjectType);
g.setTitle(entries[4]);

g.setGameFolderName(entries[2]);
return g;
}

String savePath = entries[1];
DocumentFile gameFolder = DocumentFile.fromTreeUri(context, Uri.parse(entries[2]));
String savePath = entries[0];
DocumentFile gameFolder = DocumentFile.fromTreeUri(context, Uri.parse(entries[1]));
if (gameFolder == null) {
return null;
}

String gameFolderName = entries[3];
String gameFolderName = entries[2];

String title = entries[4];
String title = entries[3];

byte[] titleRaw = null;
if (!entries[5].equals("null")) {
titleRaw = Base64.decode(entries[5], 0);
if (!entries[4].equals("null")) {
titleRaw = Base64.decode(entries[4], 0);
}

byte[] titleScreen = null;
if (!entries[6].equals("null")) {
titleScreen = Base64.decode(entries[6], 0);
if (!entries[5].equals("null")) {
titleScreen = Base64.decode(entries[5], 0);
}

Game g = new Game(entries[2], savePath, titleScreen, parsedProjectType);
Game g = new Game(entries[1], savePath, titleScreen, parsedProjectType);
g.setTitle(title);
g.titleRaw = titleRaw;

Expand All @@ -241,24 +239,22 @@ public static Game fromCacheEntry(Context context, String cache) {
public String toCacheEntry() {
StringBuilder sb = new StringBuilder();

// Cache structure: savePath | gameFolderPath | title | titleRaw | titleScreen | projectType
sb.append(cacheVersion); // 0
sb.append(escapeCode);
sb.append(savePath); // 1
// Cache structure: savePath | gameFolderPath | gameFolderName | title | titleRaw | titleScreen | projectType
sb.append(savePath); // 0
sb.append(escapeCode);
sb.append(gameFolderPath); // 2
sb.append(gameFolderPath); // 1
sb.append(escapeCode);
sb.append(gameFolderName); // 3
sb.append(gameFolderName); // 2
sb.append(escapeCode);
sb.append(title); // 4
sb.append(title); // 3
sb.append(escapeCode);
if (titleRaw != null) { // 5
if (titleRaw != null) { // 4
sb.append(Base64.encodeToString(titleRaw, Base64.NO_WRAP));
} else {
sb.append("null");
}
sb.append(escapeCode);
if (titleScreen != null) { // 6
if (titleScreen != null) { // 5
ByteArrayOutputStream baos = new ByteArrayOutputStream();
titleScreen.compress(Bitmap.CompressFormat.PNG, 90, baos);
byte[] b = baos.toByteArray();
Expand All @@ -267,7 +263,7 @@ public String toCacheEntry() {
sb.append("null");
}
sb.append(escapeCode);
sb.append(projectType.ordinal());
sb.append(projectType.ordinal()); // 6

return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.title.setText(game.getDisplayTitle());

// Subtitle - engine unsupported message
holder.subtitle.setText(String.format("%s\n%s", activity.getResources().getString(R.string.unsupported_engine), game.getProjectTypeLabel()));
holder.subtitle.setText(activity.getResources().getString(R.string.unsupported_engine_card).replace("$ENGINE", game.getProjectTypeLabel()));

// Hide settings button
holder.settingsButton.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -466,13 +466,11 @@ public void renameGame(final Context context, final ViewHolder holder, final Gam
private void showUnsupportedProjectTypeExplanation(final Context context, String projectType) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);

String part1 = context.getString(R.string.unsupported_engine_explanation_1).replace("$ENGINE", projectType);
String part2 = context.getString(R.string.unsupported_engine_explanation_2);
String part3 = context.getString(R.string.unsupported_engine_explanation_3);
String message = context.getString(R.string.unsupported_engine_explanation).replace("$ENGINE", projectType);

builder
.setTitle(R.string.information)
.setMessage(part1 + '\n' + '\n' + part2 + '\n' + '\n' + part3)
.setTitle(R.string.unsupported_engine_title)
.setMessage(message)
.setNeutralButton(R.string.ok, null);
builder.show();
}
Expand Down
8 changes: 3 additions & 5 deletions builds/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ Please tell us in detail what went wrong.\n\n
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="menu">Open Android menu</string>
<string name="unsupported_engine">Unsupported engine:</string>
<string name="unsupported_engine_explanation_1">This game cannot be played in EasyRPG because it was created with $ENGINE.</string>
<string name="unsupported_engine_explanation_2">EasyRPG is designed to support only RPG Maker 2000 and 2003 games, with no plans to expand to other engines.</string>
<string name="unsupported_engine_explanation_3">For software capable of launching this game, please check the Play Store.</string>
<string name="information">Information</string>
<string name="unsupported_engine_card">$ENGINE is unsupported</string>
<string name="unsupported_engine_title">Unsupported engine</string>
<string name="unsupported_engine_explanation">This game cannot be played in EasyRPG Player because it was created with $ENGINE.\n\nEasyRPG Player is designed to support only RPG Maker 2000 and 2003 games, with no plans to expand to other engines.\n\nFor software capable of launching this game, please check the Play Store.</string>
</resources>

0 comments on commit 305a1ea

Please sign in to comment.