summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/MaterialTexture.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/scape/MaterialTexture.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/MaterialTexture.java')
-rw-r--r--NET/worlds/scape/MaterialTexture.java201
1 files changed, 201 insertions, 0 deletions
diff --git a/NET/worlds/scape/MaterialTexture.java b/NET/worlds/scape/MaterialTexture.java
new file mode 100644
index 0000000..4fb5363
--- /dev/null
+++ b/NET/worlds/scape/MaterialTexture.java
@@ -0,0 +1,201 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.network.URL;
+import java.awt.Color;
+
+class MaterialTexture extends SuperRoot implements NonPersister {
+ private URL fileName;
+ private StringTexture stexture;
+ private String text = "";
+ private String font = Console.message("MaterialFont");
+ private int size = 48;
+ private Color foregroundColor = Color.white;
+ private Color backgroundColor = Color.black;
+
+ MaterialTexture(URL textureName) {
+ this.fileName = textureName;
+ }
+
+ MaterialTexture(StringTexture texture) {
+ this.stexture = texture;
+ this.text = this.stexture.getText();
+ this.font = this.stexture.getFont();
+ this.size = this.stexture.getSize();
+ this.foregroundColor = this.stexture.getForegroundColor();
+ this.backgroundColor = this.stexture.getBackgroundColor();
+ }
+
+ private void setFile(URL name, boolean force) {
+ this.fileName = name;
+ if (this.stexture == null || force) {
+ this.stexture = null;
+ ((Material)this.getOwner()).loadTexture(name);
+ }
+ }
+
+ private void makeString() {
+ Material owner = (Material)this.getOwner();
+ this.stexture = new StringTexture(this.text, this.font, this.size, this.foregroundColor, this.backgroundColor);
+ owner.setTexture(this.stexture);
+ }
+
+ private String getText() {
+ return this.text;
+ }
+
+ private void setText(String text) {
+ this.text = text;
+ if (this.stexture != null) {
+ this.makeString();
+ }
+ }
+
+ private void setFont(String font) {
+ this.font = font;
+ if (this.stexture != null) {
+ this.makeString();
+ }
+ }
+
+ private void setSize(int size) {
+ if (size >= 1 && size <= 720) {
+ this.size = size;
+ if (this.stexture != null) {
+ this.makeString();
+ }
+ } else {
+ Console.println(Console.message("Font-sizes"));
+ }
+ }
+
+ private void setForegroundColor(Color color) {
+ this.foregroundColor = color;
+ if (this.stexture != null) {
+ this.makeString();
+ }
+ }
+
+ private void setBackgroundColor(Color color) {
+ this.backgroundColor = color;
+ if (this.stexture != null) {
+ this.makeString();
+ }
+ }
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(
+ new Property(this, index, "Texture Type (Text String)"), "Texture loaded from an image file.", "Texture created from a text string."
+ );
+ } else if (mode == 1) {
+ ret = new Boolean(this.stexture != null);
+ } else if (mode == 2) {
+ boolean stringTexture = (Boolean)value;
+ if (stringTexture && this.stexture == null) {
+ this.makeString();
+ } else if (!stringTexture && this.stexture != null) {
+ this.setFile(this.fileName, true);
+ }
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ ret = new Property(this, index, "File");
+ if (this.stexture == null) {
+ ret = URLPropertyEditor.make((Property)ret, TextureDecoder.getAllExts());
+ }
+ } else if (mode == 1) {
+ ret = this.fileName;
+ } else if (mode == 2) {
+ this.setFile((URL)value, false);
+ }
+ break;
+ case 2:
+ if (mode == 0) {
+ ret = new Property(this, index, "Text");
+ if (this.stexture != null) {
+ ret = StringPropertyEditor.make((Property)ret);
+ }
+ } else if (mode == 1) {
+ ret = this.getText();
+ } else if (mode == 2) {
+ this.setText((String)value);
+ }
+ break;
+ case 3:
+ if (mode == 0) {
+ ret = new Property(this, index, "Font");
+ if (this.stexture != null) {
+ ret = StringPropertyEditor.make((Property)ret);
+ }
+ } else if (mode == 1) {
+ ret = this.font;
+ } else if (mode == 2) {
+ this.setFont((String)value);
+ }
+
+ System.out.println("Setting font " + (String)value + " in Material.java");
+ break;
+ case 4:
+ if (mode == 0) {
+ ret = new Property(this, index, "Size");
+ if (this.stexture != null) {
+ ret = IntegerPropertyEditor.make((Property)ret);
+ }
+ } else if (mode == 1) {
+ ret = new Integer(this.size);
+ } else if (mode == 2) {
+ this.setSize((Integer)value);
+ }
+ break;
+ case 5:
+ if (mode == 0) {
+ ret = new Property(this, index, "Foreground Color");
+ if (this.stexture != null) {
+ ret = ColorPropertyEditor.make((Property)ret);
+ }
+ } else if (mode == 1) {
+ ret = this.foregroundColor;
+ } else if (mode == 2) {
+ this.setForegroundColor((Color)value);
+ }
+ break;
+ case 6:
+ if (mode == 0) {
+ ret = new Property(this, index, "Background Color");
+ if (this.stexture != null) {
+ ret = ColorPropertyEditor.make((Property)ret);
+ }
+ } else if (mode == 1) {
+ ret = this.backgroundColor;
+ } else if (mode == 2) {
+ this.setBackgroundColor((Color)value);
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 7, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public String toString() {
+ if (this.stexture != null) {
+ return "" + this.stexture;
+ } else {
+ Material owner = (Material)this.getOwner();
+ URL name = null;
+ if (owner != null) {
+ name = owner.textureName;
+ }
+
+ return name == null ? "File " : "File " + name;
+ }
+ }
+}