Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Add game label configuration, rename buttons to X/Z #3316

Merged
merged 5 commits into from
Dec 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ Java_org_easyrpg_player_game_1browser_GameScanner_findGames(JNIEnv *env, jclass,
env->CallVoidMethod(jgame_object, jset_title_method, jtitle);
}

// Set folder name
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);
}

Expand Down Expand Up @@ -397,11 +402,6 @@ Java_org_easyrpg_player_game_1browser_Game_reencodeTitle(JNIEnv *env, jobject th
if (encoding == "auto") {
auto det_encodings = lcf::ReaderUtil::DetectEncodings(title);
for (auto &det_enc: det_encodings) {
if (det_enc == "UTF-16BE" || det_enc == "UTF-16LE") {
// Skip obviously wrong title encodings
continue;
}

if (lcf::Encoder encoder(det_enc); encoder.IsOk()) {
encoder.Encode(title);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,17 @@ public char getAppropriateChar(int keyCode) {
char charButton;

if (keyCode == ENTER) {
charButton = 'A';
if (SettingsManager.getShowZXasAB()) {
charButton = 'A';
} else {
charButton = 'Z';
}
} else if (keyCode == CANCEL) {
charButton = 'B';
if (SettingsManager.getShowZXasAB()) {
charButton = 'B';
} else {
charButton = 'X';
}
} else if (keyCode == SHIFT) {
charButton = 'S';
} else if (keyCode == KEY_0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

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;
/** 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;
/** 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 @@ -46,12 +51,20 @@ public Game(String gameFolderPath, String saveFolder, byte[] titleScreen) {
this.isFavorite = isFavoriteFromSettings();
}

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

if (SettingsManager.getGameBrowserLabelMode() == 0) {
return getTitle();
} else {
return gameFolderName;
}
}

public String getTitle() {
return title;
}

Expand Down Expand Up @@ -81,6 +94,14 @@ public void setSavePath(String path) {
savePath = path;
}

public String getGameFolderName() {
return gameFolderName;
}

public void setGameFolderName(String gameFolderName) {
this.gameFolderName = gameFolderName;
}

public boolean isFavorite() {
return isFavorite;
}
Expand All @@ -106,7 +127,7 @@ public int compareTo(Game game) {
if (!this.isFavorite() && game.isFavorite()) {
return 1;
}
return this.getTitle().compareTo(game.getTitle());
return this.getDisplayTitle().compareTo(game.getDisplayTitle());
}

/**
Expand Down Expand Up @@ -149,62 +170,70 @@ public void setStandalone(boolean standalone) {
@NonNull
@Override
public String toString() {
return getTitle();
return getDisplayTitle();
}

public static Game fromCacheEntry(Context context, String cache) {
String[] entries = cache.split(String.valueOf(escapeCode));

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

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

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

String title = entries[4];

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

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

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

if (g.titleRaw != null) {
g.reencodeTitle();
}

g.setGameFolderName(gameFolderName);

return g;
}

public String toCacheEntry() {
StringBuilder sb = new StringBuilder();

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

return sb.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

if (id == R.id.refresh) {
if (id == R.id.view) {
openView();
return true;
} else if (id == R.id.refresh) {
scanGamesAndDisplayResult(true);
return true;
} else if (id == R.id.menu) {
Expand Down Expand Up @@ -161,6 +164,26 @@ public boolean onNavigationItemSelected(MenuItem item) {
return true;
}

public void openView() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);

String[] choices_list = {
this.getResources().getString(R.string.view_show_game_title),
this.getResources().getString(R.string.view_show_game_folder)
};

builder
.setTitle(R.string.view_show_title_desc)
.setSingleChoiceItems(choices_list, SettingsManager.getGameBrowserLabelMode(), null)
.setPositiveButton(R.string.ok, (dialog, id) -> {
int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
SettingsManager.setGameBrowserLabelMode(selectedPosition);
displayGamesList();
})
.setNegativeButton(R.string.cancel, null);
builder.show();
}

public void scanGamesAndDisplayResult(boolean forceScan) {
// Verify that a scan isn't processing
// TODO : Make the use of isScanProcessing synchronized (not really useful)
Expand Down Expand Up @@ -307,7 +330,7 @@ public void onBindViewHolder(final ViewHolder holder, final int position) {
final Game game = gameList.get(position);

// Title
holder.title.setText(game.getTitle());
holder.title.setText(game.getDisplayTitle());
holder.title.setOnClickListener(v -> launchGame(position, false));

// TitleScreen Image
Expand Down Expand Up @@ -391,7 +414,7 @@ public void chooseRegion(final Context context, final ViewHolder holder, final G

if (!selectedEncoding.equals(encoding)) {
game.setEncoding(selectedEncoding);
holder.title.setText(game.getTitle());
holder.title.setText(game.getDisplayTitle());
}
})
.setNegativeButton(R.string.cancel, null);
Expand All @@ -411,12 +434,12 @@ public void renameGame(final Context context, final ViewHolder holder, final Gam
.setTitle(R.string.game_rename)
.setPositiveButton(R.string.ok, (dialog, id) -> {
game.setCustomTitle(input.getText().toString());
holder.title.setText(game.getTitle());
holder.title.setText(game.getDisplayTitle());
})
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.revert, (dialog, id) -> {
game.setCustomTitle("");
holder.title.setText(game.getTitle());
holder.title.setText(game.getDisplayTitle());
});
builder.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ enum SettingsEnum {
FONT1_URI("Font1"),
FONT2_URI("Font2"),
FONT1_SIZE("Font1Size"),
FONT2_SIZE("Font2Size")

FONT2_SIZE("Font2Size"),
GAME_BROWSER_LABEL_MODE("GAME_BROWSER_LABEL_MODE"),
SHOW_ZX_AS_AB("SHOW_ZX_AS_AB")
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void onCreate(Bundle savedInstanceState) {
enableVibrateWhenSlidingCheckbox.setChecked(SettingsManager.isVibrateWhenSlidingDirectionEnabled());
enableVibrateWhenSlidingCheckbox.setOnClickListener(this);

CheckBox showZXasABcheckbox = findViewById(R.id.settings_show_zx_as_ab);
showZXasABcheckbox.setChecked(SettingsManager.getShowZXasAB());
showZXasABcheckbox.setOnClickListener(this);

configureFastForwardButton();
configureLayoutTransparencySystem();
configureLayoutSizeSystem();
Expand All @@ -57,6 +61,8 @@ public void onClick(View v) {
enableVibrateWhenSlidingCheckbox.setEnabled(c.isChecked());
} else if (id == R.id.settings_vibrate_when_sliding){
SettingsManager.setVibrateWhenSlidingDirectionEnabled(((CheckBox) v).isChecked());
} else if (id == R.id.settings_show_zx_as_ab) {
SettingsManager.setShowZXasAB(((CheckBox)v).isChecked());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class SettingsManager {
GAMES_FOLDER_NAME = "games", SAVES_FOLDER_NAME = "saves",
FONTS_FOLDER_NAME = "fonts";
public static int FAST_FORWARD_MODE_HOLD = 0, FAST_FORWARD_MODE_TAP = 1;
private static int gameBrowserLabelMode = 0;
private static boolean showZXasAB = false;

private static List<String> imageSizeOption = Arrays.asList("nearest", "integer", "bilinear");
private static List<String> gameResolutionOption = Arrays.asList("original", "widescreen", "ultrawide");
Expand Down Expand Up @@ -102,6 +104,10 @@ private static void loadSettings(Context context) {
if (gameResolution == -1) {
gameResolution = 0;
}

gameBrowserLabelMode = sharedPref.getInt(GAME_BROWSER_LABEL_MODE.toString(), 0);

showZXasAB = sharedPref.getBoolean(SHOW_ZX_AS_AB.toString(), false);
}

public static Set<String> getFavoriteGamesList() {
Expand Down Expand Up @@ -488,4 +494,24 @@ public static void setSpeedModifierA(int speedModifierA) {
configIni.input.set(SPEED_MODIFIER_A.toString(), speedModifierA);
configIni.save();
}

public static int getGameBrowserLabelMode() {
return gameBrowserLabelMode;
}

public static void setGameBrowserLabelMode(int i) {
gameBrowserLabelMode = i;
editor.putInt(SettingsEnum.GAME_BROWSER_LABEL_MODE.toString(), i);
editor.commit();
}

public static boolean getShowZXasAB() {
return showZXasAB;
}

public static void setShowZXasAB(boolean b) {
showZXasAB = b;
editor.putBoolean(SHOW_ZX_AS_AB.toString(), b);
editor.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M360,800h440q33,0 56.5,-23.5T880,720v-80L360,640v160ZM80,320h200v-160L160,160q-33,0 -56.5,23.5T80,240v80ZM80,560h200v-160L80,400v160ZM160,800h120v-160L80,640v80q0,33 23.5,56.5T160,800ZM360,560h520v-160L360,400v160ZM360,320h520v-80q0,-33 -23.5,-56.5T800,160L360,160v160Z"
android:fillColor="#5f6368"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M360,800h440q33,0 56.5,-23.5T880,720v-80L360,640v160ZM80,320h200v-160L160,160q-33,0 -56.5,23.5T80,240v80ZM80,560h200v-160L80,400v160ZM160,800h120v-160L80,640v80q0,33 23.5,56.5T160,800ZM360,560h520v-160L360,400v160ZM360,320h520v-80q0,-33 -23.5,-56.5T800,160L360,160v160Z"
android:fillColor="#ffffff"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
android:text="@string/vibrate_when_sliding_direction"
android:textSize="20sp"/>

<CheckBox
android:id="@+id/settings_show_zx_as_ab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_input_show_zx_as_ab"
android:textSize="20sp"/>

<include layout="@layout/separator"/>

<RelativeLayout
Expand Down
8 changes: 7 additions & 1 deletion builds/android/app/src/main/res/menu/game_browser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
android:title="@string/refresh"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_refresh_white"/>
<item
android:id="@+id/view"
android:orderInCategory="100"
android:title="@string/view"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_view_list_white"/>
<item
android:id="@+id/menu"
android:orderInCategory="100"
android:title="@string/refresh"
android:title="@string/settings"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_settings_white"/>
</menu>
Loading
Loading