11package com .teammoeg .frostedheart .content .ui .dialogue ;
22
33import com .teammoeg .chorda .client .AnimationUtil ;
4+ import com .teammoeg .chorda .client .CInputHelper ;
45import com .teammoeg .chorda .client .ClientUtils ;
56import com .teammoeg .chorda .client .RenderingHint ;
67import com .teammoeg .chorda .client .TesselateHelper ;
1819import net .minecraft .network .chat .Component ;
1920import net .minecraft .util .Mth ;
2021
22+ import java .util .ArrayList ;
2123import java .util .Collection ;
22- import java .util .HashSet ;
23- import java .util .Set ;
24+ import java .util .List ;
2425
2526public 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
0 commit comments