Compare commits

...
This repository has been archived on 2022-10-09. You can view files and clone it, but cannot push or open issues or pull requests.

8 Commits

Author SHA1 Message Date
opfromthestart
22a744f65a Added Options
-Added options menu
-You can move from options to title and back
-Added language change button
*Double check the Russian, I just copied and pasted from other files
2022-01-08 21:16:51 -05:00
opfromthestart
c6de19cf19 Rebased everything on master
Now has the dynamic version thing
fixed warnings
2022-01-08 13:57:57 -05:00
opfromthestart
c1a57f7d7a Slightly better alignment
The mode for alignment is more concise
2022-01-08 12:45:28 -05:00
576cfed99f
Fixed import warnings 2021-10-17 14:05:40 +03:00
opfromthestart
5af1b7309d Better Alignment
-Created some Layouts to properly adjust where things go
    -LayoutEdges for text on the same row on opposite sides of the screen
    -LayoutColumn for a non-max width column
-More accessible version string
2021-10-13 23:37:18 -04:00
opfromthestart
0f0a94811f Cleaning
-Cleaned up offsets to make it look like a cube and not 6 squares.
-Fixed error where regions would incorrectly reset files
-Some additions to try to match the intended look. I really dont
understand layouts.
2021-09-25 20:45:17 -04:00
opfromthestart
51bcca1499 Betterish title screen
-Black background used
	-New Background class for displaying a single texture to the back of
the screen(probably not the best way)
-Title now uses an image
	-Made TextureComponent, I think this probably exists elsewhere but I
couldnt find it
-Cube faces now change color based on where they are facing, looks a lot
like the source material except for rearranging
2021-09-13 13:05:59 -04:00
opfromthestart
ce9e95e5ce Well, its [i]a[/i] cube.
-Added CubeComponent to render a cube to the screen
-Added it to the title screen
2021-09-11 21:11:59 -04:00
17 changed files with 400 additions and 61 deletions

1
logs/game.log Normal file
View File

@ -0,0 +1 @@
22:26:25.948 [Music Thread ] WARN ru.windcorp.progressia.test.TestMusicPlayer > No music found

View File

@ -0,0 +1,28 @@
package ru.windcorp.progressia.client.graphics.gui;
import glm.mat._4.Mat4;
import glm.vec._3.Vec3;
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
import ru.windcorp.progressia.client.graphics.texture.Texture;
public class Background extends GUILayer {
protected Texture backgroundTexture;
public Background(String name, Layout layout, Texture inTexture) {
super(name, layout);
backgroundTexture = inTexture;
}
@Override
protected void assemble(RenderTarget target) {
getRoot().setBounds(0, 0, getWidth(), getHeight());
getRoot().invalidate();
target.pushTransform(new Mat4(1).translate(new Vec3(0,0,500)));
target.drawTexture(0, 0, getWidth(), getHeight(), backgroundTexture);
target.popTransform();
getRoot().assemble(target);
}
}

View File

