Implemented ToolShopTutorial

This commit is contained in:
= 2017-11-23 22:31:49 +01:00
parent 8c24604447
commit 18ea4042e9
10 changed files with 177 additions and 86 deletions

View File

@ -27,7 +27,7 @@ public class DataStorageHandler {
private final String USER_TOOL_4 = "Tool4";
private final String USER_TOOLS_LOCKED = "ToolsLocked";
private final String USER_PLAYER_SHAPE = "PlayerShape";
private final String TOOL_SHOP_TUTORIAL_PART_1_FINISHED = "ToolShopTutorialPart1Finished";
private final String TOOL_SHOP_TUTORIAL_FINISHED = "ToolShopTutorialFinished";
private SharedPreferences preferences;
private MyDatabase database;
@ -61,9 +61,9 @@ public class DataStorageHandler {
toolsLocked);
String playerShapeName = preferences.getString(USER_PLAYER_SHAPE, PlayerShape.BALL.name());
PlayerShape playerShape;
try{
try {
playerShape = PlayerShape.valueOf(playerShapeName);
}catch (Exception e){
} catch (Exception e) {
playerShape = PlayerShape.BALL;
}
return new User(lvUpListener, ep, level, stars, energy, toolSlotSettings, playerShape);
@ -89,14 +89,14 @@ public class DataStorageHandler {
return toolType == null ? "null" : toolType.toString();
}
public void writeToolShopTutorialPart1Finished(boolean finished) {
public void writeToolShopTutorialFinished(boolean finished) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(TOOL_SHOP_TUTORIAL_PART_1_FINISHED, finished);
editor.putBoolean(TOOL_SHOP_TUTORIAL_FINISHED, finished);
editor.apply();
}
public boolean readToolShopTutorialPart1Finished() {
return preferences.getBoolean(TOOL_SHOP_TUTORIAL_PART_1_FINISHED, false);
public boolean readToolShopTutorialFinished() {
return preferences.getBoolean(TOOL_SHOP_TUTORIAL_FINISHED, false);
}
public MyDatabase getDatabase() {

View File

@ -93,7 +93,7 @@ public class GameActivity extends Activity implements ExceptionHandler, User.LvU
soundManager.backgroundMusic.start();
levelManager = new LevelManager(this, dataStorageHandler);
tutorialManager = new TutorialManager();
tutorialManager = new TutorialManager(this);
this.glSurfaceView = new MyGlSurfaceView(this, new GameRenderer(this));
typeface = Typeface.createFromAsset(getAssets(), "fontBaron.ttf");
@ -193,9 +193,9 @@ public class GameActivity extends Activity implements ExceptionHandler, User.LvU
public void resetData() {
user.clearData();
dataStorageHandler.writeUserData(user);
dataStorageHandler.writeToolShopTutorialPart1Finished(false);
dataStorageHandler.writeToolShopTutorialFinished(false);
levelManager.reset();
tutorialManager.getToolShopTutorial().reset();
tutorialManager.getToolShopTutorial().setFinished(false);
MyDatabase database = dataStorageHandler.getDatabase();
database.open();
database.clearLevelProgess();

View File

@ -2,6 +2,8 @@ package de.frajul.endlessroll.main.screens;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -37,6 +39,8 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
private List<ImageView> toolSlotViews = new ArrayList<>();
private List<ToolOfferSlot> toolOfferSlots = new ArrayList<>();
private Animation pulse;
private ToolInspector toolInspector;
private ToolShopTutorial tutorial;
@ -45,8 +49,9 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
this.levelUpBounties = new LevelUpBounties(0);
this.slotSettings = gameActivity.getUser().getToolSlotSettings();
this.tutorial = gameActivity.getTutorialManager().getToolShopTutorial();
tutorial.setFirstPartShown(
gameActivity.getDataStorageHandler().readToolShopTutorialPart1Finished());
tutorial.setToolShopScreen(this);
tutorial.setFinished(gameActivity.getDataStorageHandler().readToolShopTutorialFinished());
pulse = AnimationUtils.loadAnimation(gameActivity, R.anim.pulse);
topBar = super.createTopBar(R.id.toolshop_topbar);
toolSlotViews.add(getToolSlotView(R.id.toolshop_slot1));
@ -101,12 +106,7 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
toolOfferSlot.setLocked(locked);
toolOfferSlot.updateBackgroundColor();
}
tutorial.onToolShopPrepare(!levelUpBounties.isToolLocked(ToolType.SPRING));
if (tutorial.isOverNewBreakPoints()) {
gameActivity.showTutorialScreen(tutorial.getCurrentBreakPoints());
gameActivity.getDataStorageHandler()
.writeToolShopTutorialPart1Finished(tutorial.isFirstPartShown());
}
tutorial.onToolShopScreenPrepare();
}
public void onToolBought(int price, ToolType toolType) {
@ -120,9 +120,7 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
for (ToolOfferSlot toolOfferSlot : toolOfferSlots) {
toolOfferSlot.updateBackgroundColor();
}
tutorial.onToolBought(toolType);
if (tutorial.isOverNewBreakPoints())
gameActivity.showTutorialScreen(tutorial.getCurrentBreakPoints());
tutorial.onToolBought();
}
public void onToolUpgraded(int price) {
@ -135,16 +133,56 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
dataStorageHandler.getDatabase().close();
}
public void onToolOfferSlotSelected(ToolOfferSlot slot) {
selectedToolOfferSlot = slot;
for (ToolOfferSlot toolOfferSlot : toolOfferSlots)
toolOfferSlot.setSelected(toolOfferSlot.equals(slot));
toolInspector.update(slot.getToolType(), slot.isLocked());
tutorial.onToolSelected();
}
private void onToolEquipped(int index) {
slotSettings.changeToolSlotType(index, selectedToolOfferSlot.getToolType());
for (int i = 0; i < toolSlotViews.size(); i++) {
ToolSlot toolSlot = slotSettings.get(i);
ImageView view = toolSlotViews.get(i);
view.setImageResource(toolSlot.getDrawable());
}
tutorial.onToolEquipped();
}
public void stopTutorialAnimations(){
for (ToolOfferSlot toolOfferSlot : toolOfferSlots)
if(toolOfferSlot.getToolType() == ToolType.SPRING)
toolOfferSlot.getLayout().clearAnimation();
toolInspector.clearPriceButtonAnimation();
toolSlotViews.get(0).clearAnimation();
}
public void tutorialStartSpringOfferSlotPulse(){
for (ToolOfferSlot toolOfferSlot : toolOfferSlots)
if(toolOfferSlot.getToolType() == ToolType.SPRING)
toolOfferSlot.getLayout().startAnimation(pulse);
}
public void tutorialStartSpringBuyButtonPulse(){
toolInspector.startPriceButtonAnimation(pulse);
}
public void tutorialStartSpringToolSlotPulse(){
toolSlotViews.get(0).startAnimation(pulse);
}
public void writeToolShopTutorialIsFinished(){
gameActivity.getDataStorageHandler().writeToolShopTutorialFinished(true);
}
@Override
public void onBackKeyDown() {
stopTutorialAnimations();
gameActivity.getDataStorageHandler().writeUserData(gameActivity.getUser());
flipToCaller();
}
@ -154,12 +192,7 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
ImageView toolSlotView = (ImageView) v;
int index = toolSlotViews.indexOf(toolSlotView);
if (canSelectedToolBePutInSlot(index)) {
slotSettings.changeToolSlotType(index, selectedToolOfferSlot.getToolType());
for (int i = 0; i < toolSlotViews.size(); i++) {
ToolSlot toolSlot = slotSettings.get(i);
ImageView view = toolSlotViews.get(i);
view.setImageResource(toolSlot.getDrawable());
}
onToolEquipped(index);
}
}
@ -168,4 +201,12 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnCli
.isLocked() && selectedToolOfferSlot != null && selectedToolOfferSlot.getToolType()
.isBought();
}
public LevelUpBounties getLevelUpBounties() {
return levelUpBounties;
}
public ToolType getSelectedToolType() {
return selectedToolOfferSlot.getToolType();
}
}

