Backported new debug buttons from title_screen branch into master.

This commit is contained in:
Zukero
2018-02-22 16:00:33 +01:00
parent 153ea0a660
commit 2ade99eed0
4 changed files with 75 additions and 25 deletions

View File

@@ -7,18 +7,23 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.Constants;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.view.MainView;
public final class DebugInterface {
private final ControllerContext controllerContext;
private final MainActivity mainActivity;
private final Resources res;
private final WorldContext world;
private DebugButton[] buttons;
public DebugInterface(ControllerContext controllers, WorldContext world, MainActivity mainActivity) {
this.controllerContext = controllers;
@@ -30,8 +35,18 @@ public final class DebugInterface {
public void addDebugButtons() {
if (!AndorsTrailApplication.DEVELOPMENT_DEBUGBUTTONS) return;
addDebugButtons(new DebugButton[] {
new DebugButton("dmg", new OnClickListener() {
buttons = new DebugButton[] {
new DebugButton("dbg", new OnClickListener() {
boolean hidden = false;
@Override
public void onClick(View arg0) {
hidden = !hidden;
for (int i = 1; i < buttons.length; i++) {
buttons[i].b.setVisibility(hidden ? View.GONE : View.VISIBLE);
}
}
})
,new DebugButton("dmg", new OnClickListener() {
@Override
public void onClick(View arg0) {
world.model.player.damagePotential.set(500, 500);
@@ -47,7 +62,7 @@ public final class DebugInterface {
showToast(mainActivity, "DEBUG: damagePotential=1", Toast.LENGTH_SHORT);
}
})*/
,new DebugButton("items", new OnClickListener() {
,new DebugButton("itm", new OnClickListener() {
@Override
public void onClick(View arg0) {
for (ItemType type : world.itemTypes.UNITTEST_getAllItemTypes().values()) {
@@ -69,20 +84,14 @@ public final class DebugInterface {
showToast(mainActivity, "DEBUG: added items", Toast.LENGTH_SHORT);
}
})
/*,new DebugButton("prim", new OnClickListener() {
@Override
public void onClick(View arg0) {
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "blackwater_mountain29", "south", 0, 0);
}
})*/
/*,new DebugButton("exp+=10000", new OnClickListener() {
,new DebugButton("xp", new OnClickListener() {
@Override
public void onClick(View arg0) {
controllerContext.actorStatsController.addExperience(10000);
showToast(mainActivity, "DEBUG: given 10000 exp", Toast.LENGTH_SHORT);
}
})*/
,new DebugButton("reset", new OnClickListener() {
})
,new DebugButton("rst", new OnClickListener() {
@Override
public void onClick(View arg0) {
for(PredefinedMap map : world.maps.getAllMaps()) {
@@ -101,13 +110,27 @@ public final class DebugInterface {
showToast(mainActivity, "DEBUG: hp set to max", Toast.LENGTH_SHORT);
}
})
,new DebugButton("skill", new OnClickListener() {
,new DebugButton("skl", new OnClickListener() {
@Override
public void onClick(View arg0) {
world.model.player.availableSkillIncreases += 10;
showToast(mainActivity, "DEBUG: 10 skill points", Toast.LENGTH_SHORT);
}
})
,new DebugButton("spd", new OnClickListener() {
boolean fast = Constants.MINIMUM_INPUT_INTERVAL == Constants.MINIMUM_INPUT_INTERVAL_FAST;
@Override
public void onClick(View arg0) {
fast = !fast;
if (fast) {
Constants.MINIMUM_INPUT_INTERVAL = Constants.MINIMUM_INPUT_INTERVAL_FAST;
} else {
Constants.MINIMUM_INPUT_INTERVAL = Constants.MINIMUM_INPUT_INTERVAL_STD;
}
MainView.SCROLL_DURATION = Constants.MINIMUM_INPUT_INTERVAL;
AndorsTrailApplication.getApplicationFromActivity(mainActivity).getControllerContext().movementController.resetMovementHandler();
}
})
/*
,new DebugButton("cg", new OnClickListener() {
@Override
@@ -139,6 +162,12 @@ public final class DebugInterface {
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "fallhaven_ne", "clothes", 0, 0);
}
})
,new DebugButton("prim", new OnClickListener() {
@Override
public void onClick(View arg0) {
controllerContext.movementController.placePlayerAsyncAt(MapObject.MapObjectType.newmap, "blackwater_mountain29", "south", 0, 0);
}
})
,new DebugButton("rc", new OnClickListener() {
@Override
public void onClick(View arg0) {
@@ -146,7 +175,8 @@ public final class DebugInterface {
}
})
*/
});
};
addDebugButtons(buttons);
}
private void showToast(Context context, String msg, int duration) {
@@ -156,10 +186,18 @@ public final class DebugInterface {
private static class DebugButton {
public final String text;
public final OnClickListener listener;
public Button b = null;
public DebugButton(String text, OnClickListener listener) {
this.text = text;
this.listener = listener;
}
public void makeButton(Context c, int id) {
b = new Button(c);
b.setText(text);
b.setTextSize(10);//res.getDimension(R.dimen.actionbar_text));
b.setId(id);
b.setOnClickListener(listener);
}
}
private void addDebugButton(DebugButton button, int id, RelativeLayout layout) {
@@ -171,13 +209,9 @@ public final class DebugInterface {
else
lp.addRule(RelativeLayout.RIGHT_OF, id - 1);
lp.addRule(RelativeLayout.ABOVE, R.id.main_statusview);
Button b = new Button(mainActivity);
b.setText(button.text);
b.setTextSize(10);//res.getDimension(R.dimen.actionbar_text));
b.setId(id);
b.setLayoutParams(lp);
b.setOnClickListener(button.listener);
layout.addView(b);
button.makeButton(mainActivity, id);
button.b.setLayoutParams(lp);
layout.addView(button.b);
}
private void addDebugButtons(DebugButton[] buttons) {

View File

@@ -19,7 +19,10 @@ public final class Constants {
public static final int EXP_FACTOR_DAMAGERESISTANCE = 9;
public static final float EXP_FACTOR_SCALING = 0.7f;
public static final int FLEE_FAIL_CHANCE_PERCENT = 20;
public static final long MINIMUM_INPUT_INTERVAL = AndorsTrailApplication.DEVELOPMENT_FASTSPEED ? 50 : 200;
public static final long MINIMUM_INPUT_INTERVAL_FAST = 50;
public static final long MINIMUM_INPUT_INTERVAL_STD = 200;
//TODO restore final modifier before release
public static long MINIMUM_INPUT_INTERVAL = AndorsTrailApplication.DEVELOPMENT_FASTSPEED ? MINIMUM_INPUT_INTERVAL_FAST : MINIMUM_INPUT_INTERVAL_STD;
public static final int MAX_MAP_WIDTH = 33;
public static final int MAX_MAP_HEIGHT = 33;
@@ -31,6 +34,7 @@ public final class Constants {
public static final int TICKS_PER_ROUND = ROUND_DURATION / TICK_DELAY;
public static final int TICKS_PER_FULLROUND = FULLROUND_DURATION / TICK_DELAY;
public static final int SPLATTER_DURATION_MS = 20000;
public static final int STATUS_TEXT_AUTOHIDE_DELAY = ROUND_DURATION;
public static final ConstRange monsterWaitTurns = new ConstRange(5,1);
public static final long MAP_UNVISITED_RESPAWN_DURATION_MS = 3 * 60 * 1000; // 3 min in milliseconds

View File

@@ -10,7 +10,11 @@ import com.gpl.rpg.AndorsTrail.model.ModelContainer;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.map.*;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.map.TMXMapTranslator;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.L;
@@ -19,7 +23,8 @@ import com.gpl.rpg.AndorsTrail.util.TimedMessageTask;
public final class MovementController implements TimedMessageTask.Callback {
private final ControllerContext controllers;
private final WorldContext world;
private final TimedMessageTask movementHandler;
//TODO restore final modifier before release
private TimedMessageTask movementHandler;
public final PlayerMovementListeners playerMovementListeners = new PlayerMovementListeners();
public MovementController(ControllerContext controllers, WorldContext world) {
@@ -27,6 +32,12 @@ public final class MovementController implements TimedMessageTask.Callback {
this.world = world;
this.movementHandler = new TimedMessageTask(this, Constants.MINIMUM_INPUT_INTERVAL, false);
}
//TODO remove this method before release
public void resetMovementHandler() {
this.movementHandler.stop();
this.movementHandler = new TimedMessageTask(this, Constants.MINIMUM_INPUT_INTERVAL, false);
}
public void placePlayerAsyncAt(final MapObject.MapObjectType objectType, final String mapName, final String placeName, final int offset_x, final int offset_y) {

View File

@@ -101,7 +101,8 @@ public final class MainView extends SurfaceView
private boolean scrolling = false;
private Coord scrollVector;
private long scrollStartTime;
private final static long SCROLL_DURATION = Constants.MINIMUM_INPUT_INTERVAL;
//TODO restore private final modifiers before release
public static long SCROLL_DURATION = Constants.MINIMUM_INPUT_INTERVAL;
public MainView(Context context, AttributeSet attr) {