5353
5454import static orsc.Config.*;
5555import static orsc.multiclient.ClientPort.saveHideIp;
56+ import static orsc.ScaledWindow.ScalingAlgorithm;
5657
5758public final class mudclient implements Runnable {
5859
@@ -288,6 +289,12 @@ public void setProgramArgs(String[] progArgs) {
288289 public int[] achievementProgress = new int[500];
289290 public int showUiTab = 0;
290291 public boolean topMouseMenuVisible = false;
292+ public static ScalingAlgorithm scalingType = ScalingAlgorithm.INTEGER_SCALING;
293+ public static float renderingScalar = 1.0f;
294+ public static float newRenderingScalar = 1.0f;
295+ public static boolean scalarChangedSinceLogin = false;
296+ public static List<Float> integerScalars = null;
297+ public static List<Float> interpolationScalars = null;
291298 public int resizeWidth;
292299 public int resizeHeight;
293300 public Clan clan;
@@ -749,6 +756,19 @@ public mudclient(ClientPort handler) {
749756 initConfig();
750757 }
751758
759+ private static void saveScalingSettings(ScalingAlgorithm type, float scalar) {
760+ Properties props = new Properties();
761+ props.setProperty("scaling_type", String.valueOf(type.ordinal()));
762+ props.setProperty("scaling_scalar", String.valueOf(scalar));
763+
764+ try (FileOutputStream out = new FileOutputStream("./clientSettings.conf")) {
765+ props.store(out, "Client settings");
766+ } catch (Exception e) {
767+ System.out.println("Something went wrong saving scaling settings");
768+ e.printStackTrace();
769+ }
770+ }
771+
752772 private static boolean isValidEmailAddress(String email) {
753773 boolean stricterFilter = true;
754774 String stricterFilterString = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
@@ -1023,9 +1043,10 @@ private void run2() {
10231043
10241044 --this.m_b;
10251045 var6 &= 255;
1026- if (reposition()) {
1046+ if (reposition() || (this.currentViewMode == GameMode.LOGIN && scalarChangedSinceLogin) ) {
10271047 if (this.currentViewMode == GameMode.LOGIN) {
10281048 this.createLoginPanels(3845);
1049+ scalarChangedSinceLogin = false;
10291050 //this.renderLoginScreenViewports(-116);
10301051 }
10311052 continue;
@@ -9423,16 +9444,7 @@ private void drawGeneralSettingsOptions(int baseX, short boxWidth, int x, int y)
94239444 "@whi@Camera angle mode - @red@Manual", 0, null, null);
94249445 }
94259446
9426- // mouse button(s) - byte index 2
9427- if (this.optionMouseButtonOne) {
9428- this.panelSettings.setListEntry(this.controlSettingPanel, index++,
9429- "@whi@Mouse buttons - @red@One", 1, null, null);
9430- } else {
9431- this.panelSettings.setListEntry(this.controlSettingPanel, index++,
9432- "@whi@Mouse buttons - @gre@Two", 1, null, null);
9433- }
9434-
9435- // sound effects
9447+ // sound effects - byte index 2
94369448 if (wantMembers()) {
94379449 if (optionSoundDisabled) {
94389450 this.panelSettings.setListEntry(this.controlSettingPanel, index++,
@@ -9443,6 +9455,99 @@ private void drawGeneralSettingsOptions(int baseX, short boxWidth, int x, int y)
94439455 }
94449456 }
94459457
9458+ // rendering scalar - byte index 45
9459+
9460+ int scalarOptionIdx = wantMembers() ? 2 : 1;
9461+ boolean isScalarOptionOffered = !isAndroid();
9462+ boolean isScalarOptionShowing = panelSettings.controlScrollAmount[0] <= scalarOptionIdx && isScalarOptionOffered;
9463+
9464+ if (isScalarOptionOffered) {
9465+ if (isScalarOptionShowing) {
9466+ int yPos = y + ((scalarOptionIdx - panelSettings.controlScrollAmount[0] + 1) * 15);
9467+
9468+ // Scale down button
9469+ boolean scaleMinusHover = (this.gameWidth - this.mouseX) >= 125 && (this.gameWidth - this.mouseX) <= 143 &&
9470+ this.mouseY >= (yPos - 7) && this.mouseY <= (yPos + 4);
9471+
9472+ final String minusButtonLabel;
9473+ final int minusButtonColor;
9474+ if (renderingScalar <= 1) {
9475+ minusButtonLabel = " ";
9476+ minusButtonColor = 16777215;
9477+ } else {
9478+ minusButtonLabel = "-";
9479+ minusButtonColor = scaleMinusHover ? 65280 : 16616744;
9480+ }
9481+
9482+ this.getSurface().drawString("[ " + minusButtonLabel + " ]", this.gameWidth - 143, yPos, minusButtonColor, 1);
9483+
9484+ // Scalar label
9485+ final String scalarLabel = scalingType == ScalingAlgorithm.INTEGER_SCALING ?
9486+ (int) renderingScalar + "x" : renderingScalar + "x";
9487+ int scalarLabelOffset = scalingType == ScalingAlgorithm.INTEGER_SCALING ? 116 : 121;
9488+
9489+ final int scalarLabelColor;
9490+ if (renderingScalar > 1) {
9491+ // Anything above 1x, draw green
9492+ scalarLabelColor = 65280;
9493+ } else {
9494+ // At 0, draw white
9495+ scalarLabelColor = 16777215;
9496+ }
9497+
9498+ this.getSurface().drawString(scalarLabel, this.gameWidth - scalarLabelOffset, yPos + 1, scalarLabelColor, 1);
9499+
9500+ // Scale up button
9501+ boolean scalePlusHover = (this.gameWidth - this.mouseX) >= 72 && (this.gameWidth - this.mouseX) <= 92 &&
9502+ this.mouseY >= (yPos - 7) && this.mouseY <= (yPos + 4);
9503+
9504+ final List<Float> scalars = scalingType == ScalingAlgorithm.INTEGER_SCALING ? integerScalars : interpolationScalars;
9505+ boolean maxScalar = scalars.indexOf(renderingScalar) == scalars.size() - 1;
9506+
9507+ final String plusButtonLabel;
9508+ final int plusButtonColor;
9509+
9510+ if (maxScalar) {
9511+ plusButtonLabel = " ";
9512+ plusButtonColor = 16777215;
9513+ } else {
9514+ plusButtonLabel = "+";
9515+ plusButtonColor = scalePlusHover ? 65280 : 16616744;
9516+ }
9517+
9518+ this.getSurface().drawString("[ " + plusButtonLabel + " ]", this.gameWidth - 93, yPos, plusButtonColor, 1);
9519+ }
9520+
9521+ this.panelSettings.setListEntry(this.controlSettingPanel, index++, "@whi@Scaling - ", 45, null, null);
9522+
9523+ // scaling type - byte index 46
9524+ String scalingTypeDescription;
9525+ switch (scalingType) {
9526+ default:
9527+ case INTEGER_SCALING:
9528+ scalingTypeDescription = "@gre@Integer";
9529+ break;
9530+ case BILINEAR_INTERPOLATION:
9531+ scalingTypeDescription = "@yel@Bilinear";
9532+ break;
9533+ case BICUBIC_INTERPOLATION:
9534+ scalingTypeDescription = "@ora@Bicubic";
9535+ break;
9536+ }
9537+
9538+ this.panelSettings.setListEntry(this.controlSettingPanel, index++,
9539+ "@whi@Scaling type - @gre@" + scalingTypeDescription, 46, null, null);
9540+ }
9541+
9542+ // mouse button(s) - byte index 1
9543+ if (this.optionMouseButtonOne) {
9544+ this.panelSettings.setListEntry(this.controlSettingPanel, index++,
9545+ "@whi@Mouse buttons - @red@One", 1, null, null);
9546+ } else {
9547+ this.panelSettings.setListEntry(this.controlSettingPanel, index++,
9548+ "@whi@Mouse buttons - @gre@Two", 1, null, null);
9549+ }
9550+
94469551 // custom UI
94479552 if (S_WANT_CUSTOM_UI) {
94489553 if (!C_CUSTOM_UI) {
@@ -9828,15 +9933,6 @@ private void handleGeneralSettingsClicks(short var5, int var6, int yFromTopDista
98289933 this.packetHandler.getClientStream().finishPacket();
98299934 }
98309935
9831- // one or two mouse button(s) - byte index 1
9832- if (settingIndex == 1 && this.mouseButtonClick == 1) {
9833- this.optionMouseButtonOne = !this.optionMouseButtonOne;
9834- this.packetHandler.getClientStream().newPacket(111);
9835- this.packetHandler.getClientStream().bufferBits.putByte(1);
9836- this.packetHandler.getClientStream().bufferBits.putByte(this.optionMouseButtonOne ? 1 : 0);
9837- this.packetHandler.getClientStream().finishPacket();
9838- }
9839-
98409936 // sound on/off - byte index 2
98419937 if (wantMembers() && settingIndex == 2 && this.mouseButtonClick == 1) {
98429938 optionSoundDisabled = !optionSoundDisabled;
@@ -9846,6 +9942,45 @@ private void handleGeneralSettingsClicks(short var5, int var6, int yFromTopDista
98469942 this.packetHandler.getClientStream().finishPacket();
98479943 }
98489944
9945+ /* rendering scalar - (would be byte index 45) */
9946+
9947+ int scalarOptionIdx = wantMembers() ? 2 : 1;
9948+ boolean isScalarOptionShowing = panelSettings.controlScrollAmount[0] <= scalarOptionIdx;
9949+
9950+ if (isScalarOptionShowing) {
9951+ int yPos = yFromTopDistance + ((scalarOptionIdx - panelSettings.controlScrollAmount[0] + 1) * 15);
9952+
9953+ // Scale down button
9954+ boolean scaleMinusHover = (this.gameWidth - this.mouseX) >= 125 && (this.gameWidth - this.mouseX) <= 143 &&
9955+ this.mouseY >= (yPos + 3) && this.mouseY <= (yPos + 14);
9956+
9957+ if (scaleMinusHover && this.mouseButtonClick == 1) {
9958+ scaleDown();
9959+ }
9960+
9961+ // Scale up button
9962+ boolean scalePlusHover = (this.gameWidth - this.mouseX) >= 72 && (this.gameWidth - this.mouseX) <= 92 &&
9963+ this.mouseY >= (yPos + 3) && this.mouseY <= (yPos + 14);
9964+
9965+ if (scalePlusHover && this.mouseButtonClick == 1) {
9966+ scaleUp();
9967+ }
9968+ }
9969+
9970+ // scaling type - byte index 46
9971+ if (settingIndex == 46 && this.mouseButtonClick == 1) {
9972+ cycleScalingType();
9973+ }
9974+
9975+ // one or two mouse button(s) - byte index 1
9976+ if (settingIndex == 1 && this.mouseButtonClick == 1) {
9977+ this.optionMouseButtonOne = !this.optionMouseButtonOne;
9978+ this.packetHandler.getClientStream().newPacket(111);
9979+ this.packetHandler.getClientStream().bufferBits.putByte(1);
9980+ this.packetHandler.getClientStream().bufferBits.putByte(this.optionMouseButtonOne ? 1 : 0);
9981+ this.packetHandler.getClientStream().finishPacket();
9982+ }
9983+
98499984 // custom UI - byte index 39
98509985 if (S_WANT_CUSTOM_UI) {
98519986 if (settingIndex == 39 && this.mouseButtonClick == 1) {
@@ -10065,17 +10200,11 @@ private void handleGeneralSettingsClicks(short var5, int var6, int yFromTopDista
1006510200 }
1006610201 }
1006710202
10068- // items on death
10069- yFromTopDistance = 275;
10070- if (C_CUSTOM_UI)
10203+ // adjust for previous settings
10204+ if (C_CUSTOM_UI) {
1007110205 yFromTopDistance = getUITabsY() - 240 + 214;
10072- if (S_ITEMS_ON_DEATH_MENU) {
10073- if (this.mouseX > var6 && var5 + var6 > this.mouseX && this.mouseY > yFromTopDistance - 12
10074- && this.mouseY < yFromTopDistance + 4 && this.mouseButtonClick == 1) {
10075- if (!C_CUSTOM_UI)
10076- this.showUiTab = 0;
10077- lostOnDeathInterface.setVisible(true);
10078- }
10206+ } else {
10207+ yFromTopDistance = 275;
1007910208 }
1008010209
1008110210 // logout menu option
@@ -11120,6 +11249,53 @@ private void duelStakeItem(int andStakeCount, int andStakeInvIndex) {
1112011249 }
1112111250 }
1112211251
11252+ void scaleUp() {
11253+ changeRenderingScalar(true);
11254+ }
11255+
11256+ void scaleDown() {
11257+ changeRenderingScalar(false);
11258+ }
11259+
11260+ private void changeRenderingScalar(Boolean scaleUp) {
11261+ scalarChangedSinceLogin = true;
11262+
11263+ final List<Float> scalars = scalingType == ScalingAlgorithm.INTEGER_SCALING ? integerScalars : interpolationScalars;
11264+
11265+ int idx = scalars.indexOf(renderingScalar);
11266+
11267+ if (scaleUp) {
11268+ if (idx + 1 < scalars.size()) {
11269+ idx += 1;
11270+ }
11271+ } else {
11272+ if (idx - 1 >= 0) {
11273+ idx -= 1;
11274+ }
11275+ }
11276+
11277+ newRenderingScalar = scalars.get(idx);
11278+
11279+ saveScalingSettings(scalingType, newRenderingScalar);
11280+ }
11281+
11282+ void cycleScalingType() {
11283+ if (scalingType == ScalingAlgorithm.INTEGER_SCALING) {
11284+ scalingType = ScalingAlgorithm.BILINEAR_INTERPOLATION;
11285+ } else if (scalingType == ScalingAlgorithm.BILINEAR_INTERPOLATION) {
11286+ scalingType = ScalingAlgorithm.BICUBIC_INTERPOLATION;
11287+ } else {
11288+ scalingType = ScalingAlgorithm.INTEGER_SCALING;
11289+
11290+ // When going back to integer scaling, round the scalar if needed
11291+ if (renderingScalar != (int) renderingScalar) {
11292+ newRenderingScalar = (int) renderingScalar;
11293+ }
11294+ }
11295+
11296+ saveScalingSettings(scalingType, newRenderingScalar);
11297+ }
11298+
1112311299 private void fetchContainerSize() {
1112411300 try {
1112511301
@@ -14499,6 +14675,12 @@ private void login(int var1, String pass, String user, boolean reconnecting) {
1449914675 if (classJar.startsWith("jar:")) {
1450014676 runningFromJar = true;
1450114677 String path = classJar.substring(4, classJar.indexOf("!"));
14678+ if (path.startsWith("file:/")) {
14679+ path = path.substring(6);
14680+ }
14681+ if (path.startsWith("file:")) {
14682+ path = path.substring(5);
14683+ }
1450214684 jarName = Paths.get(path).getFileName().toString();
1450314685 if (jarName.length() > 19) {
1450414686 jarName = jarName.substring(0, 19);
@@ -14530,7 +14712,7 @@ private void login(int var1, String pass, String user, boolean reconnecting) {
1453014712 String osName = System.getProperty("os.name").toLowerCase();
1453114713 String javaVendor = System.getProperty("java.vendor").toLowerCase();
1453214714 boolean isAndroid = osName.contains("android") || javaVendor.contains("android");
14533- if (isAndroid) {
14715+ if (isAndroid) {
1453414716 workingDir = "Android";
1453514717 }
1453614718 //Ideally, we want this string to be less than 60 characters, and it must be less than 63 characters to be encrypted with RSA.
0 commit comments