Skip to content

Commit

Permalink
Android: Add option to rename the game
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed May 24, 2024
1 parent 1581319 commit ec7cf9d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public Game(String gameFolderPath, String saveFolder, byte[] titleScreen) {
}

public String getTitle() {
String customTitle = getCustomTitle();
if (!customTitle.isEmpty()) {
return customTitle;
}

return title;
}

Expand All @@ -56,6 +61,14 @@ public void setTitle(String title) {

public native void reencodeTitle();

public String getCustomTitle() {
return SettingsManager.getCustomGameTitle(this);
}

public void setCustomTitle(String customTitle) {
SettingsManager.setCustomGameTitle(this, customTitle);
}

public String getGameFolderPath() {
return gameFolderPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.provider.DocumentsContract;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -16,6 +17,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -313,6 +315,7 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.settingsButton.setOnClickListener(v -> {
String[] choices_list = {
activity.getResources().getString(R.string.select_game_region),
activity.getResources().getString(R.string.game_rename),
activity.getResources().getString(R.string.launch_debug_mode)
};

Expand All @@ -323,6 +326,8 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
if (which == 0) {
chooseRegion(activity, holder, gameList.get(position));
} else if (which == 1) {
renameGame(activity, holder, gameList.get(position));
} else if (which == 2) {
launchGame(position, true);
}
});
Expand Down Expand Up @@ -390,6 +395,29 @@ public void chooseRegion(final Context context, final ViewHolder holder, final G
builder.show();
}

public void renameGame(final Context context, final ViewHolder holder, final Game game) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);

// Set up text input
final EditText input = new EditText(context);
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setText(holder.title.getText());
builder.setView(input);

builder
.setTitle(R.string.game_rename)
.setPositiveButton(R.string.ok, (dialog, id) -> {
game.setCustomTitle(input.getText().toString());
holder.title.setText(game.getTitle());
})
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.revert, (dialog, id) -> {
game.setCustomTitle("");
holder.title.setText(game.getTitle());
});
builder.show();
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView title;
public ImageView titleScreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ public static void setGameEncoding(Game game, Encoding encoding) {
editor.commit();
}

public static String getCustomGameTitle(Game game) {
return pref.getString(game.getKey() + "_Title", "");
}

public static void setCustomGameTitle(Game game, String customTitle) {
editor.putString(game.getKey() + "_Title", customTitle);
editor.commit();
}

public static int getSpeedModifierA() {
return speedModifierA;
}
Expand Down
2 changes: 2 additions & 0 deletions builds/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="do_want_quit">Do you really want to quit?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="revert">Revert</string>
<string name="creating_dir_failed">Creating $PATH directory failed</string>
<string name="path_not_readable">$PATH not readable</string>
<string name="no_games_found_and_explanation_android_30">No RPG Maker 2000/2003 games found.\n\nThe EasyRPG folder you selected contains a \"games\" folder. Use a file manager app to put your games in this folder.\nGames can be put in subfolders or in ZIP/LZH archives.\n\nThe EasyRPG folder can be changed in the settings.</string>
Expand All @@ -31,6 +32,7 @@
<string name="select_game_region">Select game region</string>
<string name="change_the_layout">Change the layout</string>
<string name="launch_debug_mode">Launch in debug mode</string>
<string name="game_rename">Rename game</string>
<string name="choose_layout">Choose a layout</string>
<string name="unknown_region">Unknown region</string>
<string name="region_modification_failed">Changing region failed</string>
Expand Down

0 comments on commit ec7cf9d

Please sign in to comment.