Skip to content

Commit 9d6d3ed

Browse files
committed
move loading text to abstract SoftwareRenderer
1 parent 48ba175 commit 9d6d3ed

File tree

5 files changed

+84
-56
lines changed

5 files changed

+84
-56
lines changed

src/main/java/org/runejs/client/Game.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.runejs.client.net.*;
2424
import org.runejs.client.net.codec.MessagePacketCodec;
2525
import org.runejs.client.net.codec.runejs435.RuneJS435PacketCodec;
26+
import org.runejs.client.renderer.ScreenRenderer;
2627
import org.runejs.client.scene.*;
2728
import org.runejs.client.scene.camera.Camera;
2829
import org.runejs.client.scene.camera.CameraRotation;
@@ -49,6 +50,8 @@
4950

5051
public class Game {
5152

53+
public static ScreenRenderer renderer;
54+
5255
/**
5356
* The codec currently in use to encode and decode packets.
5457
*
@@ -2205,7 +2208,7 @@ public void updateStatusText() {
22052208
MouseHandler.addListeners(gameCanvas);
22062209
}
22072210
if (gameStatusCode == 0)
2208-
MovedStatics.drawLoadingText(MovedStatics.anInt1607, null, Native.currentLoadingText);
2211+
renderer.drawLoadingText(MovedStatics.anInt1607, null, Native.currentLoadingText);
22092212
else if (gameStatusCode == 5) {
22102213
Class60.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall);
22112214
} else if (gameStatusCode == 10) {

src/main/java/org/runejs/client/GameShell.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.runejs.client.frame.ScreenMode;
55
import org.runejs.client.language.Native;
66
import org.runejs.client.media.renderable.actor.Player;
7+
import org.runejs.client.renderer.SoftwareRenderer;
78
import org.runejs.client.util.Signlink;
89
import org.runejs.client.util.Timer;
910

@@ -272,6 +273,7 @@ public void windowDeactivated(WindowEvent windowEvent) {
272273
}
273274

274275
public synchronized void setCanvas() {
276+
Game.renderer = new SoftwareRenderer();
275277
Container container = clientFrame;
276278
if (Game.gameCanvas != null) {
277279
Game.gameCanvas.removeFocusListener(this);

src/main/java/org/runejs/client/MovedStatics.java

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ public class MovedStatics {
238238
*/
239239
public static IndexedImage tabHighlightImageBottomRight;
240240
public static ProducingGraphicsBuffer chatboxTop;
241-
public static Font helveticaBold;
242241
public static int deregisterActorCount = 0;
243242
public static int[] anIntArray456;
244243
public static int regionY;
@@ -888,7 +887,7 @@ public static void method1013() {
888887
public static void processGameStatus(int statusCode) {
889888
if (statusCode != Game.gameStatusCode) {
890889
if (Game.gameStatusCode == 0)
891-
method144(12433);
890+
Game.renderer.disposeLoadingText();
892891
if (statusCode == 20 || statusCode == 40) {
893892
Game.anInt1756 = 0;
894893
anInt2321 = 0;
@@ -1225,7 +1224,6 @@ public static void animateNpcs() {
12251224

12261225
}
12271226

1228-
public static FontMetrics fontMetrics;
12291227

12301228
public static void drawMenu(int xOffSet, int yOffSet) {
12311229
int height = menuHeight;
@@ -3087,51 +3085,6 @@ public static IndexedImage method769(int arg0, CacheArchive imageArchive, int ar
30873085
return method538();
30883086
}
30893087

3090-
public static void drawLoadingText(int percent, Color color, String desc) {
3091-
try {
3092-
Graphics graphics = Game.gameCanvas.getGraphics();
3093-
if(helveticaBold == null) {
3094-
helveticaBold = new Font("Helvetica", Font.BOLD, 13);
3095-
fontMetrics = Game.gameCanvas.getFontMetrics(helveticaBold);
3096-
}
3097-
if(clearScreen) {
3098-
clearScreen = false;
3099-
graphics.setColor(Color.black);
3100-
graphics.fillRect(0, 0, width, height);
3101-
}
3102-
if(color == null)
3103-
color = new Color(140, 17, 17);
3104-
try {
3105-
if(loadingBoxImage == null)
3106-
loadingBoxImage = Game.gameCanvas.createImage(304, 34);
3107-
Graphics loadingBoxGraphics = loadingBoxImage.getGraphics();
3108-
loadingBoxGraphics.setColor(color);
3109-
loadingBoxGraphics.drawRect(0, 0, 303, 33);
3110-
loadingBoxGraphics.fillRect(2, 2, percent * 3, 30);
3111-
loadingBoxGraphics.setColor(Color.black);
3112-
loadingBoxGraphics.drawRect(1, 1, 301, 31);
3113-
loadingBoxGraphics.fillRect(2 + 3 * percent, 2, 300 - 3 * percent, 30);
3114-
loadingBoxGraphics.setFont(helveticaBold);
3115-
loadingBoxGraphics.setColor(Color.white);
3116-
loadingBoxGraphics.drawString(desc, (304 - (fontMetrics.stringWidth(desc))) / 2, 22);
3117-
graphics.drawImage(loadingBoxImage, width / 2 - 152, height / 2 - 18, null);
3118-
} catch(Exception exception) {
3119-
int centerWidth = width / 2 - 152;
3120-
int centerHeight = height / 2 - 18;
3121-
graphics.setColor(color);
3122-
graphics.drawRect(centerWidth, centerHeight, 303, 33);
3123-
graphics.fillRect(2 + centerWidth, centerHeight + 2, 3 * percent, 30);
3124-
graphics.setColor(Color.black);
3125-
graphics.drawRect(centerWidth + 1, 1 + centerHeight, 301, 31);
3126-
graphics.fillRect(percent * 3 + 2 + centerWidth, 2 + centerHeight, 300 + -(3 * percent), 30);
3127-
graphics.setFont(helveticaBold);
3128-
graphics.setColor(Color.white);
3129-
graphics.drawString(desc, (304 - (fontMetrics.stringWidth(desc))) / 2+ centerWidth, 22 + centerHeight);
3130-
}
3131-
} catch(Exception exception) {
3132-
Game.gameCanvas.repaint();
3133-
}
3134-
}
31353088

31363089
public static void method778(HuffmanEncoding arg1) {
31373090
aHuffmanEncoding_2590 = arg1;
@@ -3317,14 +3270,7 @@ public static void method1057() {
33173270
ticksPerLoop = 0;
33183271
}
33193272

3320-
public static void method144(int arg0) {
3321-
3322-
fontMetrics = null;
3323-
helveticaBold = null;
3324-
if(arg0 == 12433)
3325-
loadingBoxImage = null;
33263273

3327-
}
33283274

33293275
public static ImageRGB method578() {
33303276
ImageRGB class40_sub5_sub14_sub4 = new ImageRGB();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.runejs.client.renderer;
2+
3+
import java.awt.*;
4+
5+
public abstract class ScreenRenderer {
6+
7+
public abstract void drawLoadingText(int percent, Color color, String desc);
8+
9+
public abstract void disposeLoadingText();
10+
11+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.runejs.client.renderer;
2+
3+
import org.runejs.client.Game;
4+
5+
import java.awt.*;
6+
7+
import static org.runejs.client.MovedStatics.*;
8+
9+
public class SoftwareRenderer extends ScreenRenderer {
10+
private Font helveticaBold;
11+
private FontMetrics helveticaBoldMetrics;
12+
13+
@Override
14+
public void drawLoadingText(int percent, Color color, String desc) {
15+
try {
16+
Graphics graphics = Game.gameCanvas.getGraphics();
17+
if (helveticaBold == null) {
18+
helveticaBold = new Font("Helvetica", Font.BOLD, 13);
19+
helveticaBoldMetrics = Game.gameCanvas.getFontMetrics(helveticaBold);
20+
}
21+
if (clearScreen) {
22+
clearScreen = false;
23+
graphics.setColor(Color.black);
24+
graphics.fillRect(0, 0, width, height);
25+
}
26+
if (color == null)
27+
color = new Color(140, 17, 17);
28+
try {
29+
if (loadingBoxImage == null)
30+
loadingBoxImage = Game.gameCanvas.createImage(304, 34);
31+
Graphics loadingBoxGraphics = loadingBoxImage.getGraphics();
32+
loadingBoxGraphics.setColor(color);
33+
loadingBoxGraphics.drawRect(0, 0, 303, 33);
34+
loadingBoxGraphics.fillRect(2, 2, percent * 3, 30);
35+
loadingBoxGraphics.setColor(Color.black);
36+
loadingBoxGraphics.drawRect(1, 1, 301, 31);
37+
loadingBoxGraphics.fillRect(2 + 3 * percent, 2, 300 - 3 * percent, 30);
38+
loadingBoxGraphics.setFont(helveticaBold);
39+
loadingBoxGraphics.setColor(Color.white);
40+
loadingBoxGraphics.drawString(desc, (304 - (helveticaBoldMetrics.stringWidth(desc))) / 2, 22);
41+
graphics.drawImage(loadingBoxImage, width / 2 - 152, height / 2 - 18, null);
42+
} catch (Exception exception) {
43+
int centerWidth = width / 2 - 152;
44+
int centerHeight = height / 2 - 18;
45+
graphics.setColor(color);
46+
graphics.drawRect(centerWidth, centerHeight, 303, 33);
47+
graphics.fillRect(2 + centerWidth, centerHeight + 2, 3 * percent, 30);
48+
graphics.setColor(Color.black);
49+
graphics.drawRect(centerWidth + 1, 1 + centerHeight, 301, 31);
50+
graphics.fillRect(percent * 3 + 2 + centerWidth, 2 + centerHeight, 300 + -(3 * percent), 30);
51+
graphics.setFont(helveticaBold);
52+
graphics.setColor(Color.white);
53+
graphics.drawString(desc, (304 - (helveticaBoldMetrics.stringWidth(desc))) / 2 + centerWidth, 22 + centerHeight);
54+
}
55+
} catch (Exception exception) {
56+
Game.gameCanvas.repaint();
57+
}
58+
}
59+
60+
@Override
61+
public void disposeLoadingText() {
62+
helveticaBoldMetrics = null;
63+
helveticaBold = null;
64+
loadingBoxImage = null;
65+
}
66+
}

0 commit comments

Comments
 (0)