From 9885a1ca42de10471d08202d67a1da53f9f8dd8c Mon Sep 17 00:00:00 2001 From: OLEGSHA Date: Sun, 17 Oct 2021 15:10:24 +0300 Subject: [PATCH] Visual improvements - Added a custom font for item amount displays - Added an indicator for openable items - Changed open item indicator to be more obvious - Fixed ExponentAnimation overshooting target during FPS spikes --- .../progressia/client/ClientProxy.java | 2 + .../client/graphics/ExponentAnimation.java | 6 ++ .../graphics/world/hud/HUDTextures.java | 17 +++++ .../world/hud/ItemAmountTypeface.java | 71 ++++++++++++++++++ .../graphics/world/hud/SlotComponent.java | 27 ++++++- .../progressia/server/PlayerManager.java | 2 +- .../textures/gui/DecorationContainerOpen.png | Bin 1011 -> 1009 bytes .../gui/DecorationContainerOpenable.png | Bin 0 -> 1024 bytes .../textures/gui/ItemAmountTypeface.png | Bin 0 -> 214 bytes 9 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 src/main/java/ru/windcorp/progressia/client/graphics/world/hud/ItemAmountTypeface.java create mode 100644 src/main/resources/assets/textures/gui/DecorationContainerOpenable.png create mode 100644 src/main/resources/assets/textures/gui/ItemAmountTypeface.png 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 af58dfa63daeda650b329b9c2f6b09ae7f36163e..b8fe7e9d84cbcfce2cb8ff77c84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2$-lMm6{Rs|K@mm2bA`BgRvMz1~&zP4H;?Z$is$@5=OnLEv)a_Ur?h(jSo^&(Qayxnq4MnzD{&912Ikn;5G@61m?*s zI;F&u++-FDqbigUf22-0ohC65Ogpg-y4k&u(;)eKxCMaV?;sZ@x-XD>&+Q{>y&hk5 zauAwjIFlL$)d!`@jt{;uKOaN*@Od000JJOGiWi000000Qp0^e*gdg32;bRa{vG?BLDy{lUM@~2?-1c9tQrZHVTt* z11MKQNklZ<+0`XEgnEnBHAwWq&A7Q92!vs^+3?+;$4D}yW puWoXJG_eu$41od#3KS@ixec(s2RtvatO@`C002ovPDHLkV1g`tYCQk| 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 0000000000000000000000000000000000000000..550d0e99a5dddc13bd9387d7b6674c20881059e4 GIT binary patch literal 1024 zcmV+b1poVqP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=KHuH+~ThTmDmECJgXo8=G)Qtx1vKR<-zT)OAz zjJjV&s!$=sIJWVJQ&r*o`^N}>;owL)BsI?^=ZGVfRJdZ`@jB}2DW=t5H+9d^M|pTA zU^WV_a@~5~@)L4~K5uz@3{up0hRV4oj*k;{8)DxMw)}P^bUBFIaH!jm@b;Xp`(sC% zi`)Apw5>nxmH2gr*(EW~n#mIS#L+AljGbdLV|(__3PuS$ip4_M*acmGopWyzat%1LhlLrL?}Pk zU&=|}-3}k~6b*ePzT-QboAtpW<9GSTRZVM1PU=(h0!9}CNCPlh9 zHbBF65J>rng_hg0+%3zT4+xaupENm1f5RYdod};6Ie!HkT~W0!793Dqym{4Io8`KoJZH2*iw9p-j=3 zgApN-4nP&5vm`!%g;cpCNKPUda8L#Cjc1IODl1=Nya)k8B?mFEDN+F|CB^=+HEp?B^Hy5z+@+(Ad+ye~mtIdgv6aqr>X}bF{VZo4 z*lI&Y8anc@;iH66A8H%xPwhWYqfLz$si|lWHAu~F6Et5ZI+=kOCjxMr1V{q&WEP!L z;z@2Yi-l1Y$_P>?oKBM%2&R)*2R-cG$Z3%LXSfA`;6FhwOmyEM_cOO&QR{Vm(a9n- z%Wx(&3aSrEl^q{^V}5-N@tcY-LoY)wLoY)wLoY)wL;q_-GVt30e;mUub)Uh4n=02y>eSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{002-)L_t(Y z$L-R~4FDhr15j$*f8~1h;DjA#xvkmb%F#55+q2_ZKwgEGzvRZ;4Mr50000{XE)7O>#DVHF(w$yt5 z#}+^#$r9Iy66gHf+|;}h2Ir#G#FEq$h4Rdj3(W literal 0 HcmV?d00001