View File

@ -1,78 +1,89 @@
package de.frajul.endlessroll.main.tutorial;
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.GameActivity;
import de.frajul.endlessroll.main.screens.Screen;
import de.frajul.endlessroll.main.screens.ToolShopScreen;
import de.frajul.endlessroll.user.LevelUpBounties;
import de.frajul.endlessroll.views.TopBar;
/**
* Created by Julian on 10.06.2017.
*/
public class ToolShopTutorial extends Tutorial {
public class ToolShopTutorial {
public enum ToolShopTutorialState{
NONE, TO_TOOLSHOP, SELECT_SPRING, BUY_SPRING, EQUIP_SPRING;
private GameActivity gameActivity;
private LevelUpBounties levelUpBounties;
private ToolShopScreen toolShopScreen;
private boolean finished = false;
public ToolShopTutorial(GameActivity gameActivity) {
this.gameActivity = gameActivity;
levelUpBounties = new LevelUpBounties(0);
}
private List<BreakPoint> atStartBreakPoints = new ArrayList<>();
private List<BreakPoint> afterSpringBoughtBreakPoints = new ArrayList<>();
public void setToolShopScreen(ToolShopScreen toolShopScreen) {
this.toolShopScreen = toolShopScreen;
}
private boolean firstPartShown;
private ToolShopTutorialState state = ToolShopTutorialState.TO_TOOLSHOP;
public ToolShopTutorial() {
super(-1, -1, new BreakPoint(0, R.string.tutorial_toolshop_welcome, -1),
new BreakPoint(0, R.string.tutorial_toolshop_toolbar,
R.drawable.tutorial_toolshop_toolbar),
new BreakPoint(0, R.string.tutorial_toolshop_all_tools,
R.drawable.tutorial_toolshop_all_tools),
new BreakPoint(0, R.string.tutorial_toolshop_inspector,
R.drawable.tutorial_toolshop_inspector),
new BreakPoint(0, R.string.tutorial_toolshop_select_buy_spring,
R.drawable.tutorial_toolshop_select_buy_spring),
new BreakPoint(1, R.string.tutorial_toolshop_equip_spring,
R.drawable.tutorial_toolshop_equip_spring));
for (BreakPoint breakPoint : super.getBreakPoints()) {
if (breakPoint.getX() == 0)
atStartBreakPoints.add(breakPoint);
else
afterSpringBoughtBreakPoints.add(breakPoint);
public void onTopBarUpdate(TopBar topBar) {
if (!finished && isSpringUnlocked()) {
boolean notOnToolShopScreen = topBar.getParent() != Screen.ScreenType.TOOL_SHOP;
if (notOnToolShopScreen && topBar.isToolShopButtonEnabled())
topBar.startToolShopButtonPulse();
}
}
@Override
public void reset() {
currentBreakPoints.clear();
firstPartShown = false;
public void onToolShopScreenPrepare() {
onToolShopUpdate();
}
public void onToolShopPrepare(boolean isSpringUnlocked) {
currentBreakPoints.clear();
if (isSpringUnlocked && !firstPartShown) {
currentBreakPoints.addAll(atStartBreakPoints);
firstPartShown = true;
public void onToolSelected() {
onToolShopUpdate();
}
public void onToolBought() {
onToolShopUpdate();
}
public void onToolEquipped() {
if (toolShopScreen.getSelectedToolType() == ToolType.SPRING) {
toolShopScreen.stopTutorialAnimations();
finished = true;
toolShopScreen.writeToolShopTutorialIsFinished();
}
}
public void onToolBought(ToolType type) {
currentBreakPoints.clear();
if (type == ToolType.SPRING) {
currentBreakPoints = afterSpringBoughtBreakPoints;
private void onToolShopUpdate() {
if (!finished && isSpringUnlocked()) {
boolean springSelected = toolShopScreen.getSelectedToolType() == ToolType.SPRING;
boolean springBought = ToolType.SPRING.isBought();
boolean isSelectSpring = !springSelected;
boolean isBuySpring = springSelected && !springBought;
boolean isEquipSpring = springSelected && springBought;
if (isSelectSpring) {
toolShopScreen.stopTutorialAnimations();
toolShopScreen.tutorialStartSpringOfferSlotPulse();
} else if (isBuySpring) {
toolShopScreen.stopTutorialAnimations();
toolShopScreen.tutorialStartSpringBuyButtonPulse();
} else if (isEquipSpring) {
toolShopScreen.stopTutorialAnimations();
toolShopScreen.tutorialStartSpringToolSlotPulse();
}
}
}
public boolean isFirstPartShown() {
return firstPartShown;
private boolean isSpringUnlocked() {
levelUpBounties.loadAllForLevel(gameActivity.getUser().getLevel());
return !levelUpBounties.isToolLocked(ToolType.SPRING);
}
public void setFirstPartShown(boolean firstPartShown) {
this.firstPartShown = firstPartShown;
}
public ToolShopTutorialState getState() {
return state;
public void setFinished(boolean finished) {
this.finished = finished;
}
}

View File

@ -5,6 +5,8 @@ import java.util.List;
import de.frajul.endlessroll.R;
import de.frajul.endlessroll.levels.Level;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.main.screens.ToolShopScreen;
/**
* Created by Julian on 17.03.2017.
@ -15,7 +17,7 @@ public class TutorialManager {
private List<Tutorial> gameTutorials;
private ToolShopTutorial toolShopTutorial;
public TutorialManager() {
public TutorialManager(GameActivity gameActivity) {
Tutorial t11 = new Tutorial(1, 1, new BreakPoint(0, R.string.tutorial_welcome, -1),
new BreakPoint(0, R.string.tutorial_place_tools, R.drawable.tutorial_place_tools),
new BreakPoint(7, R.string.tutorial_place_ramp_gap,
@ -33,7 +35,7 @@ public class TutorialManager {
gameTutorials = Arrays.asList(t11, t21, t51);
toolShopTutorial = new ToolShopTutorial();
toolShopTutorial = new ToolShopTutorial(gameActivity);
}
public void resetGameTutorials() {

View File

@ -6,6 +6,7 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;
@ -49,4 +50,12 @@ public class PriceButton {
layout.setVisibility(visibility);
}
public void startAnimation(Animation animation){
layout.startAnimation(animation);
}
public void clearAnimation(){
layout.clearAnimation();
}
}

View File

@ -2,6 +2,7 @@ package de.frajul.endlessroll.views;
import android.graphics.Typeface;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;
@ -89,4 +90,13 @@ public class ToolInspector implements View.OnClickListener {
onToolUpgraded(toolType.getUpgradePrice());
}
}
public void startPriceButtonAnimation(Animation animation){
priceButton.startAnimation(animation);
}
public void clearPriceButtonAnimation(){
priceButton.clearAnimation();
}
}

View File

@ -11,7 +11,6 @@ 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;
/**
@ -21,6 +20,7 @@ public class TopBar implements View.OnClickListener {
private GameActivity gameActivity;
private View layout;
private Screen.ScreenType parent;
private Animation starDecreaseAnimation;
private Animation energyDecreaseAnimation;
@ -38,6 +38,7 @@ public class TopBar implements View.OnClickListener {
public TopBar(GameActivity gameActivity, Screen.ScreenType parent, View layout) {
this.gameActivity = gameActivity;
this.parent = parent;
this.layout = layout;
starDecreaseAnimation = AnimationUtils.loadAnimation(gameActivity, R.anim.decrease);
@ -92,10 +93,11 @@ public class TopBar implements View.OnClickListener {
starCount.setText(user.getStarCount() + "");
energyCount.setText(user.getEnergyCount() + "");
if (gameActivity.getTutorialManager().getToolShopTutorial()
.getState() == ToolShopTutorial.ToolShopTutorialState.TO_TOOLSHOP && toolshopButton
.isEnabled())
toolshopButton.startAnimation(toolShopPulse);
gameActivity.getTutorialManager().getToolShopTutorial().onTopBarUpdate(this);
}
public void startToolShopButtonPulse(){
toolshopButton.startAnimation(toolShopPulse);
}
public void showStarcountDecrease(int decrease) {
@ -118,4 +120,12 @@ public class TopBar implements View.OnClickListener {
gameActivity.flipToScreen(Screen.ScreenType.SETTINGS);
}
}
public Screen.ScreenType getParent() {
return parent;
}
public boolean isToolShopButtonEnabled(){
return toolshopButton.isEnabled();
}
}

View File

@ -4,6 +4,7 @@
android:layout_height="match_parent"
android:background="#e6ffc936"
android:orientation="vertical"
android:clipChildren="false"
android:padding="10dp">
<TextView
@ -19,6 +20,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clipChildren="false"
android:orientation="horizontal">
<ImageView

View File

@ -18,6 +18,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:layout_toLeftOf="@+id/toolshop_toolinspector"
android:layout_toStartOf="@+id/toolshop_toolinspector">
@ -25,6 +26,7 @@
android:id="@+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal">
@ -64,18 +66,21 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:layout_below="@+id/linearLayout4">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clipChildren="false"
android:orientation="vertical">
<LinearLayout
android:id="@+id/toolshop_tool_offer_top_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false"
android:layout_marginBottom="10dp"
android:orientation="horizontal"/>
@ -83,6 +88,7 @@
android:id="@+id/toolshop_tool_offer_bottom_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false"
android:orientation="horizontal"/>
</LinearLayout>