This commit is contained in:
parent
d15da31a85
commit
8575693fe5
1 changed files with 66 additions and 57 deletions
|
@ -10,16 +10,20 @@ import finalforeach.cosmicreach.gamestates.InGame;
|
||||||
import finalforeach.cosmicreach.items.ItemSlot;
|
import finalforeach.cosmicreach.items.ItemSlot;
|
||||||
import finalforeach.cosmicreach.items.containers.SlotContainer;
|
import finalforeach.cosmicreach.items.containers.SlotContainer;
|
||||||
import finalforeach.cosmicreach.items.screens.BaseItemScreen;
|
import finalforeach.cosmicreach.items.screens.BaseItemScreen;
|
||||||
|
import finalforeach.cosmicreach.savelib.utils.TriConsumer;
|
||||||
import finalforeach.cosmicreach.ui.UI;
|
import finalforeach.cosmicreach.ui.UI;
|
||||||
import finalforeach.cosmicreach.ui.widgets.ItemSlotWidget;
|
import finalforeach.cosmicreach.ui.widgets.ItemSlotWidget;
|
||||||
import net.pietru.omni_power.OmniPower;
|
import net.pietru.omni_power.OmniPower;
|
||||||
import net.pietru.omni_power.blocks.CustomUIBlockEntity;
|
import net.pietru.omni_power.blocks.CustomUIBlockEntity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static net.pietru.omni_power.OmniPower.MOD_ID;
|
import static net.pietru.omni_power.OmniPower.MOD_ID;
|
||||||
|
|
||||||
public class CustomScreen extends BaseItemScreen {
|
public class CustomScreen extends BaseItemScreen {
|
||||||
|
public static final Map<String,TriConsumer<Table, CustomScreen,JsonValue>> components = new HashMap<>();
|
||||||
public static Skin skin = new Skin(GameAssetLoader.loadAsset(MOD_ID+":gdx-skins/default/skin/uiskin.json"));
|
public static Skin skin = new Skin(GameAssetLoader.loadAsset(MOD_ID+":gdx-skins/default/skin/uiskin.json"));
|
||||||
//vis/skin/x1/uiskin.json
|
//vis/skin/x1/uiskin.json
|
||||||
|
|
||||||
|
@ -71,63 +75,10 @@ public class CustomScreen extends BaseItemScreen {
|
||||||
String type = data.getString("type","");
|
String type = data.getString("type","");
|
||||||
if (type.isEmpty())
|
if (type.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
Button button;
|
if (!components.containsKey(type.toLowerCase()))
|
||||||
switch (type.toLowerCase()) {
|
continue;
|
||||||
case "row":
|
TriConsumer<Table, CustomScreen,JsonValue> component = components.get(type.toLowerCase());
|
||||||
table.row();
|
component.accept(table,screen,data);
|
||||||
break;
|
|
||||||
case "space":
|
|
||||||
table.add()
|
|
||||||
.height(data.getFloat("width",10F))
|
|
||||||
.height(data.getFloat("height",10F));
|
|
||||||
break;
|
|
||||||
case "label":
|
|
||||||
Label lbl = new Label(data.getString("text",""),skin);
|
|
||||||
lbl.setFontScale(data.getFloat("font_scale",1F));
|
|
||||||
table.add(lbl);
|
|
||||||
break;
|
|
||||||
case "change_ui_text_button":
|
|
||||||
button = new TextButton(data.getString("text",""),skin);
|
|
||||||
String ui_id = data.getString("gui_id","");
|
|
||||||
button.addListener(event -> {
|
|
||||||
if (!button.isPressed())
|
|
||||||
return false;
|
|
||||||
UI.openContainers.removeValue(screen.container, true);
|
|
||||||
InGame.IN_GAME.removeBaseItemScreen(screen);
|
|
||||||
addOpenContainer(screen.blockEntity,screen.blockEntity.slotContainer,ui_id);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
table.add(button);
|
|
||||||
break;
|
|
||||||
case "trigger_block_event_text_button":
|
|
||||||
button = new TextButton(data.getString("text", ""), skin);
|
|
||||||
String trigger_id = data.getString("trigger_id","");
|
|
||||||
button.addListener(event -> {
|
|
||||||
if (!button.isPressed())
|
|
||||||
return false;
|
|
||||||
UI.openContainers.removeValue(screen.container, true);
|
|
||||||
InGame.IN_GAME.removeBaseItemScreen(screen);
|
|
||||||
//INSERT CODE TO RUN BE TRIGGER
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
table.add(button);
|
|
||||||
break;
|
|
||||||
case "item_slot":
|
|
||||||
add_ui_slot(table,screen,data.getInt("slot",0),data.getBoolean("output",false));
|
|
||||||
break;
|
|
||||||
case "table":
|
|
||||||
JsonValue ui_layout = data.get("layout");
|
|
||||||
Table new_table = new Table();
|
|
||||||
build_ui(ui_layout,new_table,screen);
|
|
||||||
|
|
||||||
float default_width = Math.max(new_table.getColumns(),1) * 32;
|
|
||||||
new_table.setWidth(ui_layout.getFloat("width",default_width));
|
|
||||||
float default_height = Math.max(new_table.getRows(),1) * 32;
|
|
||||||
new_table.setHeight(ui_layout.getFloat("height",default_height));
|
|
||||||
|
|
||||||
table.add(new_table);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,4 +127,62 @@ public class CustomScreen extends BaseItemScreen {
|
||||||
screen.getActor().addAction(perFrameAct);
|
screen.getActor().addAction(perFrameAct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
//Table table, CustomScreen screen
|
||||||
|
components.put("row",(table,screen,data)->{
|
||||||
|
table.row();
|
||||||
|
});
|
||||||
|
components.put("space",(table,screen,data)->{
|
||||||
|
table.add()
|
||||||
|
.height(data.getFloat("width",10F))
|
||||||
|
.height(data.getFloat("height",10F));
|
||||||
|
});
|
||||||
|
components.put("label",(table,screen,data)->{
|
||||||
|
Label lbl = new Label(data.getString("text",""),skin);
|
||||||
|
lbl.setFontScale(data.getFloat("font_scale",1F));
|
||||||
|
table.add(lbl);
|
||||||
|
});
|
||||||
|
components.put("change_ui_text_button",(table,screen,data)->{
|
||||||
|
Button button = new TextButton(data.getString("text",""),skin);
|
||||||
|
String ui_id = data.getString("gui_id","");
|
||||||
|
button.addListener(event -> {
|
||||||
|
if (!button.isPressed())
|
||||||
|
return false;
|
||||||
|
UI.openContainers.removeValue(screen.container, true);
|
||||||
|
InGame.IN_GAME.removeBaseItemScreen(screen);
|
||||||
|
addOpenContainer(screen.blockEntity,screen.blockEntity.slotContainer,ui_id);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
table.add(button);
|
||||||
|
});
|
||||||
|
components.put("trigger_block_event_text_button",(table,screen,data)->{
|
||||||
|
Button button = new TextButton(data.getString("text", ""), skin);
|
||||||
|
String trigger_id = data.getString("trigger_id","");
|
||||||
|
button.addListener(event -> {
|
||||||
|
if (!button.isPressed())
|
||||||
|
return false;
|
||||||
|
UI.openContainers.removeValue(screen.container, true);
|
||||||
|
InGame.IN_GAME.removeBaseItemScreen(screen);
|
||||||
|
//INSERT CODE TO RUN BE TRIGGER
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
table.add(button);
|
||||||
|
});
|
||||||
|
components.put("item_slot",(table,screen,data)->{
|
||||||
|
add_ui_slot(table,screen,data.getInt("slot",0),data.getBoolean("output",false));
|
||||||
|
});
|
||||||
|
components.put("table",(table,screen,data)->{
|
||||||
|
JsonValue ui_layout = data.get("layout");
|
||||||
|
Table new_table = new Table();
|
||||||
|
build_ui(ui_layout,new_table,screen);
|
||||||
|
|
||||||
|
float default_width = Math.max(new_table.getColumns(),1) * 32;
|
||||||
|
new_table.setWidth(ui_layout.getFloat("width",default_width));
|
||||||
|
float default_height = Math.max(new_table.getRows(),1) * 32;
|
||||||
|
new_table.setHeight(ui_layout.getFloat("height",default_height));
|
||||||
|
|
||||||
|
table.add(new_table);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue