convert point to vector2

This commit is contained in:
Anthony Calosa
2022-02-08 00:06:46 +08:00
parent 1f692b165b
commit 02635ef00c
3 changed files with 46 additions and 43 deletions

View File

@@ -296,7 +296,7 @@ public class Forge implements ApplicationListener {
afterDBloaded = true; afterDBloaded = true;
//selection //selection
if (isLandscapeMode() && !GuiBase.isAndroid()) if (isLandscapeMode())
splashScreen.setShowModeSelector(true); splashScreen.setShowModeSelector(true);
else else
openHomeDefault(); openHomeDefault();

View File

@@ -18,6 +18,7 @@ import com.badlogic.gdx.utils.Align;
import forge.Forge; import forge.Forge;
import forge.adventure.util.Config; import forge.adventure.util.Config;
import forge.adventure.util.Controls; import forge.adventure.util.Controls;
import forge.gui.GuiBase;
import forge.localinstance.properties.ForgePreferences; import forge.localinstance.properties.ForgePreferences;
import forge.util.Localizer; import forge.util.Localizer;
@@ -171,29 +172,31 @@ public class SettingsScene extends UIScene {
addLabel("Plane"); addLabel("Plane");
settingGroup.add(plane).align(Align.right); settingGroup.add(plane).align(Align.right);
addSettingField("Fullscreen", Config.instance().getSettingData().fullScreen, new ChangeListener() { if (!GuiBase.isAndroid()) {
@Override addSettingField("Fullscreen", Config.instance().getSettingData().fullScreen, new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) { @Override
Config.instance().getSettingData().fullScreen=((CheckBox) actor).isChecked(); public void changed(ChangeEvent event, Actor actor) {
Config.instance().saveSettings(); Config.instance().getSettingData().fullScreen=((CheckBox) actor).isChecked();
} Config.instance().saveSettings();
}); }
addSettingField("Screen width", Config.instance().getSettingData().width, new ChangeListener() { });
@Override addSettingField("Screen width", Config.instance().getSettingData().width, new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) { @Override
String text=((TextField) actor).getText(); public void changed(ChangeEvent event, Actor actor) {
Config.instance().getSettingData().width=text==null||text.isEmpty()?0:Integer.valueOf(text); String text=((TextField) actor).getText();
Config.instance().saveSettings(); Config.instance().getSettingData().width=text==null||text.isEmpty()?0:Integer.valueOf(text);
} Config.instance().saveSettings();
}); }
addSettingField("Screen height", Config.instance().getSettingData().height, new ChangeListener() { });
@Override addSettingField("Screen height", Config.instance().getSettingData().height, new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) { @Override
String text=((TextField) actor).getText(); public void changed(ChangeEvent event, Actor actor) {
Config.instance().getSettingData().height=text==null||text.isEmpty()?0:Integer.valueOf(text); String text=((TextField) actor).getText();
Config.instance().saveSettings(); Config.instance().getSettingData().height=text==null||text.isEmpty()?0:Integer.valueOf(text);
} Config.instance().saveSettings();
}); }
});
}
addCheckBox(localizer.getMessage("lblCardName"), ForgePreferences.FPref.UI_OVERLAY_CARD_NAME); addCheckBox(localizer.getMessage("lblCardName"), ForgePreferences.FPref.UI_OVERLAY_CARD_NAME);
addSettingSlider(localizer.getMessage("cbAdjustMusicVolume"), ForgePreferences.FPref.UI_VOL_MUSIC,0,100); addSettingSlider(localizer.getMessage("cbAdjustMusicVolume"), ForgePreferences.FPref.UI_VOL_MUSIC,0,100);
addSettingSlider(localizer.getMessage("cbAdjustSoundsVolume"), ForgePreferences.FPref.UI_VOL_SOUNDS, 0,100); addSettingSlider(localizer.getMessage("cbAdjustSoundsVolume"), ForgePreferences.FPref.UI_VOL_SOUNDS, 0,100);
@@ -207,8 +210,8 @@ public class SettingsScene extends UIScene {
addCheckBox(localizer.getMessage("lblBattlefieldTextureFiltering"), ForgePreferences.FPref.UI_LIBGDX_TEXTURE_FILTERING); addCheckBox(localizer.getMessage("lblBattlefieldTextureFiltering"), ForgePreferences.FPref.UI_LIBGDX_TEXTURE_FILTERING);
addCheckBox(localizer.getMessage("lblAltZoneTabs"), ForgePreferences.FPref.UI_ALT_PLAYERZONETABS); addCheckBox(localizer.getMessage("lblAltZoneTabs"), ForgePreferences.FPref.UI_ALT_PLAYERZONETABS);
addCheckBox(localizer.getMessage("lblAnimatedCardTapUntap"), ForgePreferences.FPref.UI_ANIMATED_CARD_TAPUNTAP); addCheckBox(localizer.getMessage("lblAnimatedCardTapUntap"), ForgePreferences.FPref.UI_ANIMATED_CARD_TAPUNTAP);
addCheckBox(localizer.getMessage("lblBorderMaskOption"), ForgePreferences.FPref.UI_ENABLE_BORDER_MASKING); if (!GuiBase.isAndroid()) {
if (!Forge.isMobileAdventureMode) { addCheckBox(localizer.getMessage("lblBorderMaskOption"), ForgePreferences.FPref.UI_ENABLE_BORDER_MASKING);
addCheckBox(localizer.getMessage("lblPreloadExtendedArtCards"), ForgePreferences.FPref.UI_ENABLE_PRELOAD_EXTENDED_ART); addCheckBox(localizer.getMessage("lblPreloadExtendedArtCards"), ForgePreferences.FPref.UI_ENABLE_PRELOAD_EXTENDED_ART);
addCheckBox(localizer.getMessage("lblAutoCacheSize"), ForgePreferences.FPref.UI_AUTO_CACHE_SIZE); addCheckBox(localizer.getMessage("lblAutoCacheSize"), ForgePreferences.FPref.UI_AUTO_CACHE_SIZE);
addCheckBox(localizer.getMessage("lblDisposeTextures"), ForgePreferences.FPref.UI_ENABLE_DISPOSE_TEXTURES); addCheckBox(localizer.getMessage("lblDisposeTextures"), ForgePreferences.FPref.UI_ENABLE_DISPOSE_TEXTURES);

View File

@@ -3,10 +3,10 @@ package forge.adventure.stage;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import forge.adventure.world.WorldSave; import forge.adventure.world.WorldSave;
import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@@ -37,36 +37,36 @@ public class WorldBackground extends Actor {
if (chunks == null) { if (chunks == null) {
initialize(); initialize();
} }
Point pos = translateFromWorldToChunk(playerX, playerY); Vector2 pos = translateFromWorldToChunk(playerX, playerY);
if (currentChunkX != pos.x || currentChunkY != pos.y) { if (currentChunkX != pos.x || currentChunkY != pos.y) {
int xDiff = currentChunkX - pos.x; int xDiff = currentChunkX - (int)pos.x;
int yDiff = currentChunkY - pos.y; int yDiff = currentChunkY - (int)pos.y;
ArrayList<Point> points = new ArrayList<Point>(); ArrayList<Vector2> points = new ArrayList<>();
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) { for (int y = -1; y < 2; y++) {
points.add(new Point(pos.x + x, pos.y + y)); points.add(new Vector2(pos.x + x, pos.y + y));
} }
} }
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) { for (int y = -1; y < 2; y++) {
Point point = new Point(currentChunkX + x, currentChunkY + y); Vector2 point = new Vector2(currentChunkX + x, currentChunkY + y);
if (points.contains(point))// old Point is part of new points if (points.contains(point))// old Point is part of new points
{ {
points.remove(point); points.remove(point);
} else { } else {
if (point.y < 0 || point.x < 0 || point.y >= chunks[0].length || point.x >= chunks.length) if (point.y < 0 || point.x < 0 || point.y >= chunks[0].length || point.x >= chunks.length)
continue; continue;
unLoadChunk(point.x, point.y); unLoadChunk((int)point.x, (int)point.y);
} }
} }
} }
for (Point point : points) { for (Vector2 point : points) {
if (point.y < 0 || point.x < 0 || point.y >= chunks[0].length || point.x >= chunks.length) if (point.y < 0 || point.x < 0 || point.y >= chunks[0].length || point.x >= chunks.length)
continue; continue;
loadChunk(point.x, point.y); loadChunk((int)point.x, (int)point.y);
} }
currentChunkX = pos.x; currentChunkX = (int)pos.x;
currentChunkY = pos.y; currentChunkY = (int)pos.y;
} }
batch.disableBlending(); batch.disableBlending();
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x++) {
@@ -75,7 +75,7 @@ public class WorldBackground extends Actor {
continue; continue;
batch.draw(getChunkTexture(pos.x + x, pos.y + y), transChunkToWorld(pos.x + x), transChunkToWorld(pos.y + y)); batch.draw(getChunkTexture((int)pos.x + x, (int)pos.y + y), transChunkToWorld((int)pos.x + x), transChunkToWorld((int)pos.y + y));
} }
} }
batch.enableBlending(); batch.enableBlending();
@@ -154,10 +154,10 @@ public class WorldBackground extends Actor {
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) { for (int y = -1; y < 2; y++) {
Point point = new Point(currentChunkX + x, currentChunkY + y); Vector2 point = new Vector2(currentChunkX + x, currentChunkY + y);
if (point.y < 0 || point.x < 0 || point.y >= chunks[0].length || point.x >= chunks.length) if (point.y < 0 || point.x < 0 || point.y >= chunks[0].length || point.x >= chunks.length)
continue; continue;
loadChunk(point.x, point.y); loadChunk((int)point.x, (int)point.y);
} }
} }
} }
@@ -171,10 +171,10 @@ public class WorldBackground extends Actor {
return xy * tileSize * chunkSize; return xy * tileSize * chunkSize;
} }
Point translateFromWorldToChunk(float x, float y) { Vector2 translateFromWorldToChunk(float x, float y) {
float worldWidthTiles = x / tileSize; float worldWidthTiles = x / tileSize;
float worldHeightTiles = y / tileSize; float worldHeightTiles = y / tileSize;
return new Point((int) worldWidthTiles / chunkSize, (int) worldHeightTiles / chunkSize); return new Vector2((int) worldWidthTiles / chunkSize, (int) worldHeightTiles / chunkSize);
} }
public void setPlayerPos(float x, float y) { public void setPlayerPos(float x, float y) {