@ -23,6 +23,10 @@ import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
import ru.windcorp.progressia.client.graphics.font.Font; import ru.windcorp.progressia.client.graphics.font.Font;
import ru.windcorp.progressia.client.graphics.Colors; import ru.windcorp.progressia.client.graphics.Colors;
/** Class for a traditional button that gets clicked to activate
*
* @author opfromthestart
*/
public class Button extends BasicButton { public class Button extends BasicButton {
public Button(String name, String label, Font labelFont) { public Button(String name, String label, Font labelFont) {
@ -51,9 +55,7 @@ public class Button extends BasicButton {
// Inside area // Inside area
if (isPressed()) { if (!isPressed()) {
// Do nothing
} else {
Vec4 backgroundColor; Vec4 backgroundColor;
if (isHovered() && isEnabled()) { if (isHovered() && isEnabled()) {
backgroundColor = Colors.HOVER_BLUE; backgroundColor = Colors.HOVER_BLUE;

View File

@ -0,0 +1,23 @@
package ru.windcorp.progressia.client.graphics.gui;
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
import ru.windcorp.progressia.client.graphics.texture.Texture;
public class TextureComponent extends Component {
private final Texture texture;
public TextureComponent(String name, Texture texture2) {
super(name);
texture = texture2;
setPreferredSize(texture.getSprite().getWidth(),texture.getSprite().getHeight());
}
@Override
protected void assembleSelf(RenderTarget target)
{
target.drawTexture(getX(), getY(), getWidth(), getHeight(), texture);
}
}

View File

@ -27,8 +27,8 @@ import ru.windcorp.progressia.client.graphics.gui.Layout;
public class LayoutAlign implements Layout { public class LayoutAlign implements Layout {
private final int margin; protected final int margin;
private double alignX, alignY; protected double alignX, alignY;
public LayoutAlign(double alignX, double alignY, int margin) { public LayoutAlign(double alignX, double alignY, int margin) {
this.alignX = alignX; this.alignX = alignX;
@ -72,7 +72,7 @@ public class LayoutAlign implements Layout {
Vec2i result = new Vec2i(0, 0); Vec2i result = new Vec2i(0, 0);
c.getChildren().stream() c.getChildren().stream()
.map(child -> child.getPreferredSize()) .map(Component::getPreferredSize)
.forEach(size -> { .forEach(size -> {
result.x = max(size.x, result.x); result.x = max(size.x, result.x);
result.y = max(size.y, result.y); result.y = max(size.y, result.y);

View File

@ -0,0 +1,56 @@
package ru.windcorp.progressia.client.graphics.gui.layout;
import glm.vec._2.i.Vec2i;
import ru.windcorp.progressia.client.graphics.gui.Component;
import ru.windcorp.progressia.client.graphics.gui.Layout;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class LayoutEdges implements Layout {
private final int margin;
public LayoutEdges(int margin) {
this.margin = margin;
}
@Override
public void layout(Component c) {
for (int i=0;i<2;i++)
{
Component child = c.getChild(i);
Vec2i size = child.getPreferredSize();
int cWidth = c.getWidth() - 2 * margin;
int cHeight = c.getHeight() - 2 * margin;
size.x = min(size.x, cWidth);
size.y = min(size.y, cHeight);
if (i==0) {
child.setBounds(
c.getX() + margin,
c.getY(),
size
);
} else {
child.setBounds(
1920 - size.x - margin,
c.getY(),
size
);
}
}
}
@Override
public Vec2i calculatePreferredSize(Component c) {
Vec2i result = new Vec2i(1920,0);
c.getChildren().stream()
.map(Component::getPreferredSize)
.forEach(size -> result.y = max(Math.abs(size.y), result.y));
return result;
}
}

View File

@ -43,10 +43,8 @@ public class Region {
private static final boolean RESET_CORRUPTED = true; private static final boolean RESET_CORRUPTED = true;
public int loadedChunks; private final AtomicBoolean isUsing = new AtomicBoolean(false);
private final AtomicBoolean isClosed = new AtomicBoolean(false);
private AtomicBoolean isUsing = new AtomicBoolean(false);
private AtomicBoolean isClosed = new AtomicBoolean(false);
private final RegionFile file; private final RegionFile file;
@ -60,6 +58,7 @@ public class Region {
} catch (IOException e) { } catch (IOException e) {
RegionWorldContainer.LOG.debug("Uh the file broke"); RegionWorldContainer.LOG.debug("Uh the file broke");
RegionWorldContainer.LOG.debug(e.getLocalizedMessage());
if (RESET_CORRUPTED) { if (RESET_CORRUPTED) {
this.file.makeHeader(regionCoords); this.file.makeHeader(regionCoords);
} }
@ -132,7 +131,7 @@ public class Region {
DecodingException { DecodingException {
isUsing.set(true); isUsing.set(true);
int dataOffset = 0; int dataOffset;
Vec3i pos = RegionWorldContainer.getInRegionCoords(chunkPos); Vec3i pos = RegionWorldContainer.getInRegionCoords(chunkPos);
if (hasOffset(pos)) { if (hasOffset(pos)) {

View File

@ -26,9 +26,9 @@ public class RegionFile {
private static final int ID_HEADER_SIZE = 16; private static final int ID_HEADER_SIZE = 16;
private static final byte[] HEADER_ID = {'P','R','O','G'}; private static final byte[] HEADER_ID = {'P','R','O','G'};
final byte endBytes[] = new byte[SECTOR_SIZE]; final byte[] endBytes = new byte[SECTOR_SIZE];
public static enum SectorType { public enum SectorType {
Ending(0), // Just an empty block Ending(0), // Just an empty block
Data(1), // has a byte counting up in position 1, and then Data(1), // has a byte counting up in position 1, and then
PartitionLink(2), PartitionLink(2),
@ -54,7 +54,7 @@ public class RegionFile {
public void confirmHeaderHealth(ChunkMap<Integer> offsets, Vec3i regionCoords) throws IOException { public void confirmHeaderHealth(ChunkMap<Integer> offsets, Vec3i regionCoords) throws IOException {
Set<Integer> used = new HashSet<Integer>(); Set<Integer> used = new HashSet<>();
int maxUsed = 0; int maxUsed = 0;
final int chunksPerRegion = REGION_DIAMETER * REGION_DIAMETER * REGION_DIAMETER; final int chunksPerRegion = REGION_DIAMETER * REGION_DIAMETER * REGION_DIAMETER;
@ -63,9 +63,10 @@ public class RegionFile {
} }
char prog; byte prog;
file.seek(0);
for (int i=0;i<4;i++) { for (int i=0;i<4;i++) {
prog = file.readChar(); prog = file.readByte();
if (prog != HEADER_ID[i]) if (prog != HEADER_ID[i])
{ {
throw new IOException("File is not a .progressia_chunk file"); throw new IOException("File is not a .progressia_chunk file");
@ -109,7 +110,7 @@ public class RegionFile {
throw new IOException("A sector is used twice"); throw new IOException("A sector is used twice");
} }
file.seek(HEADER_SIZE + SECTOR_SIZE * offset); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * offset);
byte type = file.readByte(); byte type = file.readByte();
if (type == SectorType.Data.data) { if (type == SectorType.Data.data) {
@ -131,25 +132,26 @@ public class RegionFile {
} }
public void makeHeader(Vec3i regionCoords) throws IOException { public void makeHeader(Vec3i regionCoords) throws IOException {
file.seek(0);
for (int i = 0; i < HEADER_SIZE; i++) {
file.write(0);
}
file.seek(0); file.seek(0);
file.write(HEADER_ID); file.write(HEADER_ID);
file.writeInt(regionCoords.x); file.writeInt(regionCoords.x);
file.writeInt(regionCoords.y); file.writeInt(regionCoords.y);
file.writeInt(regionCoords.z); file.writeInt(regionCoords.z);
for (int i = 0; i < HEADER_SIZE; i++) {
file.write(0);
}
} }
public void writeBuffer(byte[] buffer, int dataOffset, Vec3i pos) throws IOException { public void writeBuffer(byte[] buffer, int dataOffset, Vec3i pos) throws IOException {
file.seek(HEADER_SIZE + SECTOR_SIZE * dataOffset); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * dataOffset);
int loc = 0; int loc = 0;
byte tempBuffer[] = new byte[SECTOR_SIZE]; byte[] tempBuffer = new byte[SECTOR_SIZE];
byte counter = 0; byte counter = 0;
boolean isDone = false; boolean isDone = false;
while (!isDone) { while (!isDone) {
if (file.length() > HEADER_SIZE + SECTOR_SIZE * (dataOffset + 1)) { if (file.length() > HEADER_SIZE + (long) SECTOR_SIZE * (dataOffset + 1)) {
file.seek(HEADER_SIZE + SECTOR_SIZE * (dataOffset + 1)); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * (dataOffset + 1));
byte header = file.readByte(); byte header = file.readByte();
if (header == SectorType.Data.data) { if (header == SectorType.Data.data) {
byte fileCounter = file.readByte(); byte fileCounter = file.readByte();
@ -157,7 +159,7 @@ public class RegionFile {
// partition place // partition place
{ {
int newOffset = allocateEmptySector(); int newOffset = allocateEmptySector();
file.seek(HEADER_SIZE + SECTOR_SIZE * dataOffset); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * dataOffset);
file.write(2); file.write(2);
file.writeInt(newOffset); file.writeInt(newOffset);
dataOffset = newOffset; dataOffset = newOffset;
@ -179,7 +181,7 @@ public class RegionFile {
if (file.getFilePointer() < 256) if (file.getFilePointer() < 256)
LogManager.getLogger("Region") LogManager.getLogger("Region")
.debug("at {}, ({},{},{}), {}", file.getFilePointer(), pos.x, pos.y, pos.z, dataOffset); .debug("at {}, ({},{},{}), {}", file.getFilePointer(), pos.x, pos.y, pos.z, dataOffset);
file.seek(HEADER_SIZE + SECTOR_SIZE * dataOffset); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * dataOffset);
dataOffset++; dataOffset++;
file.write(tempBuffer); file.write(tempBuffer);
} }
@ -197,7 +199,7 @@ public class RegionFile {
file.seek(definitionOffset); file.seek(definitionOffset);
file.writeInt(dataOffset + 1); file.writeInt(dataOffset + 1);
file.setLength(HEADER_SIZE + dataOffset * SECTOR_SIZE); file.setLength(HEADER_SIZE + (long) dataOffset * SECTOR_SIZE);
return dataOffset; return dataOffset;
} }
@ -206,17 +208,17 @@ public class RegionFile {
int dataOffset = (int) Math.ceil((double) (outputLen - HEADER_SIZE) / SECTOR_SIZE); int dataOffset = (int) Math.ceil((double) (outputLen - HEADER_SIZE) / SECTOR_SIZE);
file.setLength(HEADER_SIZE + dataOffset * SECTOR_SIZE); file.setLength(HEADER_SIZE + (long) dataOffset * SECTOR_SIZE);
return dataOffset; return dataOffset;
} }
public byte[] readBuffer(int dataOffset) throws IOException { public byte[] readBuffer(int dataOffset) throws IOException {
file.seek(HEADER_SIZE + SECTOR_SIZE * dataOffset); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * dataOffset);
int bufferPos = 0; int bufferPos = 0;
byte buffer[] = new byte[SECTOR_SIZE * 16]; byte[] buffer = new byte[SECTOR_SIZE * 16];
byte tempBuffer[] = new byte[SECTOR_SIZE]; byte[] tempBuffer = new byte[SECTOR_SIZE];
boolean reachedEnd = false; boolean reachedEnd = false;
byte counter = 0; byte counter = 0;
@ -229,31 +231,24 @@ public class RegionFile {
if (tempBuffer[0] == SectorType.Data.data) { if (tempBuffer[0] == SectorType.Data.data) {
if (tempBuffer[1] != counter) { if (tempBuffer[1] != counter) {
throw new IOException( throw new IOException(
"Sectors were read out of order\nExpected chunk number " + Byte.toString(counter) "Sectors were read out of order\nExpected chunk number " + counter
+ " but encountered number " + Byte.toString(tempBuffer[1]) + " but encountered number " + tempBuffer[1]
); );
} }
counter++; counter++;
if (buffer.length - bufferPos < SECTOR_SIZE - SECTOR_HEADER_SIZE - 1) { if (buffer.length - bufferPos < SECTOR_SIZE - SECTOR_HEADER_SIZE - 1) {
byte newBuffer[] = new byte[buffer.length + SECTOR_SIZE * 16]; byte[] newBuffer = new byte[buffer.length + SECTOR_SIZE * 16];
for (int i = 0; i < buffer.length; i++) // TODO dedicated System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
// copy, java-y at
// least
{
newBuffer[i] = buffer[i];
}
buffer = newBuffer; buffer = newBuffer;
} }
for (int i = 0; i < SECTOR_SIZE - SECTOR_HEADER_SIZE - 1; i++) { System.arraycopy(tempBuffer, 2, buffer, bufferPos, SECTOR_SIZE - SECTOR_HEADER_SIZE - 1);
buffer[bufferPos + i] = tempBuffer[i + 2];
}
bufferPos += SECTOR_SIZE - SECTOR_HEADER_SIZE - 1; bufferPos += SECTOR_SIZE - SECTOR_HEADER_SIZE - 1;
} else if (tempBuffer[0] == SectorType.Ending.data) { } else if (tempBuffer[0] == SectorType.Ending.data) {
reachedEnd = true; reachedEnd = true;
} else if (tempBuffer[0] == SectorType.PartitionLink.data) { } else if (tempBuffer[0] == SectorType.PartitionLink.data) {
ByteBuffer intBuffer = ByteBuffer.wrap(tempBuffer); ByteBuffer intBuffer = ByteBuffer.wrap(tempBuffer);
int newOffset = intBuffer.getInt(1); int newOffset = intBuffer.getInt(1);
file.seek(HEADER_SIZE + SECTOR_SIZE * newOffset); file.seek(HEADER_SIZE + (long) SECTOR_SIZE * newOffset);
} else { } else {
throw new IOException("Invalid sector ID."); throw new IOException("Invalid sector ID.");
} }

View File

@ -0,0 +1,108 @@
package ru.windcorp.progressia.test;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import glm.mat._4.Mat4;
import glm.vec._3.Vec3;
import glm.vec._4.Vec4;
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
import ru.windcorp.progressia.client.graphics.gui.Component;
public class CubeComponent extends Component {
private final Mat4[] transforms;
private final Vec4[] normals;
private final long startTime;
private final double r3 = Math.sqrt(3+.01);
private final int size;
public CubeComponent(String name, int size) {
super(name);
this.size = size;
transforms = new Mat4[6];
normals = new Vec4[6];
setPreferredSize((int) Math.ceil(r3*size),(int) Math.ceil(r3*size));
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(this::requestReassembly, 1, 60, TimeUnit.MILLISECONDS);
startTime = System.currentTimeMillis();
}
// Notes to me
// z axis is through the screen
// y is horizontal spin
// x is vertical spin
private void computeTransforms()
{
//Creates all of the sides
transforms[0] = new Mat4(1);
transforms[1] = new Mat4(1);
transforms[2] = new Mat4(1);
transforms[3] = new Mat4(1);
transforms[4] = new Mat4(1);
transforms[5] = new Mat4(1);
//Gets time since creation(for rotation amount)
long time = System.currentTimeMillis()-startTime;
//Initializes the way each face is facing
normals[0] = new Vec4(0,0,-1,0);
normals[1] = new Vec4(0,1,0,0);
normals[2] = new Vec4(1,0,0,0);
normals[3] = new Vec4(0,0,1,0);
normals[4] = new Vec4(0,-1,0,0);
normals[5] = new Vec4(-1,0,0,0);
for (int i=0;i<6;i++)
{
//Rotates given side with the time one first, then ot get it on its off axis, then gets the image of each axis under the given rotation
//The rotate functions do change the transforms, but the multiplication does not
normals[i] = transforms[i].rotate((float) (time%(6000*6.28) )/ 6000, new Vec3(0,1,0)).rotate((float) 24, new Vec3(1,.5,0)).mul_(normals[i]);
}
double pi2 = Math.PI / 2;
//Move and rotate the sides from the middle of the cube to the appropriate edges
transforms[0].translate(new Vec3(-size/2f,-size/2f,size/2f));
transforms[1].translate(new Vec3(-size/2f,-size/2f,-size/2f)).rotate((float) pi2, new Vec3(1,0,0));
transforms[2].translate(new Vec3(-size/2f,-size/2f,size/2f)).rotate((float) pi2, new Vec3(0,1,0));
transforms[3].translate(new Vec3(-size/2f,-size/2f,-size/2f));
transforms[4].translate(new Vec3(-size/2f,size/2f,-size/2f)).rotate((float) pi2, new Vec3(1,0,0));
transforms[5].translate(new Vec3(size/2f,-size/2f,size/2f)).rotate((float) pi2, new Vec3(0,1,0));
for (int i=0;i<6;i++) // I have no clue why this is necessary, without it the sides of the cube mess up; may need to be changed if the title screen changes position.
{
transforms[i] = transforms[i].translate(new Vec3(0,0,17.5-3*(i<2 ? 1 : 0)));
}
}
@Override
protected void assembleSelf(RenderTarget target)
{
computeTransforms();
setPosition(750,780);
target.pushTransform(new Mat4(1).translate(new Vec3(getX()+size*r3/2,getY()-size*r3/2,0))); //-size*r3/2
for (int b=0; b<6;b++)
{
target.pushTransform(transforms[b]);
float dot = normals[b].dot(new Vec4(-1,0,0,0)); //Gets the "amount" the given side is pointing in the -x direction
Vec4 color = new Vec4(.4+.3*dot, .4+.3*dot, .6+.4*dot,1.0); //More aligned means brighter color
target.fill(0,0, size, size, color);
target.popTransform();
}
target.popTransform();
}
}

View File

@ -31,6 +31,8 @@ import ru.windcorp.progressia.client.localization.MutableStringLocalized;
public class LayerAbout extends GUILayer { public class LayerAbout extends GUILayer {
public static String version = "pre-alpha 3";
public LayerAbout() { public LayerAbout() {
super("LayerAbout", new LayoutAlign(1, 1, 5)); super("LayerAbout", new LayoutAlign(1, 1, 5));

View File

@ -0,0 +1,53 @@
package ru.windcorp.progressia.test;
import ru.windcorp.progressia.client.graphics.Colors;
import ru.windcorp.progressia.client.graphics.GUI;
import ru.windcorp.progressia.client.graphics.font.Font;
import ru.windcorp.progressia.client.graphics.gui.*;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
import ru.windcorp.progressia.client.localization.Localizer;
import ru.windcorp.progressia.client.localization.MutableString;
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
import java.util.List;
public class LayerOptions extends Background {
public LayerOptions(String name) {
super(name, new LayoutAlign(0, 1f, 15), SimpleTextures.get("title/background"));
Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15));
Font font = new Font().withColor(Colors.BLUE).withAlign(0.5f);
MutableString languageText = new MutableStringLocalized("Layer" + name + ".Language");
content.addChild(new Button(name + ".Language", new Label(name + ".Language", font, languageText)).addAction(this::toggleLanguage));
MutableString playText = new MutableStringLocalized("Layer" + name + ".Return");
content.addChild(new Button(name + ".Return", new Label(name + ".Return", font, playText)).addAction(this::openTitle));
getRoot().addChild(content);
}
private void openTitle(BasicButton basicButton) {
GUI.removeLayer(this);
GUI.addTopLayer(new LayerTitle("Title"));
}
private void toggleLanguage(BasicButton basicButton)
{
String curLang = Localizer.getInstance().getLanguage();
List<String> allLangs = Localizer.getInstance().getLanguages();
int pos = allLangs.indexOf(curLang);
pos++;
if (pos >= allLangs.size())
{
Localizer.getInstance().setLanguage(allLangs.get(0));
}
else
{
Localizer.getInstance().setLanguage(allLangs.get(pos));
}
}
}

View File

@ -1,16 +1,20 @@
package ru.windcorp.progressia.test; package ru.windcorp.progressia.test;
import ru.windcorp.progressia.Progressia;
import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.client.ClientState;
import ru.windcorp.progressia.client.graphics.Colors; import ru.windcorp.progressia.client.graphics.Colors;
import ru.windcorp.progressia.client.graphics.GUI; import ru.windcorp.progressia.client.graphics.GUI;
import ru.windcorp.progressia.client.graphics.font.Font; import ru.windcorp.progressia.client.graphics.font.Font;
import ru.windcorp.progressia.client.graphics.gui.Background;
import ru.windcorp.progressia.client.graphics.gui.BasicButton; import ru.windcorp.progressia.client.graphics.gui.BasicButton;
import ru.windcorp.progressia.client.graphics.gui.Button; import ru.windcorp.progressia.client.graphics.gui.Button;
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
import ru.windcorp.progressia.client.graphics.gui.Group; import ru.windcorp.progressia.client.graphics.gui.Group;
import ru.windcorp.progressia.client.graphics.gui.Label; import ru.windcorp.progressia.client.graphics.gui.Label;
import ru.windcorp.progressia.client.graphics.gui.TextureComponent;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign; import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutEdges;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical; import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
import ru.windcorp.progressia.client.localization.MutableString; import ru.windcorp.progressia.client.localization.MutableString;
import ru.windcorp.progressia.client.localization.MutableStringLocalized; import ru.windcorp.progressia.client.localization.MutableStringLocalized;
import ru.windcorp.progressia.common.util.crash.CrashReports; import ru.windcorp.progressia.common.util.crash.CrashReports;
@ -24,34 +28,58 @@ import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor; import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
public class LayerTitle extends GUILayer { public class LayerTitle extends Background {
private final BasicButton resetButton; private final BasicButton resetButton;
public LayerTitle(String name) { public LayerTitle(String name) {
super(name, new LayoutAlign(0.5f, 0.7f, 15)); super(name, new LayoutAlign(0, 1f, 15), SimpleTextures.get("title/background"));
Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15)); Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15));
Group info = new Group("Layer"+name+".InfoGroup", new LayoutEdges(30));
Group buttonContent = new Group("Layer" + name + ".ButtonGroup", new LayoutColumn(15, 320));
MutableString title = new MutableStringLocalized("Layer" + name + ".Title"); Font titleFont = new Font().deriveBold().withColor(Colors.BLUE).withAlign(0.5f);
Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f); content.addChild(new TextureComponent(name + ".Title", SimpleTextures.get("title/progressia")));
content.addChild(new Label(name + ".Title", titleFont, title));
info.addChild(new Label(
"About",
titleFont,
new MutableStringLocalized("LayerAbout.Title")
)
);
info.addChild(
new Label(
"Version",
titleFont,
Progressia.getFullerVersion()
)
);
content.addChild(info);
Font buttonFont = titleFont.deriveNotBold(); Font buttonFont = titleFont.deriveNotBold();
MutableString playText = new MutableStringLocalized("Layer" + name + ".Play"); MutableString playText = new MutableStringLocalized("Layer" + name + ".Play");
content.addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(this::startGame)); buttonContent.addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(this::startGame));
MutableString resetText = new MutableStringLocalized("Layer" + name + ".Reset"); MutableString resetText = new MutableStringLocalized("Layer" + name + ".Reset");
this.resetButton = new Button(name + ".Reset", new Label(name + ".Reset", buttonFont, resetText)).addAction(this::resetWorld); this.resetButton = new Button(name + ".Reset", new Label(name + ".Reset", buttonFont, resetText)).addAction(this::resetWorld);
content.addChild(resetButton); buttonContent.addChild(resetButton);
updateResetButton(); updateResetButton();
MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit"); MutableString settingsText = new MutableStringLocalized("Layer" + name + ".Options");
content.addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> { buttonContent.addChild(new Button(name + ".Options", new Label(name + ".Options", buttonFont, settingsText)).addAction(this::openOptions));
System.exit(0);
}));
MutableString quitText = new MutableStringLocalized("Layer" + name + ".Quit");
buttonContent.addChild(new Button(name + "Quit", new Label(name + ".Quit", buttonFont, quitText)).addAction(b -> System.exit(0)));
content.addChild(buttonContent);
getRoot().addChild(content); getRoot().addChild(content);
buttonContent.setPreferredSize(500, 1000);
CubeComponent cube = new CubeComponent(name+".Cube",300);
getRoot().addChild(cube);
} }
private void updateResetButton() { private void updateResetButton() {
@ -92,4 +120,9 @@ public class LayerTitle extends GUILayer {
updateResetButton(); updateResetButton();
} }
private void openOptions(BasicButton basicButton) {
GUI.removeLayer(this);
GUI.addTopLayer(new LayerOptions("Options"));
}
} }

View File

@ -0,0 +1,33 @@
package ru.windcorp.progressia.test;
import ru.windcorp.progressia.client.graphics.gui.Component;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
public class LayoutColumn extends LayoutVertical {
protected int maxWidth;
private final int margin;
public LayoutColumn(int gap, int maxWidth)
{
super(gap);
this.maxWidth = maxWidth;
margin = gap;
}
@Override
public void layout(Component c) {
int x = c.getX() + margin,
y = c.getY() + c.getHeight();
synchronized (c.getChildren()) {
for (Component child : c.getChildren()) {
int height = child.getPreferredSize().y;
y -= margin + height;
child.setBounds(x, y, maxWidth, height);
}
}
}
}

View File

@ -24,5 +24,8 @@ LayerTitle.Reset = Reset World
LayerTitle.Options = Options LayerTitle.Options = Options
LayerTitle.Quit = Quit LayerTitle.Quit = Quit
LayerOptions.Return = Back To Menu
LayerOptions.Language = US English
LayerText.Load = Loading... LayerText.Load = Loading...
LayerText.Save = Saving... LayerText.Save = Saving...

View File

@ -24,5 +24,8 @@ LayerTitle.Reset = Сбросить мир
LayerTitle.Options = Настройки LayerTitle.Options = Настройки
LayerTitle.Quit = Выход LayerTitle.Quit = Выход
LayerOptions.Return = Главное меню
LayerOptions.Language = Русский
LayerText.Load = Загрузка... LayerText.Load = Загрузка...
LayerText.Save = Сохранение... LayerText.Save = Сохранение...

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB