First implementation of Shape shop
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.textures.Texture;
|
||||
import de.frajul.endlessroll.entities.textures.TexturePack;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public enum PlayerShape {
|
||||
BALL(R.string.playershape_name_ball, R.drawable.playershapes_ball), CLOCK(R.string.playershape_name_clock,
|
||||
R.drawable.playershapes_clock), HYPNO_SPIRAL(R.string.playershape_name_hypno_spiral,
|
||||
R.drawable.playershapes_hypno_spiral), PACMAN(R.string.playershape_name_pacman,
|
||||
R.drawable.playershapes_pacman), SMILEY(R.string.playershape_name_smiley,
|
||||
R.drawable.playershapes_smiley);
|
||||
|
||||
@StringRes
|
||||
private int nameId;
|
||||
@DrawableRes
|
||||
private int drawableId;
|
||||
|
||||
private Texture texture;
|
||||
|
||||
PlayerShape(@StringRes int nameId, @DrawableRes int drawableId) {
|
||||
this.nameId = nameId;
|
||||
this.drawableId = drawableId;
|
||||
}
|
||||
|
||||
public static void loadAllTextures(TexturePack texturePack) {
|
||||
for (PlayerShape playerShape : values())
|
||||
playerShape.loadTexture(texturePack);
|
||||
}
|
||||
|
||||
private void loadTexture(TexturePack texturePack) {
|
||||
if (drawableId == -1)
|
||||
return;
|
||||
texture = texturePack.loadTexture(drawableId);
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getNameId() {
|
||||
return nameId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getDrawableId() {
|
||||
return drawableId;
|
||||
}
|
||||
|
||||
public Texture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package de.frajul.endlessroll.entities.shapes;
|
||||
|
||||
import de.frajul.endlessroll.views.PlayerShapeButton;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public interface PlayerShapeButtonOnClickListener {
|
||||
|
||||
public void onClick(PlayerShapeButton button);
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package de.frajul.endlessroll.main.screens;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TableRow;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShape;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShapeButtonOnClickListener;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.views.PlayerShapeButton;
|
||||
import de.frajul.endlessroll.views.TopBar;
|
||||
|
||||
/**
|
||||
* Created by Julian on 08.07.2016.
|
||||
*/
|
||||
public class PlayerShapeShopScreen extends Screen<LinearLayout> implements PlayerShapeButtonOnClickListener {
|
||||
|
||||
private PlayerShapeButton activeButton;
|
||||
|
||||
private TopBar topBar;
|
||||
private TableRow topRow;
|
||||
private TableRow bottomRow;
|
||||
|
||||
public PlayerShapeShopScreen(GameActivity gameActivity) {
|
||||
super(ScreenType.SHAPE_SHOP, gameActivity, R.layout.shape_shop);
|
||||
topBar = super.createTopBar(R.id.shape_shop_topbar);
|
||||
topRow = (TableRow) layout.findViewById(R.id.shape_shop_topRow);
|
||||
bottomRow = (TableRow) layout.findViewById(R.id.shape_shop_bottomRow);
|
||||
}
|
||||
|
||||
private void createViews() {
|
||||
topRow.removeAllViews();
|
||||
bottomRow.removeAllViews();
|
||||
int i = 0;
|
||||
int totalShapes = PlayerShape.values().length;
|
||||
for (PlayerShape playerShape : PlayerShape.values()) {
|
||||
PlayerShapeButton button = new PlayerShapeButton(gameActivity, playerShape, this);
|
||||
if (i < totalShapes / 2)
|
||||
topRow.addView(button.getView());
|
||||
else
|
||||
bottomRow.addView(button.getView());
|
||||
|
||||
if (playerShape.equals(gameActivity.getUser().getCurrentPlayerShape())) {
|
||||
this.activeButton = button;
|
||||
button.startRotating();
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareToBeShown() {
|
||||
createViews();
|
||||
topBar.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackKeyDown() {
|
||||
flipToCaller();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(PlayerShapeButton button) {
|
||||
activeButton.stopRotating();
|
||||
activeButton = button;
|
||||
activeButton.startRotating();
|
||||
gameActivity.getUser().setCurrentPlayerShape(button.getPlayerShape());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShape;
|
||||
import de.frajul.endlessroll.entities.shapes.PlayerShapeButtonOnClickListener;
|
||||
import de.frajul.endlessroll.main.GameLog;
|
||||
|
||||
/**
|
||||
* Created by Julian on 22.10.2017.
|
||||
*/
|
||||
|
||||
public class PlayerShapeButton implements View.OnClickListener {
|
||||
|
||||
private PlayerShape playerShape;
|
||||
private PlayerShapeButtonOnClickListener clickListener;
|
||||
|
||||
private View view;
|
||||
private TextView textView;
|
||||
private Button button;
|
||||
private Animation rotation;
|
||||
|
||||
public PlayerShapeButton(Context context, PlayerShape playerShape, PlayerShapeButtonOnClickListener clickListener) {
|
||||
this.clickListener = clickListener;
|
||||
this.playerShape = playerShape;
|
||||
view = LayoutInflater.from(context).inflate(R.layout.shape_button, null);
|
||||
textView = (TextView) view.findViewById(R.id.shape_button_textview);
|
||||
textView.setText(playerShape.getNameId());
|
||||
button = (Button) view.findViewById(R.id.shape_button_button);
|
||||
button.setBackgroundDrawable(context.getResources().getDrawable(playerShape.getDrawableId()));
|
||||
button.setOnClickListener(this);
|
||||
rotation = AnimationUtils.loadAnimation(context, R.anim.shape_button_rotation);
|
||||
}
|
||||
|
||||
public void startRotating() {
|
||||
button.startAnimation(rotation);
|
||||
}
|
||||
|
||||
public void stopRotating() {
|
||||
button.clearAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
clickListener.onClick(this);
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public PlayerShape getPlayerShape() {
|
||||
return playerShape;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user