mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Code cleanup for displaying magnitude on actor condition icons.
This commit is contained in:
@@ -241,16 +241,12 @@ public final class MovementController implements TimedMessageTask.Callback {
|
||||
if (!world.model.currentMap.isWalkable(world.model.player.position)) {
|
||||
// If the player somehow spawned on an unwalkable tile, we move the player to the first mapchange area.
|
||||
// This could happen if we change some tile to non-walkable in a future version.
|
||||
MapObject dest = null;
|
||||
for (MapObject o : model.currentMap.eventObjects) {
|
||||
if (o.type == MapObject.MAPEVENT_NEWMAP) {
|
||||
dest = o;
|
||||
model.player.position.set(o.position.topLeft);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dest != null) {
|
||||
model.player.position.set(dest.position.topLeft);
|
||||
}
|
||||
}
|
||||
|
||||
// If any monsters somehow spawned on an unwalkable tile, we move the monster to a new position on the spawnarea
|
||||
|
||||
@@ -3,10 +3,19 @@ package com.gpl.rpg.AndorsTrail.model.listeners;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
|
||||
public class ListOfListeners<T> {
|
||||
private final ArrayList<WeakReference<T>> listeners = new ArrayList<WeakReference<T>>();
|
||||
|
||||
public void add(T listener) {
|
||||
if (AndorsTrailApplication.DEVELOPMENT_VALIDATEDATA) {
|
||||
for (WeakReference<T> ref : listeners) {
|
||||
if (ref.get() == listener) {
|
||||
throw new IndexOutOfBoundsException("FAIL: listener added twice to ListOfListeners.");
|
||||
}
|
||||
}
|
||||
}
|
||||
listeners.add(new WeakReference<T>(listener));
|
||||
}
|
||||
public void remove(T listenerToRemove) {
|
||||
|
||||
@@ -33,53 +33,50 @@ public class DisplayActiveActorConditionIcons implements ActorConditionListener
|
||||
this.androidContext = new WeakReference<Context>(androidContext);
|
||||
this.activeConditions = activeConditions;
|
||||
}
|
||||
|
||||
private ActiveConditionIcon getIconFor(ActorCondition condition) {
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) {
|
||||
if (icon.condition == condition) return icon;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private ActiveConditionIcon getFirstFreeIcon() {
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) {
|
||||
if (!icon.isVisible()) return icon;
|
||||
}
|
||||
return addNewActiveConditionIcon();
|
||||
}
|
||||
|
||||
private RelativeLayout.LayoutParams getLayoutParamsForIconIndex(int index) {
|
||||
RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
if (index == 0) {
|
||||
layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
} else {
|
||||
layout.addRule(RelativeLayout.LEFT_OF, currentConditionIcons.get(index-1).id);
|
||||
}
|
||||
return layout;
|
||||
|
||||
@Override
|
||||
public void onActorConditionAdded(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getFirstFreeIcon();
|
||||
icon.setActiveCondition(condition);
|
||||
icon.show();
|
||||
}
|
||||
|
||||
private ActiveConditionIcon addNewActiveConditionIcon() {
|
||||
int index = currentConditionIcons.size();
|
||||
|
||||
ActiveConditionIcon icon = new ActiveConditionIcon(androidContext.get(), index+1);
|
||||
|
||||
activeConditions.addView(icon.image, getLayoutParamsForIconIndex(index));
|
||||
|
||||
RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layout.addRule(RelativeLayout.ALIGN_RIGHT, icon.id);
|
||||
layout.addRule(RelativeLayout.ALIGN_BOTTOM, icon.id);
|
||||
activeConditions.addView(icon.text, layout);
|
||||
|
||||
/*
|
||||
layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layout.addRule(RelativeLayout.ALIGN_RIGHT, icon.image.getId());
|
||||
layout.addRule(RelativeLayout.ALIGN_BOTTOM, icon.image.getId());
|
||||
activeConditions.addView(icon.duration, layout);
|
||||
*/
|
||||
|
||||
currentConditionIcons.add(icon);
|
||||
|
||||
return icon;
|
||||
@Override
|
||||
public void onActorConditionRemoved(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.hide(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionDurationChanged(Actor actor, ActorCondition condition) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionMagnitudeChanged(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.setIconText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionRoundEffectApplied(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.pulseAnimate();
|
||||
}
|
||||
|
||||
public void unsubscribe(final WorldContext world) {
|
||||
world.model.player.conditionListener.remove(this);
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) icon.condition = null;
|
||||
}
|
||||
|
||||
public void subscribe(final WorldContext world) {
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) icon.hide(false);
|
||||
for (ActorCondition condition : world.model.player.conditions) {
|
||||
getFirstFreeIcon().setActiveCondition(condition);
|
||||
}
|
||||
world.model.player.conditionListener.add(this);
|
||||
}
|
||||
|
||||
private final class ActiveConditionIcon implements AnimationListener {
|
||||
@@ -87,7 +84,6 @@ public class DisplayActiveActorConditionIcons implements ActorConditionListener
|
||||
public ActorCondition condition;
|
||||
public final ImageView image;
|
||||
public final TextView text;
|
||||
//public final TextView duration;
|
||||
private final Animation onNewIconAnimation;
|
||||
private final Animation onRemovedIconAnimation;
|
||||
private final Animation onAppliedEffectAnimation;
|
||||
@@ -101,24 +97,9 @@ public class DisplayActiveActorConditionIcons implements ActorConditionListener
|
||||
this.onRemovedIconAnimation = AnimationUtils.loadAnimation(context, R.anim.scaledown);
|
||||
this.onAppliedEffectAnimation = AnimationUtils.loadAnimation(context, R.anim.scalebeat);
|
||||
this.onRemovedIconAnimation.setAnimationListener(this);
|
||||
//duration = new TextView(context);
|
||||
|
||||
final Resources res = context.getResources();
|
||||
|
||||
//float textSize = ;
|
||||
//magnitude.setTextSize(res.getDimension(R.dimen.smalltext));
|
||||
/*
|
||||
duration.setTextSize(res.getDimension(R.dimen.smalltext));
|
||||
|
||||
int textColor = res.getColor(android.R.color.white);
|
||||
int shadowColor = res.getColor(android.R.color.black);
|
||||
magnitude.setTextColor(textColor);
|
||||
duration.setTextColor(textColor);
|
||||
|
||||
magnitude.setShadowLayer(1, 1, 1, shadowColor);
|
||||
duration.setShadowLayer(2, 1, 1, shadowColor);
|
||||
*/
|
||||
|
||||
text.setTextColor(res.getColor(android.R.color.white));
|
||||
text.setShadowLayer(1, 1, 1, res.getColor(android.R.color.black));
|
||||
}
|
||||
@@ -132,34 +113,12 @@ public class DisplayActiveActorConditionIcons implements ActorConditionListener
|
||||
|
||||
public void setIconText() {
|
||||
boolean showMagnitude = (condition.magnitude != 1);
|
||||
boolean showDuration = condition.isTemporaryEffect();
|
||||
if (showMagnitude/* || showDuration*/) {
|
||||
/*if (showMagnitude && showDuration) {
|
||||
icon.text.setText(condition.duration + "x" + condition.magnitude);
|
||||
} else if (showDuration) {
|
||||
icon.text.setText(condition.duration);
|
||||
} else if (showMagnitude) {
|
||||
icon.text.setText("x" + condition.magnitude);
|
||||
}*/
|
||||
if (showMagnitude) {
|
||||
text.setText(Integer.toString(condition.magnitude));
|
||||
text.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
text.setVisibility(View.GONE);
|
||||
}
|
||||
/*
|
||||
if (condition.magnitude != 1) {
|
||||
icon.magnitude.setText(Integer.toString(condition.magnitude));
|
||||
icon.magnitude.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
icon.magnitude.setVisibility(View.GONE);
|
||||
}
|
||||
if (condition.isTemporaryEffect()) {
|
||||
icon.duration.setText(Integer.toString(condition.duration));
|
||||
icon.duration.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
icon.duration.setVisibility(View.GONE);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void hide(boolean useAnimation) {
|
||||
@@ -201,60 +160,48 @@ public class DisplayActiveActorConditionIcons implements ActorConditionListener
|
||||
currentConditionIcons.remove(i);
|
||||
currentConditionIcons.add(icon);
|
||||
for(; i < currentConditionIcons.size(); ++i) {
|
||||
ActiveConditionIcon aci = currentConditionIcons.get(i);
|
||||
aci.image.setLayoutParams(getLayoutParamsForIconIndex(i));
|
||||
currentConditionIcons.get(i).image.setLayoutParams(getLayoutParamsForIconIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionAdded(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getFirstFreeIcon();
|
||||
icon.setActiveCondition(condition);
|
||||
icon.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionRemoved(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.hide(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionDurationChanged(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.setIconText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionMagnitudeChanged(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.setIconText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActorConditionRoundEffectApplied(Actor actor, ActorCondition condition) {
|
||||
ActiveConditionIcon icon = getIconFor(condition);
|
||||
if (icon == null) return;
|
||||
icon.pulseAnimate();
|
||||
}
|
||||
|
||||
public void unsubscribe(final WorldContext world) {
|
||||
world.model.player.conditionListener.remove(this);
|
||||
hideAllIcons();
|
||||
}
|
||||
|
||||
public void subscribe(final WorldContext world) {
|
||||
hideAllIcons();
|
||||
for (ActorCondition condition : world.model.player.conditions) {
|
||||
getFirstFreeIcon().setActiveCondition(condition);
|
||||
}
|
||||
world.model.player.conditionListener.add(this);
|
||||
}
|
||||
|
||||
private void hideAllIcons() {
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) icon.hide(false);
|
||||
private ActiveConditionIcon getIconFor(ActorCondition condition) {
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) {
|
||||
if (icon.condition == condition) return icon;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private ActiveConditionIcon getFirstFreeIcon() {
|
||||
for (ActiveConditionIcon icon : currentConditionIcons) {
|
||||
if (!icon.isVisible()) return icon;
|
||||
}
|
||||
return addNewActiveConditionIcon();
|
||||
}
|
||||
|
||||
private RelativeLayout.LayoutParams getLayoutParamsForIconIndex(int index) {
|
||||
RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
if (index == 0) {
|
||||
layout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
} else {
|
||||
layout.addRule(RelativeLayout.LEFT_OF, currentConditionIcons.get(index-1).id);
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
private ActiveConditionIcon addNewActiveConditionIcon() {
|
||||
int index = currentConditionIcons.size();
|
||||
|
||||
ActiveConditionIcon icon = new ActiveConditionIcon(androidContext.get(), index+1);
|
||||
|
||||
activeConditions.addView(icon.image, getLayoutParamsForIconIndex(index));
|
||||
|
||||
RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layout.addRule(RelativeLayout.ALIGN_RIGHT, icon.id);
|
||||
layout.addRule(RelativeLayout.ALIGN_BOTTOM, icon.id);
|
||||
activeConditions.addView(icon.text, layout);
|
||||
|
||||
currentConditionIcons.add(icon);
|
||||
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user