diff --git a/src/main/java/ru/windcorp/progressia/client/ClientProxy.java b/src/main/java/ru/windcorp/progressia/client/ClientProxy.java index 1d154e7..c75286d 100644 --- a/src/main/java/ru/windcorp/progressia/client/ClientProxy.java +++ b/src/main/java/ru/windcorp/progressia/client/ClientProxy.java @@ -27,6 +27,7 @@ import ru.windcorp.progressia.client.graphics.font.GNUUnifontLoader; import ru.windcorp.progressia.client.graphics.font.Typefaces; import ru.windcorp.progressia.client.graphics.texture.Atlases; import ru.windcorp.progressia.client.graphics.world.WorldRenderProgram; +import ru.windcorp.progressia.client.graphics.world.hud.HUDTextures; import ru.windcorp.progressia.client.localization.Localizer; import ru.windcorp.progressia.common.resource.ResourceManager; import ru.windcorp.progressia.common.util.crash.CrashReports; @@ -46,6 +47,7 @@ public class ClientProxy implements Proxy { () -> Typefaces .setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))) ); + RenderTaskQueue.waitAndInvoke(HUDTextures::loadItemAmountTypeface); } catch (InterruptedException e) { throw CrashReports.report(e, "ClientProxy failed"); } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/ExponentAnimation.java b/src/main/java/ru/windcorp/progressia/client/graphics/ExponentAnimation.java index eaeb5d0..e7d7f33 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/ExponentAnimation.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/ExponentAnimation.java @@ -45,6 +45,12 @@ public class ExponentAnimation { float difference = value - target; value += difference * (1 - Math.exp(speed * timeStep)); + float newDifference = value - target; + if (difference * newDifference < 0) { + // Whoops, we've overshot + value = target; + } + return value; } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/HUDTextures.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/HUDTextures.java index 2d296be..58aa450 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/HUDTextures.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/HUDTextures.java @@ -17,15 +17,20 @@ */ package ru.windcorp.progressia.client.graphics.world.hud; +import java.io.IOException; + import ru.windcorp.progressia.client.graphics.texture.Atlases; import ru.windcorp.progressia.client.graphics.texture.SimpleTexture; import ru.windcorp.progressia.client.graphics.texture.Texture; import ru.windcorp.progressia.client.graphics.texture.Atlases.AtlasGroup; import ru.windcorp.progressia.common.resource.ResourceManager; +import ru.windcorp.progressia.common.util.crash.CrashReports; public class HUDTextures { private static final AtlasGroup HUD_ATLAS_GROUP = new AtlasGroup("HUD", 1 << 12); + + private static ItemAmountTypeface itemAmountTypeface = null; public static Texture getHUDTexture(String name) { return new SimpleTexture( @@ -39,5 +44,17 @@ public class HUDTextures { public static AtlasGroup getHUDAtlasGroup() { return HUD_ATLAS_GROUP; } + + public static ItemAmountTypeface getItemAmountTypeface() { + return itemAmountTypeface; + } + + public static void loadItemAmountTypeface() { + try { + itemAmountTypeface = new ItemAmountTypeface(); + } catch (IOException e) { + throw CrashReports.report(e, "Could not load item amount typeface"); + } + } } diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/ItemAmountTypeface.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/ItemAmountTypeface.java new file mode 100644 index 0000000..d0bbe4c --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/ItemAmountTypeface.java @@ -0,0 +1,71 @@ +/* + * 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 . + */ +package ru.windcorp.progressia.client.graphics.world.hud; + +import java.io.IOException; + +import ru.windcorp.progressia.client.graphics.flat.FlatRenderProgram; +import ru.windcorp.progressia.client.graphics.font.SpriteTypeface; +import ru.windcorp.progressia.client.graphics.model.ShapeRenderProgram; +import ru.windcorp.progressia.client.graphics.texture.ComplexTexture; +import ru.windcorp.progressia.client.graphics.texture.Texture; +import ru.windcorp.progressia.client.graphics.texture.TextureLoader; +import ru.windcorp.progressia.client.graphics.texture.TexturePrimitive; +import ru.windcorp.progressia.client.graphics.texture.TextureSettings; +import ru.windcorp.progressia.common.resource.ResourceManager; + +public class ItemAmountTypeface extends SpriteTypeface { + + public static final int HEIGHT = 5; + public static final int WIDTH = 3; + + private final Texture[] textures = new Texture[10]; + + public ItemAmountTypeface() throws IOException { + super("ItemAmount", HEIGHT, 1); + + ComplexTexture atlas = new ComplexTexture(new TexturePrimitive( + TextureLoader.loadPixels( + ResourceManager.getTextureResource("gui/ItemAmountTypeface"), + new TextureSettings(false) + ).getData() + ), 30, 5); + + for (int i = 0; i <= 9; ++i) { + textures[i] = atlas.get(i * WIDTH, 0, WIDTH, HEIGHT); + } + } + + @Override + public Texture getTexture(char c) { + if (!supports(c)) + return textures[0]; + return textures[c - '0']; + } + + @Override + public ShapeRenderProgram getProgram() { + return FlatRenderProgram.getDefault(); + } + + @Override + public boolean supports(char c) { + return c >= '0' && c <= '9'; + } + +} diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/SlotComponent.java b/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/SlotComponent.java index d949cd5..772c1af 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/SlotComponent.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/world/hud/SlotComponent.java @@ -20,6 +20,7 @@ package ru.windcorp.progressia.client.graphics.world.hud; import java.util.function.BooleanSupplier; import glm.mat._4.Mat4; import ru.windcorp.progressia.client.graphics.Colors; +import ru.windcorp.progressia.client.graphics.backend.InputTracker; import ru.windcorp.progressia.client.graphics.flat.FlatRenderProgram; import ru.windcorp.progressia.client.graphics.flat.RenderTarget; import ru.windcorp.progressia.client.graphics.font.Font; @@ -42,6 +43,7 @@ public class SlotComponent extends Component { static final float TEXTURE_SIZE = 24; private static Renderable containerOpenDecoration = null; + private static Renderable containerOpenableDecoration = null; private final ItemContainer container; private final int index; @@ -63,7 +65,7 @@ public class SlotComponent extends Component { setScale(2); - Font sizeFont = new Font().deriveOutlined().withScale(1); + Font sizeFont = new Font(HUDTextures.getItemAmountTypeface()).deriveOutlined().withScale(2); addChild(new DynamicLabel(getName() + ".Size", sizeFont, () -> amountDisplayString, getPreferredSize().x)); setLayout(new LayoutAlign(0, 0, 0)); @@ -74,6 +76,13 @@ public class SlotComponent extends Component { HUDTextures.getHUDTexture("DecorationContainerOpen") ).setSize(TEXTURE_SIZE + 2).setOrigin(-1, -1, 0).create(); } + + if (containerOpenableDecoration == null) { + containerOpenableDecoration = new PgmBuilder( + FlatRenderProgram.getDefault(), + HUDTextures.getHUDTexture("DecorationContainerOpenable") + ).setSize(TEXTURE_SIZE + 2).setOrigin(-1, -1, 0).create(); + } } public ItemSlot getSlot() { @@ -155,10 +164,26 @@ public class SlotComponent extends Component { if (contents instanceof ItemDataContainer) { ItemDataContainer asContainer = (ItemDataContainer) contents; + if (asContainer.isOpen()) { renderer.pushColorMultiplier().mul(Colors.BLUE); containerOpenDecoration.render(renderer); renderer.popColorMultiplier(); + } else { + + double dx = InputTracker.getCursorX() - (getX() + getWidth() / 2); + double dy = InputTracker.getCursorY() - (getY() + getHeight() / 2); + double distanceToCursorSquared = dx*dx + dy*dy; + final double maxDistanceSquared = (scale * TEXTURE_SIZE * 4) * (scale * TEXTURE_SIZE * 4); + + float opacity = (float) (1 - distanceToCursorSquared / maxDistanceSquared); + + if (opacity > 0) { + renderer.pushColorMultiplier().mul(Colors.BLUE.x, Colors.BLUE.y, Colors.BLUE.z, opacity); + containerOpenableDecoration.render(renderer); + renderer.popColorMultiplier(); + } + } } } diff --git a/src/main/java/ru/windcorp/progressia/server/PlayerManager.java b/src/main/java/ru/windcorp/progressia/server/PlayerManager.java index 48c39c9..f3bfed4 100644 --- a/src/main/java/ru/windcorp/progressia/server/PlayerManager.java +++ b/src/main/java/ru/windcorp/progressia/server/PlayerManager.java @@ -63,7 +63,7 @@ public class PlayerManager { private EntityDataPlayer spawnPlayerEntity(String login) { EntityDataPlayer player = (EntityDataPlayer) EntityDataRegistry.getInstance().create("Core:Player"); - player.getHand(0).slot().setContents(ItemDataRegistry.getInstance().create("Test:Stick"), 7); + player.getHand(0).slot().setContents(ItemDataRegistry.getInstance().create("Test:Stick"), 20); player.getEquipmentSlot(0).slot().setContents(ItemDataRegistry.getInstance().create("Test:CardboardBackpack"), 1); player.setPosition(getServer().getWorld().getGenerator().suggestSpawnLocation()); diff --git a/src/main/resources/assets/textures/gui/DecorationContainerOpen.png b/src/main/resources/assets/textures/gui/DecorationContainerOpen.png index af58dfa..b8fe7e9 100644 Binary files a/src/main/resources/assets/textures/gui/DecorationContainerOpen.png and b/src/main/resources/assets/textures/gui/DecorationContainerOpen.png differ diff --git a/src/main/resources/assets/textures/gui/DecorationContainerOpenable.png b/src/main/resources/assets/textures/gui/DecorationContainerOpenable.png new file mode 100644 index 0000000..550d0e9 Binary files /dev/null and b/src/main/resources/assets/textures/gui/DecorationContainerOpenable.png differ diff --git a/src/main/resources/assets/textures/gui/ItemAmountTypeface.png b/src/main/resources/assets/textures/gui/ItemAmountTypeface.png new file mode 100644 index 0000000..a068be8 Binary files /dev/null and b/src/main/resources/assets/textures/gui/ItemAmountTypeface.png differ