summaryrefslogtreecommitdiff
path: root/NET/worlds/console/FourTilePanel.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/FourTilePanel.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/FourTilePanel.java')
-rw-r--r--NET/worlds/console/FourTilePanel.java229
1 files changed, 229 insertions, 0 deletions
diff --git a/NET/worlds/console/FourTilePanel.java b/NET/worlds/console/FourTilePanel.java
new file mode 100644
index 0000000..f010994
--- /dev/null
+++ b/NET/worlds/console/FourTilePanel.java
@@ -0,0 +1,229 @@
+package NET.worlds.console;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.Graphics;
+import java.awt.Panel;
+import java.awt.Rectangle;
+
+public class FourTilePanel extends Panel {
+ private static final long serialVersionUID = -7002173409842219262L;
+ private static final int tw = 5;
+ private static final int th = 5;
+ private static final int aw = 7;
+ private static final int ah = 4;
+ private static final int bw = 3;
+ private static Color widgetColor = new Color(255, 238, 177);
+ private static Color lineColor = new Color(162, 162, 162);
+ private Component[] comps = new Component[4];
+ private int[] order = new int[]{0, 1, 2, 3};
+ private float[] divider = new float[]{0.22F, 0.63F};
+ private int tx;
+ private int ty;
+ private int prevWidth;
+ private int prevHeight;
+ private Rectangle moveWidget = new Rectangle();
+ private FourTileSwapper swap01 = new FourTileSwapper(this, 0, 1);
+ private FourTileSwapper swap02 = new FourTileSwapper(this, 0, 2);
+ private FourTileSwapper swap23 = new FourTileSwapper(this, 2, 3);
+ private FourTileSwapper swap13 = new FourTileSwapper(this, 1, 3);
+ private FourTileSwapper[] swaps = new FourTileSwapper[]{this.swap01, this.swap02, this.swap23, this.swap13};
+ private boolean dragging;
+ private int offsetx;
+ private int offsety;
+ private int minx;
+ private int miny;
+ private int maxx;
+ private int maxy;
+ private int specialTileIndex;
+ private Component oneTile;
+
+ public FourTilePanel(Component ul, Component ur, Component ll, Component lr, int special) {
+ this.setLayout(null);
+ this.specialTileIndex = special;
+ this.add(this.comps[0] = ul);
+ this.add(this.comps[1] = ur);
+ this.add(this.comps[2] = ll);
+ this.add(this.comps[3] = lr);
+ this.setBackground(Color.black);
+ if (GammaFrameState.restoreLayout(this.order, this.divider)) {
+ this.useOneTileMode();
+ } else {
+ this.useFourTileMode();
+ }
+ }
+
+ public boolean isOneTileMode() {
+ return this.oneTile != null;
+ }
+
+ public void useOneTileMode() {
+ if (this.oneTile == null) {
+ this.oneTile = this.comps[this.specialTileIndex];
+
+ for (int i = 0; i < 4; i++) {
+ if (i != this.specialTileIndex) {
+ this.remove(this.comps[i]);
+ }
+ }
+
+ this.moveComponents();
+ this.saveLayout();
+ this.validate();
+ }
+ }
+
+ public void useFourTileMode() {
+ if (this.oneTile != null) {
+ this.oneTile = null;
+
+ for (int i = 0; i < 4; i++) {
+ if (i != this.specialTileIndex) {
+ this.add(this.comps[i]);
+ }
+ }
+
+ this.moveComponents();
+ this.saveLayout();
+ this.validate();
+ }
+ }
+
+ @Override
+ public void reshape(int x, int y, int width, int height) {
+ super.reshape(x, y, width, height);
+ if (!GammaFrameState.isIconic()) {
+ if (this.prevWidth != width) {
+ this.tx = Math.max((int)(this.divider[0] * width), 12);
+ this.prevWidth = width;
+ }
+
+ if (this.prevHeight != height) {
+ this.ty = Math.max((int)(this.divider[1] * height), 9);
+ this.prevHeight = height;
+ }
+
+ this.moveComponents(width, height);
+ }
+ }
+
+ private void saveLayout() {
+ GammaFrameState.saveLayout(this.order, this.divider, this.oneTile != null);
+ }
+
+ private void moveComponents() {
+ Dimension size = this.getSize();
+ this.moveComponents(size.width, size.height);
+ }
+
+ private void moveComponents(int width, int height) {
+ if (this.oneTile == null) {
+ this.comps[this.order[0]].reshape(3, 3, this.tx - 3, this.ty - 3);
+ this.comps[this.order[1]].reshape(this.tx + 5, 3, width - this.tx - 5 - 3, this.ty - 3);
+ this.comps[this.order[2]].reshape(3, this.ty + 5, this.tx - 3, height - this.ty - 5 - 3);
+ this.comps[this.order[3]].reshape(this.tx + 5, this.ty + 5, width - this.tx - 5 - 3, height - this.ty - 5 - 3);
+ } else {
+ this.oneTile.reshape(0, 0, width, height);
+ }
+
+ this.repaint();
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ Dimension size = this.getSize();
+ g.setColor(this.getBackground());
+ if (this.oneTile == null) {
+ g.fillRect(0, 0, 3, size.height);
+ g.fillRect(0, 0, size.width, 3);
+ g.fillRect(0, size.height - 3, size.width, 3);
+ g.fillRect(size.width - 3, 0, 3, size.height);
+ g.fillRect(0, this.ty, size.width, 5);
+ g.fillRect(this.tx, 0, 5, size.height);
+ g.setColor(lineColor);
+ g.drawLine(0, this.ty + 2, size.width, this.ty + 2);
+ g.drawLine(this.tx + 2, 0, this.tx + 2, size.height);
+ g.setColor(widgetColor);
+ g.fillRect(this.tx, this.ty, 5, 5);
+ this.moveWidget.reshape(this.tx, this.ty, 5, 5);
+ int tmp = (this.tx + 2 - 7) / 2;
+ g.fillArc(tmp, this.ty - 2, 7, 4, 0, -180);
+ g.fillArc(tmp, this.ty + 5 - 2, 7, 4, 0, 180);
+ this.swap02.reshape(tmp, this.ty, 7, 5);
+ tmp = (this.tx + 2 + size.width - 7) / 2;
+ g.fillArc(tmp, this.ty - 2, 7, 4, 0, -180);
+ g.fillArc(tmp, this.ty + 5 - 2, 7, 4, 0, 180);
+ this.swap13.reshape(tmp, this.ty, 7, 5);
+ tmp = (this.ty + 2 - 7) / 2;
+ g.fillArc(this.tx - 2, tmp, 4, 7, 90, -180);
+ g.fillArc(this.tx + 5 - 2, tmp, 4, 7, 90, 180);
+ this.swap01.reshape(this.tx, tmp, 5, 7);
+ tmp = (this.ty + 2 + size.height - 7) / 2;
+ g.fillArc(this.tx - 2, tmp, 4, 7, 90, -180);
+ g.fillArc(this.tx + 5 - 2, tmp, 4, 7, 90, 180);
+ this.swap23.reshape(this.tx, tmp, 5, 7);
+ }
+ }
+
+ @Override
+ public boolean mouseDrag(Event evt, int x, int y) {
+ if (this.dragging) {
+ this.tx = x + this.offsetx;
+ this.ty = y + this.offsety;
+ this.divider[0] = (float)this.tx / this.getSize().width;
+ this.divider[1] = (float)this.ty / this.getSize().height;
+ this.tx = Math.max(this.tx, this.minx);
+ this.ty = Math.max(this.ty, this.miny);
+ this.tx = Math.min(this.tx, this.maxx);
+ this.ty = Math.min(this.ty, this.maxy);
+ this.moveComponents();
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean mouseUp(Event evt, int x, int y) {
+ if (this.dragging) {
+ this.validate();
+ this.saveLayout();
+ }
+
+ this.dragging = false;
+ return true;
+ }
+
+ @Override
+ public boolean mouseDown(Event evt, int x, int y) {
+ for (int i = 0; i < this.swaps.length; i++) {
+ if (this.swaps[i].maybeSwap(x, y)) {
+ return true;
+ }
+ }
+
+ if (this.moveWidget.inside(x, y)) {
+ this.offsetx = this.tx - x;
+ this.offsety = this.ty - y;
+ this.minx = 12;
+ this.maxx = this.getSize().width - this.minx;
+ this.miny = 12;
+ this.maxy = this.getSize().height - this.miny;
+ if (this.minx < this.maxx && this.miny < this.maxy) {
+ this.dragging = true;
+ }
+ }
+
+ return true;
+ }
+
+ void swap(int c1, int c2) {
+ int tmp = this.order[c1];
+ this.order[c1] = this.order[c2];
+ this.order[c2] = tmp;
+ this.moveComponents();
+ this.validate();
+ this.saveLayout();
+ }
+}