Skip to content
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
27 changes: 26 additions & 1 deletion app/src/main/java/com/bytehamster/flowitgame/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
public class GLRenderer implements Renderer {
private static final String TAG = "GLRenderer";
private final Context myContext;

private final int[] textureDrawables = new int[] {R.drawable.texture_colorscheme_0, R.drawable.texture_colorscheme_1};
public final int numberOfColorschemes = textureDrawables.length;

private int width = 0;
private int height = 0;
private final int[] textures = new int[1];
private Runnable onViewportSetupComplete = null;
private final ArrayList<Drawable> objects = new ArrayList<>();

private int currentColorschemeIndex = 0;
private boolean reloadTextureNextFrame = false;

public GLRenderer(Context c) {
myContext = c;
}
Expand All @@ -31,6 +38,11 @@ public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();

if (reloadTextureNextFrame) {
loadTexture(gl, 0, textureDrawables[currentColorschemeIndex]);
reloadTextureNextFrame = false;
}

gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
for (Drawable o : objects) {
o.draw(gl);
Expand All @@ -55,7 +67,8 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glGenTextures(textures.length, textures, 0);
loadTexture(gl, 0, R.drawable.texture);
loadTexture(gl, 0, textureDrawables[currentColorschemeIndex]);

debugOutput(gl);
}

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

public void setColorscheme(int colorschemeIndex) {
// Return to default colorscheme if given an invalid colorschemeIndex.
// For example, if the number of colorschemes decreases after an update.
if ((0 <= colorschemeIndex) && (colorschemeIndex < numberOfColorschemes)) {
currentColorschemeIndex = colorschemeIndex;
} else {
currentColorschemeIndex = 0;
}

reloadTextureNextFrame = true;
}

private void loadTexture(GL10 gl, int position, @DrawableRes int resource) {
Log.d(TAG, "loadTexture");
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[position]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void initialize(GLRenderer glRenderer) {
stepsUsedCurrentYDelta = topButtonSize * 0.6f;
stepsUsedBestYDelta = topButtonSize * 0.1f;

TextureCoordinates coordinatesHeader = TextureCoordinates.getFromBlocks(2, 15, 3, 16);
TextureCoordinates coordinatesHeader = TextureCoordinates.getFromBlocks(14, 12, 15, 13);
headerBackground = new Plane(0, glRenderer.getHeight(), glRenderer.getWidth(), topBarHeight, coordinatesHeader);
headerBackground.setVisible(false);
glRenderer.addDrawable(headerBackground);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class SettingsState extends State {
private Plane tutorialButton;
private Plane volumeButton;
private Plane editorButton;
private Plane colorsExample;
private Plane colorsButton;

private int numberOfColorschemes;
private GLRenderer glRenderer;

private SettingsState() {

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

@Override
protected void initialize(GLRenderer glRenderer) {
protected void initialize(GLRenderer glRendererIn) {
glRenderer = glRendererIn;

numberOfColorschemes = glRenderer.numberOfColorschemes;

float menuEntriesWidth = glRenderer.getWidth() * 0.75f;
float menuEntriesHeight = menuEntriesWidth / 6;
float menuEntriesAvailableSpace = getScreenHeight();
Expand All @@ -47,24 +56,35 @@ protected void initialize(GLRenderer glRenderer) {
volumeButton = new Plane(-menuEntriesWidth, menuEntriesStartY, menuEntriesWidth, menuEntriesHeight, coordinatesVolume);
glRenderer.addDrawable(volumeButton);

TextureCoordinates coordinatesColors = TextureCoordinates.getFromBlocks(0, 15, 6, 16);
colorsButton = new Plane(-menuEntriesWidth, volumeButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesColors);
glRenderer.addDrawable(colorsButton);

TextureCoordinates coordinatesTutorial = TextureCoordinates.getFromBlocks(6, 12, 12, 13);
tutorialButton = new Plane(-menuEntriesWidth, volumeButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesTutorial);
tutorialButton = new Plane(-menuEntriesWidth, colorsButton.getY() - 2 * menuEntriesHeight, menuEntriesWidth, menuEntriesHeight, coordinatesTutorial);
glRenderer.addDrawable(tutorialButton);

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

volumeOn = ObjectFactory.createSingleBox(0, 15, menuEntriesHeight);
volumeOn = ObjectFactory.createSingleBox(12, 12, menuEntriesHeight);
volumeOn.setVisible(false);
volumeOn.setX(menuEntriesWidth);
volumeOn.setY(volumeButton.getY());
glRenderer.addDrawable(volumeOn);
volumeOff = ObjectFactory.createSingleBox(1, 15, menuEntriesHeight);
volumeOff = ObjectFactory.createSingleBox(13, 12, menuEntriesHeight);
volumeOff.setVisible(false);
volumeOff.setX(menuEntriesWidth);
volumeOff.setY(volumeButton.getY());
glRenderer.addDrawable(volumeOff);

TextureCoordinates coordinatesColorsExample = TextureCoordinates.getFromBlocks(14, 1, 16, 2);
colorsExample = new Plane(-menuEntriesWidth/2, menuEntriesStartY, menuEntriesHeight*2, menuEntriesHeight, coordinatesColorsExample);
colorsExample.setVisible(false);
colorsExample.setX(menuEntriesWidth);
colorsExample.setY(colorsButton.getY());
glRenderer.addDrawable(colorsExample);
}

@Override
Expand All @@ -79,9 +99,17 @@ public void entry() {
scaleAnimation.setTo(1);
scaleAnimation.start();

colorsExample.setVisible(true);
colorsExample.setScale(0);
ScaleAnimation colorsScaleAnimation = new ScaleAnimation(colorsExample,
Animation.DURATION_LONG, Animation.DURATION_LONG + (int) 1.0f * Animation.DURATION_SHORT);
colorsScaleAnimation.setTo(1);
colorsScaleAnimation.start();

AnimationFactory.startMenuAnimationEnter(volumeButton, (int) (2.0f * Animation.DURATION_SHORT));
AnimationFactory.startMenuAnimationEnter(tutorialButton, (int) (2.5f * Animation.DURATION_SHORT));
AnimationFactory.startMenuAnimationEnter(editorButton, (int) (3.0f * Animation.DURATION_SHORT));
AnimationFactory.startMenuAnimationEnter(colorsButton, (int) (2.5f * Animation.DURATION_SHORT));
AnimationFactory.startMenuAnimationEnter(tutorialButton, (int) (3.0f * Animation.DURATION_SHORT));
AnimationFactory.startMenuAnimationEnter(editorButton, (int) (3.5f * Animation.DURATION_SHORT));
}

@Override
Expand All @@ -93,13 +121,20 @@ public void exit() {
scaleAnimation.setHideAfter(true);
scaleAnimation.start();

ScaleAnimation colorsScaleAnimation = new ScaleAnimation(colorsExample,
Animation.DURATION_LONG, 0);
colorsScaleAnimation.setTo(0);
colorsScaleAnimation.setHideAfter(true);
colorsScaleAnimation.start();

if (nextState == TutorialState.getInstance()) {
AnimationFactory.startMenuAnimationOutPressed(tutorialButton);
} else {
AnimationFactory.startMenuAnimationOut(tutorialButton);
}

AnimationFactory.startMenuAnimationOut(volumeButton);
AnimationFactory.startMenuAnimationOut(colorsButton);
AnimationFactory.startMenuAnimationOut(editorButton);
}

Expand All @@ -123,6 +158,11 @@ public void onTouchEvent(MotionEvent event) {
getPreferences().edit().putBoolean("volumeOn", newVolume).apply();
volumeOff.setVisible(!newVolume);
volumeOn.setVisible(newVolume);
} else if (colorsExample.collides(event, getScreenHeight()) || colorsButton.collides(event, getScreenHeight())) {
playSound(R.raw.click);
int newColorschemeIndex = (getPreferences().getInt("colorschemeIndex", 0) + 1) % numberOfColorschemes;
getPreferences().edit().putInt("colorschemeIndex", newColorschemeIndex).apply();
glRenderer.setColorscheme(newColorschemeIndex);
} else if (tutorialButton.collides(event, getScreenHeight())) {
nextState = TutorialState.getInstance();
playSound(R.raw.click);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void initialize(GLRenderer renderer, SoundPool soundPool, Activity activi
this.playedPrefs = activity.getSharedPreferences("playedState", Context.MODE_PRIVATE);
this.prefs = activity.getSharedPreferences("preferences", Context.MODE_PRIVATE);

renderer.setColorscheme(getPreferences().getInt("colorschemeIndex", 0));
initialize(renderer);
}

Expand Down
Binary file removed app/src/main/res/drawable-de-nodpi/texture.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/drawable-fr-nodpi/texture.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/drawable-nodpi/texture.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/texture.xcf
Binary file not shown.