First implementation of innovations in Tool Shop
This commit is contained in:
@ -33,10 +33,6 @@ public class ToolUpgrade {
|
||||
return getValueAtLevel(currentLevel);
|
||||
}
|
||||
|
||||
public float getValueAtNextLevel() {
|
||||
return getValueAtLevel(currentLevel + 1);
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
@ -20,11 +20,10 @@ public class ToolInspector implements View.OnClickListener {
|
||||
private ToolShopScreen toolShopScreen;
|
||||
|
||||
private TextView title;
|
||||
private TextView levelView;
|
||||
private ImageView imageView;
|
||||
private PriceButton priceButton;
|
||||
|
||||
private ToolUpgradeView toolUpgradeView0;
|
||||
private ToolUpgradeView toolUpgradeView1;
|
||||
private TextView description;
|
||||
|
||||
private ToolType toolType;
|
||||
private boolean locked;
|
||||
@ -35,47 +34,54 @@ public class ToolInspector implements View.OnClickListener {
|
||||
Typeface typeface = gameActivity.getTypeface();
|
||||
title = (TextView) layout.findViewById(R.id.tool_inspector_title);
|
||||
title.setTypeface(typeface);
|
||||
levelView = (TextView) layout.findViewById(R.id.tool_inspector_level_view);
|
||||
levelView.setTypeface(typeface);
|
||||
imageView = (ImageView) layout.findViewById(R.id.tool_inspector_imageview);
|
||||
priceButton = new PriceButton(gameActivity, typeface,
|
||||
layout.findViewById(R.id.tool_inspector_pricebutton), this);
|
||||
toolUpgradeView0 = new ToolUpgradeView(this, gameActivity, typeface,
|
||||
layout.findViewById(R.id.tool_inspector_toolupgrade0));
|
||||
toolUpgradeView1 = new ToolUpgradeView(this, gameActivity, typeface,
|
||||
layout.findViewById(R.id.tool_inspector_toolupgrade1));
|
||||
description = (TextView) layout.findViewById(R.id.tool_inspector_description);
|
||||
description.setTypeface(typeface);
|
||||
}
|
||||
|
||||
public void update(ToolType toolType, boolean locked) {
|
||||
this.toolType = toolType;
|
||||
this.locked = locked;
|
||||
this.title.setText(locked ? R.string.tool_name_unknown : toolType.getName());
|
||||
this.imageView.setImageDrawable(gameActivity.getResources().getDrawable(
|
||||
title.setText(locked ? R.string.tool_name_locked : toolType.getName());
|
||||
levelView.setText(gameActivity.getString(R.string.tool_level_format_d, toolType.getUpgrade().getCurrentLevel()));
|
||||
levelView.setVisibility(locked ? View.INVISIBLE : View.VISIBLE);
|
||||
imageView.setImageDrawable(gameActivity.getResources().getDrawable(
|
||||
locked ? R.drawable.tools_button_locked : toolType.getButtonDrawable()));
|
||||
priceButton.init(R.string.price_button_buy, toolType.getPrice(), R.drawable.currency_star);
|
||||
priceButton.setLayoutVisible(toolType.isBought() || locked ? View.GONE : View.VISIBLE);
|
||||
priceButton.setLayoutEnabled(toolType.getPrice() <= gameActivity.getUser().getStarCount());
|
||||
description.setText(locked ? R.string.tool_description_locked : toolType.getDescription());
|
||||
|
||||
toolUpgradeView0.update(toolType.getUpgrades()[0], toolType.isBought(),
|
||||
gameActivity.getUser().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(),
|
||||
gameActivity.getUser().getEnergyCount());
|
||||
if (!toolType.isBought()) {
|
||||
priceButton
|
||||
.init(R.string.price_button_buy, toolType.getPrice(), R.drawable.currency_star);
|
||||
priceButton.setLayoutVisible(locked ? View.GONE : View.VISIBLE);
|
||||
priceButton
|
||||
.setLayoutEnabled(toolType.getPrice() <= gameActivity.getUser().getStarCount());
|
||||
} else {
|
||||
priceButton.init(R.string.price_button_upgrade, toolType.getUpgrade().getPrice(),
|
||||
R.drawable.currency_energy);
|
||||
priceButton.setLayoutVisible(toolType.getUpgrade().getCurrentLevel() == toolType.getUpgrade().getMaxLevel() ? View.GONE : View.VISIBLE);
|
||||
priceButton.setLayoutEnabled(
|
||||
toolType.getUpgrade().getPrice() <= gameActivity.getUser().getEnergyCount());
|
||||
}
|
||||
}
|
||||
|
||||
public void onToolUpgraded(int price) {
|
||||
private void onToolUpgraded(int price) {
|
||||
toolType.getUpgrade().setCurrentLevel(toolType.getUpgrade().getCurrentLevel()+1);
|
||||
toolShopScreen.onToolUpgraded(price);
|
||||
update(toolType, locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(!toolType.isBought()){
|
||||
toolType.setBought(true);
|
||||
update(toolType, locked);
|
||||
toolShopScreen.onToolBought(toolType.getPrice(), toolType);
|
||||
}else{
|
||||
onToolUpgraded(toolType.getUpgrade().getPrice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +0,0 @@
|
||||
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(context.getString(R.string.tool_upgrade_title_format_sd,
|
||||
context.getString(toolUpgrade.getType().getName()), toolUpgrade.getCurrentLevel()));
|
||||
this.imageView.setImageDrawable(
|
||||
context.getResources().getDrawable(toolUpgrade.getType().getDrawable()));
|
||||
updateValueViews();
|
||||
priceButton.init(R.string.price_button_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(R.string.tool_upgrade_value_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