Skip to content

Commit

Permalink
Make undo/redo new game a little less surprising
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisboyle committed Mar 24, 2019
1 parent 702aede commit b3d2ce9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
25 changes: 19 additions & 6 deletions app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java
Expand Up @@ -133,6 +133,8 @@ public class GamePlay extends AppCompatActivity implements OnSharedPreferenceCha
private static final String LIGHTUP_383_NEED_MIGRATE = "lightup_383_need_migrate";
private static final String LIGHTUP_383_PARAMS_ROT4 = "^(\\d+(?:x\\d+)?(?:b\\d+)?)s4(.*)$";
private static final String LIGHTUP_383_REPLACE_ROT4 = "$1s3$2";
private static final String UNDO_NEW_GAME_SEEN = "undoNewGameSeen";
private static final String REDO_NEW_GAME_SEEN = "redoNewGameSeen";

private ProgressDialog progress;
private CountDownTimer progressResetRevealer;
Expand Down Expand Up @@ -1343,6 +1345,11 @@ void sendKey(PointF p, int k)
}

void sendKey(int x, int y, int k)
{
sendKey(x, y, k, false);
}

void sendKey(int x, int y, int k, boolean isRepeat)
{
if (progress != null || currentBackend == null) return;
if (k == '\f') {
Expand All @@ -1351,15 +1358,21 @@ void sendKey(int x, int y, int k)
return;
}
if (k == UI_UNDO && undoIsLoadGame) {
final GameLaunch launchUndo = GameLaunch.undoingOrRedoingNewGame(undoToGame);
redoToGame = saveToString();
startGame(launchUndo);
if (!isRepeat) {
Utils.toastFirstFewTimes(this, state, UNDO_NEW_GAME_SEEN, 3, R.string.undo_new_game_toast);
final GameLaunch launchUndo = GameLaunch.undoingOrRedoingNewGame(undoToGame);
redoToGame = saveToString();
startGame(launchUndo);
}
return;
}
if (k == UI_REDO && redoIsLoadGame) {
final GameLaunch launchRedo = GameLaunch.undoingOrRedoingNewGame(redoToGame);
redoToGame = null;
startGame(launchRedo, true);
if (!isRepeat) {
Utils.toastFirstFewTimes(this, state, REDO_NEW_GAME_SEEN, 3, R.string.redo_new_game_toast);
final GameLaunch launchRedo = GameLaunch.undoingOrRedoingNewGame(redoToGame);
redoToGame = null;
startGame(launchRedo, true);
}
return;
}
if (swapLR && (k >= GameView.FIRST_MOUSE && k <= GameView.LAST_MOUSE)) {
Expand Down
Expand Up @@ -573,7 +573,7 @@ public boolean onKeyDown(int keyCode, @NonNull KeyEvent event)
}
}
if( key == 0 ) return super.onKeyDown(keyCode, event); // handles Back etc.
parent.sendKey(0, 0, key);
parent.sendKey(0, 0, key, repeat > 0);
keysHandled++;
return true;
}
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/name/boyle/chris/sgtpuzzles/SmallKeyboard.java
Expand Up @@ -29,6 +29,8 @@ public class SmallKeyboard extends KeyboardView implements KeyboardView.OnKeyboa
public static final char SWAP_L_R_KEY = '*';
private boolean swapLR = false;
private final SharedPreferences state;
private int lastPress = -1;
private int releasesThisPress = 0;

enum ArrowMode {
NO_ARROWS, // untangle
Expand Down Expand Up @@ -608,8 +610,18 @@ public void swipeUp() {}
public void swipeDown() {}
public void swipeLeft() {}
public void swipeRight() {}
public void onPress(int k) {}
public void onRelease(int k) {}

public void onPress(int k) {
lastPress = k;
releasesThisPress = 0;
}

public void onRelease(int k) {
if (lastPress == k) {
releasesThisPress++;
}
}

public void onText(CharSequence s) {
for (int i=0; i<s.length();i++) parent.sendKey(0,0,s.charAt(i));
}
Expand All @@ -624,7 +636,7 @@ public void onKey(int k, int[] ignore) {
key.on ? R.string.toast_swap_l_r_on : R.string.toast_swap_l_r_off);
} else {
if (!swapLR && "palisade".equals(backendForIcons) && "HJKL".indexOf(k) > -1) k = Character.toLowerCase(k);
parent.sendKey(0,0,k);
parent.sendKey(0,0, k, releasesThisPress > 0);
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -59,6 +59,8 @@ Version %s"</string>
<string name="file_exists">File exists; overwrite it?</string>
<string name="file_saved">Saved the game in {0}</string>
<string name="replaceGame">You have an unfinished game of {0} which this will replace. Continue loading?</string>
<string name="undo_new_game_toast">Undoing into previous game</string>
<string name="redo_new_game_toast">Redoing into previously generated game</string>
<string name="storage_permission_explanation">"To import this file an extra permission is needed. Android might describe this permission in terms of photos and media.

If you don’t want to grant it you can instead locate the file from within Puzzles using the Open button on the game chooser."</string>
Expand Down

0 comments on commit b3d2ce9

Please sign in to comment.