feat: support to select item in GuiItemList
package unknowndomaingame.foundation.client.gui.game;
import nullengine.client.gui.component.ItemView;
+import nullengine.client.gui.event.MouseEvent;
import nullengine.client.gui.layout.AnchorPane;
import nullengine.client.gui.layout.HBox;
import nullengine.client.gui.layout.VBox;
import nullengine.client.gui.misc.Background;
import nullengine.client.gui.text.Text;
import nullengine.client.rendering.RenderContext;
+import nullengine.entity.component.TwoHands;
import nullengine.item.Item;
import nullengine.item.ItemStack;
+import nullengine.registry.Registries;
import nullengine.util.Color;
import java.util.Map;
@@ -25,8 +28,15 @@ public class GuiItemList extends AnchorPane {
var text = new Text("Registered Item List");
vBox.getChildren().add(text);
var hBox = new HBox();
- for (Map.Entry<String, Item> entry : context.getEngine().getCurrentGame().getRegistryManager().getRegistry(Item.class).getEntries()) {
- ItemView view = new ItemView(new ItemStack(entry.getValue()));
+ for (Map.Entry<String, Item> entry : Registries.getItemRegistry().getEntries()) {
+ ItemView view = new ItemView(new ItemStack(entry.getValue())) {
+ @Override
+ public void onClick(MouseEvent.MouseClickEvent event) {
+ context.getEngine().getCurrentGame().getPlayer().getControlledEntity()
+ .getComponent(TwoHands.class)
+ .ifPresent(twoHands -> twoHands.setMainHand(item().getValue()));
+ }
+ };
view.viewSize().set(40);
hBox.getChildren().add(view);
}
