Levels on LevelScreen have different order
Tools can be set in Toolbar by clicking, no longer dragging
This commit is contained in:
@ -46,17 +46,22 @@ public class LevelsScreen extends Screen<LinearLayout> implements View.OnClickLi
|
||||
topRow.removeAllViews();
|
||||
bottomRow.removeAllViews();
|
||||
levelButtons.clear();
|
||||
int levelCount = levelPack.getLevels().size();
|
||||
for (Level level : levelPack.getLevels())
|
||||
createButton(activity, level);
|
||||
createButton(activity, level, levelCount);
|
||||
}
|
||||
|
||||
private void createButton(Context context, Level level) {
|
||||
private void createButton(Context context, Level level, int levelCount) {
|
||||
int levelNumber = level.getNumber();
|
||||
LevelButton button = new LevelButton(context, typeface, this, levelNumber, !level.isUnlocked());
|
||||
//TODO: light only collected star
|
||||
button.setStarCount(level.getCollectedStars().length());
|
||||
levelButtons.put(levelNumber, button);
|
||||
if (levelNumber % 2 == 1)
|
||||
int halfLevelCount = levelCount / 2;
|
||||
if(levelCount % 2 == 1)
|
||||
halfLevelCount++;
|
||||
|
||||
if (levelNumber <= halfLevelCount)
|
||||
topRow.addView(button);
|
||||
else
|
||||
bottomRow.addView(button);
|
||||
|
@ -12,6 +12,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.example.julian.endlessroll.R;
|
||||
import com.example.julian.endlessroll.entities.tools.ToolSlot;
|
||||
import com.example.julian.endlessroll.entities.tools.ToolSlotSettings;
|
||||
import com.example.julian.endlessroll.entities.tools.ToolType;
|
||||
import com.example.julian.endlessroll.levels.levelup.LevelUpBounties;
|
||||
@ -28,7 +29,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by Julian on 08.07.2016.
|
||||
*/
|
||||
public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnDragListener, View.OnClickListener, View.OnTouchListener {
|
||||
public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnClickListener, View.OnTouchListener {
|
||||
|
||||
private LevelUpBounties levelUpBounties;
|
||||
private GameActivity activity;
|
||||
@ -71,7 +72,7 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnDra
|
||||
params.setMargins(20, 0, 20, 0);
|
||||
for (ToolType type : ToolType.values()) {
|
||||
if (type != ToolType.NONE) {
|
||||
ToolOfferSlot slot = new ToolOfferSlot(this, activity, topBarData.getTypeface(), type, levelUpBounties);
|
||||
ToolOfferSlot slot = new ToolOfferSlot(this, activity, topBarData.getTypeface(), type);
|
||||
toolOfferSlots.add(slot);
|
||||
toolOfferLayout.addView(slot.getLayout(), params);
|
||||
}
|
||||
@ -79,7 +80,7 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnDra
|
||||
}
|
||||
|
||||
public void showPriceButton(ToolOfferSlot slot) {
|
||||
selectedToolOfferSlot = slot;
|
||||
setSelectedToolOfferSlot(slot);
|
||||
int[] slotLocation = new int[2];
|
||||
slot.getImage().getLocationOnScreen(slotLocation);
|
||||
priceButton.setX(slotLocation[0]);
|
||||
@ -90,10 +91,18 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnDra
|
||||
priceButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void setSelectedToolOfferSlot(ToolOfferSlot slot) {
|
||||
selectedToolOfferSlot = slot;
|
||||
for(ToolOfferSlot offerSlot : toolOfferSlots){
|
||||
if(!offerSlot.equals(slot))
|
||||
offerSlot.setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
private ImageView getToolSlotView(int id) {
|
||||
FrameLayout slotLayout = (FrameLayout) layout.findViewById(id);
|
||||
ImageView imageView = (ImageView) slotLayout.findViewById(R.id.toolslot_image);
|
||||
imageView.setOnDragListener(this);
|
||||
imageView.setOnClickListener(this);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
@ -124,44 +133,6 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnDra
|
||||
activity.flipToScreen(caller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDrag(View v, DragEvent event) {
|
||||
if (event.getAction() == DragEvent.ACTION_DRAG_ENDED) {
|
||||
for (ToolOfferSlot toolOfferSlot : toolOfferSlots)
|
||||
toolOfferSlot.setDragged(false);
|
||||
return true;
|
||||
}
|
||||
int slot = -1;
|
||||
slot = v.equals(toolSlot1) ? 0 : slot;
|
||||
slot = v.equals(toolSlot2) ? 1 : slot;
|
||||
slot = v.equals(toolSlot3) ? 2 : slot;
|
||||
slot = v.equals(toolSlot4) ? 3 : slot;
|
||||
if (!slotSettings.get(slot).isLocked()) {
|
||||
if (event.getAction() == DragEvent.ACTION_DRAG_ENTERED) {
|
||||
//TODO: animation
|
||||
}
|
||||
if (event.getAction() == DragEvent.ACTION_DRAG_EXITED) {
|
||||
//TODO: ggf. animation
|
||||
}
|
||||
if (event.getAction() == DragEvent.ACTION_DROP) {
|
||||
//TODO: animation??
|
||||
slotSettings.changeToolSlotType(slot, getDraggedToolType());
|
||||
prepareToBeShown();
|
||||
dataStorageHandler.writeUserData(user);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private ToolType getDraggedToolType() {
|
||||
for (ToolOfferSlot toolOfferSlot : toolOfferSlots) {
|
||||
if (toolOfferSlot.isDragged())
|
||||
return toolOfferSlot.getToolType();
|
||||
}
|
||||
return ToolType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.equals(layout)) {
|
||||
@ -175,6 +146,17 @@ public class ToolShopScreen extends Screen<RelativeLayout> implements View.OnDra
|
||||
topBar.update();
|
||||
dataStorageHandler.writeBoughtTools();
|
||||
}
|
||||
int slot = -1;
|
||||
slot = v.equals(toolSlot1) ? 0 : slot;
|
||||
slot = v.equals(toolSlot2) ? 1 : slot;
|
||||
slot = v.equals(toolSlot3) ? 2 : slot;
|
||||
slot = v.equals(toolSlot4) ? 3 : slot;
|
||||
if (slot != -1 && !slotSettings.get(slot).isLocked() && selectedToolOfferSlot != null && selectedToolOfferSlot.isBought()) {
|
||||
slotSettings.changeToolSlotType(slot, selectedToolOfferSlot.getToolType());
|
||||
selectedToolOfferSlot.setSelected(false);
|
||||
prepareToBeShown();
|
||||
dataStorageHandler.writeUserData(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.example.julian.endlessroll.views;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@ -14,42 +13,46 @@ import android.widget.TextView;
|
||||
|
||||
import com.example.julian.endlessroll.R;
|
||||
import com.example.julian.endlessroll.entities.tools.ToolType;
|
||||
import com.example.julian.endlessroll.levels.levelup.LevelUpBounties;
|
||||
import com.example.julian.endlessroll.main.screens.ToolShopScreen;
|
||||
|
||||
/**
|
||||
* Created by Julian on 16.07.2016.
|
||||
*/
|
||||
public class ToolOfferSlot implements View.OnClickListener, View.OnLongClickListener {
|
||||
public class ToolOfferSlot implements View.OnClickListener {
|
||||
|
||||
private ToolShopScreen toolShopScreen;
|
||||
private boolean dragged;
|
||||
private Context context;
|
||||
private ToolType toolType;
|
||||
private LevelUpBounties levelUpBounties;
|
||||
private boolean locked;
|
||||
private boolean bought;
|
||||
private boolean selected;
|
||||
|
||||
private int colorDisabled;
|
||||
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, LevelUpBounties levelUpBounties) {
|
||||
public ToolOfferSlot(ToolShopScreen toolShopScreen, Context context, Typeface typeface, ToolType toolType) {
|
||||
this.toolShopScreen = toolShopScreen;
|
||||
this.context = context;
|
||||
this.toolType = toolType;
|
||||
this.levelUpBounties = levelUpBounties;
|
||||
bought = toolType.isBought();
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
layout = (LinearLayout) inflater.inflate(R.layout.tool_offer_slot, null);
|
||||
layout.setOnClickListener(this);
|
||||
layout.setOnLongClickListener(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(createColoredBackground());
|
||||
setLocked(false);
|
||||
|
||||
colorDisabled = context.getResources().getColor(R.color.toolslotDisabled);
|
||||
colorEnabled = context.getResources().getColor(R.color.toolslotEnabled);
|
||||
colorEnabledSelected = context.getResources().getColor(R.color.toolslotEnabledSelected);
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
@ -63,23 +66,36 @@ public class ToolOfferSlot implements View.OnClickListener, View.OnLongClickList
|
||||
}
|
||||
}
|
||||
|
||||
public void updateIsBought(){
|
||||
public boolean isBought() {
|
||||
return bought;
|
||||
}
|
||||
|
||||
public void updateIsBought() {
|
||||
bought = toolType.isBought();
|
||||
image.setBackgroundDrawable(createColoredBackground());
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
image.setBackgroundDrawable(createColoredBackground());
|
||||
}
|
||||
|
||||
public void buy() {
|
||||
this.bought = true;
|
||||
toolType.setBought(true);
|
||||
toolShopScreen.setSelectedToolOfferSlot(null);
|
||||
setColor(R.color.toolslotEnabled);
|
||||
}
|
||||
|
||||
private Drawable createColoredBackground() {
|
||||
GradientDrawable gd = new GradientDrawable();
|
||||
if (bought) {
|
||||
gd.setColor(context.getResources().getColor(R.color.toolslotEnabled));
|
||||
if (selected)
|
||||
gd.setColor(colorEnabledSelected);
|
||||
else
|
||||
gd.setColor(colorEnabled);
|
||||
} else {
|
||||
gd.setColor(context.getResources().getColor(R.color.toolslotDisabled));
|
||||
gd.setColor(colorDisabled);
|
||||
}
|
||||
gd.setCornerRadius(10);
|
||||
return gd;
|
||||
@ -102,7 +118,7 @@ public class ToolOfferSlot implements View.OnClickListener, View.OnLongClickList
|
||||
return layout;
|
||||
}
|
||||
|
||||
public ImageView getImage(){
|
||||
public ImageView getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -110,26 +126,10 @@ public class ToolOfferSlot implements View.OnClickListener, View.OnLongClickList
|
||||
public void onClick(View v) {
|
||||
if (!locked && !bought) {
|
||||
toolShopScreen.showPriceButton(this);
|
||||
} else if (bought) {
|
||||
selected = true;
|
||||
image.setBackgroundDrawable(createColoredBackground());
|
||||
toolShopScreen.setSelectedToolOfferSlot(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (!locked && bought) {
|
||||
dragged = true;
|
||||
ClipData clipData = ClipData.newPlainText("", "");
|
||||
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(image);
|
||||
image.startDrag(clipData, shadowBuilder, image, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDragged() {
|
||||
return dragged;
|
||||
}
|
||||
|
||||
public void setDragged(boolean dragged) {
|
||||
this.dragged = dragged;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
<color name="toolbuttonLocked">#db494b49</color>
|
||||
<color name="toolslotDisabled">#715f5f</color>
|
||||
<color name="toolslotEnabled">#db41e42b</color>
|
||||
<color name="toolslotEnabledSelected">#b3d700</color>
|
||||
<color name="countdown3">#f0f41e02</color>
|
||||
<color name="countdown2">#f0f28117</color>
|
||||
<color name="countdown1">#f0d7b106</color>
|
||||
|
Reference in New Issue
Block a user