Fixed GUI buttons and a rare crash on startup

This commit is contained in:
OLEGSHA 2021-08-27 12:20:58 +03:00
parent 98c383bf7d
commit f74c731a3d
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
7 changed files with 141 additions and 1 deletions

View File

@ -120,6 +120,7 @@ public abstract class BasicButton extends Component {
public void setPressed(boolean isPressed) { public void setPressed(boolean isPressed) {
if (this.isPressed != isPressed) { if (this.isPressed != isPressed) {
this.isPressed = isPressed; this.isPressed = isPressed;
requestReassembly();
if (isPressed) { if (isPressed) {
takeFocus(); takeFocus();

View File

@ -20,10 +20,12 @@ package ru.windcorp.progressia.client.graphics.model;
import java.util.Map; import java.util.Map;
import glm.mat._4.Mat4;
import glm.vec._3.Vec3; import glm.vec._3.Vec3;
import glm.vec._4.Vec4; import glm.vec._4.Vec4;
import ru.windcorp.progressia.client.graphics.backend.Usage; import ru.windcorp.progressia.client.graphics.backend.Usage;
import ru.windcorp.progressia.client.graphics.texture.Texture; import ru.windcorp.progressia.client.graphics.texture.Texture;
import ru.windcorp.progressia.common.util.VectorUtil;
import ru.windcorp.progressia.common.world.rels.AbsFace; import ru.windcorp.progressia.common.world.rels.AbsFace;
public class Shapes { public class Shapes {
@ -272,6 +274,22 @@ public class Shapes {
return this; return this;
} }
public PppBuilder apply(Mat4 transform) {
VectorUtil.applyMat4(origin, transform);
VectorUtil.rotateOnly(width, transform);
VectorUtil.rotateOnly(height, transform);
VectorUtil.rotateOnly(depth, transform);
return this;
}
public PppBuilder scale(float factor) {
origin.mul(factor);
width.mul(factor);
height.mul(factor);
depth.mul(factor);
return this;
}
public PppBuilder flip() { public PppBuilder flip() {
this.flip = true; this.flip = true;
return this; return this;

View File

@ -95,7 +95,7 @@ public class ClientManager {
} }
public void processPackets() { public void processPackets() {
getClients().forEach(CommsChannel::processPackets); clients.forEach(CommsChannel::processPackets);
} }
/** /**

View File

@ -86,6 +86,11 @@ class PlanetTerrainGenerator {
} }
private void generateBorderTerrain(Server server, DefaultChunkData chunk) { private void generateBorderTerrain(Server server, DefaultChunkData chunk) {
if (chunk.getPosition().x == 0 && chunk.getPosition().y == 0 && chunk.getPosition().z == 0) {
generateCore(server, chunk);
return;
}
BlockData stone = BlockDataRegistry.getInstance().get("Test:Stone"); BlockData stone = BlockDataRegistry.getInstance().get("Test:Stone");
BlockData air = BlockDataRegistry.getInstance().get("Test:Air"); BlockData air = BlockDataRegistry.getInstance().get("Test:Air");
@ -109,4 +114,16 @@ class PlanetTerrainGenerator {
}); });
} }
private void generateCore(Server server, DefaultChunkData chunk) {
BlockData tux = BlockDataRegistry.getInstance().get("Test:Tux");
BlockData air = BlockDataRegistry.getInstance().get("Test:Air");
GenericChunks.forEachBiC(bic -> {
chunk.setBlock(bic, air, false);
});
chunk.setBlock(new Vec3i(7, 7, 0), tux, false);
}
} }

View File

@ -0,0 +1,100 @@
/*
* Progressia
* Copyright (C) 2020-2021 Wind Corporation and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.windcorp.progressia.test;
import glm.mat._4.Mat4;
import glm.vec._3.Vec3;
import glm.vec._3.i.Vec3i;
import ru.windcorp.progressia.client.graphics.Colors;
import ru.windcorp.progressia.client.graphics.backend.Usage;
import ru.windcorp.progressia.client.graphics.model.Renderable;
import ru.windcorp.progressia.client.graphics.model.Shape;
import ru.windcorp.progressia.client.graphics.model.ShapeParts;
import ru.windcorp.progressia.client.graphics.model.Shapes;
import ru.windcorp.progressia.client.graphics.model.StaticModel;
import ru.windcorp.progressia.client.graphics.texture.ComplexTexture;
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
import ru.windcorp.progressia.client.graphics.texture.TexturePrimitive;
import ru.windcorp.progressia.client.graphics.world.WorldRenderProgram;
import ru.windcorp.progressia.client.world.block.BlockRender;
import ru.windcorp.progressia.common.world.DefaultChunkData;
public class TestBlockRenderTux extends BlockRender {
private final Renderable model;
public TestBlockRenderTux(String id) {
super(id);
TexturePrimitive primitive = SimpleTextures.get("blocks/Tux").getSprite().getPrimitive();
ComplexTexture texture = new ComplexTexture(primitive, 72, 60);
WorldRenderProgram program = WorldRenderProgram.getDefault();
StaticModel.Builder builder = StaticModel.builder();
final float scale = 1f / 40;
final float lift = -1f / 2 / scale;
builder.addPart(
new Shapes.PppBuilder(program, texture.getCuboidTextures(0, 36, 12)).setSize(12)
.centerAt(0, 0, 18 + (12 / 2) + lift).scale(scale).create()
);
builder.addPart(
new Shapes.PppBuilder(program, texture.getCuboidTextures(0, 0, 18)).setSize(18)
.centerAt(0, 0, 18 / 2 + lift).scale(scale).create()
);
builder.addPart(
new Shape(
Usage.STATIC,
program,
ShapeParts.createRectangle(
program,
texture.get(48, 44, 24, 16),
Colors.WHITE,
new Vec3(18 / 2 + 1, -(24 / 2), lift),
new Vec3(0, 24, 0),
new Vec3(0, 0, 16),
false
),
ShapeParts.createRectangle(
program,
texture.get(48, 44, 24, 16),
Colors.WHITE,
new Vec3(18 / 2 + 1, -(24 / 2), lift),
new Vec3(0, 24, 0),
new Vec3(0, 0, 16),
true
)
),
new Mat4().scale(scale)
);
this.model = builder.build();
}
@Override
public Renderable createRenderable(DefaultChunkData chunk, Vec3i relBlockInChunk) {
return model;
}
@Override
public boolean needsOwnRenderable() {
return true;
}
}

View File

@ -136,6 +136,10 @@ public class TestContent {
register(new BlockRenderOpaqueCube("Test:StatieSpawner", getBlockTexture("StatieSpawner"))); register(new BlockRenderOpaqueCube("Test:StatieSpawner", getBlockTexture("StatieSpawner")));
register(new TestBlockLogicStatieSpawner("Test:StatieSpawner")); register(new TestBlockLogicStatieSpawner("Test:StatieSpawner"));
register(new BlockData("Test:Tux"));
register(new TestBlockRenderTux("Test:Tux"));
register(new BlockLogic("Test:Tux"));
BlockDataRegistry.getInstance().values().forEach(PLACEABLE_BLOCKS::add); BlockDataRegistry.getInstance().values().forEach(PLACEABLE_BLOCKS::add);
PLACEABLE_BLOCKS.removeIf(b -> placeableBlacklist.contains(b.getId())); PLACEABLE_BLOCKS.removeIf(b -> placeableBlacklist.contains(b.getId()));
PLACEABLE_BLOCKS.sort(Comparator.comparing(BlockData::getId)); PLACEABLE_BLOCKS.sort(Comparator.comparing(BlockData::getId));

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B