use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class GuiProgrammer method validateProgram.
private void validateProgram() {
Panel panel = new Panel(mc, this).setLayout(new VerticalLayout()).setFilledBackground(0xff666666, 0xffaaaaaa).setFilledRectThickness(1);
panel.setBounds(new Rectangle(60, 10, 200, 130));
Window modalWindow = getWindowManager().createModalWindow(panel);
WidgetList errorList = new WidgetList(mc, this);
errorList.addSelectionEvent(new SelectionEvent() {
@Override
public void select(Widget parent, int index) {
}
@Override
public void doubleClick(Widget parent, int index) {
if (errorList.getSelected() != -1) {
Widget<?> child = errorList.getChild(errorList.getSelected());
GridPos pos = (GridPos) child.getUserObject();
if (pos != null) {
window.setTextFocus(getHolder(pos.getX(), pos.getY()));
}
}
getWindowManager().closeWindow(modalWindow);
}
});
panel.addChild(errorList);
panel.addChild(new Button(mc, this).addButtonEvent(w -> {
getWindowManager().closeWindow(modalWindow);
}).setText("Close"));
ProgramCardInstance instance = makeGridInstance(false);
List<Pair<GridPos, String>> errors = ProgramValidator.validate(instance);
for (Pair<GridPos, String> entry : errors) {
GridPos p = entry.getKey();
errorList.addChild(new Label(mc, this).setColor(0xffff0000).setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT).setText(entry.getValue()).setUserObject(p));
}
}
use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class GuiProgrammer method handleConnectorHighlight.
private void handleConnectorHighlight(int finalX, int finalY, IIcon iIcon, int dx, int dy) {
if (prevHighlightConnector != null) {
IconHolder h = getHolder(prevHighlightConnector.getX(), prevHighlightConnector.getY());
if (h.getIcon() != null) {
h.getIcon().removeOverlay("H");
}
prevHighlightConnector = null;
}
if (iIcon == null) {
return;
}
iIcon.removeOverlay("H");
Connection connection = getConnectionHandle(dx, dy);
if (connection != null) {
iIcon.addOverlay(HIGHLIGHT_ICONS.get(connection));
prevHighlightConnector = new GridPos(finalX, finalY);
}
}
use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class GuiProgrammer method mergeProgram.
private void mergeProgram(ProgramCardInstance instance, GridPos pos) {
// Find the left-most/top-most icon in this program
GridPos leftTop = new GridPos(10000, 10000);
int posx;
int posy;
if (pos == null) {
posx = 0;
posy = 0;
leftTop = new GridPos(0, 0);
} else {
posx = pos.getX();
posy = pos.getY();
for (Map.Entry<GridPos, GridInstance> entry : instance.getGridInstances().entrySet()) {
int x = entry.getKey().getX();
int y = entry.getKey().getY();
if (x < leftTop.getX()) {
leftTop = entry.getKey();
} else if (x == leftTop.getX() && y < leftTop.getY()) {
leftTop = entry.getKey();
}
}
if (leftTop.getX() > 1000) {
// Nothing to do
return;
}
}
// Check if the program fits in the grid
for (Map.Entry<GridPos, GridInstance> entry : instance.getGridInstances().entrySet()) {
int x = entry.getKey().getX() - leftTop.getX() + posx;
int y = entry.getKey().getY() - leftTop.getY() + posy;
if (!checkValidGridPos(new GridPos(x, y))) {
GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "No room for clipboard here!");
return;
}
if (getHolder(x, y).getIcon() != null) {
GuiTools.showMessage(mc, this, getWindowManager(), 50, 50, TextFormatting.RED + "No room for clipboard here!");
return;
}
}
// There is room
for (Map.Entry<GridPos, GridInstance> entry : instance.getGridInstances().entrySet()) {
int x = entry.getKey().getX() - leftTop.getX() + posx;
int y = entry.getKey().getY() - leftTop.getY() + posy;
loadGridInstance(entry, x, y);
}
}
use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class GuiProgrammer method setupGridPanel.
private Panel setupGridPanel() {
Panel panel = new Panel(mc, this).setLayout(new PositionalLayout()).setLayoutHint(new PositionalLayout.PositionalHint(5, 5, 246, 130));
gridList = new WidgetList(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(0, 0, 236, 130)).setPropagateEventsToChildren(true).setInvisibleSelection(true).setDrawHorizontalLines(false).setRowheight(ICONSIZE + 1);
Slider slider = new Slider(mc, this).setVertical().setScrollable(gridList).setLayoutHint(new PositionalLayout.PositionalHint(237, 0, 9, 130));
for (int y = 0; y < GRID_HEIGHT; y++) {
Panel rowPanel = new Panel(mc, this).setLayout(new HorizontalLayout().setSpacing(-1).setHorizontalMargin(0).setVerticalMargin(0));
for (int x = 0; x < GRID_WIDTH; x++) {
int finalX = x;
int finalY = y;
IconHolder holder = new IconHolder(mc, this) {
@Override
public List<String> getTooltips() {
return getGridIconTooltips(finalX, finalY);
}
}.setDesiredWidth(ICONSIZE + 2).setDesiredHeight(ICONSIZE + 2).setBorder(1).setBorderColor(0xff777777).setSelectable(true).setUserObject(new GridPos(finalX, finalY)).addIconHoverEvent(((iconHolder, iIcon, dx, dy) -> {
handleConnectorHighlight(finalX, finalY, iIcon, dx, dy);
})).addIconLeavesEvent(((parent, icon) -> {
iconLeavesFromX = finalX;
iconLeavesFromY = finalY;
return true;
})).addIconArrivesEvent(((parent, icon) -> {
if (icon != null && !loading) {
handleNewIconOverlay(icon, finalX, finalY);
}
return true;
})).addIconClickedEvent((parent, icon, dx, dy) -> {
gridIconClicked(icon, finalX, finalY, dx, dy);
return true;
});
rowPanel.addChild(holder);
}
gridList.addChild(rowPanel);
}
panel.addChild(gridList).addChild(slider);
return panel;
}
use of mcjty.rftoolscontrol.logic.grid.GridPos in project RFToolsControl by McJty.
the class ProgramValidator method validate.
public static List<Pair<GridPos, String>> validate(ProgramCardInstance program) {
List<Pair<GridPos, String>> errors = new ArrayList<>();
Map<GridPos, GridInstance> grid = program.getGridInstances();
// Find all unreachable instances:
Set<GridPos> reachableLocations = new HashSet<>();
for (Map.Entry<GridPos, GridInstance> entry : grid.entrySet()) {
GridInstance g = entry.getValue();
if (g.getPrimaryConnection() != null) {
reachableLocations.add(g.getPrimaryConnection().offset(entry.getKey()));
}
if (g.getSecondaryConnection() != null) {
reachableLocations.add(g.getSecondaryConnection().offset(entry.getKey()));
}
}
for (Map.Entry<GridPos, GridInstance> entry : grid.entrySet()) {
GridInstance g = entry.getValue();
Opcode opcode = Opcodes.OPCODES.get(g.getId());
GridPos p = entry.getKey();
if (!opcode.isEvent() && !reachableLocations.contains(p)) {
errors.add(Pair.of(p, "Unreachable: " + p.getX() + "," + p.getY()));
}
}
// Find all missing required parameters:
for (Map.Entry<GridPos, GridInstance> entry : grid.entrySet()) {
GridPos p = entry.getKey();
GridInstance g = entry.getValue();
Opcode opcode = Opcodes.OPCODES.get(g.getId());
List<ParameterDescription> descriptions = opcode.getParameters();
List<Parameter> parameters = g.getParameters();
for (int i = 0; i < descriptions.size(); i++) {
ParameterDescription desc = descriptions.get(i);
Parameter par = i < parameters.size() ? parameters.get(i) : null;
if (!desc.isOptional()) {
if (par == null || par.getParameterValue() == null || (par.getParameterValue().isConstant() && par.getParameterValue().getValue() == null)) {
errors.add(Pair.of(p, "Missing parameter (" + desc.getName() + "): " + p.getX() + "," + p.getY()));
}
}
}
}
return errors;
}
Aggregations