Added toolinspector -> tool-upgrades can be bought (not saved yet)
only the time upgrade is used
This commit is contained in:
@ -0,0 +1,55 @@
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
/**
|
||||
* Created by Julian on 09.06.2017.
|
||||
*/
|
||||
|
||||
public class ToolUpgrade {
|
||||
|
||||
private ToolUpgradeType type;
|
||||
private float first, step;
|
||||
private int price;
|
||||
|
||||
private int maxLevel;
|
||||
private int currentLevel = 1;
|
||||
|
||||
public ToolUpgrade(ToolUpgradeType type, float first, float last, float step, int price) {
|
||||
this.type = type;
|
||||
this.first = first;
|
||||
this.step = step;
|
||||
this.price = price;
|
||||
maxLevel = (int) Math.abs((first - last) / step) + 1;
|
||||
}
|
||||
|
||||
public ToolUpgradeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public float getValueAtLevel(int level) {
|
||||
return first + step * (level - 1);
|
||||
}
|
||||
|
||||
public float getValueAtCurrentLevel() {
|
||||
return getValueAtLevel(currentLevel);
|
||||
}
|
||||
|
||||
public float getValueAtNextLevel() {
|
||||
return getValueAtLevel(currentLevel + 1);
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public int getCurrentLevel() {
|
||||
return currentLevel;
|
||||
}
|
||||
|
||||
public void setCurrentLevel(int currentLevel) {
|
||||
this.currentLevel = currentLevel;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package de.frajul.endlessroll.entities.tools;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
|
||||
/**
|
||||
* Created by Julian on 07.06.2017.
|
||||
*/
|
||||
|
||||
public enum ToolUpgradeType {
|
||||
|
||||
NONE("None", "", R.drawable.tools_rampbutton), TIME("Time", "s", R.drawable.clock), RADIUS(
|
||||
"Radius", "%", R.drawable.radius), FORCE("Force", "%", R.drawable.magnet_field);
|
||||
|
||||
private String name;
|
||||
private String unit;
|
||||
@DrawableRes
|
||||
private int drawable;
|
||||
|
||||
ToolUpgradeType(String name, String unit, @DrawableRes int drawable) {
|
||||
this.name = name;
|
||||
this.unit = unit;
|
||||
this.drawable = drawable;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getDrawable() {
|
||||
return drawable;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.08.2016.
|
||||
*/
|
||||
public class PriceButton {
|
||||
|
||||
private Context context;
|
||||
|
||||
private View layout;
|
||||
private TextView title;
|
||||
private TextView price;
|
||||
private ImageView currencyView;
|
||||
|
||||
public PriceButton(Context context, Typeface typeface, View layout, View.OnClickListener onClickListener) {
|
||||
this.context = context;
|
||||
this.layout = layout;
|
||||
layout.setOnClickListener(onClickListener);
|
||||
|
||||
title = (TextView) layout.findViewById(R.id.price_button_title);
|
||||
title.setTypeface(typeface);
|
||||
price = (TextView) layout.findViewById(R.id.price_button_price);
|
||||
price.setTypeface(typeface);
|
||||
currencyView = (ImageView) layout.findViewById(R.id.price_button_currency);
|
||||
}
|
||||
|
||||
public void init(String title, int price, @DrawableRes int currencyDrawable) {
|
||||
this.title.setText(title);
|
||||
this.price.setText(price + "");
|
||||
this.currencyView.setImageDrawable(context.getResources().getDrawable(currencyDrawable));
|
||||
}
|
||||
|
||||
public void setLayoutEnabled(boolean enabled){
|
||||
layout.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setLayoutVisible(int visibility){
|
||||
layout.setVisibility(visibility);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.tools.ToolType;
|
||||
import de.frajul.endlessroll.main.screens.ToolShopScreen;
|
||||
import de.frajul.endlessroll.user.User;
|
||||
|
||||
/**
|
||||
* Created by Julian on 03.06.2017.
|
||||
*/
|
||||
|
||||
public class ToolInspector implements View.OnClickListener {
|
||||
|
||||
private ToolShopScreen toolShopScreen;
|
||||
private User user;
|
||||
private Context context;
|
||||
|
||||
private TextView title;
|
||||
private ImageView imageView;
|
||||
private PriceButton priceButton;
|
||||
|
||||
private ToolUpgradeView toolUpgradeView0;
|
||||
private ToolUpgradeView toolUpgradeView1;
|
||||
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
|
||||
public ToolInspector(ToolShopScreen toolShopScreen, User user, Context context, Typeface typeface, View layout) {
|
||||
this.toolShopScreen = toolShopScreen;
|
||||
this.user = user;
|
||||
this.context = context;
|
||||
title = (TextView) layout.findViewById(R.id.tool_inspector_title);
|
||||
title.setTypeface(typeface);
|
||||
imageView = (ImageView) layout.findViewById(R.id.tool_inspector_imageview);
|
||||
priceButton = new PriceButton(context, typeface,
|
||||
layout.findViewById(R.id.tool_inspector_pricebutton), this);
|
||||
toolUpgradeView0 = new ToolUpgradeView(this, context, typeface,
|
||||
layout.findViewById(R.id.tool_inspector_toolupgrade0));
|
||||
toolUpgradeView1 = new ToolUpgradeView(this, context, typeface,
|
||||
layout.findViewById(R.id.tool_inspector_toolupgrade1));
|
||||
}
|
||||
|
||||
public void update(ToolType toolType, boolean locked) {
|
||||
this.toolType = toolType;
|
||||
this.locked = locked;
|
||||
this.title.setText(locked ? "???" : toolType.getName());
|
||||
this.imageView.setImageDrawable(context.getResources().getDrawable(
|
||||
locked ? R.drawable.tools_lockedbutton : toolType.getButtonDrawable()));
|
||||
priceButton.init("Buy", toolType.getPrice(), R.drawable.currency_star);
|
||||
priceButton.setLayoutVisible(toolType.isBought() || locked ? View.GONE : View.VISIBLE);
|
||||
priceButton.setLayoutEnabled(toolType.getPrice() <= user.getStarCount());
|
||||
|
||||
toolUpgradeView0
|
||||
.update(toolType.getUpgrades()[0], toolType.isBought(), user.getEnergyCount());
|
||||
toolUpgradeView0.setLayoutVisiblity(locked ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (toolType.getUpgrades().length <= 1 || locked)
|
||||
toolUpgradeView1.setLayoutVisiblity(View.GONE);
|
||||
else {
|
||||
toolUpgradeView1.setLayoutVisiblity(View.VISIBLE);
|
||||
toolUpgradeView1
|
||||
.update(toolType.getUpgrades()[1], toolType.isBought(), user.getEnergyCount());
|
||||
}
|
||||
}
|
||||
|
||||
public void onToolUpgraded(int price) {
|
||||
toolShopScreen.onToolUpgraded(price);
|
||||
update(toolType, locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
toolType.setBought(true);
|
||||
update(toolType, locked);
|
||||
toolShopScreen.onToolBought(toolType.getPrice());
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package de.frajul.endlessroll.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.frajul.endlessroll.R;
|
||||
import de.frajul.endlessroll.entities.tools.ToolUpgrade;
|
||||
|
||||
/**
|
||||
* Created by Julian on 01.08.2016.
|
||||
*/
|
||||
public class ToolUpgradeView implements View.OnClickListener {
|
||||
|
||||
private ToolInspector toolInspector;
|
||||
private Context context;
|
||||
|
||||
private View layout;
|
||||
private TextView title;
|
||||
private ImageView imageView;
|
||||
private TextView valueOld;
|
||||
private TextView valueNew;
|
||||
private PriceButton priceButton;
|
||||
|
||||
private ToolUpgrade upgrade;
|
||||
private boolean toolBought;
|
||||
private int availableEnergy;
|
||||
|
||||
public ToolUpgradeView(ToolInspector toolInspector, Context context, Typeface typeface, View layout) {
|
||||
this.toolInspector = toolInspector;
|
||||
this.context = context;
|
||||
this.layout = layout;
|
||||
|
||||
title = (TextView) layout.findViewById(R.id.tool_upgrade_title);
|
||||
title.setTypeface(typeface);
|
||||
imageView = (ImageView) layout.findViewById(R.id.tool_upgrade_imageview);
|
||||
valueOld = (TextView) layout.findViewById(R.id.tool_upgrade_value_old);
|
||||
valueOld.setTypeface(typeface);
|
||||
valueNew = (TextView) layout.findViewById(R.id.tool_upgrade_value_new);
|
||||
valueNew.setTypeface(typeface);
|
||||
priceButton = new PriceButton(context, typeface,
|
||||
layout.findViewById(R.id.tool_upgrade_pricebutton), this);
|
||||
}
|
||||
|
||||
public void update(ToolUpgrade toolUpgrade, boolean toolBought, int availableEnergy) {
|
||||
this.upgrade = toolUpgrade;
|
||||
this.toolBought = toolBought;
|
||||
this.availableEnergy = availableEnergy;
|
||||
this.title.setText(
|
||||
toolUpgrade.getType().getName() + " (Lv" + toolUpgrade.getCurrentLevel() + ")");
|
||||
this.imageView.setImageDrawable(
|
||||
context.getResources().getDrawable(toolUpgrade.getType().getDrawable()));
|
||||
updateValueViews();
|
||||
priceButton.init("Upgrade", toolUpgrade.getPrice(), R.drawable.currency_energy);
|
||||
priceButton.setLayoutVisible(isAtMaxLevel() ? View.GONE : View.VISIBLE);
|
||||
priceButton.setLayoutEnabled(toolBought && toolUpgrade.getPrice() <= availableEnergy);
|
||||
}
|
||||
|
||||
public void setLayoutVisiblity(int visiblity) {
|
||||
layout.setVisibility(visiblity);
|
||||
}
|
||||
|
||||
private void updateValueViews() {
|
||||
String unit = upgrade.getType().getUnit();
|
||||
valueOld.setText(upgrade.getValueAtCurrentLevel() + unit);
|
||||
valueNew.setText(upgrade.getValueAtNextLevel() + unit);
|
||||
if(isAtMaxLevel())
|
||||
valueNew.setText("Max.");
|
||||
}
|
||||
|
||||
private boolean isAtMaxLevel() {
|
||||
return upgrade.getCurrentLevel() >= upgrade.getMaxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
upgrade.setCurrentLevel(upgrade.getCurrentLevel() + 1);
|
||||
update(upgrade, toolBought, availableEnergy);
|
||||
toolInspector.onToolUpgraded(upgrade.getPrice());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user