Skip to content

Commit 688839b

Browse files
committed
ui
1 parent 601b1c4 commit 688839b

6 files changed

Lines changed: 75 additions & 31 deletions

File tree

src/main/java/com/teammoeg/chorda/client/CInputHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.lwjgl.glfw.GLFW;
2828
import org.lwjgl.system.MemoryUtil;
2929

30+
import static org.lwjgl.glfw.GLFW.GLFW_KEY_0;
31+
import static org.lwjgl.glfw.GLFW.GLFW_KEY_KP_0;
32+
3033
/**
3134
* 客户端输入辅助工具类,提供键盘和鼠标输入状态检测、剪贴板操作和光标管理功能。
3235
* 封装了GLFW底层输入API,提供更方便的修饰键检测(Shift/Ctrl/Alt)、
@@ -125,6 +128,15 @@ public static boolean isPrevKey(int keyCode, int scanCode, int modifier) {
125128
return (keyCode == GLFW.GLFW_KEY_TAB && modifier == GLFW.GLFW_MOD_SHIFT) || keyCode == GLFW.GLFW_KEY_W || keyCode == GLFW.GLFW_KEY_UP || keyCode == GLFW.GLFW_KEY_PAGE_UP;
126129
}
127130

131+
public static int mapNumber(int keyCode, int offset) {
132+
if (keyCode >= GLFW_KEY_KP_0) {
133+
return keyCode - GLFW_KEY_KP_0 + offset;
134+
} else if (keyCode >= GLFW_KEY_0) {
135+
return keyCode - GLFW_KEY_0 + offset;
136+
}
137+
return 0;
138+
}
139+
128140
/**
129141
* 标准光标样式枚举,封装GLFW光标类型。
130142
* <p>

src/main/java/com/teammoeg/chorda/client/ClickActions.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.teammoeg.chorda.text.Components;
3434
import com.teammoeg.chorda.util.CRegistryHelper;
3535
import net.minecraft.Util;
36+
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
3637
import net.minecraft.network.chat.Component;
3738
import net.minecraft.network.chat.MutableComponent;
3839
import net.minecraft.resources.ResourceLocation;
@@ -79,11 +80,16 @@ public static ClickAction create(ResourceLocation action, String content) {
7980
static {
8081
register(EMPTY);
8182
register(Chorda.rl("open_url"), "tips.frostedheart.click_action.open_url", s -> {
82-
try {
83-
Util.getPlatform().openUrl(new URL(s));
84-
} catch (MalformedURLException e) {
85-
throw new RuntimeException("Invalid URL '" + s + "'");
86-
}
83+
ClientUtils.getMc().setScreen(new ConfirmLinkScreen(b -> {
84+
try {
85+
if (b) Util.getPlatform().openUrl(new URL(s));
86+
} catch (MalformedURLException e) {
87+
String message = "Invalid URL '" + s + "'";
88+
PopupOverlay.pop(Components.withColor(message, Colors.RED).append("\n").append(Component.translatable("tips.frostedheart.error.desc")));
89+
} finally {
90+
ClientUtils.getMc().popGuiLayer();
91+
}
92+
}, s, false));
8793
});
8894
register(Chorda.rl("open_quest"), "tips.frostedheart.click_action.open_quest", s -> {
8995
if (!CompatModule.isFTBQLoaded()) {

src/main/java/com/teammoeg/chorda/client/cui/CUIDebugHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ private CUIDebugHelper() {
5757

5858
}
5959
public static boolean isDebugEnabled() {
60-
return ClientUtils.getMc().options.renderDebug&&isDebugEnabled;
60+
return /*ClientUtils.getMc().options.renderDebug&&*/isDebugEnabled;
6161

6262
}
6363
public static void toggleDebug() {
64-
if(ClientUtils.getMc().options.renderDebug)
64+
// if(ClientUtils.getMc().options.renderDebug)
6565
isDebugEnabled=!isDebugEnabled;
6666
}
6767

src/main/java/com/teammoeg/chorda/client/cui/widgets/OverlayItemSlot.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@
1919

2020
package com.teammoeg.chorda.client.cui.widgets;
2121

