Compare commits

...

12 Commits

Author SHA1 Message Date
OMGeeky
b1c2a4ef8c remove unused stuff 2024-09-07 15:36:00 +02:00
OMGeeky
af3109b9d9 Fix visual Bugs & slowdowns 2024-09-07 15:06:04 +02:00
Ian
bac004ae33 Visual Glitch Fix
-Fix the issue where the application is not able to handle multiple effects simultanously
2024-09-07 18:23:07 +08:00
Nut.andor
e5acb89f1b authors 2024-08-30 22:56:00 +02:00
Nut.andor
950310906e new map_brightport.png 2024-08-28 20:56:14 +02:00
Nut.andor
4f2733324f Merge branch 'pulls/1829009049/74' into AT_Source_Next_Release 2024-08-25 23:10:48 +02:00
Nut.andor
7379277b1d Pass time debug button 2024-08-25 23:05:59 +02:00
Nut.andor
6387b87ced Add tick-increase Debug-Button (for testing timers) 2024-08-25 23:04:31 +02:00
Nut.andor
f01c5ff237 Only add the loot once 2024-08-25 23:00:27 +02:00
Nut.andor
5843be57c0 Pull Request #74: Add tick-increase Debug-Button (for testing timers) 2024-08-25 14:04:07 +02:00
Nut.andor
bec17c65e4 Pull Request #73: Only add the loot once 2024-08-25 13:31:29 +02:00
OMGeeky
315e34185a Only add the loot once to the killedMonsterBags
without this, the loot might be added multiple times to the UI when showing what has been dropped, allowing the player to get more items than they should be allowed to
2024-08-25 13:23:25 +02:00
10 changed files with 135 additions and 85 deletions

View File

