From 50ad6dcfc627adea1dff945de56671b2357d201c Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 24 Oct 2024 13:30:44 -0400 Subject: [PATCH] craftingpanel implementation --- assets/Data/game/recipes.json | 17 ++ docs/src/progress/renderertodo.md | 3 + .../client/ui/components/CraftingPanel.java | 152 ++++++++++++++++++ .../mainmenu/MenuGeneratorsUITesting.java | 5 + .../game/data/crafting/RecipeData.java | 13 ++ 5 files changed, 190 insertions(+) create mode 100644 src/main/java/electrosphere/client/ui/components/CraftingPanel.java diff --git a/assets/Data/game/recipes.json b/assets/Data/game/recipes.json index a2b8ab22..8a2086b1 100644 --- a/assets/Data/game/recipes.json +++ b/assets/Data/game/recipes.json @@ -2,6 +2,7 @@ "recipes": [ { "id": 0, + "displayName": "Katana (Two Hand)", "ingredients": [ { "itemType": "katana2H", @@ -14,6 +15,22 @@ "count": 1 } ] + }, + { + "id": 1, + "displayName": "Katana (One Hand)", + "ingredients": [ + { + "itemType": "katana", + "count": 1 + } + ], + "products": [ + { + "itemType": "katana", + "count": 1 + } + ] } ], "files": [ diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 0f8673e7..9e70631a 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -903,6 +903,9 @@ Notes on biomes OpenSimplex util class Chemistry system collision engine instance on server and client +(10/24/2024) +CraftingPanel implementation + # TODO diff --git a/src/main/java/electrosphere/client/ui/components/CraftingPanel.java b/src/main/java/electrosphere/client/ui/components/CraftingPanel.java new file mode 100644 index 00000000..f738458a --- /dev/null +++ b/src/main/java/electrosphere/client/ui/components/CraftingPanel.java @@ -0,0 +1,152 @@ +package electrosphere.client.ui.components; + +import electrosphere.client.ui.menu.WindowStrings; +import electrosphere.engine.Globals; +import electrosphere.engine.signal.Signal.SignalType; +import electrosphere.game.data.crafting.RecipeData; +import electrosphere.game.data.crafting.RecipeIngredientData; +import electrosphere.renderer.ui.elements.Button; +import electrosphere.renderer.ui.elements.Div; +import electrosphere.renderer.ui.elements.Label; +import electrosphere.renderer.ui.elements.VirtualScrollable; +import electrosphere.renderer.ui.elementtypes.Element; +import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; + +/** + * The crafting panel + */ +public class CraftingPanel { + + /** + * The title of the panel + */ + public static final String PANEL_TITLE = "Crafting"; + + + /** + * The width of the recipe scrollable + */ + public static final int SCROLLABLE_WIDTH = 500; + + /** + * The height of the recipe scrollable + */ + public static final int SCROLLABLE_HEIGHT = 800; + + /** + * The width of the details section + */ + public static final int DETAILS_WIDTH = 500; + + /** + * The height of the spacer on the details panel + */ + public static final int DETAILS_SPACER_HEIGHT = 10; + + /** + * The selected recipe + */ + private static RecipeData selectedRecipe = null; + + + /** + * Creates the crafting panel component + * @return The component + */ + public static Element createCraftingPanelComponent(){ + + //top level element + Div rVal = Div.createCol(); + + + //title label + Label titleLabel = Label.createLabel(PANEL_TITLE); + titleLabel.setMarginBottom(DETAILS_SPACER_HEIGHT); + + + + //details about the current recipe selected + Div recipeDetailsSection = Div.createDiv(); + recipeDetailsSection.setWidth(DETAILS_WIDTH); + recipeDetailsSection.setHeight(SCROLLABLE_HEIGHT); + + + + //select the first recipe + selectedRecipe = Globals.gameConfigCurrent.getRecipeMap().getTypes().iterator().next(); + setDetails(rVal, recipeDetailsSection, selectedRecipe); + + + + //the scrollable containing the list of recipes to select + VirtualScrollable recipeScrollable = new VirtualScrollable(SCROLLABLE_WIDTH, SCROLLABLE_HEIGHT); + Globals.gameConfigCurrent.getRecipeMap().getTypes().forEach((RecipeData recipe) -> { + Button recipeButton = Button.createButton(recipe.getDisplayName(), () -> { + setDetails(rVal, recipeDetailsSection, selectedRecipe); + }); + recipeScrollable.addChild(recipeButton); + }); + + + + //the button to actually craft + Button craftButton = Button.createButton("Craft", () -> { + System.out.println("Craft an item here"); + }); + Div buttonRow = Div.createRow( + craftButton + ); + + + + //actually layout the panel + rVal.addChild(titleLabel); + rVal.addChild(Div.createRow( + recipeScrollable, + recipeDetailsSection + )); + rVal.addChild(buttonRow); + rVal.setAlignItems(YogaAlignment.Center); + + return rVal; + } + + /** + * Sets the details panel when a recipe is selected + * @param detailsPanel The details panel + * @param currentRecipe The recipe that was selected + */ + private static void setDetails(Div topLevelEl, Div detailsPanel, RecipeData currentRecipe){ + Globals.signalSystem.post(SignalType.UI_MODIFICATION,() -> { + //clear the panel + detailsPanel.clearChildren(); + + //ingredients + detailsPanel.addChild(Label.createLabel("Ingredients")); + currentRecipe.getIngredients().forEach((RecipeIngredientData ingredient) -> { + Label label = Label.createLabel(ingredient.getItemType()); + label.setMarginTop(5); + label.setMarginLeft(15); + detailsPanel.addChild(label); + }); + + //spacer + Div spacerDiv = Div.createDiv(); + spacerDiv.setMarginBottom(DETAILS_SPACER_HEIGHT); + detailsPanel.addChild(spacerDiv); + + //products + detailsPanel.addChild(Label.createLabel("Products")); + currentRecipe.getProducts().forEach((RecipeIngredientData ingredient) -> { + Label label = Label.createLabel(ingredient.getItemType()); + label.setMarginTop(5); + label.setMarginLeft(15); + detailsPanel.addChild(label); + }); + + //apply yoga + Globals.signalSystem.post(SignalType.YOGA_APPLY, Globals.elementService.getWindow(WindowStrings.WINDOW_CHARACTER)); + }); + } + +} diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java index f2d84f97..0e2cc124 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java @@ -8,6 +8,7 @@ import org.joml.Vector3f; import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.ui.components.CharacterCustomizer; +import electrosphere.client.ui.components.CraftingPanel; import electrosphere.client.ui.components.EquipmentInventoryPanel; import electrosphere.client.ui.components.InputMacros; import electrosphere.client.ui.components.NaturalInventoryPanel; @@ -63,6 +64,7 @@ public class MenuGeneratorsUITesting { "EquipInventoryPanel", "VoxelPicker", "EntitySpawnPicker", + "CraftingPanel", }), (ValueChangeEvent event) -> { attachComponent(rVal,event.getAsString()); @@ -151,6 +153,9 @@ public class MenuGeneratorsUITesting { System.out.println(entType.getId()); })); } break; + case "CraftingPanel": { + formEl.addChild(CraftingPanel.createCraftingPanelComponent()); + } break; } } diff --git a/src/main/java/electrosphere/game/data/crafting/RecipeData.java b/src/main/java/electrosphere/game/data/crafting/RecipeData.java index 4670f5d9..c97eac78 100644 --- a/src/main/java/electrosphere/game/data/crafting/RecipeData.java +++ b/src/main/java/electrosphere/game/data/crafting/RecipeData.java @@ -11,6 +11,11 @@ public class RecipeData { * The id of the recipe */ int id; + + /** + * The display name for the recipe + */ + String displayName; /** * The ingredients required for the recipe @@ -70,6 +75,14 @@ public class RecipeData { this.id = id; } + /** + * Gets the display name + * @return The display name + */ + public String getDisplayName(){ + return displayName; + } +