From c05192695f854eee1fda55b8985ac9af6d042d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20R=C4=99bacz?= Date: Sun, 22 Apr 2018 18:33:20 +0200 Subject: [PATCH] Added an option to retain connection to a Logitow device when a build is finished --- build.gradle | 2 +- .../client/gui/BluetoothDialogGui.java | 23 +++- .../logimine/client/gui/DeviceManagerGui.java | 111 ++++++++------- .../logimine/client/gui/SaveStructureGui.java | 4 +- .../client/gui/UnassignDialogGui.java | 128 ++++++++++++++++++ .../LogitowDeviceAssignMessageHandler.java | 4 +- .../LogitowSaveStructureMessageHandler.java | 6 + .../LogitowSavedStructureMessageHandler.java | 8 +- .../logitow/logimine/proxy/ClientProxy.java | 9 +- .../logimine/tiles/TileEntityBlockKey.java | 1 + .../assets/logimine/gui/unassign-dialog.png | Bin 0 -> 4250 bytes .../resources/assets/logimine/lang/en_us.lang | 21 ++- 12 files changed, 251 insertions(+), 66 deletions(-) create mode 100644 src/main/java/com/logitow/logimine/client/gui/UnassignDialogGui.java create mode 100644 src/main/resources/assets/logimine/gui/unassign-dialog.png diff --git a/build.gradle b/build.gradle index a0c7566..653f5cf 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ dependencies { // https://mvnrepository.com/artifact/net.sf.jni4net/jni4net.j compile group: 'net.sf.jni4net', name: 'jni4net.j', version: '0.8.8.0', ext: 'pom' compile 'org.apache.commons:commons-lang3:3.5' - compile name: 'logitow-bridge-0.9-all' + compile name: 'logitow-bridge-0.9.1-all' // you may put jars on which you depend on in ./libs // or you may define them like so.. diff --git a/src/main/java/com/logitow/logimine/client/gui/BluetoothDialogGui.java b/src/main/java/com/logitow/logimine/client/gui/BluetoothDialogGui.java index ad4127f..5e9bf4d 100644 --- a/src/main/java/com/logitow/logimine/client/gui/BluetoothDialogGui.java +++ b/src/main/java/com/logitow/logimine/client/gui/BluetoothDialogGui.java @@ -6,6 +6,8 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -24,7 +26,7 @@ public class BluetoothDialogGui extends GuiScreen { /** * The height of the container graphic. */ - final int containerHeight = 140; + final int containerHeight = 210; /** * The width of the container graphic. */ @@ -40,6 +42,13 @@ public class BluetoothDialogGui extends GuiScreen { */ final int CLOSE_DIALOG_BUTTON_ID = 0; + public static final ITextComponent TEXT_BLUETOOTH_DIALOG_ENABLE_BLUETOOTH = new TextComponentTranslation("logitow.bluetoothdialog.enablebluetooth"); + public static final ITextComponent TEXT_BLUETOOTH_DIALOG_ENABLE_BLUETOOTH_INFO = new TextComponentTranslation("logitow.bluetoothdialog.enablebluetooth.infotext"); + public static final ITextComponent TEXT_BLUETOOTH_DIALOG_COULDNT_ACCESS_BT = new TextComponentTranslation("logitow.bluetoothdialog.couldntaccessbluetooth"); + public static final ITextComponent TEXT_BLUETOOTH_DIALOG_COULDNT_ACCESS_BT_INFO = new TextComponentTranslation("logitow.bluetoothdialog.couldntaccessbluetooth.infotext"); + public static final ITextComponent TEXT_BLUETOOTH_DIALOG_DISMISS = new TextComponentTranslation("logitow.bluetoothdialog.dismiss"); + + /** * Creates the dialog based on the bluetooth state. * @param bluetoothState @@ -78,17 +87,17 @@ public void drawScreen(int p_drawScreen_1_, int p_drawScreen_2_, float p_drawScr //Bluetooth enabled, closing the dialog. Minecraft.getMinecraft().displayGuiScreen(null); } else if(currentBluetoothState == BluetoothState.PoweredOff) { - drawString(fontRenderer, "Enable Bluetooth!", (width/2) - fontRenderer.getStringWidth("Enable Bluetooth!")/2 + 42, (height/2) - containerHeight/2+30, 0xff0055); - infoText = "Make sure that Bluetooth\nfunctionality is enabled\non your system."; + drawString(fontRenderer, TEXT_BLUETOOTH_DIALOG_ENABLE_BLUETOOTH.getFormattedText(), (width/2) - fontRenderer.getStringWidth(TEXT_BLUETOOTH_DIALOG_ENABLE_BLUETOOTH.getFormattedText())/2 + 42, (height/2) - containerHeight/2+30, 0xff0055); + infoText = TEXT_BLUETOOTH_DIALOG_ENABLE_BLUETOOTH_INFO.getFormattedText(); } else { - drawString(fontRenderer, "Couldn't access Bluetooth!", (width/2) - fontRenderer.getStringWidth("Couldn't access Bluetooth!")/2+42, (height/2) - containerHeight/2+30, 0xff0055); - infoText = "Make sure that your \nsystem supports \nBluetooth Low Energy \nand no other application \nis using it."; + drawString(fontRenderer, TEXT_BLUETOOTH_DIALOG_COULDNT_ACCESS_BT.getFormattedText(), (width/2) - fontRenderer.getStringWidth(TEXT_BLUETOOTH_DIALOG_COULDNT_ACCESS_BT.getFormattedText())/2+42, (height/2) - containerHeight/2+30, 0xff0055); + infoText = TEXT_BLUETOOTH_DIALOG_COULDNT_ACCESS_BT_INFO.getFormattedText(); } //Drawing each line. int lineOffset = 0; for (String line : - infoText.split("\n")) { + infoText.split("/")) { drawString(fontRenderer, line, (width/2) - fontRenderer.getStringWidth(line)/2 + 42, (height/2) - containerHeight/2+47 + lineOffset, 0xffffff); lineOffset += 11; } @@ -99,7 +108,7 @@ public void drawScreen(int p_drawScreen_1_, int p_drawScreen_2_, float p_drawScr @Override public void initGui() { buttonList.clear(); - buttonList.add(new GuiButton(CLOSE_DIALOG_BUTTON_ID, width/2 - 40 + 42, height/2 + 30, 80, 20, "Dismiss")); + buttonList.add(new GuiButton(CLOSE_DIALOG_BUTTON_ID, width/2 - 40 + 42, height/2 + 30, 80, 20, TEXT_BLUETOOTH_DIALOG_DISMISS.getFormattedText())); super.initGui(); } diff --git a/src/main/java/com/logitow/logimine/client/gui/DeviceManagerGui.java b/src/main/java/com/logitow/logimine/client/gui/DeviceManagerGui.java index 4968178..7dbdac3 100644 --- a/src/main/java/com/logitow/logimine/client/gui/DeviceManagerGui.java +++ b/src/main/java/com/logitow/logimine/client/gui/DeviceManagerGui.java @@ -8,6 +8,7 @@ import com.logitow.logimine.LogiMine; import com.logitow.logimine.event.LogitowBridgeEvent; import com.logitow.logimine.networking.LogitowDeviceAssignMessage; +import com.logitow.logimine.proxy.ClientProxy; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -100,15 +101,16 @@ private int getDeviceStartPosition () { //Translated elements. public static final ITextComponent TEXT_DEVICE_MANAGER_TITLE = new TextComponentTranslation("logitow.devicemanager.title"); public static final ITextComponent TEXT_DEVICE_MANAGER_SELECT_DEVICE = new TextComponentTranslation("logitow.devicemanager.selectdevice"); - public static final ITextComponent TEXT_DEVICE_MANAGER_AVAILEBLE_DEVICES = new TextComponentTranslation("logitow.devicemanager.availabledevices"); + public static final ITextComponent TEXT_DEVICE_MANAGER_AVAILABLE_DEVICES = new TextComponentTranslation("logitow.devicemanager.availabledevices"); public static final ITextComponent TEXT_DEVICE_MANAGER_SCANNING = new TextComponentTranslation("logitow.devicemanager.scanning"); public static final ITextComponent TEXT_DEVICE_MANAGER_CONNECT_BUTTON = new TextComponentTranslation("logitow.devicemanager.connectbutton"); - public static final ITextComponent TEXT_DEVICE_MANAGER_DISCONNECT_BUTTON = new TextComponentTranslation("logitow.devicemanager.disconnectbutton"); + public static final ITextComponent TEXT_DEVICE_MANAGER_ASSIGN_BUTTON = new TextComponentTranslation("logitow.devicemanager.assignbutton"); + public static final ITextComponent TEXT_DEVICE_MANAGER_UNASSIGN_BUTTON = new TextComponentTranslation("logitow.devicemanager.unassignbutton"); + public static final ITextComponent TEXT_DEVICE_MANAGER_CONNECTED_LABEL = new TextComponentTranslation("logitow.devicemanager.connectedlabel"); public static final ITextComponent TEXT_DEVICE_MANAGER_SCAN_BUTTON = new TextComponentTranslation("logitow.devicemanager.scanbutton"); public static final ITextComponent TEXT_DEVICE_MANAGER_CANCEL_BUTTON = new TextComponentTranslation("logitow.devicemanager.cancelbutton"); public static final String TEXT_DEVICE_MANAGER_CONNECTING = "logitow.devicemanager.connecting"; - public static final String TEXT_DEVICE_MANAGER_DISCONNECTING = "logitow.devicemanager.disconnecting"; - public static final String TEXT_DEVICE_MANAGER_NOTCONNECTED = "logitow.devicemanager.notconnected"; + public static final String TEXT_DEVICE_MANAGER_ASSIGNING = "logitow.devicemanager.assigning"; /** * Draws the screen and all the components in it. @@ -139,6 +141,15 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { } } + //Connect/Assign button. + if(deviceChosen != -1) { + if(deviceChosen >= 200) { + connectButton.displayString = TEXT_DEVICE_MANAGER_CONNECT_BUTTON.getFormattedText(); + } else { + connectButton.displayString = TEXT_DEVICE_MANAGER_ASSIGN_BUTTON.getFormattedText(); + } + } + //Available devices/Select device if(HubGui.instance.getSelectedKeyBlock() != null) { String selectDevice = TEXT_DEVICE_MANAGER_SELECT_DEVICE.getFormattedText(); @@ -149,7 +160,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { connectButton.enabled = false; } } else { - String availableDevices = TEXT_DEVICE_MANAGER_AVAILEBLE_DEVICES.getFormattedText(); + String availableDevices = TEXT_DEVICE_MANAGER_AVAILABLE_DEVICES.getFormattedText(); drawString(fontRenderer, availableDevices, (width/2) - fontRenderer.getStringWidth(availableDevices)/2, (height/2) - containerHeight/3 +17, 0x8b8b8b); connectButton.enabled = false; } @@ -217,8 +228,32 @@ public void initGui() { //Adding the new device. int buttonId = 100 + instance.buttonList.size() - 3; instance.ASSIGNED_DEVICE_BUTTON_ID = buttonId; - instance.buttonList.add(new GuiButton(buttonId, instance.width / 2 - 70, newYPos + instance.deviceButtonSeparation, 140, 20, "[" + TEXT_DEVICE_MANAGER_DISCONNECT_BUTTON.getFormattedText().toUpperCase() + "] " + HubGui.instance.getSelectedKeyBlock().getAssignedDevice())); + instance.buttonList.add(new GuiButton(buttonId, instance.width / 2 - 70, newYPos + instance.deviceButtonSeparation, 140, 20, "[" + TEXT_DEVICE_MANAGER_UNASSIGN_BUTTON.getFormattedText().toUpperCase() + "] " + HubGui.instance.getSelectedKeyBlock().getAssignedDevice())); + } + + //Adding the connected devices list. + for (Device connected : + LogitowDeviceManager.current.connectedDevices) { + //Skipping the assigned device. + if (HubGui.instance.getSelectedKeyBlock() != null && HubGui.instance.getSelectedKeyBlock().getAssignedDevice() != null && connected.equals(HubGui.instance.getSelectedKeyBlock().getAssignedDevice())) return; + + //The new y pos of the element. + int newYPos = getDeviceStartPosition() - deviceButtonSeparation; + + //Getting the highest y position of the elements. + for (GuiButton button : + buttonList) { + if (button.id > 100 && button.y > newYPos) { + newYPos = button.y; + } + } + + //Adding the new device. + int buttonId = 100 + buttonList.size() - 3; + buttonList.add(new GuiButton(buttonId, width / 2 - 70, newYPos + deviceButtonSeparation, 140, 20, "[" + TEXT_DEVICE_MANAGER_CONNECTED_LABEL.getFormattedText().toUpperCase() + "] " + connected.toString())); + discoveredDevices.put(connected, buttonId); } + super.initGui(); } @@ -234,18 +269,31 @@ protected void actionPerformed(GuiButton button) throws IOException { for (Device device : discoveredDevices.keySet()) { if(discoveredDevices.get(device) == deviceChosen) { - Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_CONNECTING, device.info.friendlyName)); - + //Unassigning if there is one device connected already. if(instance != null && HubGui.instance.getSelectedKeyBlock() != null && HubGui.instance.getSelectedKeyBlock().getAssignedDevice() != null) { - HubGui.instance.getSelectedKeyBlock().getAssignedDevice().disconnect(); + if(HubGui.instance.getSelectedKeyBlock().getAssignedDevice().equals(device)) { + Minecraft.getMinecraft().displayGuiScreen(null); + return; + } + LogiMine.networkWrapper.sendToServer(new LogitowDeviceAssignMessage(HubGui.instance.getSelectedKeyBlock().getPos(), null)); + HubGui.instance.getSelectedKeyBlock().assignDevice(null, null); } - //Found the appropriate device. Assigning on client. + //Assigning the new device locally. HubGui.instance.getSelectedKeyBlock().assignDevice(Minecraft.getMinecraft().player, device); - //Avoiding slowdowns. - new Thread(() -> device.connect()).start(); + if(deviceChosen >= 200) { + //Connect + Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_CONNECTING, device)); + //Avoiding slowdowns. + new Thread(() -> device.connect()).start(); + } else { + //Assigning on the server. + Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_ASSIGNING, device)); + + LogiMine.networkWrapper.sendToServer(new LogitowDeviceAssignMessage(HubGui.instance.getSelectedKeyBlock().getPos(), device)); + } } } Minecraft.getMinecraft().displayGuiScreen(null); @@ -266,44 +314,11 @@ protected void actionPerformed(GuiButton button) throws IOException { //Device button has been selected. if(button.id >= 100) { if(button.id == ASSIGNED_DEVICE_BUTTON_ID) { - //Disconnecting the device. - Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_DISCONNECTING, HubGui.instance.getSelectedKeyBlock().getAssignedDevice().info.friendlyName)); - if(!HubGui.instance.getSelectedKeyBlock().getAssignedDevice().disconnect()) { - //Not connected - Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_NOTCONNECTED, HubGui.instance.getSelectedKeyBlock().getAssignedDevice().info.friendlyName)); - //Closing the dialog. - Minecraft.getMinecraft().displayGuiScreen(null); - } - button.enabled = false; - System.out.println("Disconnecting device: " + HubGui.instance.getSelectedKeyBlock().getAssignedDevice() + ", unassigning it from block " + HubGui.instance.getSelectedKeyBlock()); - - //Unassigning - HubGui.instance.getSelectedKeyBlock().assignDevice(null, null); - LogiMine.networkWrapper.sendToServer(new LogitowDeviceAssignMessage(HubGui.instance.getSelectedKeyBlock().getPos(), null)); - - //Updating the buttons. - GuiButton buttonToRemove = null; - int lastY = getDeviceStartPosition()-deviceButtonSeparation; - for (GuiButton registered : - buttonList) { - if(registered.id == ASSIGNED_DEVICE_BUTTON_ID) { - buttonToRemove = registered; - } - else if(registered.id > 100) { - registered.y = lastY + deviceButtonSeparation; - lastY = registered.y; - } - } - - //Removing the button. - buttonList.remove(buttonToRemove); - - //Closing the dialog. - Minecraft.getMinecraft().displayGuiScreen(null); + ((ClientProxy)LogiMine.proxy).showUnassignDialog(HubGui.instance.getSelectedKeyBlock().getAssignedDevice(), HubGui.getSelectedKeyBlock()); } if(HubGui.instance.getSelectedKeyBlock() != null) { - System.out.println("Selected device " + deviceChosen); deviceChosen = button.id; + System.out.println("Selected device " + deviceChosen); } } @@ -360,7 +375,7 @@ public void logitowEventReceived(LogitowBridgeEvent event) { } //Adding the new device. - int buttonId = 100 + buttonList.size()-3; + int buttonId = 200 + buttonList.size()-3; buttonList.add(new GuiButton(buttonId, width/2 - 70, newYPos + deviceButtonSeparation, 140, 20, discoveredEvent.device.toString())); discoveredDevices.put(discoveredEvent.device, buttonId); } else if(event.deviceEvent instanceof DeviceLostEvent) { diff --git a/src/main/java/com/logitow/logimine/client/gui/SaveStructureGui.java b/src/main/java/com/logitow/logimine/client/gui/SaveStructureGui.java index 59b2620..47f8213 100644 --- a/src/main/java/com/logitow/logimine/client/gui/SaveStructureGui.java +++ b/src/main/java/com/logitow/logimine/client/gui/SaveStructureGui.java @@ -85,8 +85,6 @@ public void drawScreen(int p_drawScreen_1_, int p_drawScreen_2_, float p_drawScr @Override protected void actionPerformed(GuiButton button) throws IOException { - System.out.println("Action performed!"); - if(button.id == CANCEL_BUTTON_ID) { Minecraft.getMinecraft().displayGuiScreen(null); return; @@ -130,7 +128,7 @@ public void initGui() { field.setFocused(true); field.setCursorPosition(0); - Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor(); + //Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor(); open = true; diff --git a/src/main/java/com/logitow/logimine/client/gui/UnassignDialogGui.java b/src/main/java/com/logitow/logimine/client/gui/UnassignDialogGui.java new file mode 100644 index 0000000..5ee4c5c --- /dev/null +++ b/src/main/java/com/logitow/logimine/client/gui/UnassignDialogGui.java @@ -0,0 +1,128 @@ +package com.logitow.logimine.client.gui; + +import com.logitow.bridge.communication.Device; +import com.logitow.logimine.LogiMine; +import com.logitow.logimine.networking.LogitowDeviceAssignMessage; +import com.logitow.logimine.tiles.TileEntityBlockKey; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.io.IOException; + +/** + * Represents an unassign device gui dialog. + */ +@SideOnly(Side.CLIENT) +public class UnassignDialogGui extends GuiScreen { + /** + * The location of the gui texture. + */ + final public ResourceLocation guiTexture = new ResourceLocation(LogiMine.modId, "gui/unassign-dialog.png"); + + /** + * The height of the container graphic. + */ + final int containerHeight = 71; + /** + * The width of the container graphic. + */ + final int containerWidth = 210; + + private Device selectedDevice; + private TileEntityBlockKey selectedKeyBlock; + + /** + * ID of the unassign device button. + */ + final int UNASSIGN_DEVICE_BUTTON_ID = 0; + /** + * ID of the disconnect device button. + */ + final int DISCONNECT_DEVICE_BUTTON_ID = 1; + + public static final ITextComponent TEXT_UNASSIGN_DIALOG_TITLE = new TextComponentTranslation("logitow.unassigndialog.title"); + public static final String TEXT_UNASSIGN_DIALOG_INFO_KEY = "logitow.unassigndialog.info"; + public static final ITextComponent TEXT_UNASSIGN_DIALOG_DISCONNECT = new TextComponentTranslation("logitow.unassigndialog.disconnect"); + public static final ITextComponent TEXT_UNASSIGN_DIALOG_UNASSIGN = new TextComponentTranslation("logitow.unassigndialog.unassign"); + public static final String TEXT_DEVICE_MANAGER_DISCONNECTING = "logitow.devicemanager.disconnecting"; + public static final String TEXT_DEVICE_MANAGER_NOTCONNECTED = "logitow.devicemanager.notconnected"; + + public UnassignDialogGui(Device device, TileEntityBlockKey keyBlock) { + this.selectedDevice = device; + this.selectedKeyBlock = keyBlock; + } + + @Override + protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException { + //Unassign + Device device = selectedKeyBlock.getAssignedDevice(); + selectedKeyBlock.assignDevice(null, null); + selectedKeyBlock.assignStructure(device.currentStructure.clone()); + LogiMine.networkWrapper.sendToServer(new LogitowDeviceAssignMessage(selectedKeyBlock.getPos(), null)); + + if(p_actionPerformed_1_.id == DISCONNECT_DEVICE_BUTTON_ID) { + //Disconnecting the device. + Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_DISCONNECTING, selectedDevice)); + if(!selectedDevice.disconnect()) { + //Not connected + Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_NOTCONNECTED, selectedDevice)); + } + } + + //Closing the dialog. + Minecraft.getMinecraft().displayGuiScreen(null); + + super.actionPerformed(p_actionPerformed_1_); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } + + @Override + public void drawScreen(int p_drawScreen_1_, int p_drawScreen_2_, float p_drawScreen_3_) { + drawDefaultBackground(); + Minecraft.getMinecraft().renderEngine.bindTexture(guiTexture); + + //Getting the center coords. + int centerX = (width/2) - containerWidth/2; + int centerY = (height/2) - containerHeight/2; + + drawTexturedModalRect(centerX,centerY,0,0,containerWidth,containerHeight); + + //Text depending on bluetooth state. + drawString(fontRenderer, TEXT_UNASSIGN_DIALOG_TITLE.getFormattedText(), (width/2) - fontRenderer.getStringWidth(TEXT_UNASSIGN_DIALOG_TITLE.getFormattedText())/2, (height/2) - containerHeight/2 + 10, 0xff0055); + + //Drawing each line. + int lineOffset = 0; + for (String line : + new TextComponentTranslation(TEXT_UNASSIGN_DIALOG_INFO_KEY, selectedDevice).getFormattedText().split("/")) { + drawString(fontRenderer, line, (width/2) - fontRenderer.getStringWidth(line)/2, (height/2) -13 + lineOffset, 0xffffff); + lineOffset += 11; + } + + super.drawScreen(p_drawScreen_1_,p_drawScreen_2_,p_drawScreen_3_); + } + + @Override + public void initGui() { + //Checking if a device is selected. + if(selectedDevice == null || selectedKeyBlock == null) { + System.out.println("No device assigned!"); + Minecraft.getMinecraft().displayGuiScreen(null); + return; + } + + buttonList.clear(); + buttonList.add(new GuiButton(UNASSIGN_DEVICE_BUTTON_ID, width/2 - 40 + 50, height/2 + 11, 80, 20, TEXT_UNASSIGN_DIALOG_UNASSIGN.getFormattedText())); + buttonList.add(new GuiButton(DISCONNECT_DEVICE_BUTTON_ID, width/2 - 40 - 50, height/2 + 11, 80, 20, TEXT_UNASSIGN_DIALOG_DISCONNECT.getFormattedText())); + super.initGui(); + } +} diff --git a/src/main/java/com/logitow/logimine/networking/LogitowDeviceAssignMessageHandler.java b/src/main/java/com/logitow/logimine/networking/LogitowDeviceAssignMessageHandler.java index 97e36fc..a2c4442 100644 --- a/src/main/java/com/logitow/logimine/networking/LogitowDeviceAssignMessageHandler.java +++ b/src/main/java/com/logitow/logimine/networking/LogitowDeviceAssignMessageHandler.java @@ -49,9 +49,11 @@ public IMessage onMessage(LogitowDeviceAssignMessage message, MessageContext ctx if(keyBlock != null) { if(message.deviceUUID.equals("NULL")) { - //Assigning the keyblock. + //Unassigning the keyblock. serverPlayer.sendMessage(new TextComponentTranslation(TEXT_DEVICE_MANAGER_UNASSIGNED, keyBlock.getAssignedDevice().info.friendlyName)); + Device device = keyBlock.getAssignedDevice(); keyBlock.assignDevice(null, null); + keyBlock.assignStructure(device.currentStructure.clone()); } else { //Assigning the keyblock. keyBlock.assignDevice(serverPlayer, Device.getConnectedFromUuid(message.deviceUUID)); diff --git a/src/main/java/com/logitow/logimine/networking/LogitowSaveStructureMessageHandler.java b/src/main/java/com/logitow/logimine/networking/LogitowSaveStructureMessageHandler.java index f40f974..4f1dcdb 100644 --- a/src/main/java/com/logitow/logimine/networking/LogitowSaveStructureMessageHandler.java +++ b/src/main/java/com/logitow/logimine/networking/LogitowSaveStructureMessageHandler.java @@ -1,6 +1,7 @@ package com.logitow.logimine.networking; import com.logitow.bridge.build.Structure; +import com.logitow.bridge.communication.Device; import com.logitow.logimine.LogiMine; import com.logitow.logimine.tiles.TileEntityBlockKey; import net.minecraft.entity.player.EntityPlayerMP; @@ -64,6 +65,11 @@ public LogitowSavedStructureMessage onMessage(LogitowSaveStructureMessage messag //deleting old file Structure.removeFile(usedKeyBlock.getAssignedStructure()); + //deassociating from the device structure. + Device device = usedKeyBlock.getAssignedDevice(); + usedKeyBlock.assignDevice(null, null); + usedKeyBlock.assignStructure(device.currentStructure.clone()); + //setting custom name usedKeyBlock.getAssignedStructure().customName = strucName; diff --git a/src/main/java/com/logitow/logimine/networking/LogitowSavedStructureMessageHandler.java b/src/main/java/com/logitow/logimine/networking/LogitowSavedStructureMessageHandler.java index 8a1fcbd..0027398 100644 --- a/src/main/java/com/logitow/logimine/networking/LogitowSavedStructureMessageHandler.java +++ b/src/main/java/com/logitow/logimine/networking/LogitowSavedStructureMessageHandler.java @@ -1,5 +1,6 @@ package com.logitow.logimine.networking; +import com.logitow.bridge.communication.Device; import com.logitow.logimine.LogiMine; import com.logitow.logimine.tiles.TileEntityBlockKey; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; @@ -17,8 +18,11 @@ public IMessage onMessage(LogitowSavedStructureMessage logitowSavedStructureMess //Disconnecting the device. for (TileEntityBlockKey keyBlock : LogiMine.activeKeyBlocks) { - if (keyBlock.getAssignedDevice() != null && keyBlock.getAssignedDevice().info.uuid.equals(logitowSavedStructureMessage.deviceUuid)) { - keyBlock.getAssignedDevice().disconnect(); + if (keyBlock.getWorld().isRemote && keyBlock.getAssignedDevice() != null && keyBlock.getAssignedDevice().info.uuid.equals(logitowSavedStructureMessage.deviceUuid)) { + //LogiMine.networkWrapper.sendToServer(new LogitowDeviceAssignMessage(keyBlock.getPos(), null)); + Device device = keyBlock.getAssignedDevice(); + keyBlock.assignDevice(null, null); + keyBlock.assignStructure(device.currentStructure.clone()); } } } diff --git a/src/main/java/com/logitow/logimine/proxy/ClientProxy.java b/src/main/java/com/logitow/logimine/proxy/ClientProxy.java index 7c77987..b814526 100644 --- a/src/main/java/com/logitow/logimine/proxy/ClientProxy.java +++ b/src/main/java/com/logitow/logimine/proxy/ClientProxy.java @@ -34,7 +34,7 @@ public void registerLogitowEvents() { } public void setSelectedKeyBlock(BlockPos blockKey) { - if(HubGui.instance != null) { + if(blockKey != null && HubGui.instance != null) { HubGui.setSelectedKeyBlock(blockKey); } } @@ -54,7 +54,9 @@ public void showClientGui(int type) { } public void showSaveStructureGui(TileEntityBlockKey blockKey) { - Minecraft.getMinecraft().displayGuiScreen(new SaveStructureGui(blockKey)); + if(blockKey != null) { + Minecraft.getMinecraft().displayGuiScreen(new SaveStructureGui(blockKey)); + } } public void hideSaveStructureGui() { if(SaveStructureGui.open) { @@ -82,4 +84,7 @@ public void notifySavedStructuresPageLoaded(StructuresPage page) { LoadStructureGui.instance.onPageLoaded(page); } } + public void showUnassignDialog(Device device, TileEntityBlockKey keyBlock) { + Minecraft.getMinecraft().displayGuiScreen(new UnassignDialogGui(device, keyBlock)); + } } diff --git a/src/main/java/com/logitow/logimine/tiles/TileEntityBlockKey.java b/src/main/java/com/logitow/logimine/tiles/TileEntityBlockKey.java index b579211..8b20597 100644 --- a/src/main/java/com/logitow/logimine/tiles/TileEntityBlockKey.java +++ b/src/main/java/com/logitow/logimine/tiles/TileEntityBlockKey.java @@ -420,6 +420,7 @@ public static void onWorldSave(WorldEvent.Save saveEvent) { //Saving the current structures to file. try { if(keyBlock.getWorld().isRemote) continue; + if(!keyBlock.getWorld().equals(saveEvent.getWorld())) continue; if(keyBlock.assignedStructure != null) { keyBlock.assignedStructure.saveToFile(); } diff --git a/src/main/resources/assets/logimine/gui/unassign-dialog.png b/src/main/resources/assets/logimine/gui/unassign-dialog.png new file mode 100644 index 0000000000000000000000000000000000000000..0e37b64bfa9e338270d455c06dff4fc2ced103a3 GIT binary patch literal 4250 zcmeHLe{9rL9PiGA$S*NblmMBfBu0Y0_Vw4bWe2jmjV*98XekYP+DN)U|^BrNLd{T#5dA(&{w<(9s_ z_kG`=pZEE`+bfL?D`rlcJB=WSne}zaCW5HI!wTa5DfqG0+iBv*RJU%8PY| zL9#W~NG2Q)kz!P$bs%tLOo;-CRXE{El4C)PVPg#7X%?ugr1A<`_)yrIXP9bJvbJCg zzs0HcAaGTN>FMc-_V7{1Yh!?-C=AOn97kgb+V8akn5AuhVNpX8`MPJhf#uj_s1a&T zR}iPLr}+>vZb_}}7t(|i#$=((fG8V=loNE@oxt(iopHoV%hzo(^pbM7%S-1xHgpE1 zQ3lz8k7Ys008VWxRT3Z5mrSN4?FTj8IE+F<#+3G3dR@dcA>ZlpbX3!gEiNoZ;|EQs zoX<&Y$Ks{Ufn|=fH(a?c0Vr#YBO0!hL|rxEAs9Gbi{qq=*l8?goJ=IhCsI(i?63lh z!War0P!a|xPGKO)7(z71w{SoefGUE;A)?s4XbMBqfB_sWEYKX+0wh(CR90Nfa%Ex1 zu*}{GMN9Qo6HeOkQjUTB;3={^U!O=cdX8zO@q*v9qMEF)Nk~AEB$|r?iZpc9bi542 zMYJ-o4Kc3WmUB0iQtNF$fVPh6lW_{i8nrA#$_TyEP0chBq$Nd^X~Ps^*dY5~WOE+|gpY#2nu!F;>(AO2P9{f@A++*kX~ryv(~qs?<{GUmO1CC0oEtyq z1}9?g%1di*Si&S!PFXSh<+w0DhN@qnsA||&7^SVH30bNYmD<|s>O_r@Uk2+#$LjsxzfChCPV{1IeIaT0QPA;<4?K@u3thYnE z4dK4c+(9UkCK!f}DHQNJpjkl>Xjzmc+K@Rx#B6~1B{o(lc@E`OURHUw$f5sgD7s^J zBX1O>T-r%cbukkED0mY!o7rrS0O4ZVbFGH}Q;-Huy*19{e{`j56!a)G>y z_9jFdkY$0>WPwIV6lswa_>ld18YvPFBoWF6{Ew7q!cZpH$ZkG3V|MJjg|-|8=9!GS zk>v94$vh-#Ly+ZePwH57Hrb_rc-Q?_MH^`@XJEE^oKW_UXWuT8>mv(h&5xX{{V?+VsgYy5f3k-C=Tdtrr>~2@y6>C0kDl@m zY#{nC^zYjD`;526q30i1y5aM|gnQ-kk;9KPA9`)u$Cc-%pZIOg(3!vBmd*+~D|%K80&EZOnZk7v@yhGw425QBq*d*7V;XUFEla0~e2*X*ZuWdAT>D&0~ zwD-b-1BcdjY(1|GT|B;d*ZVJR|0F(grQ^hjDOcayKk!2T<_{`1N<)47MuzRkp*akWnh8~Tz+Vtv+AvRZ!DP|{`a81rXjhz`o)+32G!W#_5c6? literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/logimine/lang/en_us.lang b/src/main/resources/assets/logimine/lang/en_us.lang index c5a92fd..d3ab8b6 100644 --- a/src/main/resources/assets/logimine/lang/en_us.lang +++ b/src/main/resources/assets/logimine/lang/en_us.lang @@ -27,15 +27,19 @@ logitow.devicemanager.selectdevice=Select Device logitow.devicemanager.availabledevices=Available Devices logitow.devicemanager.scanning=Scanning... logitow.devicemanager.connecting=Connecting to device: %s +logitow.devicemanager.assigning=Assigning device: %s logitow.devicemanager.disconnecting=Disconnecting device: %s +logitow.devicemanager.notconnected=Device %s hasn't been connected yet logitow.devicemanager.assigneddevice=Device %s assigned to key block logitow.devicemanager.unassigneddevice=Device %s unassigned from key block logitow.devicemanager.cancelbutton=Cancel logitow.devicemanager.scanbutton=Scan -logitow.devicemanager.disconnectbutton=Disconnect +logitow.devicemanager.unassignbutton=Unassign logitow.devicemanager.connectbutton=Connect +logitow.devicemanager.assignbutton=Assign logitow.devicemanager.keyblocknotinitialized=The key block hasn't been initialized yet! logitow.devicemanager.blockisnotkeyblock=This is not a LOGITOW key block! +logitow.devicemanager.connectedlabel=Connected #hub logitow.managerchoice.devicemanager=Device Manager @@ -65,4 +69,17 @@ logitow.loadstructuremanager.structureauthor=Author: %s #rotatestructure logitow.structure.rotated=Rotated structure by: %s -logitow.structure.cantrotatenotattached=Can't rotate, no structure attached to the key block! \ No newline at end of file +logitow.structure.cantrotatenotattached=Can't rotate, no structure attached to the key block! + +#bluetoothdialog +logitow.bluetoothdialog.enablebluetooth=Enable Bluetooth! +logitow.bluetoothdialog.enablebluetooth.infotext=Make sure that Bluetooth/functionality is enabled/on your system. +logitow.bluetoothdialog.couldntaccessbluetooth=Couldn't access Bluetooth! +logitow.bluetoothdialog.couldntaccessbluetooth.infotext=Make sure that your /system supports /Bluetooth Low Energy /and no other application /is using it. +logitow.bluetoothdialog.dismiss=Dismiss + +#unassigndialog +logitow.unassigndialog.title=Unassigning device +logitow.unassigndialog.info=Would you like to disconnect/or unassign the device %s +logitow.unassigndialog.disconnect=Disconnect +logitow.unassigndialog.unassign=Unassign \ No newline at end of file