Skip to content

Commit 513716c

Browse files
committed
1.加快动画速度;
2.显示鼠标; 3.添加关闭轮盘选项; 4.没有选项时不再捕获鼠标
1 parent 93833e7 commit 513716c

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

src/main/java/com/teammoeg/frostedheart/content/tips/Popup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public static void put(Component message) {
114114
}
115115

116116
public static void put(String message) {
117+
if (message.isBlank())
118+
return;
117119
put(Components.translateOrElseStr(message));
118120
}
119121

src/main/java/com/teammoeg/frostedheart/content/wheelmenu/WheelMenuRenderer.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import net.minecraft.network.chat.Component;
4444
import net.minecraft.util.Mth;
4545
import net.minecraft.world.item.ItemStack;
46-
import net.minecraft.world.item.Items;
4746
import net.minecraftforge.api.distmarker.Dist;
4847
import net.minecraftforge.api.distmarker.OnlyIn;
4948
import net.minecraftforge.client.gui.overlay.ForgeGui;
@@ -72,21 +71,22 @@ public class WheelMenuRenderer {
7271
@Getter
7372
public static boolean isOpened;
7473
public static boolean isClosing;
75-
static float openningStatus;
74+
static float openingStatus;
75+
7676
public static void render(ForgeGui gui, GuiGraphics graphics, float partialTicks, int width, int height) {
77-
if(!isOpened)return;
78-
if (visibleSelections.isEmpty())
79-
return;
77+
if(!isOpened || visibleSelections.isEmpty()) return;
78+
8079
float p;
8180
if(isClosing)
82-
p=Mth.clamp((openningStatus+(1-partialTicks)*2)/6f, 0, 1);
81+
p=Mth.clamp((openingStatus +(1-partialTicks)*2)/3f, 0, 1);
8382
else
84-
p=Mth.clamp((openningStatus+(partialTicks))/6f, 0, 1);
83+
p=Mth.clamp((openingStatus + partialTicks)/3f, 0, 1);
8584
int size = visibleSelections.size();
8685
int cw = ClientUtils.screenCenterX();
8786
int ch = ClientUtils.screenCenterY();
8887
var font = gui.getFont();
8988
var pose = graphics.pose();
89+
virtualScreen.addPos(MouseCaptureUtil.getAndResetCapturedX(),MouseCaptureUtil.getAndResetCapturedY());
9090

9191
pose.pushPose();
9292
pose.translate(cw, ch, 0);
@@ -97,8 +97,6 @@ public static void render(ForgeGui gui, GuiGraphics graphics, float partialTicks
9797
ColorHelper.setAlpha(ColorHelper.BLACK, 0.5F * p));
9898
FGuis.drawRing(graphics, 0, 0, WHEEL_INNER_RADIUS - 4, WHEEL_INNER_RADIUS - 2, 0, 360,
9999
ColorHelper.setAlpha(ColorHelper.BLACK, 0.5F * p));
100-
101-
102100

103101
float halfSliceSize = 360F / (size * 2);
104102
double radian = Math.atan2(virtualScreen.getX() , -(virtualScreen.getY()));
@@ -113,7 +111,7 @@ public static void render(ForgeGui gui, GuiGraphics graphics, float partialTicks
113111
hoveredSelection.hoverAction.execute(lastHovered);
114112
}
115113
} else {
116-
mouseMoved = !MouseHelper.isMouseIn(virtualScreen.getX(), virtualScreen.getY(), -25, -25, 50,50);
114+
mouseMoved = !MouseHelper.isMouseIn(virtualScreen.getX(), virtualScreen.getY(), -10, -10, 20,20);
117115
hoveredSelection = null;
118116
}
119117
// 跟随鼠标移动的细圆环
@@ -123,7 +121,7 @@ public static void render(ForgeGui gui, GuiGraphics graphics, float partialTicks
123121
ColorHelper.setAlpha(ColorHelper.CYAN, p));
124122
pose.popPose();
125123

126-
// 选择选项的圆环
124+
// 当前选择的选项的圆环
127125
pose.pushPose();
128126
pose.rotateAround(new Quaternionf().rotateZ((float) Math.toRadians(degrees.get(selectedIndex))), 0, 0, 0);
129127
FGuis.drawRing(graphics, 0, 0, WHEEL_INNER_RADIUS, WHEEL_OUTER_RADIUS, -halfSliceSize, halfSliceSize,
@@ -137,6 +135,10 @@ public static void render(ForgeGui gui, GuiGraphics graphics, float partialTicks
137135
visibleSelections.get(i).render(gui, graphics, partialTicks, width, height);
138136
}
139137

138+
// 渲染“鼠标”
139+
FGuis.drawRing(graphics, (int) virtualScreen.getX(), (int) virtualScreen.getY(), 3, 6, 0, 360,
140+
ColorHelper.setAlpha(ColorHelper.CYAN, p));
141+
140142
// 渲染选项标题
141143
if (hoveredSelection != null) {
142144
CGuiHelper.drawCenteredStrings(graphics, font,
@@ -168,19 +170,20 @@ protected static void init() {
168170
positions.clear();
169171
degrees.clear();
170172
// 在此处添加轮盘选项
173+
addSelection(new Selection(Component.translatable("gui.close"), IconButton.Icon.CROSS, Selection.NO_ACTION));
174+
171175
if (CompatModule.isFTBQLoaded()) {
172176
addSelection(new Selection(Component.translatable("key.ftbquests.quests"), FTBQuestsItems.BOOK,
173177
s -> FTBQuestsClient.openGui()));
174-
} else {
175-
176-
addSelection(new Selection(Component.literal("Open Quests"), Items.BOOK.getDefaultInstance(),
177-
Selection.NO_ACTION));
178178
}
179+
179180
addSelection(new Selection(Component.translatable("gui.frostedheart.wheel_menu.selection.debug"),
180181
FHItems.debug_item.get().getDefaultInstance(), ColorHelper.CYAN,
181182
s -> ClientUtils.getPlayer().isCreative(), s -> DebugScreen.openDebugScreen(), Selection.NO_ACTION));
183+
182184
addSelection(new Selection(Component.translatable("gui.frostedheart.wheel_menu.selection.nutrition"),
183185
NutritionScreen.fat_icon, s -> FHNetwork.sendToServer(new C2SOpenNutritionScreenMessage())));
186+
184187
addSelection(new Selection(Component.translatable("gui.frostedheart.wheel_menu.selection.clothing"),
185188
FHItems.gambeson.get().getDefaultInstance(),
186189
s -> FHNetwork.sendToServer(new C2SOpenClothesScreenMessage())));
@@ -208,26 +211,26 @@ private static void update() {
208211

209212
public static void tick() {
210213
if(ClientUtils.getPlayer()==null) {//not in world
211-
openningStatus=0;
214+
openingStatus =0;
212215
onClose();
213216
}
214217
if (FHKeyMappings.key_openWheelMenu.get().isDown()) {
215218
if(!isOpened) {
216-
MouseCaptureUtil.setCaptureMouse(true);
217219
init();
220+
if (!selections.isEmpty()) {
221+
MouseCaptureUtil.setCaptureMouse(true);
222+
}
218223
isOpened=true;
219224
}else {
220-
virtualScreen.addPos(MouseCaptureUtil.getAndResetCapturedX(),MouseCaptureUtil.getAndResetCapturedY());
221-
222-
if(openningStatus<6)
223-
openningStatus++;
225+
if(openingStatus <6)
226+
openingStatus++;
224227
}
225228
} else {
226-
if(openningStatus>0) {
229+
if(openingStatus >0) {
227230
isClosing=true;
228-
openningStatus-=2;
229-
if (openningStatus <= 0) {
230-
openningStatus=0;
231+
openingStatus -=2;
232+
if (openingStatus <= 0) {
233+
openingStatus =0;
231234
isClosing=false;
232235
onClose();
233236
}
@@ -251,10 +254,10 @@ public static void tick() {
251254
}
252255

253256
public static void onClose() {
254-
255257
MouseCaptureUtil.setCaptureMouse(false);
256258
virtualScreen.reset();
257259
isOpened=false;
260+
mouseMoved = false;
258261
if(ClientUtils.getPlayer()!=null&&hoveredSelection!=null) {
259262
hoveredSelection.selectAction.execute(hoveredSelection);
260263
}
@@ -266,8 +269,7 @@ private static void addSelection(Selection selection) {
266269

267270
public static class Selection {
268271
public static final Predicate<Selection> ALWAYS_VISIBLE = s -> true;
269-
public static final Action NO_ACTION = s -> {
270-
};
272+
public static final Action NO_ACTION = s -> {};
271273

272274
protected final Predicate<Selection> visibility;
273275
protected final Action selectAction;
@@ -286,28 +288,28 @@ public static class Selection {
286288
/**
287289
* @param icon {@link ItemStack}, {@link IconButton.Icon},
288290
* {@link Component}, {@code null}
289-
* @param pressAction 选择后的行动
291+
* @param selectAction 选择后的行动 (选中 -> 松开Tab)
290292
*/
291-
public Selection(Component message, Object icon, Action pressAction) {
292-
this(message, icon, ColorHelper.CYAN, ALWAYS_VISIBLE, pressAction, NO_ACTION);
293+
public Selection(Component message, Object icon, Action selectAction) {
294+
this(message, icon, ColorHelper.CYAN, ALWAYS_VISIBLE, selectAction, NO_ACTION);
293295
}
294296

295297
/**
296298
* @param icon {@link ItemStack}, {@link IconButton.Icon},
297299
* {@link Component}, {@code null}
298300
* @param color 图标为 {@link IconButton.Icon} 时的颜色
299301
* @param visibility 选项在什么情况下可见,每tick更新
300-
* @param pressAction 选择后的行动 (选中 -> 松开Tab)
302+
* @param selectAction 选择后的行动 (选中 -> 松开Tab)
301303
* @param hoverAction 选中选项后的行动
302304
*/
303-
public Selection(Component message, Object icon, int color, Predicate<Selection> visibility, Action pressAction,
305+
public Selection(Component message, Object icon, int color, Predicate<Selection> visibility, Action selectAction,
304306
Action hoverAction) {
305307
this.message = message;
306308
this.iconType = getIconType(icon);
307309
this.icon = icon;
308310
this.color = color;
309311
this.visibility = visibility;
310-
this.selectAction = pressAction;
312+
this.selectAction = selectAction;
311313
this.hoverAction = hoverAction;
312314
}
313315

@@ -320,6 +322,7 @@ protected void render(ForgeGui gui, GuiGraphics graphics, float partialTick, int
320322
}
321323
}
322324

325+
@SuppressWarnings("unused")
323326
protected void renderSelection(ForgeGui gui, GuiGraphics graphics, float partialTick, int width, int height) {
324327
switch (iconType) {
325328
case ITEM -> graphics.renderItem((ItemStack) icon, x - 8, y - 8);

0 commit comments

Comments
 (0)