Finished toolbars opengl-rendering!!! and removed old ones
This commit is contained in:
@ -3,6 +3,7 @@ precision mediump float;
|
||||
uniform sampler2D texture;
|
||||
uniform float useCustomColor;
|
||||
uniform vec4 color;
|
||||
uniform float alpha;
|
||||
uniform float roundValue;
|
||||
uniform float visibleAmount;
|
||||
|
||||
@ -19,7 +20,7 @@ void main() {
|
||||
} else {
|
||||
gl_FragColor = texture2D(texture, pass_TexCoords);
|
||||
}
|
||||
|
||||
gl_FragColor.a = min(gl_FragColor.a, alpha);
|
||||
gl_FragColor.rgb = gl_FragColor.rgb / gl_FragColor.a;
|
||||
} else {
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
@ -22,6 +22,7 @@ public class ToolButton {
|
||||
private Gui border;
|
||||
private Gui background;
|
||||
private Progressbar progressbar;
|
||||
private ToolButtonAnimationLayer animationLayer;
|
||||
|
||||
private Game game;
|
||||
private ToolType toolType;
|
||||
@ -40,22 +41,25 @@ public class ToolButton {
|
||||
border.setRoundValue(0.3f);
|
||||
background = new Gui(null, position, height, height);
|
||||
progressbar = new Progressbar(texturePack.white, position, height, height, 0);
|
||||
progressbar.setColor(new Color4f(0.55f, 0.55f, 0.55f, 0.62f));
|
||||
progressbar.setColor(new Color4f(0.4f, 0.4f, 0.4f, 0.6f));
|
||||
progressbar.setRoundValue(1);
|
||||
progressbar.setProgress(0.6f);
|
||||
animationLayer = new ToolButtonAnimationLayer(toolButtonLockedTexture, position, height,
|
||||
height);
|
||||
}
|
||||
|
||||
public void setToolSlot(ToolSlot toolSlot) {
|
||||
this.toolType = toolSlot.getToolType();
|
||||
this.locked = toolSlot.isLocked();
|
||||
|
||||
if (locked)
|
||||
if (locked) {
|
||||
background.setTexture(toolButtonLockedTexture);
|
||||
else if (toolType == null)
|
||||
} else if (toolType == null) {
|
||||
background.setTexture(toolButtonEmptyTexture);
|
||||
else
|
||||
} else {
|
||||
background.setTexture(toolType.getToolButtonTexture());
|
||||
|
||||
animationLayer.setTexture(toolType.getToolButtonTexture());
|
||||
}
|
||||
if (toolType != null)
|
||||
progressbar.setMaxTime(toolType.getCurrentUpgradeValue(ToolUpgradeType.COOLDOWN));
|
||||
|
||||
@ -74,15 +78,20 @@ public class ToolButton {
|
||||
return progressbar.hasFinished();
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
if (progressbar.hasFinished())
|
||||
return;
|
||||
progressbar.update(frameTime);
|
||||
if (progressbar.hasFinished()) {
|
||||
if (active.get())
|
||||
game.onToolButtonFinishedLoading(toolType);
|
||||
public void update(float frameTime, boolean gameRunning) {
|
||||
if (gameRunning) {
|
||||
if (!progressbar.hasFinished()) {
|
||||
progressbar.update(frameTime);
|
||||
if (progressbar.hasFinished()) {
|
||||
animationLayer.startAnimation();
|
||||
if (active.get())
|
||||
game.onToolButtonFinishedLoading(toolType);
|
||||
}
|
||||
}
|
||||
updateBorderColor();
|
||||
}
|
||||
updateBorderColor();
|
||||
|
||||
animationLayer.update(frameTime);
|
||||
}
|
||||
|
||||
public synchronized void updateBorderColor() {
|
||||
@ -121,6 +130,10 @@ public class ToolButton {
|
||||
return progressbar;
|
||||
}
|
||||
|
||||
public ToolButtonAnimationLayer getAnimationLayer() {
|
||||
return animationLayer;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package de.frajul.endlessroll.entities.guis;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
|
||||
public class ToolButtonAnimationLayer extends Gui {
|
||||
|
||||
private final float ANIMATION_TIME = 500;
|
||||
|
||||
private float startWidth;
|
||||
private float startHeight;
|
||||
private boolean animationRunning = false;
|
||||
private float elapsedTime = 0;
|
||||
|
||||
public ToolButtonAnimationLayer(Texture texture, Vector position, float width, float height) {
|
||||
super(texture, position, width, height);
|
||||
super.setVisible(false);
|
||||
this.startWidth = width;
|
||||
this.startHeight = height;
|
||||
}
|
||||
|
||||
public void startAnimation() {
|
||||
reset();
|
||||
super.setVisible(true);
|
||||
animationRunning = true;
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
if (animationRunning) {
|
||||
elapsedTime += frameTime;
|
||||
if (elapsedTime >= ANIMATION_TIME) {
|
||||
reset();
|
||||
}
|
||||
float progress = elapsedTime / ANIMATION_TIME;
|
||||
super.setAlpha(0.5f - 0.5f * progress);
|
||||
float scaleFactor = 1 + 2 * progress;
|
||||
super.setWidth(scaleFactor * startWidth);
|
||||
super.setHeight(scaleFactor * startHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
animationRunning = false;
|
||||
elapsedTime = 0;
|
||||
super.setVisible(false);
|
||||
super.setAlpha(0.5f);
|
||||
super.setWidth(startWidth);
|
||||
super.setHeight(startHeight);
|
||||
}
|
||||
|
||||
}
|
@ -5,9 +5,9 @@ import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.data.Vector;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.user.ToolSlotSettings;
|
||||
import de.frajul.endlessroll.views.ToolButtonView;
|
||||
|
||||
public class ToolButtonBar {
|
||||
|
||||
@ -32,9 +32,9 @@ public class ToolButtonBar {
|
||||
}
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
public void update(float frameTime, boolean gameRunning) {
|
||||
for (ToolButton button : toolButtons)
|
||||
button.update(frameTime);
|
||||
button.update(frameTime, gameRunning);
|
||||
}
|
||||
|
||||
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
|
||||
@ -45,20 +45,28 @@ public class ToolButtonBar {
|
||||
|
||||
public void reset(ToolSlotSettings toolSlotSettings) {
|
||||
changeToolButtonTypes(toolSlotSettings);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (toolSlotSettings.get(i).getToolType() != null) {
|
||||
toolButtons.get(i).setActive(true);
|
||||
toolButtons.get(i).updateBorderColor();
|
||||
break;
|
||||
}
|
||||
|
||||
boolean activeButtonAlreadySet = false;
|
||||
for (ToolButton toolButton : toolButtons) {
|
||||
if (!activeButtonAlreadySet && toolButton.getToolType() != null) {
|
||||
toolButton.setActive(true);
|
||||
activeButtonAlreadySet = true;
|
||||
} else
|
||||
toolButton.setActive(false);
|
||||
toolButton.updateBorderColor();
|
||||
toolButton.setProgress(1);
|
||||
toolButton.getAnimationLayer().reset();
|
||||
}
|
||||
for (ToolButton button : toolButtons)
|
||||
button.setProgress(1);
|
||||
}
|
||||
|
||||
public ToolButton getActiveButton(){
|
||||
for(ToolButton button : toolButtons)
|
||||
if(button.getActive().get())
|
||||
public void setActive(ToolType activeType) {
|
||||
for (ToolButton button : toolButtons)
|
||||
button.setActive(button.getToolType() == activeType);
|
||||
}
|
||||
|
||||
public ToolButton getActiveButton() {
|
||||
for (ToolButton button : toolButtons)
|
||||
if (button.getActive().get())
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
@ -69,7 +77,12 @@ public class ToolButtonBar {
|
||||
list.add(button.getBorder());
|
||||
list.add(button.getBackground());
|
||||
list.add(button.getProgressbar());
|
||||
list.add(button.getAnimationLayer());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ToolButton> getToolButtons() {
|
||||
return toolButtons;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import de.frajul.endlessroll.entities.Obstacle;
|
||||
import de.frajul.endlessroll.entities.Player;
|
||||
import de.frajul.endlessroll.entities.collectables.Energy;
|
||||
import de.frajul.endlessroll.entities.collectables.Star;
|
||||
import de.frajul.endlessroll.entities.collision.CollisionDetector;
|
||||
import de.frajul.endlessroll.entities.collision.CollisionManager;
|
||||
import de.frajul.endlessroll.entities.guis.Countdown;
|
||||
import de.frajul.endlessroll.entities.guis.ToolButton;
|
||||
import de.frajul.endlessroll.entities.guis.ToolButtonBar;
|
||||
import de.frajul.endlessroll.entities.particles.Firework;
|
||||
@ -31,9 +33,6 @@ import de.frajul.endlessroll.main.screens.GameScreen;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
import de.frajul.endlessroll.rendering.Rendering;
|
||||
import de.frajul.endlessroll.sqlDatabase.MyDatabase;
|
||||
import de.frajul.endlessroll.entities.guis.Countdown;
|
||||
import de.frajul.endlessroll.views.ToolButtonView;
|
||||
import de.frajul.endlessroll.views.ToolButtonBarView;
|
||||
import de.frajul.endlessroll.views.ViewManager;
|
||||
|
||||
/**
|
||||
@ -54,6 +53,7 @@ public class Game extends Rendering<GameScene> {
|
||||
private Player player;
|
||||
private Physics physics;
|
||||
private CollisionManager collisionManager;
|
||||
private CollisionDetector collisionDetector;
|
||||
private Timer timer;
|
||||
private GameState gameState = GameState.COUNTDOWN;
|
||||
|
||||
@ -67,6 +67,7 @@ public class Game extends Rendering<GameScene> {
|
||||
this.gameActivity = gameActivity;
|
||||
physics = new Physics();
|
||||
collisionManager = new CollisionManager(this);
|
||||
collisionDetector = new CollisionDetector();
|
||||
particleSystem = new ParticleSystem(getContext());
|
||||
viewManager = new ViewManager(this, gameScreen, handler, gameActivity);
|
||||
}
|
||||
@ -80,7 +81,8 @@ public class Game extends Rendering<GameScene> {
|
||||
scene = new GameScene(gameActivity, texturePack, particleSystem);
|
||||
firework = new Firework(particleSystem.firework, scene.getCamera());
|
||||
countdown = new Countdown(this, gameActivity.getSoundManager(), texturePack);
|
||||
toolButtonBar = new ToolButtonBar(texturePack, this, gameActivity.getUser().getToolSlotSettings());
|
||||
toolButtonBar = new ToolButtonBar(texturePack, this,
|
||||
gameActivity.getUser().getToolSlotSettings());
|
||||
scene.getGuis().addAll(toolButtonBar.toGuiList());
|
||||
scene.getGuis().add(countdown);
|
||||
if (level != null)
|
||||
@ -144,10 +146,9 @@ public class Game extends Rendering<GameScene> {
|
||||
|
||||
float playerProgress = player.getProgress();
|
||||
viewManager.update(gameState == GameState.RUNNING, timer, playerProgress);
|
||||
toolButtonBar.update(timer.getFrameTimeSeconds(), gameState == GameState.RUNNING);
|
||||
switch (gameState) {
|
||||
case RUNNING:
|
||||
toolButtonBar.update(timer.getFrameTimeSeconds());
|
||||
|
||||
if (player.getPosition().y < -2f) {
|
||||
onGameOver(false);
|
||||
return;
|
||||
@ -175,38 +176,47 @@ public class Game extends Rendering<GameScene> {
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (gameState == GameState.RUNNING) {
|
||||
ToolButton currentToolButton = toolButtonBar.getActiveButton();
|
||||
if (currentToolButton != null && currentToolButton.hasFinishedLoading() && currentToolButton.getToolType() != null) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
try {
|
||||
if (gameState == GameState.RUNNING && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
Vector touchPoint = scene.calcWorldFromScreenCoords(event.getX(), event.getY());
|
||||
|
||||
for (ToolButton toolButton : toolButtonBar.getToolButtons()) {
|
||||
ToolType toolType = toolButton.getToolType();
|
||||
if (collisionDetector.isPointQuadCollision(touchPoint,
|
||||
toolButton.getBorder()) && toolType != null) {
|
||||
toolButtonBar.setActive(toolType);
|
||||
setCurrentTool(toolType, toolButton.hasFinishedLoading());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
touchPoint.translate(scene.camera.getX(), scene.camera.getY());
|
||||
ToolButton currentToolButton = toolButtonBar.getActiveButton();
|
||||
if (currentToolButton != null && currentToolButton
|
||||
.hasFinishedLoading() && currentToolButton.getToolType() != null) {
|
||||
if (currentTool == ToolType.BOMB) {
|
||||
try {
|
||||
Vector touchPoint = scene
|
||||
.calcWorldFromScreenCoords(event.getX(), event.getY());
|
||||
Obstacle selectedObstacle = scene.getObstacleAtPoint(touchPoint);
|
||||
if (selectedObstacle == null) {
|
||||
viewManager.showBombErrorMessage(event.getX(), event.getY());
|
||||
return true;
|
||||
} else {
|
||||
currentToolButton.setProgress(0);
|
||||
scene.getBombSelected().set(false);
|
||||
Tool tool = addTool(event.getX(), event.getY());
|
||||
if (tool != null && tool instanceof Bomb)
|
||||
((Bomb) tool).setAttachedObstacle(selectedObstacle);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
onException(e);
|
||||
Obstacle selectedObstacle = scene.getObstacleAtPoint(touchPoint);
|
||||
if (selectedObstacle == null) {
|
||||
viewManager.showBombErrorMessage(event.getX(), event.getY());
|
||||
return true;
|
||||
} else {
|
||||
currentToolButton.setProgress(0);
|
||||
scene.getBombSelected().set(false);
|
||||
Tool tool = addTool(touchPoint);
|
||||
if (tool != null && tool instanceof Bomb)
|
||||
((Bomb) tool).setAttachedObstacle(selectedObstacle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
currentToolButton.setProgress(0);
|
||||
addTool(event.getX(), event.getY());
|
||||
addTool(touchPoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
onException(e);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetViews() {
|
||||
@ -271,10 +281,10 @@ public class Game extends Rendering<GameScene> {
|
||||
gameState = GameState.RUNNING;
|
||||
}
|
||||
|
||||
private Tool addTool(float x, float y) {
|
||||
private Tool addTool(Vector position) {
|
||||
try {
|
||||
gameActivity.getSoundManager().playSound(gameActivity.getSoundManager().placeToolSound);
|
||||
return scene.addTool(currentTool, x, y, physics);
|
||||
return scene.addTool(currentTool, position, physics);
|
||||
} catch (Exception e) {
|
||||
onException(e);
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ public class GameScene extends Scene {
|
||||
obstacles.add(obstacle);
|
||||
}
|
||||
|
||||
public Tool addTool(ToolType type, float screenX, float screenY, Physics physics) throws Exception {
|
||||
Vector position = calcWorldFromScreenCoords(screenX, screenY);
|
||||
public Tool addTool(ToolType type, Vector position, Physics physics) throws Exception {
|
||||
Tool tool = type.newInstance(position, particleSystem, gameActivity.getSoundManager());
|
||||
physics.checkSingleToolCollision(tool, this);
|
||||
|
||||
|
@ -156,9 +156,7 @@ public abstract class Scene {
|
||||
throw new Exception("ScreenSize not set");
|
||||
float glCoordWidth = (2f * screenSize.x / screenSize.y);
|
||||
float x = ((screenX / screenSize.x) * 2f - 1f) * glCoordWidth / 2;
|
||||
x += camera.getX();
|
||||
float y = -((screenY / screenSize.y) * 2f - 1f);
|
||||
y += camera.getY();
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
|
@ -150,6 +150,7 @@ public class GameRenderer implements GLSurfaceView.Renderer {
|
||||
gl.glBindTexture(GL10.GL_TEXTURE_2D, gui.getTexture().getId());
|
||||
guiShader.loadTransformationMatrix(matrixCreator, gui);
|
||||
guiShader.loadCustomColor(gui.getColor());
|
||||
guiShader.loadAlpha(gui.getAlpha());
|
||||
guiShader.loadRoundValue(gui.getRoundValue());
|
||||
if (gui instanceof Progressbar)
|
||||
guiShader.loadVisibleAmount(((Progressbar) gui).getProgress());
|
||||
|
@ -16,6 +16,7 @@ public class GuiShader extends ShaderProgram {
|
||||
private int location_transformationMatrix;
|
||||
private int location_useCustomColor;
|
||||
private int location_color;
|
||||
private int location_alpha;
|
||||
private int location_roundValue;
|
||||
private int location_visibleAmount;
|
||||
|
||||
@ -29,6 +30,7 @@ public class GuiShader extends ShaderProgram {
|
||||
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
|
||||
location_useCustomColor = super.getUniformLocation("useCustomColor");
|
||||
location_color = super.getUniformLocation("color");
|
||||
location_alpha = super.getUniformLocation("alpha");
|
||||
location_roundValue = super.getUniformLocation("roundValue");
|
||||
location_visibleAmount = super.getUniformLocation("visibleAmount");
|
||||
}
|
||||
@ -50,6 +52,10 @@ public class GuiShader extends ShaderProgram {
|
||||
color.getA());
|
||||
}
|
||||
|
||||
public void loadAlpha(float alpha){
|
||||
GLES20.glUniform1f(location_alpha, alpha);
|
||||
}
|
||||
|
||||
public void loadRoundValue(float roundValue) {
|
||||
GLES20.glUniform1f(location_roundValue, roundValue);
|
||||
}
|
||||
|
@ -1,114 +0,0 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.main.game.GameState;
|
||||
import de.frajul.endlessroll.user.ToolSlotSettings;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.01.2016.
|
||||
*/
|
||||
public class ToolButtonBarView implements View.OnClickListener{
|
||||
|
||||
private Game game;
|
||||
private List<ToolButtonView> buttons = new ArrayList<>(4);
|
||||
private RelativeLayout button1;
|
||||
private RelativeLayout button2;
|
||||
private RelativeLayout button3;
|
||||
private RelativeLayout button4;
|
||||
|
||||
|
||||
public ToolButtonBarView(Game game, ToolSlotSettings toolSlotSettings, LinearLayout layout1) {
|
||||
this.game = game;
|
||||
Context context = game.getContext();
|
||||
|
||||
button1 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_1);
|
||||
button1.setOnClickListener(this);
|
||||
button2 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_2);
|
||||
button2.setOnClickListener(this);
|
||||
button3 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_3);
|
||||
button3.setOnClickListener(this);
|
||||
button4 = (RelativeLayout) layout1.findViewById(R.id.toolbutton_4);
|
||||
button4.setOnClickListener(this);
|
||||
buttons.add(new ToolButtonView(toolSlotSettings.get(0), game, context, button1));
|
||||
buttons.add(new ToolButtonView(toolSlotSettings.get(1), game, context, button2));
|
||||
buttons.add(new ToolButtonView(toolSlotSettings.get(2), game, context, button3));
|
||||
buttons.add(new ToolButtonView(toolSlotSettings.get(3), game, context, button4));
|
||||
}
|
||||
|
||||
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buttons.get(i).changeToolSlot(toolSlotSettings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(ToolSlotSettings toolSlotSettings) {
|
||||
changeToolButtonTypes(toolSlotSettings);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (toolSlotSettings.get(i).getToolType() != null) {
|
||||
setActive(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (ToolButtonView button : buttons)
|
||||
button.setProgress(100);
|
||||
}
|
||||
|
||||
public void update(float frameTime, boolean showAnimation) {
|
||||
for (ToolButtonView button : buttons)
|
||||
button.update(frameTime, showAnimation);
|
||||
}
|
||||
|
||||
public void setActive(ToolType activeType) {
|
||||
for (ToolButtonView button : buttons)
|
||||
button.setActive(button.getToolType() == activeType);
|
||||
}
|
||||
|
||||
private void setActive(int index) {
|
||||
for (ToolButtonView button : buttons)
|
||||
button.setActive(buttons.indexOf(button) == index);
|
||||
}
|
||||
|
||||
public ToolButtonView getByToolType(ToolType type) {
|
||||
for (ToolButtonView button : buttons)
|
||||
if (button.getToolType() == type)
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ToolButtonView getActiveButton() {
|
||||
for (ToolButtonView button : buttons)
|
||||
if (button.isActive())
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (game.getGameState() == GameState.RUNNING) {
|
||||
ToolButtonView clickedButton = null;
|
||||
if (v.equals(button1) && !buttons.get(0).isLocked()) {
|
||||
clickedButton = buttons.get(0);
|
||||
} else if (v.equals(button2) && !buttons.get(1).isLocked()) {
|
||||
clickedButton = buttons.get(1);
|
||||
} else if (v.equals(button3) && !buttons.get(2).isLocked()) {
|
||||
clickedButton = buttons.get(2);
|
||||
} else if (v.equals(button4) && !buttons.get(3).isLocked()) {
|
||||
clickedButton = buttons.get(3);
|
||||
}
|
||||
if (clickedButton != null && clickedButton.getToolType() != null) {
|
||||
game.setCurrentTool(clickedButton.getToolType(), clickedButton.finishedLoading());
|
||||
setActive(clickedButton.getToolType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.tools.ToolSlot;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.entities.tools.ToolUpgradeType;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
|
||||
/**
|
||||
* Created by Julian on 15.01.2016.
|
||||
*/
|
||||
public class ToolButtonView {
|
||||
|
||||
private Game game;
|
||||
private boolean locked;
|
||||
private ToolType toolType;
|
||||
private Context context;
|
||||
private float progress = 100;
|
||||
private boolean active = false;
|
||||
|
||||
private RelativeLayout layout;
|
||||
private ProgressBar progressBar;
|
||||
private ImageView backgroundView;
|
||||
private ImageView animationView;
|
||||
private Animation scaleAnimation;
|
||||
|
||||
public ToolButtonView(ToolSlot slot, Game game, Context context, RelativeLayout layout) {
|
||||
this.context = context;
|
||||
this.game = game;
|
||||
this.layout = layout;
|
||||
progressBar = (ProgressBar) layout.findViewById(R.id.tool_button_progress_bar);
|
||||
|
||||
scaleAnimation = AnimationUtils.loadAnimation(context, R.anim.scale_up);
|
||||
changeToolSlot(slot);
|
||||
}
|
||||
|
||||
public void changeToolSlot(ToolSlot toolSlot) {
|
||||
this.toolType = toolSlot.getToolType();
|
||||
this.locked = toolSlot.isLocked();
|
||||
backgroundView = createImageView(toolType, R.id.tool_button_background_layer);
|
||||
animationView = createImageView(toolType, R.id.tool_button_animation_layer);
|
||||
}
|
||||
|
||||
private ImageView createImageView(ToolType type, int id) {
|
||||
ImageView view = (ImageView) layout.findViewById(id);
|
||||
if (locked)
|
||||
view.setImageResource(R.drawable.tools_button_locked);
|
||||
else if (type != null)
|
||||
view.setImageResource(type.getButtonDrawable());
|
||||
else
|
||||
view.setImageResource(R.drawable.tools_button_empty);
|
||||
view.setBackgroundDrawable(createColoredBackground());
|
||||
return view;
|
||||
}
|
||||
|
||||
private Drawable createColoredBackground() {
|
||||
GradientDrawable gd = new GradientDrawable();
|
||||
gd.setColor(context.getResources().getColor(R.color.toolbuttonInactiveNotReady));
|
||||
if (locked || toolType == null) {
|
||||
gd.setColor(context.getResources().getColor(R.color.toolbuttonLocked));
|
||||
}
|
||||
gd.setCornerRadius(15);
|
||||
return gd;
|
||||
}
|
||||
|
||||
public void update(float frameTime, boolean showAnimation) {
|
||||
if (progress != 100) {
|
||||
progress += (frameTime) / (toolType
|
||||
.getCurrentUpgradeValue(ToolUpgradeType.COOLDOWN) / 100);
|
||||
progress = Math.min(progress, 100);
|
||||
if (progress == 100 && showAnimation)
|
||||
animationView.startAnimation(scaleAnimation);
|
||||
}
|
||||
progressBar.setProgress(100 - (int) progress);
|
||||
if (!locked && toolType != null) {
|
||||
if (active) {
|
||||
if (progress == 100) {
|
||||
game.onToolButtonFinishedLoading(toolType);
|
||||
setColor(R.color.toolbuttonActiveReady);
|
||||
} else
|
||||
setColor(R.color.toolbuttonActiveNotReady);
|
||||
} else {
|
||||
if (progress == 100)
|
||||
setColor(R.color.toolbuttonInactiveReady);
|
||||
else
|
||||
setColor(R.color.toolbuttonInactiveNotReady);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setColor(int id) {
|
||||
GradientDrawable gd = (GradientDrawable) backgroundView.getBackground();
|
||||
GradientDrawable animGd = (GradientDrawable) animationView.getBackground();
|
||||
gd.setColor(context.getResources().getColor(id));
|
||||
animGd.setColor(context.getResources().getColor(id));
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public boolean finishedLoading() {
|
||||
return progress == 100;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#00fff700" />
|
||||
<corners android:radius="200dp" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:id="@android:id/progress">
|
||||
<clip android:gravity="right">
|
||||
<shape android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="45"
|
||||
android:endColor="#a06c6c6c"
|
||||
android:startColor="#a0ababab" />
|
||||
<corners android:radius="200dp" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
@ -14,15 +14,6 @@
|
||||
android:layout_margin="10dp"
|
||||
android:src="@drawable/guis_pausebutton"/>
|
||||
|
||||
<!--<include-->
|
||||
<!--android:id="@+id/game_toolbuttonbar"-->
|
||||
<!--layout="@layout/toolbuttonbar"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_alignParentTop="true"-->
|
||||
<!--android:layout_centerHorizontal="true"-->
|
||||
<!--android:layout_marginTop="3dp"/>-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/game_playerprogress"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -57,7 +57,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="A simple tool which will get you in the air"
|
||||
android:text="@string/placeholder_textview"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"/>
|
||||
</RelativeLayout>
|
||||
|
@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tool_button_background_layer"
|
||||
android:layout_width="@dimen/tool_button_width"
|
||||
android:layout_height="@dimen/tool_button_height"
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/tools_ramp_button"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tool_button_animation_layer"
|
||||
android:layout_width="@dimen/tool_button_width"
|
||||
android:layout_height="@dimen/tool_button_height"
|
||||
android:src="@drawable/tools_ramp_button"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/tool_button_progress_bar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="@dimen/tool_button_height"
|
||||
android:layout_centerInParent="true"
|
||||
android:max="100"
|
||||
android:progress="100"
|
||||
android:progressDrawable="@drawable/xml_layers_toolprogressbar"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbutton_1"
|
||||
layout="@layout/toolbutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbutton_2"
|
||||
layout="@layout/toolbutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbutton_3"
|
||||
layout="@layout/toolbutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbutton_4"
|
||||
layout="@layout/toolbutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="2dp"/>
|
||||
</LinearLayout>
|
Reference in New Issue
Block a user