@@ -32,7 +32,6 @@ public class DeathLogScreen extends BaseUIModelScreen<FlowLayout> {
3232 private final DirectDeathLogStorage storage ;
3333
3434 private FlowLayout detailPanel ;
35- private DropdownComponent activeDropdown = null ;
3635
3736 private final Observable <String > currentSearchTerm = Observable .of ("" );
3837 private boolean canRestore = true ;
@@ -118,28 +117,29 @@ private void buildDeathList() {
118117 container .mouseDown ().subscribe ((mouseX , mouseY , button ) -> {
119118 if (button != GLFW .GLFW_MOUSE_BUTTON_RIGHT ) return false ;
120119
121- this .uiAdapter .rootComponent .removeChild (this .activeDropdown );
122- this .uiAdapter .rootComponent .child (Components .dropdown (Sizing .content ()).<DropdownComponent >configure (dropdown -> {
123- this .activeDropdown = dropdown ;
124-
125- if (this .canRestore ) {
126- dropdown .button (Text .translatable ("text.deathlog.action.restore" ), dropdown_ -> {
127- this .storage .restore (infoIndex );
128- this .removeDropdown ();
129- });
130- }
131-
132- dropdown .button (Text .translatable ("text.deathlog.action.delete" ), dropdown_ -> {
120+ var root = this .uiAdapter .rootComponent ;
121+ DropdownComponent .openContextMenu (
122+ this ,
123+ root , FlowLayout ::child ,
124+ container .x () - root .padding ().get ().left () + mouseX ,
125+ container .y () - root .padding ().get ().top () + mouseY ,
126+ dropdown -> {
127+ dropdown .surface (Surface .flat (0xBB000000 ).and (Surface .outline (0xA75F5F5F )));
128+
129+ if (this .canRestore ) {
130+ dropdown .button (Text .translatable ("text.deathlog.action.restore" ), dropdown_ -> {
131+ this .storage .restore (infoIndex );
132+ dropdown .remove ();
133+ });
134+ }
135+
136+ dropdown .button (Text .translatable ("text.deathlog.action.delete" ), dropdown_ -> {
133137 this .storage .delete (deathInfo );
134138 this .buildDeathList ();
135- this .removeDropdown ();
136- })
137- .surface (Surface .flat (0xBB000000 ))
138- .positioning (Positioning .absolute (
139- container .x () + (int ) mouseX - this .uiAdapter .rootComponent .padding ().get ().left (),
140- container .y () + (int ) mouseY - this .uiAdapter .rootComponent .padding ().get ().top ()
141- ));
142- }));
139+ dropdown .remove ();
140+ });
141+ }
142+ );
143143
144144 return true ;
145145 });
@@ -242,20 +242,6 @@ private ItemComponent makeItem(ItemStack stack, Insets margins) {
242242 return item ;
243243 }
244244
245- private void removeDropdown () {
246- this .uiAdapter .rootComponent .removeChild (this .activeDropdown );
247- this .activeDropdown = null ;
248- }
249-
250- @ Override
251- public boolean mouseClicked (double mouseX , double mouseY , int button ) {
252- if (this .activeDropdown != null && !this .activeDropdown .isInBoundingBox (mouseX , mouseY )) {
253- this .removeDropdown ();
254- }
255-
256- return super .mouseClicked (mouseX , mouseY , button );
257- }
258-
259245 @ Override
260246 public void close () {
261247 this .client .setScreen (this .parent );
0 commit comments