Skip to content

Commit

Permalink
Add setting to use old color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
GunshipPenguin committed Mar 21, 2016
1 parent d21be17 commit ed70b50
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void drawGame(Game game) {

public void setPaints(Paint[] paints) {
this.paints = paints;
invalidate();
return;
}

Expand Down
28 changes: 22 additions & 6 deletions app/src/main/java/com/gunshippenguin/openflood/GameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ private int getNumColors(){
}

private void initPaints() {
int[] colors = getResources().getIntArray(R.array.boardColorScheme);
int[] colors;
if (sp.getBoolean("use_old_colors", false)){
colors = getResources().getIntArray(R.array.oldBoardColorScheme);
} else {
colors = getResources().getIntArray(R.array.boardColorScheme);
}

paints = new Paint[colors.length];
for (int i = 0; i < colors.length; i++) {
paints[i] = new Paint();
Expand All @@ -127,6 +133,14 @@ private void newGame() {
gameFinished = false;
lastColor = game.getColor(0, 0);

layoutColorButtons();

stepsTextView.setText(game.getSteps() + " / " + game.getMaxSteps());
floodView.setBoardSize(getBoardSize());
floodView.drawGame(game);
}

private void layoutColorButtons() {
// Add color buttons
LinearLayout buttonLayout = (LinearLayout) findViewById(R.id.buttonLayout);
buttonLayout.removeAllViews();
Expand All @@ -151,10 +165,7 @@ public void onClick(View v) {
newButton.setColor(paints[i].getColor());
buttonLayout.addView(newButton);
}

stepsTextView.setText(game.getSteps() + " / " + game.getMaxSteps());
floodView.setBoardSize(getBoardSize());
floodView.drawGame(game);
return;
}

@Override
Expand All @@ -163,9 +174,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
// Only start a new game if the settings have been changed
if (extras.getBoolean("settingsChanged")) {
if (extras.getBoolean("gameSettingsChanged")) {
newGame();
}
if (extras.getBoolean("colorSettingsChanged")) {
initPaints();
floodView.setPaints(paints);
layoutColorButtons();
}
}
} else if (requestCode == NEW_GAME) {
if (resultCode == RESULT_OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class SettingsActivity extends AppCompatActivity {
Spinner boardSizeSpinner, numColorsSpinner;
CheckBox colorBlindCheckBox;
CheckBox colorBlindCheckBox, oldColorsCheckBox;
int[] boardSizeChoices, numColorsChoices;

@Override
Expand Down Expand Up @@ -60,45 +60,61 @@ protected void onCreate(Bundle savedInstanceState) {
colorBlindCheckBox = (CheckBox) findViewById(R.id.colorBlindCheckBox);
colorBlindCheckBox.setChecked(sp.getBoolean("color_blind_mode", false));

// Set up the old color scheme checkbox
oldColorsCheckBox = (CheckBox) findViewById(R.id.oldColorsCheckBox);
oldColorsCheckBox.setChecked(sp.getBoolean("use_old_colors", false));

// Set up the apply button
Button applyButton = (Button) findViewById(R.id.applyButton);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent dataIntent = new Intent();
dataIntent.putExtra("settingsChanged", saveSettings());
setResult(RESULT_OK, dataIntent);
Intent s = saveSettings();
setResult(RESULT_OK, s);
finish();
}
});
}

private boolean saveSettings() {
private Intent saveSettings() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor spEditor = sp.edit();
boolean settingsChanged = false;
Intent dataIntent = new Intent();
dataIntent.putExtra("gameSettingsChanged", false);
dataIntent.putExtra("colorSettingsChanged", false);

// Update boardSize
int selectedBoardSize = ((BoardSize) boardSizeSpinner.getSelectedItem()).getBoardSize();
int defaultBoardSize = getResources().getInteger(R.integer.default_board_size);
if (selectedBoardSize != sp.getInt("board_size", defaultBoardSize)) {
settingsChanged = true;
dataIntent.putExtra("gameSettingsChanged", true);
spEditor.putInt("board_size", selectedBoardSize);
}

// Update number of colors
int selectedNumColors = ((ColorNum) numColorsSpinner.getSelectedItem()).getColorNum();
int defaultNumColors = getResources().getInteger(R.integer.default_num_colors);
if (selectedNumColors != sp.getInt("num_colors", defaultNumColors)) {
settingsChanged = true;
dataIntent.putExtra("gameSettingsChanged", true);
spEditor.putInt("num_colors", selectedNumColors);
}

// Update color blind mode
spEditor.putBoolean("color_blind_mode", colorBlindCheckBox.isChecked());
boolean selectedColorBlindMode = colorBlindCheckBox.isChecked();
if (selectedColorBlindMode != sp.getBoolean("color_blind_mode", false)) {
dataIntent.putExtra("colorSettingsChanged", true);
spEditor.putBoolean("color_blind_mode", selectedColorBlindMode);
}

// Update whether or not to use the old color scheme
boolean selectedOldColorScheme = oldColorsCheckBox.isChecked();
if (selectedOldColorScheme != sp.getBoolean("use_old_colors", false)) {
dataIntent.putExtra("colorSettingsChanged", true);
spEditor.putBoolean("use_old_colors", selectedOldColorScheme);
}

spEditor.apply();
return settingsChanged;
return dataIntent;
}

private class BoardSize {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
android:textSize="@dimen/small_text_size"
android:id="@+id/colorBlindCheckBox" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_old_colors"
android:textSize="@dimen/small_text_size"
android:id="@+id/oldColorsCheckBox" />

</LinearLayout>

<LinearLayout
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
<color name="cyan">#18ffff</color>
<color name="pink">#f2739d</color>

<!-- Old Board Colors -->
<color name="hamberMaroon">#813237</color>
<color name="hamberBlue">#8296FF</color>
<color name="pwGold">#FFD700</color>
<color name="pwBlack">#000000</color>
<color name="madronaBlue">#1B13C8</color>
<color name="madronaGreen">#008834</color>
<color name="old_orange">#CC5200</color>
<color name="magenta">#FF00FF</color>

<array name="boardColorScheme">
<item>@color/red</item>
<item>@color/blue</item>
Expand All @@ -22,4 +32,15 @@
<item>@color/cyan</item>
<item>@color/pink</item>
</array>

<array name="oldBoardColorScheme">
<item>@color/hamberMaroon</item>
<item>@color/hamberBlue</item>
<item>@color/pwGold</item>
<item>@color/pwBlack</item>
<item>@color/madronaBlue</item>
<item>@color/madronaGreen</item>
<item>@color/old_orange</item>
<item>@color/magenta</item>
</array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="settings_board_size">Board Size</string>
<string name="settings_apply_button">Apply</string>
<string name="settings_color_blind">Color Blind Mode</string>
<string name="settings_old_colors">Old Color Scheme</string>

<!--Info activity-->
<string name="info_license">Released under the MIT License</string>
Expand Down

0 comments on commit ed70b50

Please sign in to comment.