use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.
the class GuiProgrammer method tryConnectToThis.
private void tryConnectToThis(int x, int y, IIcon icon, Connection connection) {
if (x < 0 || x >= GRID_WIDTH) {
return;
}
if (y < 0 || y >= GRID_HEIGHT) {
return;
}
IconHolder holder = getHolder(x, y);
IIcon sourceIcon = holder.getIcon();
if (sourceIcon != null) {
Opcode opcode = Opcodes.OPCODES.get(sourceIcon.getID());
if (opcode.getOpcodeOutput() == OpcodeOutput.NONE) {
return;
} else if (opcode.getOpcodeOutput() == OpcodeOutput.SINGLE) {
int cnt = countConnections(sourceIcon);
if (cnt == 0) {
sourceIcon.addOverlay(CONNECTION_ICONS.get(connection));
}
} else if (opcode.getOpcodeOutput() == OpcodeOutput.YESNO) {
int cnt = countPrimaryConnections(sourceIcon);
if (cnt == 0) {
sourceIcon.addOverlay(CONNECTION_ICONS.get(connection));
} else {
cnt = countSecondaryConnections(sourceIcon);
if (cnt == 0) {
sourceIcon.addOverlay(CONNECTION_ICONS.get(connection.getOpposite()));
}
}
}
}
}
use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.
the class GuiProgrammer method initIcons.
private void initIcons() {
if (ICONS.isEmpty()) {
for (Map.Entry<String, Opcode> entry : Opcodes.OPCODES.entrySet()) {
String id = entry.getKey();
Opcode opcode = entry.getValue();
ResourceLocation iconResource = icons;
if (opcode.getIconResource() != null) {
iconResource = new ResourceLocation(opcode.getIconResource());
}
ICONS.put(id, new ImageIcon(id).setDimensions(ICONSIZE, ICONSIZE).setImage(iconResource, opcode.getIconU() * ICONSIZE, opcode.getIconV() * ICONSIZE));
}
}
}
use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.
the class GuiProgrammer method getIconTooltip.
private List<String> getIconTooltip(IIcon icon) {
if (icon != null) {
Opcode opcode = Opcodes.OPCODES.get(icon.getID());
List<String> description = opcode.getDescription();
List<String> tooltips = new ArrayList<>();
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
tooltips.addAll(description);
for (ParameterDescription parameter : opcode.getParameters()) {
boolean first = true;
for (int i = 0; i < parameter.getDescription().size(); i++) {
String s = parameter.getDescription().get(i);
if (first) {
s = TextFormatting.BLUE + "Par '" + parameter.getName() + "': " + s;
first = false;
} else {
s = TextFormatting.BLUE + " " + s;
}
if (parameter.isOptional() && i == parameter.getDescription().size() - 1) {
s += TextFormatting.GOLD + " [Optional]";
}
tooltips.add(s);
}
}
tooltips.add(TextFormatting.YELLOW + "Result: " + opcode.getOutputDescription());
} else {
tooltips.add(description.get(0));
tooltips.add("<Shift for more info>");
}
return tooltips;
}
return Collections.emptyList();
}
use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.
the class GuiProgrammer method setEditorPanel.
private void setEditorPanel(IconHolder iconHolder, IIcon icon) {
String id = icon.getID();
Opcode opcode = Opcodes.OPCODES.get(id);
Map<String, Object> data = icon.getData() == null ? Collections.emptyMap() : icon.getData();
clearEditorPanel();
for (ParameterDescription parameter : opcode.getParameters()) {
String name = parameter.getName();
ParameterValue value = (ParameterValue) data.get(name);
Panel panel;
if (value != null) {
panel = createValuePanel(parameter, icon, iconHolder, ParameterTypeTools.stringRepresentation(parameter.getType(), value), opcode.isEvent());
} else {
panel = createValuePanel(parameter, icon, iconHolder, "", opcode.isEvent());
}
editorList.addChild(panel);
}
}
use of mcjty.rftoolscontrol.api.code.Opcode in project RFToolsControl by McJty.
the class GuiProgrammer method handleIconOverlay.
private void handleIconOverlay(IIcon icon, Connection connection) {
Opcode opcode = Opcodes.OPCODES.get(icon.getID());
if (opcode.getOpcodeOutput() == OpcodeOutput.NONE) {
return;
}
if (opcode.getOpcodeOutput() == OpcodeOutput.SINGLE) {
boolean has = icon.hasOverlay(connection.getId());
for (Connection c : Connection.values()) {
icon.removeOverlay(c.getId());
}
if (!has) {
if (!icon.hasOverlay(connection.getId())) {
icon.addOverlay(CONNECTION_ICONS.get(connection));
}
}
} else {
if (icon.hasOverlay(connection.getId())) {
icon.removeOverlay(Connection.DOWN_NEG.getId());
icon.removeOverlay(Connection.UP_NEG.getId());
icon.removeOverlay(Connection.LEFT_NEG.getId());
icon.removeOverlay(Connection.RIGHT_NEG.getId());
icon.removeOverlay(connection.getId());
icon.addOverlay(CONNECTION_ICONS.get(connection.getOpposite()));
} else if (icon.hasOverlay(connection.getOpposite().getId())) {
icon.removeOverlay(connection.getOpposite().getId());
} else {
if (connection.isPrimary()) {
icon.removeOverlay(Connection.DOWN.getId());
icon.removeOverlay(Connection.UP.getId());
icon.removeOverlay(Connection.LEFT.getId());
icon.removeOverlay(Connection.RIGHT.getId());
} else {
icon.removeOverlay(Connection.DOWN_NEG.getId());
icon.removeOverlay(Connection.UP_NEG.getId());
icon.removeOverlay(Connection.LEFT_NEG.getId());
icon.removeOverlay(Connection.RIGHT_NEG.getId());
}
icon.addOverlay(CONNECTION_ICONS.get(connection));
}
}
}
Aggregations