Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

public class WidgetListSyncmaticaServerPlacement extends WidgetListBase<ServerPlacement, WidgetSyncmaticaServerPlacementEntry> {

public final GuiSyncmaticaServerPlacementList parent;
private final int infoWidth;
private final int infoHeight;
private final GuiSyncmaticaServerPlacementList parent;

public WidgetListSyncmaticaServerPlacement(final int x, final int y, final int width, final int height, final GuiSyncmaticaServerPlacementList parent,
final ISelectionListener<ServerPlacement> selectionListener) {
Expand Down Expand Up @@ -125,7 +125,7 @@ protected List<String> getEntryStringsForFilter(final ServerPlacement entry) {

@Override
protected WidgetSyncmaticaServerPlacementEntry createListEntryWidget(final int x, final int y, final int listIndex, final boolean isOdd, final ServerPlacement entry) {
return new WidgetSyncmaticaServerPlacementEntry(x, y, browserEntryWidth, getBrowserEntryHeightFor(entry), entry, listIndex);
return new WidgetSyncmaticaServerPlacementEntry(x, y, browserEntryWidth, getBrowserEntryHeightFor(entry), entry, listIndex, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import ch.endte.syncmatica.communication.ExchangeTarget;
import ch.endte.syncmatica.communication.PacketType;
import ch.endte.syncmatica.litematica.LitematicManager;
import fi.dy.masa.malilib.gui.GuiBase;
import fi.dy.masa.malilib.gui.Message;
import fi.dy.masa.malilib.gui.button.ButtonBase;
import fi.dy.masa.malilib.gui.button.ButtonGeneric;
import fi.dy.masa.malilib.gui.button.IButtonActionListener;
Expand All @@ -26,12 +28,14 @@
public class WidgetSyncmaticaServerPlacementEntry extends WidgetListEntryBase<ServerPlacement> {

private final ServerPlacement placement;
private final WidgetListSyncmaticaServerPlacement parent;
private final boolean isOdd;

public WidgetSyncmaticaServerPlacementEntry(final int x, int y, final int width, final int height, final ServerPlacement entry,
final int listIndex) {
final int listIndex, final WidgetListSyncmaticaServerPlacement parent) {
super(x, y, width, height, entry, listIndex);
placement = entry;
this.parent = parent;
isOdd = (listIndex % 2 == 1);
y += 1;

Expand All @@ -43,13 +47,13 @@ public WidgetSyncmaticaServerPlacementEntry(final int x, int y, final int width,
text = StringUtils.translate("syncmatica.gui.button.remove");
len = getStringWidth(text) + 10;
posX -= (len + 2);
listener = new ButtonListener(ButtonListener.Type.REMOVE, this);
listener = new ButtonListener(ButtonListener.Type.REMOVE, this, this.parent.parent);
addButton(new ButtonGeneric(posX, y, len, 20, text), listener);

text = StringUtils.translate("syncmatica.gui.button.material_gathering_placement");
len = getStringWidth(text) + 10;
posX -= (len + 2);
listener = new ButtonListener(ButtonListener.Type.MATERIAL_GATHERING, this);
listener = new ButtonListener(ButtonListener.Type.MATERIAL_GATHERING, this, this.parent.parent);
final ButtonGeneric matGathering = new ButtonGeneric(posX, y, len, 20, text);
matGathering.setEnabled(false);
addButton(matGathering, listener);
Expand All @@ -63,13 +67,13 @@ public WidgetSyncmaticaServerPlacementEntry(final int x, int y, final int width,
final Context con = LitematicManager.getInstance().getActiveContext();
final LocalLitematicState state = con.getFileStorage().getLocalState(placement);
return !state.isLocalFileReady() && state.isReadyForDownload();
}, new ButtonListener(ButtonListener.Type.DOWNLOAD, this)));
}, new ButtonListener(ButtonListener.Type.DOWNLOAD, this, this.parent.parent)));
multi.add(new BaseButtonType("syncmatica.gui.button.load",
() -> !LitematicManager.getInstance().isRendered(placement),
new ButtonListener(ButtonListener.Type.LOAD, this)));
new ButtonListener(ButtonListener.Type.LOAD, this, this.parent.parent)));
multi.add(new BaseButtonType("syncmatica.gui.button.unload",
() -> LitematicManager.getInstance().isRendered(placement),
new ButtonListener(ButtonListener.Type.UNLOAD, this)));
new ButtonListener(ButtonListener.Type.UNLOAD, this, this.parent.parent)));

