craftingpanel implementation
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-10-24 13:30:44 -04:00
parent df8991e875
commit 50ad6dcfc6
5 changed files with 190 additions and 0 deletions

View File

@ -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": [

View File

@ -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

View File

@ -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));
});
}
}

View File

@ -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;
}
}

View File

@ -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;
}