block & replace packets UI

This commit is contained in:
sirjonasxx 2018-11-06 20:32:36 +01:00
parent 4ef6789bf0
commit e141cf0f2c
6 changed files with 137 additions and 11 deletions

View File

@ -1,27 +1,37 @@
package extensions.blockreplacepackets;
import extensions.blockreplacepackets.rules.BlockReplaceRule;
import extensions.blockreplacepackets.rules.RuleFactory;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
import gearth.ui.GEarthController;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import gearth.extensions.ExtensionForm;
import gearth.extensions.ExtensionInfo;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Jonas on 22/09/18.
*/
@ExtensionInfo(
Title = "iManipulate",
Title = "G-Manipulate",
Description = "Block &/ replace packets",
Version = "0.1",
Author = "sirjonasxx"
@ -33,6 +43,11 @@ public class BlockAndReplacePackets extends ExtensionForm {
public Button btn_add;
public volatile ComboBox<String> cmb_side;
public TextField txt_value;
public ScrollPane scrollpane;
public VBox vbox;
public GridPane header;
List<BlockReplaceRule> rules = new ArrayList<>();
public static void main(String[] args) {
runExtensionForm(args, BlockAndReplacePackets.class);
@ -149,6 +164,13 @@ public class BlockAndReplacePackets extends ExtensionForm {
}
}
private void clearInput() {
txt_value.clear();
txt_replacement.clear();
refreshOptions();
cmb_type.requestFocus();
}
@Override
protected void initExtension() {
intercept(HMessage.Side.TOSERVER, message -> System.out.println("just testing"));
@ -173,6 +195,12 @@ public class BlockAndReplacePackets extends ExtensionForm {
}
public void click_btnAddRule(ActionEvent actionEvent) {
BlockReplaceRule rule = RuleFactory.getRule(cmb_type.getSelectionModel().getSelectedItem(), cmb_side.getSelectionModel().getSelectedItem(), txt_value.getText(), txt_replacement.getText());
rules.add(rule);
rule.onDelete(observable -> rules.remove(rule));
new RuleContainer(rule, vbox);
clearInput();
}
}

View File

@ -1,7 +1,91 @@
package extensions.blockreplacepackets;
import extensions.blockreplacepackets.rules.BlockReplaceRule;
import gearth.ui.buttons.DeleteButton;
import gearth.ui.scheduler.ScheduleItem;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
/**
* Created by Jeunez on 6/11/2018.
*/
public class RuleContainer {
public class RuleContainer extends GridPane {
public static final int[] columnWidths = {12, 14, 18, 33, 15, 6};
VBox parent;
BlockReplaceRule item;
RuleContainer(BlockReplaceRule item, VBox parent) {
super();
this.parent = parent;
this.item = item;
setGridLinesVisible(true);
VBox.setMargin(this, new Insets(2, -2, -2, -2));
setPrefWidth(parent.getWidth());
setPrefHeight(23);
initialize();
}
private void initialize() {
RowConstraints rowConstraints = new RowConstraints(23);
getRowConstraints().addAll(rowConstraints);
for (int i = 0; i < columnWidths.length; i++) {
ColumnConstraints columnConstraints = new ColumnConstraints(20);
columnConstraints.setPercentWidth(columnWidths[i]);
getColumnConstraints().add(columnConstraints);
}
Label optionLabel = initNewLabelColumn(item.option().name());
Label typeLabel = initNewLabelColumn(item.type().name());
Label valueLabel = initNewLabelColumn(item.value());
Label replacementLabel = initNewLabelColumn(item.replacement());
Label destinationLabel = initNewLabelColumn(item.side().name());
add(optionLabel, 0, 0);
add(typeLabel, 1, 0);
add(valueLabel, 2, 0);
add(replacementLabel, 3, 0);
add(destinationLabel, 4, 0);
DeleteButton deleteButton = new DeleteButton();
deleteButton.setAlignment(Pos.CENTER);
deleteButton.show();
RuleContainer thiss = this;
item.onDelete(observable -> parent.getChildren().remove(thiss));
deleteButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.delete());
add(deleteButton, 5, 0);
parent.getChildren().add(this);
}
private Label initNewLabelColumn(String text) {
Label label = new Label();
// label.setMaxWidth(Double.MAX_VALUE);
// label.setMinHeight(Double.MAX_VALUE);
// label.setAlignment(Pos.CENTER);
label.setFont(new Font(12));
GridPane.setMargin(label, new Insets(0, 0, 0, 5));
label.setText(text);
return label;
}
}

View File

@ -36,10 +36,10 @@
<children>
<GridPane prefHeight="41.0" prefWidth="580.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="191.0" minWidth="10.0" prefWidth="127.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="346.0" minWidth="10.0" prefWidth="52.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="136.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="123.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="191.0" minWidth="10.0" prefWidth="139.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="346.0" minWidth="10.0" prefWidth="50.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="148.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="110.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" vgrow="SOMETIMES" />
@ -107,16 +107,16 @@
</GridPane>
<ScrollPane fx:id="scrollpane" hbarPolicy="NEVER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-border-color: #888888; -fx-background: #FFFFFF; -fx-border-radius: 4px;" vbarPolicy="ALWAYS">
<content>
<VBox fx:id="schedulecontainer" maxHeight="1.7976931348623157E308" prefWidth="574.0">
<VBox fx:id="vbox" maxHeight="1.7976931348623157E308" prefWidth="574.0">
<children>
<GridPane fx:id="header" gridLinesVisible="true">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="163.0" minWidth="10.0" percentWidth="12.0" prefWidth="57.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" percentWidth="12.0" prefWidth="189.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" percentWidth="14.0" prefWidth="189.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="118.0" minWidth="10.0" percentWidth="18.0" prefWidth="66.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="33.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="15.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="8.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="6.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />

View File

@ -49,6 +49,6 @@ public class BlockPacketRule extends BlockReplaceRule{
@Override
public String replacement() {
return "";
return "/";
}
}

View File

@ -1,6 +1,10 @@
package extensions.blockreplacepackets.rules;
import gearth.protocol.HMessage;
import javafx.beans.InvalidationListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Jonas on 6/11/2018.
@ -35,4 +39,14 @@ public abstract class BlockReplaceRule {
public abstract String value();
public abstract String replacement();
private List<InvalidationListener> onDeleteListeners = new ArrayList<>();
public void onDelete(InvalidationListener listener) {
onDeleteListeners.add(listener);
}
public void delete() {
for (int i = onDeleteListeners.size() - 1; i >= 0; i--) {
onDeleteListeners.get(i).invalidated(null);
}
}
}

View File

@ -10,7 +10,7 @@ public class RuleFactory {
public static BlockReplaceRule getRule(String type, String side, String value, String replacement) {
BlockReplaceRule.Option rOption = BlockReplaceRule.Option.valueOf(type.split(" ")[0].toUpperCase());
BlockReplaceRule.Type rType = BlockReplaceRule.Type.valueOf(type.split(" ")[1].toUpperCase());
BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(type.toUpperCase());
BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(side.toUpperCase());
if (rOption == BlockReplaceRule.Option.BLOCK) {
return new BlockPacketRule(rSide, Integer.parseInt(value));