use of mcjty.rftoolscontrol.api.parameters.Parameter in project RFToolsControl by McJty.
the class GuiProgrammer method loadGridInstance.
private void loadGridInstance(Map.Entry<GridPos, GridInstance> entry, int x, int y) {
GridInstance gridInstance = entry.getValue();
IIcon icon = ICONS.get(gridInstance.getId());
if (icon == null) {
// Ignore missing icon
Logging.logError("Opcode with id '" + gridInstance.getId() + "' is missing!");
return;
}
icon = icon.clone();
if (gridInstance.getPrimaryConnection() != null) {
icon.addOverlay(CONNECTION_ICONS.get(gridInstance.getPrimaryConnection()));
}
if (gridInstance.getSecondaryConnection() != null) {
icon.addOverlay(CONNECTION_ICONS.get(gridInstance.getSecondaryConnection()));
}
Opcode opcode = Opcodes.OPCODES.get(icon.getID());
List<Parameter> parameters = gridInstance.getParameters();
for (int i = 0; i < parameters.size(); i++) {
String name = opcode.getParameters().get(i).getName();
icon.addData(name, parameters.get(i).getParameterValue());
}
loading = true;
getHolder(x, y).setIcon(icon);
loading = false;
}
use of mcjty.rftoolscontrol.api.parameters.Parameter in project RFToolsControl by McJty.
the class GuiProgrammer method createValuePanel.
private Panel createValuePanel(ParameterDescription parameter, IIcon icon, IconHolder iconHolder, String tempDefault, boolean constantOnly) {
Label<?> label = (Label<?>) new Label(mc, this).setText(StringUtils.capitalize(parameter.getName()) + ":").setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setDesiredHeight(13).setLayoutHint(new PositionalLayout.PositionalHint(0, 0, 53, 13));
List<String> description = new ArrayList<>(parameter.getDescription());
if (parameter.isOptional()) {
description.set(description.size() - 1, description.get(description.size() - 1) + TextFormatting.GOLD + " [Optional]");
}
if (tempDefault != null && !tempDefault.isEmpty()) {
description.add(TextFormatting.BLUE + tempDefault);
}
String[] tooltips = description.toArray(new String[description.size()]);
TextField field = new TextField(mc, this).setText(tempDefault).setTooltips(tooltips).setDesiredHeight(13).setEditable(false).setLayoutHint(new PositionalLayout.PositionalHint(0, 12, 68, 13));
Button button = new Button(mc, this).setText("...").setDesiredHeight(13).setTooltips(tooltips).addButtonEvent(w -> openValueEditor(icon, iconHolder, parameter, field, constantOnly)).setLayoutHint(new PositionalLayout.PositionalHint(58, 0, 11, 13));
return new Panel(mc, this).setLayout(new PositionalLayout()).addChild(label).addChild(field).addChild(button).setDesiredWidth(68);
}
use of mcjty.rftoolscontrol.api.parameters.Parameter in project RFToolsControl by McJty.
the class Commands method handleDebugCommand.
private static void handleDebugCommand(ProcessorTileEntity processor, String[] splitted) {
List<CpuCore> cores = processor.getCpuCores();
String sub = splitted[1].toLowerCase();
if ("debug".equals(sub)) {
if (splitted.length > 2) {
try {
int core = Integer.parseInt(splitted[2]);
cores.get(core).setDebug(true);
processor.log(TextFormatting.YELLOW + "Debug mode for core: " + core);
} catch (Exception e) {
processor.log(TextFormatting.RED + "Bad core number");
return;
}
} else {
for (CpuCore core : cores) {
core.setDebug(true);
}
processor.log(TextFormatting.YELLOW + "Debug mode for all cores");
}
} else if ("resume".equals(sub)) {
if (splitted.length > 2) {
try {
int core = Integer.parseInt(splitted[2]);
cores.get(core).setDebug(false);
processor.log(TextFormatting.YELLOW + "Resume core: " + core);
} catch (Exception e) {
processor.log(TextFormatting.RED + "Bad core number");
return;
}
} else {
for (CpuCore core : cores) {
core.setDebug(false);
}
processor.log(TextFormatting.YELLOW + "Resume all cores");
}
} else if ("info".equals(sub)) {
for (int i = 0; i < cores.size(); i++) {
CpuCore core = cores.get(i);
if (core.isDebug()) {
RunningProgram program = core.getProgram();
if (program == null) {
processor.log("Core " + i + ": " + "not running");
} else {
showCurrent(processor, i, program);
}
}
}
} else if ("last".equals(sub)) {
if (splitted.length > 2) {
try {
int i = Integer.parseInt(splitted[2]);
CpuCore core = cores.get(i);
if (core.hasProgram()) {
Parameter value = core.getProgram().getLastValue();
if (value == null || value.getParameterValue() == null) {
processor.log(TextFormatting.YELLOW + "Last value not set");
} else {
ParameterType type = value.getParameterType();
processor.log(TextFormatting.YELLOW + "Last " + type.getName() + ": " + TypeConverters.convertToString(value));
}
} else {
processor.log(TextFormatting.YELLOW + "No program!");
}
} catch (Exception e) {
processor.log(TextFormatting.RED + "Bad core number");
return;
}
} else {
int i = 0;
for (CpuCore core : cores) {
if (core.hasProgram()) {
Parameter value = core.getProgram().getLastValue();
if (value == null || value.getParameterValue() == null) {
processor.log(TextFormatting.YELLOW + "" + i + ": Last value not set");
} else {
ParameterType type = value.getParameterType();
processor.log(TextFormatting.YELLOW + "" + i + ": Last " + type.getName() + ": " + TypeConverters.convertToString(value));
}
}
i++;
}
}
} else if ("step".equals(sub) || "s".equals(sub)) {
int cnt = 0;
for (CpuCore core : cores) {
if (core.isDebug()) {
cnt++;
}
}
int c = 0;
if (cnt == 0) {
processor.log(TextFormatting.RED + "Not debugging");
return;
} else if (cnt > 1) {
if (splitted.length <= 2) {
processor.log(TextFormatting.RED + "Missing core number");
return;
}
try {
c = Integer.parseInt(splitted[2]);
} catch (Exception e) {
processor.log(TextFormatting.RED + "Bad core number");
return;
}
}
CpuCore core = cores.get(c);
RunningProgram program = core.getProgram();
if (program == null) {
processor.log(TextFormatting.RED + "Core " + c + ": " + "not running");
return;
}
core.step(processor);
showCurrent(processor, c, program);
} else {
processor.log("Unknown 'db' command!");
}
}
use of mcjty.rftoolscontrol.api.parameters.Parameter in project RFToolsControl by McJty.
the class GuiProcessor method openValueEditor.
private void openValueEditor(int varIdx) {
if (fromServer_vars == null || varIdx > fromServer_vars.size()) {
return;
}
if (fromServer_vars.get(varIdx) == null) {
GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, "Variable is not defined!");
return;
}
Parameter parameter = fromServer_vars.get(varIdx);
if (parameter == null) {
GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, "Variable is not defined!");
return;
}
ParameterType type = parameter.getParameterType();
ParameterEditor editor = ParameterEditors.getEditor(type);
Panel editPanel;
if (editor != null) {
editPanel = new Panel(mc, this).setLayout(new PositionalLayout()).setFilledRectThickness(1);
editor.build(mc, this, editPanel, o -> {
NBTTagCompound tag = new NBTTagCompound();
ParameterTypeTools.writeToNBT(tag, type, o);
RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketVariableToServer(tileEntity.getPos(), varIdx, tag));
});
editor.writeValue(parameter.getParameterValue());
editor.constantOnly();
} else {
return;
}
Panel panel = new Panel(mc, this).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
panel.setBounds(new Rectangle(50, 50, 200, 60 + editor.getHeight()));
Window modalWindow = getWindowManager().createModalWindow(panel);
panel.addChild(new Label(mc, this).setText("Var " + varIdx + ":"));
panel.addChild(editPanel);
panel.addChild(new Button(mc, this).addButtonEvent(w -> {
getWindowManager().closeWindow(modalWindow);
}).setText("Close"));
}
use of mcjty.rftoolscontrol.api.parameters.Parameter in project RFToolsControl by McJty.
the class VariableClientScreenModule method render.
@Override
public void render(IModuleRenderHelper renderHelper, FontRenderer fontRenderer, int currenty, ModuleDataVariable screenData, ModuleRenderInfo renderInfo) {
if (labelCache == null) {
labelCache = renderHelper.createTextRenderHelper().align(textAlign);
}
GlStateManager.disableLighting();
int xoffset;
if (!line.isEmpty()) {
labelCache.setup(line, 160, renderInfo);
labelCache.renderText(0, currenty, color, renderInfo);
xoffset = 7 + 40;
} else {
xoffset = 7;
}
if (screenData != null) {
Parameter parameter = screenData.getParameter();
if (parameter != null && parameter.getParameterValue() != null) {
String str = TypeConverters.convertToString(parameter);
renderHelper.renderText(xoffset, currenty, varcolor, renderInfo, str);
}
}
}
Aggregations