From 8f2366c1fd9850c0689306419343265099cfca7a Mon Sep 17 00:00:00 2001 From: syeyoung Date: Thu, 26 Jan 2023 01:27:59 +0900 Subject: - do not break contract - richtext Signed-off-by: syeyoung --- .../dungeonsguide/mod/guiv2/BindableAttribute.java | 15 ++++--- .../dungeonsguide/mod/guiv2/GuiScreenAdapter.java | 51 ++++++++++++---------- .../dungeonsguide/mod/guiv2/elements/Text.java | 2 +- .../mod/guiv2/elements/richtext/RichText.java | 4 +- .../dungeonsguide/mod/overlay/OverlayManager.java | 1 - 5 files changed, 42 insertions(+), 31 deletions(-) (limited to 'mod/src') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/BindableAttribute.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/BindableAttribute.java index 35bf616f..5161ee97 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/BindableAttribute.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/BindableAttribute.java @@ -46,12 +46,15 @@ public class BindableAttribute { updating = true; T old = this.value; this.value = t; - if (!Objects.equals(t, old)) - for (BiConsumer onUpdate : onUpdates) { - onUpdate.accept(old, value); - } - updating = false; - initialized = true; + try { + if (!Objects.equals(t, old)) + for (BiConsumer onUpdate : onUpdates) { + onUpdate.accept(old, value); + } + } finally { + updating = false; + initialized = true; + } } public T getValue() { return value; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java index ffbd27df..902b92c1 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java @@ -59,16 +59,20 @@ public class GuiScreenAdapter extends GuiScreen { super.initGui(); Keyboard.enableRepeatEvents(true); isOpen = true; - view.setRelativeBound(new Rect(0,0,Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)); - view.setAbsBounds(new Rect(0,0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)); - view.setSize(new Size(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)); + try { + view.setRelativeBound(new Rect(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)); + view.setAbsBounds(new Rect(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)); + view.setSize(new Size(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)); view.getLayouter().layout(view, new ConstraintBox( Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight, Minecraft.getMinecraft().displayHeight )); - view.setMounted(true); + view.setMounted(true); + }catch (Exception e) { + e.printStackTrace(); + } } @Override @@ -76,33 +80,36 @@ public class GuiScreenAdapter extends GuiScreen { int i = Mouse.getEventX(); int j = this.mc.displayHeight - Mouse.getEventY(); - if (view.isRelayoutRequested()) { + try { + if (view.isRelayoutRequested()) { - view.setRelayoutRequested(false); + view.setRelayoutRequested(false); view.getLayouter().layout(view, new ConstraintBox( Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight, Minecraft.getMinecraft().displayHeight )); - } + } - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - GlStateManager.pushMatrix(); - GlStateManager.disableDepth(); - GlStateManager.enableBlend(); - GlStateManager.enableAlpha(); - GlStateManager.alphaFunc(GL_GREATER, 0); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); - GlStateManager.color(1, 1, 1, 1); - GlStateManager.scale(1.0 / scaledResolution.getScaleFactor(), 1.0 / scaledResolution.getScaleFactor(), 1.0d); - view.getRenderer().doRender(i, j, i, j, partialTicks, new RenderingContext(), view); - GlStateManager.alphaFunc(GL_GREATER, 0.1f); - GlStateManager.popMatrix(); - GlStateManager.enableDepth(); - GlStateManager.disableTexture2D(); - GL11.glDisable(GL11.GL_SCISSOR_TEST); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + GlStateManager.pushMatrix(); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.alphaFunc(GL_GREATER, 0); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GlStateManager.color(1, 1, 1, 1); + GlStateManager.scale(1.0 / scaledResolution.getScaleFactor(), 1.0 / scaledResolution.getScaleFactor(), 1.0d); + view.getRenderer().doRender(i, j, i, j, partialTicks, new RenderingContext(), view); + GlStateManager.alphaFunc(GL_GREATER, 0.1f); + GlStateManager.popMatrix(); + GlStateManager.enableDepth(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } catch (Exception e) { + e.printStackTrace(); + } } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java index 23442d06..4ec68bab 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/Text.java @@ -50,7 +50,7 @@ public class Text extends AnnotatedExportOnlyWidget { public final BindableAttribute text = new BindableAttribute<>(String.class, ""); private final ParentDelegatingTextStyle textStyle = ParentDelegatingTextStyle.ofDefault(); - private final RichText richText = new RichText(new TextSpan(textStyle, ""), BreakWord.WORD, true,RichText.TextAlign.LEFT); + private final RichText richText = new RichText(new TextSpan(textStyle, ""), BreakWord.WORD, false,RichText.TextAlign.LEFT); @Override public List build(DomElement buildContext) { return Collections.singletonList(richText); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java index 3dc58c7e..ae09501d 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/richtext/RichText.java @@ -120,7 +120,9 @@ public class RichText extends Widget implements Layouter, Renderer { richLines = lines; - return new Size(takeAllSpace ? constraintBox.getMaxWidth() : maxWidth, sumHeight); + return new Size(takeAllSpace ? constraintBox.getMaxWidth() : + Layouter.clamp(maxWidth, constraintBox.getMinWidth(), constraintBox.getMaxWidth()), + Layouter.clamp(sumHeight, constraintBox.getMinHeight(), constraintBox.getMaxHeight())); } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManager.java index a9fb429e..dcfa033f 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManager.java @@ -156,7 +156,6 @@ public class OverlayManager { GlStateManager.alphaFunc(GL_GREATER, 0.1f); GlStateManager.popMatrix(); GlStateManager.enableDepth(); - GlStateManager.enableTexture2D(); GL11.glDisable(GL11.GL_SCISSOR_TEST); } -- cgit