final ButtonGeneric button = new MultiTypeButton(posX, y, true, multi);
addButton(button, null);
Expand Down Expand Up @@ -100,10 +104,12 @@ private static class ButtonListener implements IButtonActionListener {

Type type;
WidgetSyncmaticaServerPlacementEntry placement;
GuiBase messageDisplay;

public ButtonListener(final Type type, final WidgetSyncmaticaServerPlacementEntry placement) {
public ButtonListener(final Type type, final WidgetSyncmaticaServerPlacementEntry placement, final GuiBase messageDisplay) {
this.type = type;
this.placement = placement;
this.messageDisplay = messageDisplay;
}

@Override
Expand All @@ -112,25 +118,25 @@ public void actionPerformedWithButton(final ButtonBase button, final int arg1) {
return;
}
button.setEnabled(false);
type.onAction(placement);
type.onAction(button, placement, messageDisplay);
}

public enum Type {
LOAD() {
@Override
void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
void onAction(final ButtonBase button, final WidgetSyncmaticaServerPlacementEntry placement, final GuiBase messageDisplay) {
LitematicManager.getInstance().renderSyncmatic(placement.placement);
}
},
UNLOAD() {
@Override
void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
void onAction(final ButtonBase button, final WidgetSyncmaticaServerPlacementEntry placement, final GuiBase messageDisplay) {
LitematicManager.getInstance().unrenderSyncmatic(placement.placement);
}
},
DOWNLOAD() {
@Override
void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
void onAction(final ButtonBase button, final WidgetSyncmaticaServerPlacementEntry placement, final GuiBase messageDisplay) {
final Context con = LitematicManager.getInstance().getActiveContext();
final ExchangeTarget server = ((ClientCommunicationManager) con.getCommunicationManager()).getServer();
if (con.getCommunicationManager().getDownloadState(placement.placement)) {
Expand All @@ -145,7 +151,12 @@ void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
},
REMOVE() {
@Override
void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
void onAction(final ButtonBase button, final WidgetSyncmaticaServerPlacementEntry placement, final GuiBase messageDisplay) {
if(!GuiBase.isShiftDown()) {
messageDisplay.addMessage(Message.MessageType.ERROR, "syncmatica.error.remove_without_shift");
button.setEnabled(true);
return;
}
final Context con = LitematicManager.getInstance().getActiveContext();
final ExchangeTarget server = ((ClientCommunicationManager) con.getCommunicationManager()).getServer();
final PacketByteBuf packetBuf = new PacketByteBuf(Unpooled.buffer());
Expand All @@ -155,12 +166,12 @@ void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
},
MATERIAL_GATHERING() {
@Override
void onAction(final WidgetSyncmaticaServerPlacementEntry placement) {
void onAction(final ButtonBase button, final WidgetSyncmaticaServerPlacementEntry placement, final GuiBase messageDisplay) {
LogManager.getLogger().info("Opened Material Gatherings GUI - currently unsupported operation");
}
};

abstract void onAction(WidgetSyncmaticaServerPlacementEntry placement);
abstract void onAction(ButtonBase button, WidgetSyncmaticaServerPlacementEntry placement, GuiBase messageDisplay);
}

}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/syncmatica/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"syncmatica.error.share_incompatible_schematic": "Convert this file using the Schematic Manager from the main menu to share it",
"syncmatica.error.invalid_file": "Cannot share this type of file",
"syncmatica.error.failed_to_load": "Failed to load litematic {}",
"syncmatica.error.remove_without_shift": "Press shift to remove from server",
"syncmatica.success.modification_accepted": "Modification request accept - Lock the placement again to share the results to the server"
}