@@ -153,7 +153,7 @@ public final class DebugInterface {
showToast(mainActivity, "DEBUG: map=" + world.model.currentMaps.map.name , Toast.LENGTH_SHORT);
}
})
,new DebugButton("tick-10", new OnClickListener() {
,new DebugButton("tim", new OnClickListener() {
@Override
public void onClick(View arg0) {
world.model.worldData.tickWorldTime(10);

View File

@@ -250,7 +250,8 @@ public final class CombatController implements VisualEffectCompletedCallback {
if (!loot.hasItemsOrGold()) {
world.model.currentMaps.map.removeGroundLoot(loot);
} else if (world.model.uiSelections.isInCombat) {
killedMonsterBags.add(loot);
if(!killedMonsterBags.contains(loot))
killedMonsterBags.add(loot);
}
combatActionListeners.onPlayerKilledMonster(killedMonster);

View File

@@ -21,14 +21,23 @@ import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.Size;
import java.util.ArrayList;
import java.util.List;
public final class VisualEffectController {
private static final long EFFECT_UPDATE_INTERVAL = 25;
private int effectCount = 0;
private final ControllerContext controllers;
private final WorldContext world;
private final VisualEffectCollection effectTypes;
private final Handler animationHandler = new Handler();
private final List<VisualEffectAnimation> activeAnimations = new ArrayList<>();
public final VisualEffectFrameListeners visualEffectFrameListeners = new VisualEffectFrameListeners();
private long getEffectUpdateInterval() {
return EFFECT_UPDATE_INTERVAL * controllers.preferences.attackspeed_milliseconds / AndorsTrailPreferences.ATTACKSPEED_DEFAULT_MILLISECONDS;
}
public VisualEffectController(ControllerContext controllers, WorldContext world) {
this.controllers = controllers;
@@ -38,10 +47,42 @@ public final class VisualEffectController {
public void startEffect(Coord position, VisualEffectCollection.VisualEffectID effectID, String displayValue, VisualEffectCompletedCallback callback, int callbackValue) {
++effectCount;
(new VisualEffectAnimation(effectTypes.getVisualEffect(effectID), position, displayValue, callback, callbackValue))
.start();
VisualEffectAnimation animation = new VisualEffectAnimation(effectTypes.getVisualEffect(effectID), position, displayValue, callback, callbackValue);
animation.start();
}
private void startAnimation(VisualEffectAnimation animation) {
activeAnimations.add(animation);
animation.update();
if (activeAnimations.size() == 1) {
animationHandler.postDelayed(animationRunnable, 0);
}
}
private final Runnable animationRunnable = new Runnable() {
@Override
public void run() {
if(!activeAnimations.isEmpty()) {
long updateInterval = getEffectUpdateInterval();
animationHandler.postDelayed(this, updateInterval);
for (int i = 0; i < activeAnimations.size(); i++) {
VisualEffectAnimation animation = activeAnimations.get(i);
animation.durationPassed += updateInterval;
animation.updateFrame();
animation.update();
if (animation.currentFrame >= animation.effect.lastFrame) {
animation.onCompleted();
activeAnimations.remove(i);
effectCount--;
i--;
}
}
visualEffectFrameListeners.onNewAnimationFrames(activeAnimations);
}
}
};
private VisualEffectCollection.VisualEffectID enqueuedEffectID = null;
private int enqueuedEffectValue = 0;
public void enqueueEffect(VisualEffectCollection.VisualEffectID effectID, int displayValue) {
@@ -65,10 +106,9 @@ public final class VisualEffectController {
.start();
}
public final class SpriteMoveAnimation extends Handler implements Runnable {
// private static final int millisecondsPerFrame=25;
public final class SpriteMoveAnimation implements Runnable {
private final Handler handler = new Handler();
private final VisualEffectCompletedCallback callback;
private final int callbackValue;
@@ -82,11 +122,6 @@ public final class VisualEffectController {
@Override
public void run() {
onCompleted();
// update();
// if (System.currentTimeMillis() - actor.vfxStartTime >= duration) {
// } else {
// postDelayed(this, millisecondsPerFrame);
// }
}
public SpriteMoveAnimation(Coord origin, Coord destination, int duration, Actor actor, PredefinedMap map, VisualEffectCompletedCallback callback, int callbackValue) {
@@ -99,11 +134,6 @@ public final class VisualEffectController {
this.destination = destination;
}
// private void update() {
//
// visualEffectFrameListeners.onNewSpriteMoveFrame(this);
// }
private void onCompleted() {
--effectCount;
@@ -111,7 +141,6 @@ public final class VisualEffectController {
if (callback != null) callback.onVisualEffectCompleted(callbackValue);
visualEffectFrameListeners.onSpriteMoveCompleted(this);
}
public void start() {
actor.hasVFXRunning = true;
@@ -120,12 +149,9 @@ public final class VisualEffectController {
visualEffectFrameListeners.onSpriteMoveStarted(this);
if (duration == 0 || !controllers.preferences.enableUiAnimations) onCompleted();
else {
postDelayed(this, duration);
handler.postDelayed(this, duration);
}
}
}
public static final Paint textPaint = new Paint();
@@ -134,41 +160,42 @@ public final class VisualEffectController {
textPaint.setAlpha(255);
textPaint.setTextAlign(Align.CENTER);
}
public final class VisualEffectAnimation extends Handler implements Runnable {
@Override
public void run() {
if (currentFrame >= effect.lastFrame) {
onCompleted();
} else {
postDelayed(this, effect.millisecondPerFrame * controllers.preferences.attackspeed_milliseconds / AndorsTrailPreferences.ATTACKSPEED_DEFAULT_MILLISECONDS);
update();
public final class VisualEffectAnimation {
public int tileID;
public int textYOffset;
public long durationPassed = 0;
private void updateFrame() {
long frameDuration = (long) effect.millisecondPerFrame * controllers.preferences.attackspeed_milliseconds / AndorsTrailPreferences.ATTACKSPEED_DEFAULT_MILLISECONDS;
while (durationPassed > frameDuration) {
currentFrame++;
durationPassed -= frameDuration;
}
}
private void update() {
++currentFrame;
int frame = currentFrame;
int tileID = effect.frameIconIDs[frame];
int textYOffset = -2 * (frame);
if (frame >= beginFadeAtFrame && displayText != null) {
textPaint.setAlpha(255 * (effect.lastFrame - frame) / (effect.lastFrame - beginFadeAtFrame));
if (currentFrame >= effect.lastFrame) {
return;
}
tileID = effect.frameIconIDs[currentFrame];
textYOffset = -2 * (currentFrame);
if (currentFrame >= beginFadeAtFrame && displayText != null) {
textPaint.setAlpha(255 * (effect.lastFrame - currentFrame) / (effect.lastFrame - beginFadeAtFrame));
}
area.topLeft.y = position.y - 1;
visualEffectFrameListeners.onNewAnimationFrame(this, tileID, textYOffset);
}
private void onCompleted() {
--effectCount;
visualEffectFrameListeners.onAnimationCompleted(this);
if (callback != null) callback.onVisualEffectCompleted(callbackValue);
}
public void start() {
if (!controllers.preferences.enableUiAnimations) onCompleted();
else postDelayed(this, 0);
else startAnimation(this);
}
private int currentFrame = 0;
@@ -197,7 +224,7 @@ public final class VisualEffectController {
this.area = new CoordRect(new Coord(position.x - (widthNeededInTiles / 2), position.y - 1), new Size(widthNeededInTiles, 2));
this.beginFadeAtFrame = effect.lastFrame / 2;
}
public Paint getTextPaint(){
return textPaint;
}

View File

@@ -4,8 +4,10 @@ import com.gpl.rpg.AndorsTrail.controller.VisualEffectController.SpriteMoveAnima
import com.gpl.rpg.AndorsTrail.controller.VisualEffectController.VisualEffectAnimation;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import java.util.List;
public interface VisualEffectFrameListener {
void onNewAnimationFrame(VisualEffectAnimation animation, int tileID, int textYOffset);
void onNewAnimationFrames(List<VisualEffectAnimation> effects);
void onAnimationCompleted(VisualEffectAnimation animation);
void onSpriteMoveStarted(SpriteMoveAnimation animation);
void onNewSpriteMoveFrame(SpriteMoveAnimation animation);

View File

@@ -5,10 +5,12 @@ import com.gpl.rpg.AndorsTrail.controller.VisualEffectController.VisualEffectAni
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import java.util.List;
public final class VisualEffectFrameListeners extends ListOfListeners<VisualEffectFrameListener> implements VisualEffectFrameListener {
private final Function3<VisualEffectFrameListener, VisualEffectAnimation, Integer, Integer> onNewAnimationFrame = new Function3<VisualEffectFrameListener, VisualEffectAnimation, Integer, Integer>() {
@Override public void call(VisualEffectFrameListener listener, VisualEffectAnimation animation, Integer tileID, Integer textYOffset) { listener.onNewAnimationFrame(animation, tileID, textYOffset); }
private final Function1<VisualEffectFrameListener, List<VisualEffectAnimation>> onNewAnimationFrames = new Function1<VisualEffectFrameListener, List<VisualEffectAnimation>>() {
@Override public void call(VisualEffectFrameListener listener, List<VisualEffectAnimation> effects) { listener.onNewAnimationFrames(effects); }
};
private final Function1<VisualEffectFrameListener, VisualEffectAnimation> onAnimationCompleted = new Function1<VisualEffectFrameListener, VisualEffectAnimation>() {
@@ -30,10 +32,10 @@ public final class VisualEffectFrameListeners extends ListOfListeners<VisualEffe
private final Function1<VisualEffectFrameListener, CoordRect> onAsyncAreaUpdate = new Function1<VisualEffectFrameListener, CoordRect>() {
@Override public void call(VisualEffectFrameListener listener, CoordRect area) { listener.onAsyncAreaUpdate(area); }
};
@Override
public void onNewAnimationFrame(VisualEffectAnimation animation, int tileID, int textYOffset) {
callAllListeners(this.onNewAnimationFrame, animation, tileID, textYOffset);
public void onNewAnimationFrames(List<VisualEffectAnimation> effects) {
callAllListeners(this.onNewAnimationFrames, effects);
}
@Override

View File

@@ -387,6 +387,7 @@ public final class ResourceLoader {
loader.prepareTileset(R.drawable.map_border_1, "map_border_1", mapTileSize, sz1x1, mTileSize);
loader.prepareTileset(R.drawable.map_bridge_1, "map_bridge_1", mapTileSize, sz1x1, mTileSize);
loader.prepareTileset(R.drawable.map_bridge_2, "map_bridge_2", mapTileSize, sz1x1, mTileSize);
loader.prepareTileset(R.drawable.map_brightport, "map_brightport", new Size(7, 5), sz1x1, mTileSize);
loader.prepareTileset(R.drawable.map_broken_1, "map_broken_1", mapTileSize, sz1x1, mTileSize);
loader.prepareTileset(R.drawable.map_cavewall_1, "map_cavewall_1", new Size(18, 6), sz1x1, mTileSize);
loader.prepareTileset(R.drawable.map_cavewall_2, "map_cavewall_2", new Size(18, 6), sz1x1, mTileSize);

View File

@@ -30,6 +30,18 @@ public final class CoordRect {
return true;
}
public static CoordRect union(CoordRect r1, CoordRect r2) {
int left = Math.min(r1.topLeft.x, r2.topLeft.x);
int top = Math.min(r1.topLeft.y, r2.topLeft.y);
int right = Math.max(r1.topLeft.x + r1.size.width, r2.topLeft.x + r2.size.width);
int bottom = Math.max(r1.topLeft.y + r1.size.height, r2.topLeft.y + r2.size.height);
int width = right - left;
int height = bottom - top;
return new CoordRect(new Coord(left, top), new Size(width, height));
}
/*
public static boolean contains(final int x, final int y, final Size size, final Coord p) {
if (p.x < x) return false;

View File

@@ -1,6 +1,7 @@
package com.gpl.rpg.AndorsTrail.view;
import java.lang.ref.WeakReference;
import java.util.List;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
@@ -158,8 +159,8 @@ public final class MainView extends SurfaceView
// this.surfaceSize = new Size(w, h);
this.surfaceSize = new Size((int) (getWidth() / scale), (int) (getHeight() / scale));
this.screenSizeTileCount = new Size(
(int) Math.floor(getWidth() / scaledTileSize)
,(int) Math.floor(getHeight() / scaledTileSize)
getWidth() / scaledTileSize
,getHeight() / scaledTileSize
);
if (sh.getSurfaceFrame().right != surfaceSize.width || sh.getSurfaceFrame().bottom != surfaceSize.height) {
@@ -226,28 +227,28 @@ public final class MainView extends SurfaceView
if (scrolling && why != RedrawAllDebugReason.MapScrolling) return;
if (!scrolling && movingSprites > 0 && why != RedrawAllDebugReason.SpriteMoved) return;
}
redrawArea_(mapViewArea, null, 0, 0);
redrawArea_(mapViewArea, null);
}
private void redrawTile(final Coord p, RedrawTileDebugReason why) {
if (scrolling) return;
p1x1.topLeft.set(p);
redrawArea_(p1x1, null, 0, 0);
redrawArea_(p1x1, null);
}
private void redrawArea(final CoordRect area, RedrawAreaDebugReason why) {
if (scrolling) return;
redrawArea_(area, null, 0, 0);
redrawArea_(area, null);
}
private void redrawArea_(CoordRect area, final VisualEffectAnimation effect, int tileID, int textYOffset) {
private void redrawArea_(CoordRect area, final List<VisualEffectAnimation> effects) {
if (!hasSurface) return;
if (!currentMap.intersects(area)) return;
if (!mapViewArea.intersects(area)) return;
if (shouldRedrawEverything()) {
area = mapViewArea;
}
calculateRedrawRect(area);
redrawRect.intersect(redrawClip);
Canvas c = null;
@@ -263,7 +264,7 @@ public final class MainView extends SurfaceView
if (area == mapViewArea) {
area = adaptAreaToScrolling(area);
}
synchronized (holder) { synchronized (tiles) {
int xScroll = 0;
int yScroll = 0;
@@ -275,32 +276,25 @@ public final class MainView extends SurfaceView
}
c.clipRect(redrawClip);
c.translate(screenOffset.x + xScroll, screenOffset.y + yScroll);
// c.scale(scale, scale);
doDrawRect(c, area);
if (effect != null) {
drawFromMapPosition(c, area, effect.position, tileID);
if (effect.displayText != null) {
drawEffectText(c, area, effect, textYOffset, effect.getTextPaint());
}
}
// c.drawRect(new Rect(
// (area.topLeft.x - mapViewArea.topLeft.x) * tileSize,
// (area.topLeft.y - mapViewArea.topLeft.y) * tileSize,
// (area.topLeft.x - mapViewArea.topLeft.x + area.size.width) * tileSize - 1,
// (area.topLeft.y - mapViewArea.topLeft.y + area.size.height) * tileSize - 1),
// redrawHighlight);
// if (touchedTile != null) c.drawRect(new Rect(
// (touchedTile.x - mapViewArea.topLeft.x) * tileSize,
// (touchedTile.y - mapViewArea.topLeft.y) * tileSize,
// (touchedTile.x - mapViewArea.topLeft.x + 1) * tileSize - 1,
// (touchedTile.y - mapViewArea.topLeft.y + 1) * tileSize - 1),
// touchHighlight);
renderEffects(c, effects);
} }
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
}
}
private void renderEffects(Canvas canvas ,List<VisualEffectAnimation> effects) {
if(effects == null) return;
for (VisualEffectAnimation effect : effects) {
int tileID = effect.tileID;
int textYOffset = effect.textYOffset;
drawFromMapPosition(canvas, effect.area, effect.position, tileID);
if (effect.displayText != null) {
drawEffectText(canvas, effect.area, effect, textYOffset, effect.getTextPaint());
}
}
}
private boolean isRedrawRectWholeScreen(Rect redrawRect) {
// if (redrawRect.width() < mapViewArea.size.width * scaledTileSize) return false;
@@ -317,11 +311,21 @@ public final class MainView extends SurfaceView
return true;
}
private final Rect redrawRect = new Rect();
private void redrawAreaWithEffect(final VisualEffectAnimation effect, int tileID, int textYOffset) {
CoordRect area = effect.area;
// if (shouldRedrawEverythingForVisualEffect()) area = mapViewArea;
redrawArea_(area, effect, tileID, textYOffset);
private void redrawAreaWithEffect(List<VisualEffectAnimation> effects) {
CoordRect area = null;
for (int i = 0; i < effects.size(); i++) {
VisualEffectAnimation effect = effects.get(i);
if (area == null) {
area = effect.area;
} else {
area = CoordRect.union(area, effect.area);
}
}
if (area != null) {
redrawArea_(area, effects);
}
}
private void clearCanvas() {
if (!hasSurface) return;
Canvas c = null;
@@ -794,8 +798,8 @@ public final class MainView extends SurfaceView
}
@Override
public void onNewAnimationFrame(VisualEffectAnimation animation, int tileID, int textYOffset) {
redrawAreaWithEffect(animation, tileID, textYOffset);
public void onNewAnimationFrames(List<VisualEffectAnimation> effects) {
redrawAreaWithEffect(effects);
}
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -59,6 +59,7 @@
• Draze<br/>
• Antison<br/>
• Raphi<br/>
• Dimitri Vellemans (Odin)<br/>
<br/>
<b>Translations</b><br/>
• Russian translation by Dreamer..., e.solodookhin, shell.andor, konstmih, istasman, Aleksey Kabanov, Alexander Zubok, Paul Sulemenkov, dromoz, avatar232 and Mingun<br/>