Skip to content

Commit fdff857

Browse files
authored
Refactor RewardActor, remove holdtooltip and use CardZoom via ViewRewardScene (#11737)
* Refactor RewardActor, remove holdtooltip and use CardZoom via ViewRewardScene * remove unnecesary changes * rename batch, add comment * return generated image for cardpacks if cached image is not found * use RewardActor object reference for CardView image * clear CardView Object, update Zoom renders * refactor Graphics, cached CardView with objects to clear, limit graphics spritebatch capacity
1 parent 9547c6c commit fdff857

28 files changed

Lines changed: 826 additions & 761 deletions

forge-game/src/main/java/forge/game/card/CardView.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public static CardView getCardForUi(IPaperCard pc) {
5959
return Card.getCardForUi(pc).getView();
6060
}
6161

62+
public Object getObject() {
63+
return get(TrackableProperty.Object);
64+
}
65+
public void clearObject() {
66+
set(TrackableProperty.Object, null);
67+
}
68+
6269
public static TrackableCollection<CardView> getCollection(Iterable<Card> cards) {
6370
TrackableCollection<CardView> collection = new TrackableCollection<>();
6471
if (cards != null) {
@@ -86,6 +93,14 @@ public CardView(final int id0, final Tracker tracker) {
8693
super(id0, tracker);
8794
set(TrackableProperty.CurrentState, new CardStateView(id0, CardStateName.Original, tracker));
8895
}
96+
public CardView(final int id0, final Tracker tracker, final String name0, final String description, final Object object) {
97+
super(id0, tracker);
98+
set(TrackableProperty.CurrentState, new CardStateView(id0, CardStateName.Original, tracker));
99+
getCurrentState().setName(name0);
100+
getCurrentState().setOracleText(description);
101+
set(TrackableProperty.Name, name0);
102+
set(TrackableProperty.Object, object);
103+
}
89104
public CardView(final int id0, final Tracker tracker, final String name0) {
90105
this(id0, tracker);
91106
getCurrentState().setName(name0);
@@ -94,10 +109,8 @@ public CardView(final int id0, final Tracker tracker, final String name0) {
94109
set(TrackableProperty.ChangedTypes, new HashMap<String, String>());
95110
set(TrackableProperty.Sickness, true);
96111
}
97-
public CardView(final int id0, final Tracker tracker, final String name0, final PlayerView ownerAndController, final String imageKey) {
112+
public CardView(final int id0, final Tracker tracker, final String name0, final String imageKey) {
98113
this(id0, tracker, name0);
99-
set(TrackableProperty.Owner, ownerAndController);
100-
set(TrackableProperty.Controller, ownerAndController);
101114
set(TrackableProperty.ImageKey, imageKey);
102115
}
103116

forge-game/src/main/java/forge/trackable/TrackableProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ public enum TrackableProperty {
257257
PoisonCountersToLose(TrackableTypes.IntegerType),
258258
PlayerTurn(TrackableTypes.PlayerViewType, FreezeMode.IgnoresFreeze),
259259
Phase(TrackableTypes.EnumType(PhaseType.class), FreezeMode.IgnoresFreeze),
260+
Object(TrackableTypes.ObjectType, FreezeMode.IgnoresFreeze),
260261
Dependencies(TrackableTypes.StringType);
261262

262263
public enum FreezeMode {

forge-game/src/main/java/forge/trackable/TrackableTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ protected void copyChangedProps(TrackableObject from, TrackableObject to, Tracka
133133
public static final TrackableType<Integer> IntegerType = new TrackableType<Integer>(0);
134134
public static final TrackableType<Float> FloatType = new TrackableType<Float>(0f);
135135
public static final TrackableType<String> StringType = new TrackableType<String>("");
136+
public static final TrackableType<Object> ObjectType = new TrackableType<Object>(null);
136137

137138
//make this quicker than having to define a new class for every single enum
138139
private static Map<Class<? extends Enum<?>>, TrackableType<?>> enumTypes = Maps.newHashMap();

forge-gui-mobile/src/forge/Adventure.java

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88

99
public class Adventure implements Disposable {
1010
private static Adventure instance;
11-
private float animationTimeout;
11+
private float transitionTimeout;
1212
boolean sceneWasSwapped;
13-
private SpriteBatch animationBatch, adventureBatch;
13+
private SpriteBatch transitionBatch, adventureBatch;
14+
public boolean renderTransitionScreen = true;
1415

1516
private Adventure() {
1617
sceneWasSwapped = false;
17-
animationBatch = new SpriteBatch(30);
18-
adventureBatch = new SpriteBatch(600);
18+
transitionBatch = new SpriteBatch(Forge.LOW_SPRITES_CAP);
19+
// adventureBatch is used on UIScene so every scene passed will use this shared batch
20+
// instead of creating new SpriteBatch each with default 1000 capacity (14 scenes currently)
21+
adventureBatch = new SpriteBatch(Forge.HIGH_SPRITES_CAP);
1922
}
2023

2124
public SpriteBatch getAdventureBatch() {
@@ -28,41 +31,45 @@ public static Adventure getInstance() {
2831

2932
void render(float delta) {
3033
try {
31-
float transitionTime = 0.12f;
32-
if (sceneWasSwapped) {
33-
sceneWasSwapped = false;
34-
animationTimeout = transitionTime;
35-
clear();
36-
return;
37-
}
38-
if (animationTimeout >= 0) {
39-
clear();
40-
animationBatch.begin();
41-
animationTimeout -= delta;
42-
animationBatch.setColor(1, 1, 1, 1);
43-
animationBatch.draw(ScreenUtil.getInstance().getLastScreenTexture(), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
44-
animationBatch.setColor(1, 1, 1, 1 - (1 / transitionTime) * animationTimeout);
45-
animationBatch.draw(Forge.getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
46-
animationBatch.end();
47-
if (animationTimeout < 0) {
48-
Forge.currentScene.render();
49-
Forge.storeScreen();
50-
clear();
51-
} else {
34+
if (renderTransitionScreen) {
35+
// Transition Overlay
36+
float transitionTime = 0.12f;
37+
if (sceneWasSwapped) {
38+
sceneWasSwapped = false;
39+
transitionTimeout = transitionTime;
40+
clearScreen();
41+
return;
42+
}
43+
if (transitionTimeout >= 0) {
44+
clearScreen();
45+
transitionBatch.begin();
46+
transitionTimeout -= delta;
47+
transitionBatch.setColor(1, 1, 1, 1);
48+
transitionBatch.draw(ScreenUtil.getInstance().getLastScreenTexture(), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
49+
transitionBatch.setColor(1, 1, 1, 1 - (1 / transitionTime) * transitionTimeout);
50+
transitionBatch.draw(Forge.getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
51+
transitionBatch.end();
52+
if (transitionTimeout < 0) {
53+
Forge.currentScene.render();
54+
Forge.storeScreen();
55+
clearScreen();
56+
} else {
57+
return;
58+
}
59+
}
60+
if (transitionTimeout >= -transitionTime) {
61+
clearScreen();
62+
transitionBatch.begin();
63+
transitionTimeout -= delta;
64+
transitionBatch.setColor(1, 1, 1, 1);
65+
transitionBatch.draw(ScreenUtil.getInstance().getLastScreenTexture(), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
66+
transitionBatch.setColor(1, 1, 1, (1 / transitionTime) * (transitionTimeout + transitionTime));
67+
transitionBatch.draw(Forge.getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
68+
transitionBatch.end();
5269
return;
5370
}
5471
}
55-
if (animationTimeout >= -transitionTime) {
56-
clear();
57-
animationBatch.begin();
58-
animationTimeout -= delta;
59-
animationBatch.setColor(1, 1, 1, 1);
60-
animationBatch.draw(ScreenUtil.getInstance().getLastScreenTexture(), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
61-
animationBatch.setColor(1, 1, 1, (1 / transitionTime) * (animationTimeout + transitionTime));
62-
animationBatch.draw(Forge.getAssets().fallback_skins().get("transition"), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
63-
animationBatch.end();
64-
return;
65-
}
72+
// Adventure UIScene
6673
Forge.currentScene.render();
6774
Forge.currentScene.act(delta);
6875
} catch (IllegalStateException | NullPointerException ie) {
@@ -71,14 +78,14 @@ void render(float delta) {
7178
}
7279
}
7380

74-
void clear() {
81+
void clearScreen() {
7582
Gdx.gl.glClearColor(0, 0, 0, 1);
7683
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
7784
}
7885
@Override
7986
public void dispose() {
80-
if (animationBatch != null)
81-
animationBatch.dispose();
87+
if (transitionBatch != null)
88+
transitionBatch.dispose();
8289
if (adventureBatch != null)
8390
adventureBatch.dispose();
8491
}

forge-gui-mobile/src/forge/Forge.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@
6666
import forge.toolbox.FGestureAdapter;
6767
import forge.toolbox.FOptionPane;
6868
import forge.toolbox.FOverlay;
69-
import forge.util.CardTranslation;
70-
import forge.util.FileUtil;
71-
import forge.util.HWInfo;
72-
import forge.util.Localizer;
73-
import forge.util.OperatingSystem;
74-
import forge.util.ScreenUtil;
75-
import forge.util.Utils;
69+
import forge.util.*;
7670
import io.sentry.ScopeType;
7771
import io.sentry.Sentry;
7872

@@ -151,6 +145,8 @@ public class Forge implements ApplicationListener {
151145
public static boolean createNewAdventureMap = false;
152146
private static Localizer localizer;
153147
private static boolean desktopAutoOrientation = true;
148+
public static final int LOW_SPRITES_CAP = 30; // max capacity for transition, generated image renders
149+
public static final int HIGH_SPRITES_CAP = 700; // max sprite capacity for adventure, classic renders
154150

155151
public static ApplicationListener getApp(HWInfo hwInfo, Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0, boolean androidOrientation, boolean isTablet, int AndroidAPI) {
156152
if (app == null) {
@@ -205,7 +201,7 @@ public void create() {
205201
if (!GuiBase.isAndroid() || (androidVersion > 25 && totalDeviceRAM > 3400)) {
206202
allowCardBG = true;
207203
}
208-
graphics = new Graphics();
204+
graphics = new Graphics(Forge.HIGH_SPRITES_CAP);
209205
splashScreen = new SplashScreen();
210206
inputProcessor = new MainInputProcessor();
211207

@@ -672,8 +668,11 @@ public static void back(boolean clearLastMatch) {
672668
exit(false); //prompt to exit if attempting to go back from home screen
673669
return;
674670
}
675-
if(currentScreen == null)
671+
if (currentScreen == null)
676672
return;
673+
// trigger leave
674+
if (currentScene instanceof ForgeScene forgeScene)
675+
forgeScene.leave();
677676
currentScreen.onClose(result -> {
678677
if (result) {
679678
Dscreens.pollFirst();
@@ -1029,6 +1028,7 @@ public void dispose() {
10291028
AdventureScreen.dispose();
10301029
Adventure.getInstance().dispose();
10311030
ScreenUtil.getInstance().dispose();
1031+
ShaderUtil.getInstance().dispose();
10321032
try {
10331033
ExceptionHandler.unregisterErrorHandling();
10341034
if (lastPreview != null)

0 commit comments

Comments
 (0)