22-
import java.util.function.Consumer;
23-
2422
import com.teammoeg.chorda.client.RenderingHint;
2523
import com.teammoeg.chorda.client.cui.base.TooltipBuilder;
2624
import com.teammoeg.chorda.client.cui.base.UIElement;
2725
import com.teammoeg.chorda.client.icon.CIcons.CIcon;
28-
2926
import lombok.Getter;
3027
import lombok.Setter;
3128
import net.minecraft.client.gui.GuiGraphics;
3229
import net.minecraft.world.item.ItemStack;
3330
import net.minecraft.world.item.crafting.Ingredient;
3431

32+
import java.util.function.Consumer;
33+
3534
/**
3635
* 带覆盖层图标的物品槽控件。在物品上方绘制一个额外的覆盖层图标,并支持自定义提示信息。
3736
* <p>
@@ -111,7 +110,7 @@ public void render(GuiGraphics graphics, int x, int y, int w, int h, RenderingHi
111110

112111
if (overlay != null) {
113112
graphics.pose().pushPose();
114-
graphics.pose().translate(0, 0, 200);
113+
graphics.pose().translate(0, 0, 300);
115114
overlay.draw(graphics, x, y, overlayWidth, overlayHeight);
116115
graphics.pose().popPose();
117116
}

src/main/java/com/teammoeg/frostedheart/content/ui/dialogue/DialogueOverlay.java

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.teammoeg.frostedheart.content.ui.dialogue;
22

33
import com.teammoeg.chorda.client.AnimationUtil;
4+
import com.teammoeg.chorda.client.CInputHelper;
45
import com.teammoeg.chorda.client.ClientUtils;
56
import com.teammoeg.chorda.client.RenderingHint;
67
import com.teammoeg.chorda.client.TesselateHelper;
@@ -18,9 +19,9 @@
1819
import net.minecraft.network.chat.Component;
1920
import net.minecraft.util.Mth;
2021

22+
import java.util.ArrayList;
2123
import java.util.Collection;
22-
import java.util.HashSet;
23-
import java.util.Set;
24+
import java.util.List;
2425

2526
public class DialogueOverlay extends PrimaryLayer {
2627
public static final DialogueOverlay INSTANCE = new DialogueOverlay();
@@ -29,7 +30,7 @@ private DialogueOverlay() {
2930
setEnabled(false);
3031
}
3132

32-
private final Set<Selection> selections = new HashSet<>();
33+
private final List<Selection> selections = new ArrayList<>();
3334
private final Button close = TextButton.create(this, Component.translatable("gui.close"), FlatIcon.LEAVE.toCIcon(), mb -> {
3435
close();
3536
ClientUtils.getMc().popGuiLayer();
@@ -90,8 +91,8 @@ public void refresh() {
9091
}
9192
alignWidgets();
9293

93-
var pos = OverlayPositioner.position(this, OverlayPositioner.LeftAndRight.RIGHT.startPos(this));
94-
setOffsetX(pos.getX());
94+
var pos = OverlayPositioner.position(this, OverlayPositioner.All.MIDDLE.startPos(this));
95+
setOffsetX(pos.getX()+110);
9596
setOffsetY(pos.getY()+6);
9697
}
9798

@@ -110,6 +111,18 @@ public boolean onMousePressed(MouseButton button) {
110111
return super.onMousePressed(button);
111112
}
112113

114+
@Override
115+
public boolean onKeyPressed(int keyCode, int scanCode, int modifiers) {
116+
if (!selections.isEmpty()) {
117+
int index = CInputHelper.mapNumber(keyCode, -1);
118+
if (index >= 0 && index < selections.size()) {
119+
selections.get(index).onClicked(MouseButton.LEFT);
120+
return true;
121+
}
122+
}
123+
return super.onKeyPressed(keyCode, scanCode, modifiers);
124+
}
125+
113126
public class Selection extends Button {
114127
final Button original;
115128
final FadeAnimationController animation = new FadeAnimationController("DialogueSelection" + hashCode(), 200);
@@ -118,12 +131,12 @@ public class Selection extends Button {
118131
public Selection(Button original) {
119132
super(DialogueOverlay.this, original.getTitle(), original.getIcon());
120133
this.original = original;
121-
setSize(175, 18);
134+
setSize(175, 17);
122135
}
123136

124137
@Override
125138
public boolean hasTooltip() {
126-
return original.hasTooltip();
139+
return isMouseOver() && isVisible();
127140
}
128141

129142
@Override
@@ -150,30 +163,40 @@ public boolean isVisible() {
150163
@Override
151164
public void render(GuiGraphics graphics, int x, int y, int w, int h, RenderingHint hint) {
152165
if (!isVisible()) return;
153-
float change = 10F / ClientUtils.getMc().getFps();
154-
if (isEnabled())
155-
hover = Mth.clamp(hover + (isMouseOver ? change : -change), 0, 1);
166+
if (isEnabled()) {
167+
float change = 10F / ClientUtils.getMc().getFps();
168+
hover = Mth.clamp(hover + (isMouseOver ? change : -change), 0, 1.3F);
169+
}
170+
171+
// 到动画实际显示前的延迟
172+
float delay = 0.3F;
173+
float h2 = hover < delay ? 0 : hover-delay;
156174

157175
graphics.pose().pushPose();
158-
graphics.pose().translate(16*(1-animation.progress+(hover*hover*0.5F)), 0, 0);
176+
graphics.pose().translate(16*(1-animation.progress+(h2*h2*0.5F)), 0, 0);
159177
graphics.setColor(1, 1, 1, animation.progress);
160178

161179
animation.update();
162-
int color = Colors.blend(Colors.themeColor(), Colors.setAlpha(Colors.BLACK, 0.5F), hover*hover*0.5F);
180+
int color = Colors.blend(Colors.themeColor(), Colors.setAlpha(Colors.BLACK, 0.5F), h2*h2*0.5F);
163181
TesselateHelper.getShapeTesslator()
164-
.fillRect(graphics.pose().last().pose(), x, y+1, x+100, y+h-2, color)
165-
.fillGradient(graphics.pose().last().pose(), x+100, y+1, x+150, y+h-2, color, Colors.setAlpha(color, 0))
182+
.fillRect(graphics.pose().last().pose(), x, y+1, x+100, y+h-1, color)
183+
.fillGradient(graphics.pose().last().pose(), x+100, y+1, x+150, y+h-1, color, Colors.setAlpha(color, 0))
166184
.close();
167-
if (hasIcon() && animation.progress > 0.5F) {
168-
icon.draw(graphics, x+4, y+3, 10, 10);
169-
}
185+
if (hasIcon() && animation.progress > 0.5F)
186+
icon.draw(graphics, x + 4, y + 3, 10, 10);
170187
if (!isEnabled())
171-
graphics.setColor(1, 1, 1, 0.5F);
188+
graphics.setColor(1, 1, 1, 0.35F);
172189
graphics.drawString(getFont(), getTitle(), x+18, y+4, Colors.setAlpha(Colors.themeColor(), Math.max(animation.progress, 0.05F)));
173190

174191
graphics.setColor(1, 1, 1, 1);
175192
graphics.pose().popPose();
176193
}
194+
195+
@Override
196+
public void onClosed() {
197+
super.onClosed();
198+
animation.close();
199+
}
177200
}
178201

179202
@Getter

src/main/java/com/teammoeg/frostedheart/content/ui/keyhint/KeyHintRegistrate.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public static void init() {
4141
}
4242
if (!sled.hasPuller()) {
4343
for (Mob mob : ClientUtils.getWorld().getEntitiesOfClass(Mob.class, new AABB(player.blockPosition()).inflate(5))) {
44-
if (mob instanceof Wolf wolf && wolf.isOwnedBy(player) && wolf.getLeashHolder() == player) {
45-
return List.of(customHint(Component.translatable("key.mouse.right"), Component.translatable("hint.frostedheart.sled.leash")));
44+
if (mob instanceof Wolf wolf && wolf.isOwnedBy(player)) {
45+
if (wolf.getLeashHolder() == player) {
46+
return List.of(customHint(Component.translatable("key.mouse.right"), Component.translatable("hint.frostedheart.sled.leash")));
47+
} else {
48+
return List.of(customHint(Component.empty(), Component.translatable("hint.frostedheart.sled.wolf")));
49+
}
4650
}
4751
}
4852
}

0 commit comments

Comments
 (0)