Init der fehlenden Dateien
This commit is contained in:
@ -0,0 +1,89 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
|
||||
/**
|
||||
* Created by Julian on 15.07.2016.
|
||||
*/
|
||||
public class BountyMessage implements View.OnClickListener {
|
||||
|
||||
public interface ScreenSwitchCaller {
|
||||
public void switchScreen(Screen.ScreenType screenType);
|
||||
}
|
||||
|
||||
public enum MessageType {
|
||||
STARS(R.string.bounty_message_resource_format_s, Screen.ScreenType.NONE),
|
||||
ENERGY(R.string.bounty_message_resource_format_s, Screen.ScreenType.NONE),
|
||||
TOOL(R.string.bounty_message_tool_format_s, Screen.ScreenType.TOOL_SHOP),
|
||||
TOOL_SLOT(R.string.bounty_message_tool_slot, Screen.ScreenType.TOOL_SHOP),
|
||||
SHAPE_UNLOCKED(R.string.bounty_message_shape_unlocked, Screen.ScreenType.SHAPE_SHOP);
|
||||
|
||||
@StringRes
|
||||
private int textId;
|
||||
private Screen.ScreenType goalScreenType;
|
||||
|
||||
MessageType(@StringRes int textId, Screen.ScreenType goalScreenType) {
|
||||
this.textId = textId;
|
||||
this.goalScreenType = goalScreenType;
|
||||
}
|
||||
|
||||
public String formatText(Context context, @Nullable String textArgs) {
|
||||
String text = context.getString(textId);
|
||||
if (textArgs == null)
|
||||
return text;
|
||||
return String.format(text, textArgs);
|
||||
}
|
||||
|
||||
|
||||
public Screen.ScreenType getGoalScreenType() {
|
||||
return goalScreenType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private LinearLayout layout;
|
||||
private ImageView image;
|
||||
private TextView text;
|
||||
|
||||
private MessageType messageType;
|
||||
private ScreenSwitchCaller screenSwitchCaller;
|
||||
|
||||
public BountyMessage(GameActivity gameActivity, MessageType messageType, @Nullable String textArgs, ScreenSwitchCaller screenSwitchCaller, @DrawableRes int drawableId) {
|
||||
findViews(gameActivity);
|
||||
this.image.setImageResource(drawableId);
|
||||
this.text.setText(messageType.formatText(gameActivity, textArgs));
|
||||
this.text.setTypeface(gameActivity.getTypeface());
|
||||
this.messageType = messageType;
|
||||
this.screenSwitchCaller = screenSwitchCaller;
|
||||
}
|
||||
|
||||
private void findViews(Context context) {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
layout = (LinearLayout) inflater.inflate(R.layout.unlock_message, null);
|
||||
layout.setOnClickListener(this);
|
||||
image = (ImageView) layout.findViewById(R.id.unlockmessage_toolimage);
|
||||
text = (TextView) layout.findViewById(R.id.unlockmessage_message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (messageType.getGoalScreenType() != Screen.ScreenType.NONE)
|
||||
screenSwitchCaller.switchScreen(messageType.getGoalScreenType());
|
||||
}
|
||||
|
||||
public LinearLayout getLayout() {
|
||||
return layout;
|
||||
}
|
||||
}
|
69
app/src/main/java/de/frajul/endlessroll/views/Countdown.java
Normal file
69
app/src/main/java/de/frajul/endlessroll/views/Countdown.java
Normal file
@ -0,0 +1,69 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
|
||||
/**
|
||||
* Created by Julian on 31.07.2016.
|
||||
*/
|
||||
public class Countdown implements Animation.AnimationListener {
|
||||
|
||||
private Game game;
|
||||
private AnimationSet animations;
|
||||
private TextView textView;
|
||||
|
||||
private boolean firstHalfRepeated = true;
|
||||
private int repeatCount = 0;
|
||||
|
||||
public Countdown(Game game, Typeface typeface, TextView textView) {
|
||||
this.game = game;
|
||||
this.textView = textView;
|
||||
this.textView.setTypeface(typeface);
|
||||
animations = (AnimationSet) AnimationUtils.loadAnimation(game.getContext(), R.anim.countdown);
|
||||
for (Animation animation : animations.getAnimations())
|
||||
animation.setAnimationListener(this);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reset();
|
||||
textView.startAnimation(animations);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
textView.clearAnimation();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
repeatCount = 0;
|
||||
textView.setText("3");
|
||||
textView.setTextColor(game.getContext().getResources().getColor(R.color.countdown3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
game.countdownFinished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
if (!firstHalfRepeated)
|
||||
repeatCount++;
|
||||
firstHalfRepeated = !firstHalfRepeated;
|
||||
textView.setText((3 - repeatCount) + "");
|
||||
if (repeatCount == 1) {
|
||||
textView.setTextColor(game.getContext().getResources().getColor(R.color.countdown2));
|
||||
} else if (repeatCount == 2) {
|
||||
textView.setTextColor(game.getContext().getResources().getColor(R.color.countdown1));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
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.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
|
||||
/**
|
||||
* Created by Julian on 09.07.2016.
|
||||
*/
|
||||
public class GameOverMessage implements View.OnClickListener {
|
||||
|
||||
private Animation fadeIn;
|
||||
private Game game;
|
||||
|
||||
private View layout;
|
||||
private TopBar topBar;
|
||||
private Button tryAgain;
|
||||
private Button toMenu;
|
||||
|
||||
public GameOverMessage(Game game, GameActivity gameActivity, View layout) {
|
||||
this.game = game;
|
||||
this.layout = layout;
|
||||
layout.setVisibility(View.GONE);
|
||||
Typeface typeface = gameActivity.getTypeface();
|
||||
fadeIn = AnimationUtils.loadAnimation(gameActivity, R.anim.fade_in);
|
||||
topBar = new TopBar(gameActivity, Screen.ScreenType.GAME,
|
||||
layout.findViewById(R.id.game_over_message_topbar));
|
||||
topBar.setShopsEnabled(true);
|
||||
TextView title = (TextView) layout.findViewById(R.id.game_over_message_title);
|
||||
title.setTypeface(typeface);
|
||||
tryAgain = (Button) layout.findViewById(R.id.game_over_message_try_again);
|
||||
tryAgain.setTypeface(typeface);
|
||||
tryAgain.setOnClickListener(this);
|
||||
toMenu = (Button) layout.findViewById(R.id.game_over_message_to_menu);
|
||||
toMenu.setTypeface(typeface);
|
||||
toMenu.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void fadeIn() {
|
||||
topBar.update();
|
||||
layout.startAnimation(fadeIn);
|
||||
layout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
layout.clearAnimation();
|
||||
layout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.equals(tryAgain)) {
|
||||
hide();
|
||||
game.restartLevel();
|
||||
} else if (v.equals(toMenu)) {
|
||||
hide();
|
||||
game.toLevelsScreen();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.Level;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
|
||||
/**
|
||||
* Created by Julian on 23.04.2016.
|
||||
*/
|
||||
public class LevelButton implements View.OnClickListener {
|
||||
|
||||
private GameActivity gameActivity;
|
||||
private LevelButtonOnClickListener clickListener;
|
||||
private Level level;
|
||||
|
||||
private View layout;
|
||||
private TextView text;
|
||||
private ImageView star1;
|
||||
private ImageView star2;
|
||||
private ImageView star3;
|
||||
private ImageView energy;
|
||||
private ImageView lockImage;
|
||||
|
||||
public LevelButton(GameActivity gameActivity, LevelButtonOnClickListener clickListener, @LayoutRes int layoutId) {
|
||||
this.gameActivity = gameActivity;
|
||||
this.clickListener = clickListener;
|
||||
LayoutInflater inflater = LayoutInflater.from(gameActivity);
|
||||
layout = inflater.inflate(layoutId, null);
|
||||
layout.setOnClickListener(this);
|
||||
findViews(layout);
|
||||
}
|
||||
|
||||
private void findViews(View layout) {
|
||||
text = (TextView) layout.findViewById(R.id.levelbutton_textview);
|
||||
text.setTypeface(gameActivity.getTypeface());
|
||||
star1 = (ImageView) layout.findViewById(R.id.levelbutton_star1);
|
||||
star2 = (ImageView) layout.findViewById(R.id.levelbutton_star2);
|
||||
star3 = (ImageView) layout.findViewById(R.id.levelbutton_star3);
|
||||
energy = (ImageView) layout.findViewById(R.id.levelbutton_energy);
|
||||
lockImage = (ImageView) layout.findViewById(R.id.levelbutton_lock);
|
||||
}
|
||||
|
||||
public void init(Level level) {
|
||||
this.level = level;
|
||||
setLockVisible(level.isLocked());
|
||||
text.setText(gameActivity.getString(R.string.level_button_format_d, level.getId()));
|
||||
showCollectedCurrency(level.getCollectedStars(), level.isEnergyCollected());
|
||||
}
|
||||
|
||||
private void setLockVisible(boolean locked) {
|
||||
int visibility = locked ? View.VISIBLE : View.GONE;
|
||||
lockImage.setVisibility(visibility);
|
||||
}
|
||||
|
||||
private void showCollectedCurrency(boolean[] stars, boolean energy) {
|
||||
if (stars[0])
|
||||
this.star1.setImageResource(R.drawable.currency_star);
|
||||
if (stars[1])
|
||||
this.star2.setImageResource(R.drawable.currency_star);
|
||||
if (stars[2])
|
||||
this.star3.setImageResource(R.drawable.currency_star);
|
||||
if (energy)
|
||||
this.energy.setImageResource(R.drawable.currency_energy);
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public View getView(){
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
clickListener.onClick(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.tileLists.TileList;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
import de.frajul.endlessroll.user.LevelBounty;
|
||||
import de.frajul.endlessroll.user.User;
|
||||
|
||||
/**
|
||||
* Created by Julian on 15.07.2016.
|
||||
*/
|
||||
public class LevelupMessage implements View.OnClickListener, BountyMessage.ScreenSwitchCaller {
|
||||
|
||||
private GameActivity gameActivity;
|
||||
private FrameLayout layout;
|
||||
|
||||
private TextView levelView;
|
||||
private TextView text;
|
||||
private LinearLayout unlockMessages;
|
||||
|
||||
public LevelupMessage(GameActivity gameActivity) {
|
||||
this.gameActivity = gameActivity;
|
||||
|
||||
Typeface typeface = gameActivity.getTypeface();
|
||||
LayoutInflater inflater = LayoutInflater.from(gameActivity);
|
||||
layout = (FrameLayout) inflater.inflate(R.layout.levelup_message, null);
|
||||
layout.setOnClickListener(this);
|
||||
layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
layout.setVisibility(View.GONE);
|
||||
levelView = (TextView) layout.findViewById(R.id.levelup_level);
|
||||
levelView.setTypeface(typeface);
|
||||
text = (TextView) layout.findViewById(R.id.levelup_text);
|
||||
text.setTypeface(typeface);
|
||||
unlockMessages = (LinearLayout) layout.findViewById(R.id.levelup_unlocklist);
|
||||
}
|
||||
|
||||
public void show(int level) {
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(0, 5, 0, 5);
|
||||
|
||||
levelView.setText(level + "");
|
||||
|
||||
LevelBounty bounty = gameActivity.getUser().getLevelUpBounties().get(level);
|
||||
if (bounty != null)
|
||||
for (BountyMessage message : bounty.createBountyMessages(gameActivity, this))
|
||||
unlockMessages.addView(message.getLayout(), params);
|
||||
|
||||
layout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
layout.setVisibility(View.GONE);
|
||||
unlockMessages.removeAllViews();
|
||||
}
|
||||
|
||||
public FrameLayout getLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void switchScreen(Screen.ScreenType screenType) {
|
||||
gameActivity.flipToScreen(screenType);
|
||||
hide();
|
||||
}
|
||||
}
|
93
app/src/main/java/de/frajul/endlessroll/views/ShortMenu.java
Normal file
93
app/src/main/java/de/frajul/endlessroll/views/ShortMenu.java
Normal file
@ -0,0 +1,93 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
|
||||
/**
|
||||
* Created by Julian on 23.01.2016.
|
||||
*/
|
||||
public class ShortMenu implements View.OnClickListener {
|
||||
|
||||
private Game game;
|
||||
private Random random;
|
||||
private Animation slideLeft;
|
||||
private Animation slideRight;
|
||||
private Animation slideTop;
|
||||
|
||||
private View layout;
|
||||
private TopBar topBar;
|
||||
private TextView continueView;
|
||||
private TextView restartView;
|
||||
private TextView exitView;
|
||||
|
||||
public ShortMenu(final Game game, GameActivity gameActivity, View layout) {
|
||||
this.game = game;
|
||||
this.layout = layout;
|
||||
Typeface typeface = gameActivity.getTypeface();
|
||||
topBar = new TopBar(gameActivity, Screen.ScreenType.GAME,
|
||||
layout.findViewById(R.id.shortmenu_topbar));
|
||||
continueView = (TextView) layout.findViewById(R.id.shortmenu_continue);
|
||||
continueView.setTypeface(typeface);
|
||||
continueView.setOnClickListener(this);
|
||||
restartView = (TextView) layout.findViewById(R.id.shortmenu_restart);
|
||||
restartView.setTypeface(typeface);
|
||||
restartView.setOnClickListener(this);
|
||||
exitView = (TextView) layout.findViewById(R.id.shortmenu_exit);
|
||||
exitView.setTypeface(typeface);
|
||||
exitView.setOnClickListener(this);
|
||||
|
||||
random = new Random();
|
||||
Context context = game.getContext();
|
||||
slideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_in_left);
|
||||
slideRight = AnimationUtils.loadAnimation(context, R.anim.slide_in_right);
|
||||
slideTop = AnimationUtils.loadAnimation(context, R.anim.slide_in_top);
|
||||
}
|
||||
|
||||
public void startAnims() {
|
||||
startRandomAnimation(continueView);
|
||||
startRandomAnimation(restartView);
|
||||
startRandomAnimation(exitView);
|
||||
topBar.startAnimation(slideTop);
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
layout.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
|
||||
if (visible)
|
||||
topBar.update();
|
||||
}
|
||||
|
||||
private void startRandomAnimation(View view) {
|
||||
float r = random.nextFloat();
|
||||
if (r >= 0.5)
|
||||
view.startAnimation(slideRight);
|
||||
else
|
||||
view.startAnimation(slideLeft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.equals(continueView)) {
|
||||
setVisible(false);
|
||||
game.continueGame();
|
||||
} else if (v.equals(restartView)) {
|
||||
setVisible(false);
|
||||
game.restartLevel();
|
||||
} else if (v.equals(exitView)) {
|
||||
setVisible(false);
|
||||
game.toLevelsScreen();
|
||||
}
|
||||
}
|
||||
}
|
126
app/src/main/java/de/frajul/endlessroll/views/ToolButton.java
Normal file
126
app/src/main/java/de/frajul/endlessroll/views/ToolButton.java
Normal file
@ -0,0 +1,126 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by Julian on 15.01.2016.
|
||||
*/
|
||||
public class ToolButton {
|
||||
|
||||
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 ToolButton(ToolSlot slot, Context context, RelativeLayout layout) {
|
||||
this.context = context;
|
||||
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) {
|
||||
if (progress != 100) {
|
||||
progress += (frameTime) / (toolType
|
||||
.getCurrentUpgradeValue(ToolUpgradeType.COOLDOWN) / 100);
|
||||
progress = Math.min(progress, 100);
|
||||
if (progress == 100)
|
||||
animationView.startAnimation(scaleAnimation);
|
||||
}
|
||||
progressBar.setProgress(100 - (int) progress);
|
||||
if (!locked && toolType != null) {
|
||||
if (active) {
|
||||
if (progress == 100)
|
||||
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;
|
||||
}
|
||||
}
|
149
app/src/main/java/de/frajul/endlessroll/views/ToolButtonBar.java
Normal file
149
app/src/main/java/de/frajul/endlessroll/views/ToolButtonBar.java
Normal file
@ -0,0 +1,149 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
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.GameLog;
|
||||
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 ToolButtonBar implements View.OnClickListener, Animation.AnimationListener {
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
|
||||
private Animation fadeIn, fadeOut;
|
||||
private Game game;
|
||||
private List<ToolButton> buttons = new ArrayList<>(4);
|
||||
private RelativeLayout button1;
|
||||
private RelativeLayout button2;
|
||||
private RelativeLayout button3;
|
||||
private RelativeLayout button4;
|
||||
|
||||
|
||||
public ToolButtonBar(Game game, ToolSlotSettings toolSlotSettings, LinearLayout layout1) {
|
||||
this.game = game;
|
||||
Context context = game.getContext();
|
||||
fadeIn = AnimationUtils.loadAnimation(game.getContext(), R.anim.fade_in);
|
||||
fadeIn.setAnimationListener(this);
|
||||
fadeOut = AnimationUtils.loadAnimation(game.getContext(), R.anim.fade_out);
|
||||
|
||||
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 ToolButton(toolSlotSettings.get(0), context, button1));
|
||||
buttons.add(new ToolButton(toolSlotSettings.get(1), context, button2));
|
||||
buttons.add(new ToolButton(toolSlotSettings.get(2), context, button3));
|
||||
buttons.add(new ToolButton(toolSlotSettings.get(3), context, button4));
|
||||
}
|
||||
|
||||
public void setTopPrimary() {
|
||||
button1.startAnimation(fadeIn);
|
||||
button2.startAnimation(fadeIn);
|
||||
button3.startAnimation(fadeIn);
|
||||
button4.startAnimation(fadeIn);
|
||||
}
|
||||
|
||||
public void setBottomPrimary() {
|
||||
button1.startAnimation(fadeOut);
|
||||
button2.startAnimation(fadeOut);
|
||||
button3.startAnimation(fadeOut);
|
||||
button4.startAnimation(fadeOut);
|
||||
}
|
||||
|
||||
public void changeToolButtonTypes(ToolSlotSettings toolSlotSettings) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buttons.get(i).changeToolSlot(toolSlotSettings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(ToolSlotSettings toolSlotSettings) {
|
||||
GameLog.i("Reset toolbuttonBar");
|
||||
changeToolButtonTypes(toolSlotSettings);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (toolSlotSettings.get(i).getToolType() != null) {
|
||||
setActive(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (ToolButton button : buttons)
|
||||
button.setProgress(100);
|
||||
}
|
||||
|
||||
public void update(float frameTime) {
|
||||
for (ToolButton button : buttons)
|
||||
button.update(frameTime);
|
||||
}
|
||||
|
||||
public void setActive(ToolType activeType) {
|
||||
for (ToolButton button : buttons)
|
||||
button.setActive(button.getToolType() == activeType);
|
||||
}
|
||||
|
||||
private void setActive(int index) {
|
||||
for (ToolButton button : buttons)
|
||||
button.setActive(buttons.indexOf(button) == index);
|
||||
}
|
||||
|
||||
public ToolButton getByToolType(ToolType type) {
|
||||
for (ToolButton button : buttons)
|
||||
if (button.getToolType() == type)
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ToolButton getActiveButton() {
|
||||
for (ToolButton button : buttons)
|
||||
if (button.isActive())
|
||||
return button;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (game.getGameState() == GameState.RUNNING) {
|
||||
ToolType clickedType = null;
|
||||
if (v.equals(button1) && !buttons.get(0).isLocked()) {
|
||||
clickedType = buttons.get(0).getToolType();
|
||||
} else if (v.equals(button2) && !buttons.get(1).isLocked()) {
|
||||
clickedType = buttons.get(1).getToolType();
|
||||
} else if (v.equals(button3) && !buttons.get(2).isLocked()) {
|
||||
clickedType = buttons.get(2).getToolType();
|
||||
} else if (v.equals(button4) && !buttons.get(3).isLocked()) {
|
||||
clickedType = buttons.get(3).getToolType();
|
||||
}
|
||||
if (clickedType != null) {
|
||||
game.setCurrentTool(clickedType);
|
||||
setActive(clickedType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
101
app/src/main/java/de/frajul/endlessroll/views/ToolOfferSlot.java
Normal file
101
app/src/main/java/de/frajul/endlessroll/views/ToolOfferSlot.java
Normal file
@ -0,0 +1,101 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.main.screens.ToolShopScreen;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.07.2016.
|
||||
*/
|
||||
public class ToolOfferSlot implements View.OnClickListener {
|
||||
|
||||
private ToolShopScreen toolShopScreen;
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
private boolean selected;
|
||||
|
||||
private int colorDisabled;
|
||||
private int colorDisabledSelected;
|
||||
private int colorEnabled;
|
||||
private int colorEnabledSelected;
|
||||
|
||||
private LinearLayout layout;
|
||||
private TextView title;
|
||||
private ImageView image;
|
||||
|
||||
public ToolOfferSlot(ToolShopScreen toolShopScreen, Context context, Typeface typeface, ToolType toolType) {
|
||||
this.toolShopScreen = toolShopScreen;
|
||||
this.toolType = toolType;
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
layout = (LinearLayout) inflater.inflate(R.layout.tool_offer_slot, null);
|
||||
layout.setOnClickListener(this);
|
||||
FrameLayout slotLayout = (FrameLayout) layout.findViewById(R.id.toolofferslot_slot);
|
||||
title = (TextView) layout.findViewById(R.id.toolofferslot_title);
|
||||
title.setTypeface(typeface);
|
||||
image = (ImageView) slotLayout.findViewById(R.id.toolslot_image);
|
||||
image.setBackgroundDrawable(createImageBackground());
|
||||
|
||||
colorDisabled = context.getResources().getColor(R.color.toolslotDisabled);
|
||||
colorDisabledSelected = context.getResources().getColor(R.color.toolslotDisabledSelected);
|
||||
colorEnabled = context.getResources().getColor(R.color.toolslotEnabled);
|
||||
colorEnabledSelected = context.getResources().getColor(R.color.toolslotEnabledSelected);
|
||||
}
|
||||
|
||||
private Drawable createImageBackground() {
|
||||
GradientDrawable gd = new GradientDrawable();
|
||||
gd.setCornerRadius(10);
|
||||
return gd;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
if (locked) {
|
||||
title.setText(R.string.tool_name_locked);
|
||||
image.setImageResource(R.drawable.tools_button_locked);
|
||||
} else {
|
||||
title.setText(toolType.getName());
|
||||
image.setImageResource(toolType.getButtonDrawable());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBackgroundColor() {
|
||||
GradientDrawable gd = (GradientDrawable) image.getBackground();
|
||||
if (toolType.isBought())
|
||||
gd.setColor(selected ? colorEnabledSelected : colorEnabled);
|
||||
else
|
||||
gd.setColor(selected ? colorDisabledSelected : colorDisabled);
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public ToolType getToolType() {
|
||||
return toolType;
|
||||
}
|
||||
|
||||
public LinearLayout getLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
toolShopScreen.onToolOfferSlotSelected(this);
|
||||
}
|
||||
}
|
121
app/src/main/java/de/frajul/endlessroll/views/TopBar.java
Normal file
121
app/src/main/java/de/frajul/endlessroll/views/TopBar.java
Normal file
@ -0,0 +1,121 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.screens.Screen;
|
||||
import de.frajul.endlessroll.main.tutorial.ToolShopTutorial;
|
||||
import de.frajul.endlessroll.user.User;
|
||||
|
||||
/**
|
||||
* Created by Julian on 08.07.2016.
|
||||
*/
|
||||
public class TopBar implements View.OnClickListener {
|
||||
|
||||
private GameActivity gameActivity;
|
||||
private View layout;
|
||||
|
||||
private Animation starDecreaseAnimation;
|
||||
private Animation energyDecreaseAnimation;
|
||||
private Animation toolShopPulse;
|
||||
|
||||
private TextView levelDisplay;
|
||||
private ProgressBar levelProgress;
|
||||
private TextView starCount;
|
||||
private TextView energyCount;
|
||||
private Button settingsButton;
|
||||
private Button toolshopButton;
|
||||
private Button shapeshopButton;
|
||||
private TextView starCountDecrease;
|
||||
private TextView energyCountDecrease;
|
||||
|
||||
public TopBar(GameActivity gameActivity, Screen.ScreenType parent, View layout) {
|
||||
this.gameActivity = gameActivity;
|
||||
this.layout = layout;
|
||||
|
||||
starDecreaseAnimation = AnimationUtils.loadAnimation(gameActivity, R.anim.decrease);
|
||||
energyDecreaseAnimation = AnimationUtils.loadAnimation(gameActivity, R.anim.decrease);
|
||||
toolShopPulse = AnimationUtils.loadAnimation(gameActivity, R.anim.pulse);
|
||||
|
||||
Typeface typeface = gameActivity.getTypeface();
|
||||
levelDisplay = (TextView) layout.findViewById(R.id.topbar_leveldisplay);
|
||||
levelDisplay.setTypeface(typeface);
|
||||
levelProgress = (ProgressBar) layout.findViewById(R.id.topbar_levelprogress);
|
||||
starCount = (TextView) layout.findViewById(R.id.topbar_starcount);
|
||||
starCount.setTypeface(typeface);
|
||||
energyCount = (TextView) layout.findViewById(R.id.topbar_energycount);
|
||||
energyCount.setTypeface(typeface);
|
||||
settingsButton = (Button) layout.findViewById(R.id.topbar_settings);
|
||||
settingsButton.setOnClickListener(this);
|
||||
toolshopButton = (Button) layout.findViewById(R.id.topbar_toolshop);
|
||||
toolshopButton.setOnClickListener(this);
|
||||
shapeshopButton = (Button) layout.findViewById(R.id.topbar_shapeshop);
|
||||
shapeshopButton.setOnClickListener(this);
|
||||
if (parent == Screen.ScreenType.TOOL_SHOP || parent == Screen.ScreenType.SHAPE_SHOP || parent == Screen.ScreenType.SETTINGS) {
|
||||
toolshopButton.setEnabled(false);
|
||||
shapeshopButton.setEnabled(false);
|
||||
settingsButton.setEnabled(false);
|
||||
}
|
||||
if (parent == Screen.ScreenType.GAME) {
|
||||
toolshopButton.setEnabled(false);
|
||||
shapeshopButton.setEnabled(false);
|
||||
}
|
||||
starCountDecrease = (TextView) layout.findViewById(R.id.topbar_starcount_decrease);
|
||||
starCountDecrease.setTypeface(typeface);
|
||||
energyCountDecrease = (TextView) layout.findViewById(R.id.topbar_energycount_decrease);
|
||||
energyCountDecrease.setTypeface(typeface);
|
||||
}
|
||||
|
||||
public void setShopsEnabled(boolean enabled) {
|
||||
toolshopButton.setEnabled(enabled);
|
||||
shapeshopButton.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void startAnimation(Animation animation) {
|
||||
layout.startAnimation(animation);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
toolshopButton.clearAnimation();
|
||||
|
||||
User user = gameActivity.getUser();
|
||||
levelDisplay
|
||||
.setText(gameActivity.getString(R.string.topbar_level_format_d, user.getLevel()));
|
||||
levelProgress.setProgress(user.getEp());
|
||||
starCount.setText(user.getStarCount() + "");
|
||||
energyCount.setText(user.getEnergyCount() + "");
|
||||
|
||||
if (gameActivity.getTutorialManager().getToolShopTutorial()
|
||||
.getState() == ToolShopTutorial.ToolShopTutorialState.TO_TOOLSHOP && toolshopButton
|
||||
.isEnabled())
|
||||
toolshopButton.startAnimation(toolShopPulse);
|
||||
}
|
||||
|
||||
public void showStarcountDecrease(int decrease) {
|
||||
starCountDecrease.setText(decrease + "");
|
||||
starCountDecrease.startAnimation(starDecreaseAnimation);
|
||||
}
|
||||
|
||||
public void showEnergycountDecrease(int decrease) {
|
||||
energyCountDecrease.setText(decrease + "");
|
||||
energyCountDecrease.startAnimation(energyDecreaseAnimation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.equals(toolshopButton)) {
|
||||
gameActivity.flipToScreen(Screen.ScreenType.TOOL_SHOP);
|
||||
} else if (v.equals(shapeshopButton)) {
|
||||
gameActivity.flipToScreen(Screen.ScreenType.SHAPE_SHOP);
|
||||
} else if (v.equals(settingsButton)) {
|
||||
gameActivity.flipToScreen(Screen.ScreenType.SETTINGS);
|
||||
}
|
||||
}
|
||||
}
|
144
app/src/main/java/de/frajul/endlessroll/views/ViewManager.java
Normal file
144
app/src/main/java/de/frajul/endlessroll/views/ViewManager.java
Normal file
@ -0,0 +1,144 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.Level;
|
||||
import de.frajul.endlessroll.levels.LevelPack;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
import de.frajul.endlessroll.main.GameHandler;
|
||||
import de.frajul.endlessroll.main.game.Game;
|
||||
import de.frajul.endlessroll.main.game.Timer;
|
||||
import de.frajul.endlessroll.user.User;
|
||||
|
||||
/**
|
||||
* Created by Julian on 11.12.2015.
|
||||
*/
|
||||
public class ViewManager implements View.OnClickListener {
|
||||
|
||||
private GameHandler gameViewHandler;
|
||||
private Game game;
|
||||
|
||||
private TextView fpsView;
|
||||
private TextView playerProgress;
|
||||
private TextView playerSpeed;
|
||||
private ImageView pauseButton;
|
||||
private GameOverMessage gameOverMessage;
|
||||
private GoalMessage goalMessage;
|
||||
public ToolButtonBar toolButtonBar;
|
||||
public ShortMenu shortMenu;
|
||||
private Countdown countdown;
|
||||
|
||||
private String fpsFormat, playerProgressFormat, playerSpeedFormat;
|
||||
|
||||
public ViewManager(final Game game, final GameHandler gameViewHandler, final GameActivity gameActivity) {
|
||||
this.game = game;
|
||||
this.gameViewHandler = gameViewHandler;
|
||||
|
||||
final RelativeLayout layout = gameViewHandler.getRootLayout();
|
||||
gameViewHandler.startInUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toolButtonBar = new ToolButtonBar(game,
|
||||
gameActivity.getUser().getToolSlotSettings(),
|
||||
(LinearLayout) layout.findViewById(R.id.game_toolbuttonbar));
|
||||
shortMenu = new ShortMenu(game, gameActivity,
|
||||
(LinearLayout) layout.findViewById(R.id.game_shortmenu));
|
||||
gameOverMessage = new GameOverMessage(game, gameActivity,
|
||||
layout.findViewById(R.id.game_game_over_message));
|
||||
goalMessage = new GoalMessage(game, gameActivity, layout.findViewById(R.id.game_goal_message));
|
||||
countdown = new Countdown(game, gameActivity.getTypeface(),
|
||||
(TextView) layout.findViewById(R.id.game_countdown));
|
||||
}
|
||||
});
|
||||
pauseButton = (ImageView) layout.findViewById(R.id.game_pausebutton);
|
||||
pauseButton.setOnClickListener(this);
|
||||
playerProgress = (TextView) layout.findViewById(R.id.game_playerprogress);
|
||||
playerSpeed = (TextView) layout.findViewById(R.id.game_playerspeed);
|
||||
fpsView = (TextView) layout.findViewById(R.id.game_fps);
|
||||
|
||||
fpsFormat = game.getContext().getString(R.string.game_fps_format_d);
|
||||
playerProgressFormat = game.getContext().getString(R.string.game_playerprogress_format_f);
|
||||
playerSpeedFormat = game.getContext().getString(R.string.game_playerspeed_format_f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
game.tryToPause();
|
||||
}
|
||||
|
||||
public void resetViews(final User user) {
|
||||
gameViewHandler.startInUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toolButtonBar.reset(user.getToolSlotSettings());
|
||||
toolButtonBar.update(0);
|
||||
playerProgress.setText(R.string.game_playerprogress_placeholder);
|
||||
playerSpeed.setText(R.string.game_playerspeed_placeholder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onGoalMessageKeyBack(){
|
||||
goalMessage.onKeyBack();
|
||||
}
|
||||
|
||||
public void showGameOverMessage() {
|
||||
gameViewHandler.startInUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gameOverMessage.fadeIn();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showGoalMessage(final LevelPack levelPack, final Level level){
|
||||
gameViewHandler.startInUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
goalMessage.fadeInWithDelay(levelPack, level);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showShortMenu() {
|
||||
shortMenu.startAnims();
|
||||
shortMenu.setVisible(true);
|
||||
}
|
||||
|
||||
public void hideShortMenu() {
|
||||
shortMenu.setVisible(false);
|
||||
}
|
||||
|
||||
public void startCountdown() {
|
||||
countdown.start();
|
||||
}
|
||||
|
||||
public void stopCountdown() {
|
||||
countdown.stop();
|
||||
}
|
||||
|
||||
public void update(final boolean gameRunning, final Timer timer, final float playerX, final float playerXMov) {
|
||||
gameViewHandler.startInUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fpsView.setText(String.format(fpsFormat, timer.getFps()));
|
||||
if (gameRunning) {
|
||||
playerProgress.setText(String.format(playerProgressFormat, toMeters(playerX)));
|
||||
playerSpeed
|
||||
.setText(String.format(playerSpeedFormat, toMeters(playerXMov * 1000)));
|
||||
toolButtonBar.update(timer.getFrameTimeSeconds());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private float toMeters(float value) {
|
||||
return ((int) (value * 20)) / 10f;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.levels.LevelPack;
|
||||
import de.frajul.endlessroll.main.GameActivity;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.08.2016.
|
||||
*/
|
||||
public class WorldButton implements View.OnClickListener {
|
||||
|
||||
private GameActivity gameActivity;
|
||||
private LevelPack levelPack;
|
||||
private WorldButtonOnClickListener clickListener;
|
||||
|
||||
private View layout;
|
||||
private TextView title;
|
||||
private ImageView previewImage;
|
||||
private View lock;
|
||||
private TextView levelCount;
|
||||
private TextView starCount;
|
||||
private TextView energyCount;
|
||||
|
||||
public WorldButton(GameActivity gameActivity, LevelPack levelPack, WorldButtonOnClickListener clickListener) {
|
||||
this.gameActivity = gameActivity;
|
||||
this.levelPack = levelPack;
|
||||
this.clickListener = clickListener;
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(gameActivity);
|
||||
layout = inflater.inflate(R.layout.world_button, null);
|
||||
layout.setOnClickListener(this);
|
||||
|
||||
Typeface typeface = gameActivity.getTypeface();
|
||||
title = (TextView) layout.findViewById(R.id.worldbutton_title);
|
||||
title.setTypeface(typeface);
|
||||
previewImage = (ImageView) layout.findViewById(R.id.worldbutton_preview);
|
||||
lock = layout.findViewById(R.id.worldbutton_lock);
|
||||
levelCount = (TextView) layout.findViewById(R.id.worldbutton_levelcount);
|
||||
levelCount.setTypeface(typeface);
|
||||
starCount = (TextView) layout.findViewById(R.id.worldbutton_starcount);
|
||||
starCount.setTypeface(typeface);
|
||||
energyCount = (TextView) layout.findViewById(R.id.worldbutton_energycount);
|
||||
energyCount.setTypeface(typeface);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
title.setText(levelPack.getName());
|
||||
previewImage.setImageDrawable(
|
||||
gameActivity.getResources().getDrawable(levelPack.getWorld().getPreviewId()));
|
||||
levelCount.setText(gameActivity
|
||||
.getString(R.string.world_button_count_format_dd, levelPack.getFinishedLevelCount(),
|
||||
levelPack.getLevels().size()));
|
||||
starCount.setText(gameActivity
|
||||
.getString(R.string.world_button_count_format_dd, levelPack.getCollectedStarCount(),
|
||||
levelPack.getAvailableStars()));
|
||||
energyCount.setText(gameActivity.getString(R.string.world_button_count_format_dd,
|
||||
levelPack.getCollectedEnergyCount(), levelPack.getAvailableEnergy()));
|
||||
setLockVisible(levelPack.isLocked());
|
||||
}
|
||||
|
||||
public void setLockVisible(boolean locked) {
|
||||
int visibility = locked ? View.VISIBLE : View.GONE;
|
||||
lock.setVisibility(visibility);
|
||||
}
|
||||
|
||||
public LevelPack getLevelPack() {
|
||||
return levelPack;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
clickListener.onClick(this);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user