Skip to content

Commit cce9361

Browse files
authored
Implement alternate colorscheme option for accessibility (resolves #10) (#25)
- Add a new setting, which allows the user to switch between two colorschemes - Colorscheme preference is an int (0 = default, 1 = alternate), so that if it were desired to add colorschemes later (e.g., for dark theme), it would be easy to do so. - Update texture.xcf to include a second set of colors - Each drawable-nodpi dir now has 2 texture files: texture_colorscheme_0.png (the original) and texture_colorscheme_1.png
1 parent 74ad221 commit cce9361

14 files changed

Lines changed: 74 additions & 8 deletions

File tree

app/src/main/java/com/bytehamster/flowitgame/GLRenderer.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
public class GLRenderer implements Renderer {
1717
private static final String TAG = "GLRenderer";
1818
private final Context myContext;
19+
20+
private final int[] textureDrawables = new int[] {R.drawable.texture_colorscheme_0, R.drawable.texture_colorscheme_1};
21+
public final int numberOfColorschemes = textureDrawables.length;
22+
1923
private int width = 0;
2024
private int height = 0;
2125
private final int[] textures = new int[1];
2226
private Runnable onViewportSetupComplete = null;
2327
private final ArrayList<Drawable> objects = new ArrayList<>();
2428

29+
private int currentColorschemeIndex = 0;
30+
private boolean reloadTextureNextFrame = false;
31+
2532
public GLRenderer(Context c) {
2633
myContext = c;
2734
}
@@ -31,6 +38,11 @@ public void onDrawFrame(GL10 gl) {
3138
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
3239
gl.glLoadIdentity();
3340

41+
if (reloadTextureNextFrame) {
42+
loadTexture(gl, 0, textureDrawables[currentColorschemeIndex]);
43+
reloadTextureNextFrame = false;
44+
}
45+
3446
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
3547
for (Drawable o : objects) {
3648
o.draw(gl);
@@ -55,7 +67,8 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
5567
gl.glEnable(GL10.GL_TEXTURE_2D);
5668
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
5769
gl.glGenTextures(textures.length, textures, 0);
58-
loadTexture(gl, 0, R.drawable.texture);
70+
loadTexture(gl, 0, textureDrawables[currentColorschemeIndex]);
71+
5972
debugOutput(gl);
6073
}
6174

@@ -80,6 +93,18 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
8093
}
8194
}
8295

96+
public void setColorscheme(int colorschemeIndex) {
97+
// Return to default colorscheme if given an invalid colorschemeIndex.
98+
// For example, if the number of colorschemes decreases after an update.
99+
if ((0 <= colorschemeIndex) && (colorschemeIndex < numberOfColorschemes)) {
100+
currentColorschemeIndex = colorschemeIndex;
101+
} else {
102+
currentColorschemeIndex = 0;
103+
}
104+
105+
reloadTextureNextFrame = true;
106+
}
107+
83108
private void loadTexture(GL10 gl, int position, @DrawableRes int resource) {
84109
Log.d(TAG, "loadTexture");
85110
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[position]);

app/src/main/java/com/bytehamster/flowitgame/state/GameState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected void initialize(GLRenderer glRenderer) {
7676
stepsUsedCurrentYDelta = topButtonSize * 0.6f;
7777
stepsUsedBestYDelta = topButtonSize * 0.1f;
7878

79-
TextureCoordinates coordinatesHeader = TextureCoordinates.getFromBlocks(2, 15, 3, 16);
79+
TextureCoordinates coordinatesHeader = TextureCoordinates.getFromBlocks(14, 12, 15, 13);
8080
headerBackground = new Plane(0, glRenderer.getHeight(), glRenderer.getWidth(), topBarHeight, coordinatesHeader);
8181
headerBackground.setVisible(false);
8282
glRenderer.addDrawable(headerBackground);

app/src/main/java/com/bytehamster/flowitgame/state/SettingsState.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public class SettingsState extends State {
2424
private Plane tutorialButton;
2525
private Plane volumeButton;
2626
private Plane editorButton;
27+
private Plane colorsExample;
28+
private Plane colorsButton;
29+
30+
private int numberOfColorschemes;
31+
private GLRenderer glRenderer;
2732

2833
private SettingsState() {
2934

@@ -37,7 +42,11 @@ public static SettingsState getInstance() {
3742
}
3843

3944
@Override
40-
protected void initialize(GLRenderer glRenderer) {
45+
protected void initialize(GLRenderer glRendererIn) {
46+
glRenderer = glRendererIn;
47+
48+
numberOfColorschemes = glRenderer.numberOfColorschemes;
49+
4150
float menuEntriesWidth = glRenderer.getWidth() * 0.75f;
4251
float menuEntriesHeight = menuEntriesWidth / 6;
4352
float menuEntriesAvailableSpace = getScreenHeight();
@@ -47,24 +56,35 @@ protected void initialize(GLRenderer glRenderer) {
4756
volumeButton = new Plane(-menuEntriesWidth, menuEntriesStartY, menuEntriesWidth, menuEntriesHeight, coordinatesVolume);
4857
glRenderer.addDrawable(volumeButton);
4958

59+
TextureCoordinates coordinatesColors = TextureCoordinates.getFromBlocks(0, 15, 6, 16);
60+
colorsButton = new Plane(-menuEntriesWidth, volumeButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesColors);
61+
glRenderer.addDrawable(colorsButton);
62+
5063
TextureCoordinates coordinatesTutorial = TextureCoordinates.getFromBlocks(6, 12, 12, 13);
51-
tutorialButton = new Plane(-menuEntriesWidth, volumeButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesTutorial);
64+
tutorialButton = new Plane(-menuEntriesWidth, colorsButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesTutorial);
5265
glRenderer.addDrawable(tutorialButton);
5366

5467
TextureCoordinates coordinatesEditor = TextureCoordinates.getFromBlocks(6, 15, 12, 16);
5568
editorButton = new Plane(-menuEntriesWidth, tutorialButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesEditor);
5669
glRenderer.addDrawable(editorButton);
5770

58-
volumeOn = ObjectFactory.createSingleBox(0, 15, menuEntriesHeight);
71+
volumeOn = ObjectFactory.createSingleBox(12, 12, menuEntriesHeight);
5972
volumeOn.setVisible(false);
6073
volumeOn.setX(menuEntriesWidth);
6174
volumeOn.setY(volumeButton.getY());
6275
glRenderer.addDrawable(volumeOn);
63-
volumeOff = ObjectFactory.createSingleBox(1, 15, menuEntriesHeight);
76+
volumeOff = ObjectFactory.createSingleBox(13, 12, menuEntriesHeight);
6477
volumeOff.setVisible(false);
6578
volumeOff.setX(menuEntriesWidth);
6679
volumeOff.setY(volumeButton.getY());
6780
glRenderer.addDrawable(volumeOff);
81+
82+
TextureCoordinates coordinatesColorsExample = TextureCoordinates.getFromBlocks(14, 1, 16, 2);
83+
colorsExample = new Plane(-menuEntriesWidth/2, menuEntriesStartY, menuEntriesHeight*2, menuEntriesHeight, coordinatesColorsExample);
84+
colorsExample.setVisible(false);
85+
colorsExample.setX(menuEntriesWidth);
86+
colorsExample.setY(colorsButton.getY());
87+
glRenderer.addDrawable(colorsExample);
6888
}
6989

7090
@Override
@@ -79,9 +99,17 @@ public void entry() {
7999
scaleAnimation.setTo(1);
80100
scaleAnimation.start();
81101

102+
colorsExample.setVisible(true);
103+
colorsExample.setScale(0);
104+
ScaleAnimation colorsScaleAnimation = new ScaleAnimation(colorsExample,
105+
Animation.DURATION_LONG, Animation.DURATION_LONG + (int) 1.0f * Animation.DURATION_SHORT);
106+
colorsScaleAnimation.setTo(1);
107+
colorsScaleAnimation.start();
108+
82109
AnimationFactory.startMenuAnimationEnter(volumeButton, (int) (2.0f * Animation.DURATION_SHORT));
83-
AnimationFactory.startMenuAnimationEnter(tutorialButton, (int) (2.5f * Animation.DURATION_SHORT));
84-
AnimationFactory.startMenuAnimationEnter(editorButton, (int) (3.0f * Animation.DURATION_SHORT));
110+
AnimationFactory.startMenuAnimationEnter(colorsButton, (int) (2.5f * Animation.DURATION_SHORT));
111+
AnimationFactory.startMenuAnimationEnter(tutorialButton, (int) (3.0f * Animation.DURATION_SHORT));
112+
AnimationFactory.startMenuAnimationEnter(editorButton, (int) (3.5f * Animation.DURATION_SHORT));
85113
}
86114

87115
@Override
@@ -93,13 +121,20 @@ public void exit() {
93121
scaleAnimation.setHideAfter(true);
94122
scaleAnimation.start();
95123

124+
ScaleAnimation colorsScaleAnimation = new ScaleAnimation(colorsExample,
125+
Animation.DURATION_LONG, 0);
126+
colorsScaleAnimation.setTo(0);
127+
colorsScaleAnimation.setHideAfter(true);
128+
colorsScaleAnimation.start();
129+
96130
if (nextState == TutorialState.getInstance()) {
97131
AnimationFactory.startMenuAnimationOutPressed(tutorialButton);
98132
} else {
99133
AnimationFactory.startMenuAnimationOut(tutorialButton);
100134
}
101135

102136
AnimationFactory.startMenuAnimationOut(volumeButton);
137+
AnimationFactory.startMenuAnimationOut(colorsButton);
103138
AnimationFactory.startMenuAnimationOut(editorButton);
104139
}
105140

@@ -123,6 +158,11 @@ public void onTouchEvent(MotionEvent event) {
123158
getPreferences().edit().putBoolean("volumeOn", newVolume).apply();
124159
volumeOff.setVisible(!newVolume);
125160
volumeOn.setVisible(newVolume);
161+
} else if (colorsExample.collides(event, getScreenHeight()) || colorsButton.collides(event, getScreenHeight())) {
162+
playSound(R.raw.click);
163+
int newColorschemeIndex = (getPreferences().getInt("colorschemeIndex", 0) + 1) % numberOfColorschemes;
164+
getPreferences().edit().putInt("colorschemeIndex", newColorschemeIndex).apply();
165+
glRenderer.setColorscheme(newColorschemeIndex);
126166
} else if (tutorialButton.collides(event, getScreenHeight())) {
127167
nextState = TutorialState.getInstance();
128168
playSound(R.raw.click);

app/src/main/java/com/bytehamster/flowitgame/state/State.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void initialize(GLRenderer renderer, SoundPool soundPool, Activity activi
4949
this.playedPrefs = activity.getSharedPreferences("playedState", Context.MODE_PRIVATE);
5050
this.prefs = activity.getSharedPreferences("preferences", Context.MODE_PRIVATE);
5151

52+
renderer.setColorscheme(getPreferences().getInt("colorschemeIndex", 0));
5253
initialize(renderer);
5354
}
5455

-264 KB
Binary file not shown.
268 KB
Loading
264 KB
Loading
-256 KB
Binary file not shown.
282 KB
Loading
277 KB
Loading

0 commit comments

Comments
 (0)