Finished toolbars opengl-rendering!!! and removed old ones

This commit is contained in:
= 2018-05-11 15:01:00 +02:00
parent 7f7b53b8a0
commit cd1932a9df
20 changed files with 224 additions and 482 deletions

View File

@ -547,11 +547,11 @@ public final class R {
public static final int time = 0x7f0800a6;
public static final int title = 0x7f0800a7;
public static final int title_template = 0x7f0800a8;
public static final int topPanel = 0x7f0800c0;
public static final int up = 0x7f0800d2;
public static final int useLogo = 0x7f0800d3;
public static final int withText = 0x7f0800d4;
public static final int wrap_content = 0x7f0800dd;
public static final int topPanel = 0x7f0800b9;
public static final int up = 0x7f0800cb;
public static final int useLogo = 0x7f0800cc;
public static final int withText = 0x7f0800cd;
public static final int wrap_content = 0x7f0800d6;
}
public static final class integer {
public static final int abc_config_activityDefaultDur = 0x7f090000;

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,6 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:testOnly="true"
android:theme="@style/AppTheme" >
<activity
android:name="de.frajul.endlessroll.main.GameActivity"

View File

@ -564,16 +564,15 @@ int drawable xml_background_tutorialimageview 0x7f070099
int drawable xml_background_tutorialtextview 0x7f07009a
int drawable xml_background_worldbutton 0x7f07009b
int drawable xml_layers_levelprogressbar 0x7f07009c
int drawable xml_layers_toolprogressbar 0x7f07009d
int drawable xml_selector_backbutton 0x7f07009e
int drawable xml_selector_gamebutton 0x7f07009f
int drawable xml_selector_music 0x7f0700a0
int drawable xml_selector_pricebutton 0x7f0700a1
int drawable xml_selector_settings_button 0x7f0700a2
int drawable xml_selector_settingsbutton 0x7f0700a3
int drawable xml_selector_shapeshopbutton 0x7f0700a4
int drawable xml_selector_sound 0x7f0700a5
int drawable xml_selector_toolshopbutton 0x7f0700a6
int drawable xml_selector_backbutton 0x7f07009d
int drawable xml_selector_gamebutton 0x7f07009e
int drawable xml_selector_music 0x7f07009f
int drawable xml_selector_pricebutton 0x7f0700a0
int drawable xml_selector_settings_button 0x7f0700a1
int drawable xml_selector_settingsbutton 0x7f0700a2
int drawable xml_selector_shapeshopbutton 0x7f0700a3
int drawable xml_selector_sound 0x7f0700a4
int drawable xml_selector_toolshopbutton 0x7f0700a5
int id action0 0x7f080000
int id action_bar 0x7f080001
int id action_bar_activity_content 0x7f080002
@ -743,59 +742,52 @@ int id textSpacerNoButtons 0x7f0800a5
int id time 0x7f0800a6
int id title 0x7f0800a7
int id title_template 0x7f0800a8
int id tool_button_animation_layer 0x7f0800a9
int id tool_button_background_layer 0x7f0800aa
int id tool_button_progress_bar 0x7f0800ab
int id tool_inspector_description 0x7f0800ac
int id tool_inspector_imageview 0x7f0800ad
int id tool_inspector_level_view 0x7f0800ae
int id tool_inspector_pricebutton 0x7f0800af
int id tool_inspector_title 0x7f0800b0
int id toolbutton_1 0x7f0800b1
int id toolbutton_2 0x7f0800b2
int id toolbutton_3 0x7f0800b3
int id toolbutton_4 0x7f0800b4
int id toolofferslot_slot 0x7f0800b5
int id toolofferslot_title 0x7f0800b6
int id toolshop_slot1 0x7f0800b7
int id toolshop_slot2 0x7f0800b8
int id toolshop_slot3 0x7f0800b9
int id toolshop_slot4 0x7f0800ba
int id toolshop_tool_offer_bottom_row 0x7f0800bb
int id toolshop_tool_offer_top_row 0x7f0800bc
int id toolshop_toolinspector 0x7f0800bd
int id toolshop_topbar 0x7f0800be
int id toolslot_image 0x7f0800bf
int id topPanel 0x7f0800c0
int id topbar_back_button 0x7f0800c1
int id topbar_energycount 0x7f0800c2
int id topbar_energycount_decrease 0x7f0800c3
int id topbar_energyview 0x7f0800c4
int id topbar_leveldisplay 0x7f0800c5
int id topbar_levellayout 0x7f0800c6
int id topbar_levelprogress 0x7f0800c7
int id topbar_settings 0x7f0800c8
int id topbar_shapeshop 0x7f0800c9
int id topbar_starcount 0x7f0800ca
int id topbar_starcount_decrease 0x7f0800cb
int id topbar_starview 0x7f0800cc
int id topbar_toolshop 0x7f0800cd
int id tutorial_image_view 0x7f0800ce
int id tutorial_text_view 0x7f0800cf
int id unlockmessage_message 0x7f0800d0
int id unlockmessage_toolimage 0x7f0800d1
int id up 0x7f0800d2
int id useLogo 0x7f0800d3
int id withText 0x7f0800d4
int id worldbutton_energycount 0x7f0800d5
int id worldbutton_levelcount 0x7f0800d6
int id worldbutton_lock 0x7f0800d7
int id worldbutton_preview 0x7f0800d8
int id worldbutton_starcount 0x7f0800d9
int id worldbutton_title 0x7f0800da
int id worlds_layout 0x7f0800db
int id worlds_topbar 0x7f0800dc
int id wrap_content 0x7f0800dd
int id tool_inspector_description 0x7f0800a9
int id tool_inspector_imageview 0x7f0800aa
int id tool_inspector_level_view 0x7f0800ab
int id tool_inspector_pricebutton 0x7f0800ac
int id tool_inspector_title 0x7f0800ad
int id toolofferslot_slot 0x7f0800ae
int id toolofferslot_title 0x7f0800af
int id toolshop_slot1 0x7f0800b0
int id toolshop_slot2 0x7f0800b1
int id toolshop_slot3 0x7f0800b2
int id toolshop_slot4 0x7f0800b3
int id toolshop_tool_offer_bottom_row 0x7f0800b4
int id toolshop_tool_offer_top_row 0x7f0800b5
int id toolshop_toolinspector 0x7f0800b6
int id toolshop_topbar 0x7f0800b7
int id toolslot_image 0x7f0800b8
int id topPanel 0x7f0800b9
int id topbar_back_button 0x7f0800ba
int id topbar_energycount 0x7f0800bb
int id topbar_energycount_decrease 0x7f0800bc
int id topbar_energyview 0x7f0800bd
int id topbar_leveldisplay 0x7f0800be
int id topbar_levellayout 0x7f0800bf
int id topbar_levelprogress 0x7f0800c0
int id topbar_settings 0x7f0800c1
int id topbar_shapeshop 0x7f0800c2
int id topbar_starcount 0x7f0800c3
int id topbar_starcount_decrease 0x7f0800c4
int id topbar_starview 0x7f0800c5
int id topbar_toolshop 0x7f0800c6
int id tutorial_image_view 0x7f0800c7
int id tutorial_text_view 0x7f0800c8
int id unlockmessage_message 0x7f0800c9
int id unlockmessage_toolimage 0x7f0800ca
int id up 0x7f0800cb
int id useLogo 0x7f0800cc
int id withText 0x7f0800cd
int id worldbutton_energycount 0x7f0800ce
int id worldbutton_levelcount 0x7f0800cf
int id worldbutton_lock 0x7f0800d0
int id worldbutton_preview 0x7f0800d1
int id worldbutton_starcount 0x7f0800d2
int id worldbutton_title 0x7f0800d3
int id worlds_layout 0x7f0800d4
int id worlds_topbar 0x7f0800d5
int id wrap_content 0x7f0800d6
int integer abc_config_activityDefaultDur 0x7f090000
int integer abc_config_activityShortDur 0x7f090001
int integer abc_max_action_buttons 0x7f090002
@ -862,14 +854,12 @@ int layout task_completed_message 0x7f0a0039
int layout tool_inspector 0x7f0a003a
int layout tool_offer_slot 0x7f0a003b
int layout tool_slot 0x7f0a003c
int layout toolbutton 0x7f0a003d
int layout toolbuttonbar 0x7f0a003e
int layout toolshop 0x7f0a003f
int layout topbar 0x7f0a0040
int layout tutorial 0x7f0a0041
int layout unlock_message 0x7f0a0042
int layout world_button 0x7f0a0043
int layout worlds 0x7f0a0044
int layout toolshop 0x7f0a003d
int layout topbar 0x7f0a003e
int layout tutorial 0x7f0a003f
int layout unlock_message 0x7f0a0040
int layout world_button 0x7f0a0041
int layout worlds 0x7f0a0042
int mipmap ic_launcher 0x7f0b0000
int raw music_game_1 0x7f0c0000
int raw music_game_2 0x7f0c0001

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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());

View File

@ -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);
}

View File

@ -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());
}
}
}
}

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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"

View File

@ -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>

View File

@ -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>

View File

@ -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>