|
@@ -1,23 +1,59 @@
|
|
|
package eu.oschl.gui;
|
|
package eu.oschl.gui;
|
|
|
|
|
|
|
|
|
|
+import eu.oschl.gui.actions.Action;
|
|
|
|
|
+import eu.oschl.gui.exceptions.InvalidActionId;
|
|
|
import javafx.event.ActionEvent;
|
|
import javafx.event.ActionEvent;
|
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.FXML;
|
|
|
-import javafx.scene.text.Text;
|
|
|
|
|
|
|
+import javafx.scene.control.Button;
|
|
|
|
|
+import javafx.scene.layout.VBox;
|
|
|
import javafx.scene.text.TextFlow;
|
|
import javafx.scene.text.TextFlow;
|
|
|
|
|
|
|
|
-public class GameController {
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+
|
|
|
|
|
+public class GameController implements Observer {
|
|
|
@FXML
|
|
@FXML
|
|
|
private TextFlow output;
|
|
private TextFlow output;
|
|
|
|
|
|
|
|
@FXML
|
|
@FXML
|
|
|
- private void onTestButtonClick(ActionEvent actionEvent) {
|
|
|
|
|
|
|
+ private VBox inputButtonContainer;
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ public void initialize() {
|
|
|
|
|
+ Output.setOutputElement(output);
|
|
|
|
|
+ update();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void exectuteAction(ActionEvent event) throws InvalidActionId {
|
|
|
|
|
+ Button clickedButton = (Button) event.getSource();
|
|
|
|
|
+ ButtonData buttonData = (ButtonData) clickedButton.getUserData();
|
|
|
|
|
+
|
|
|
|
|
+ var actionProcessor = Session.getActionProcessor();
|
|
|
|
|
+
|
|
|
|
|
+ actionProcessor.executeAction(buttonData.actionId(), buttonData.arguments());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void renderActionButtons() {
|
|
|
|
|
+ inputButtonContainer.getChildren().clear();
|
|
|
|
|
+
|
|
|
|
|
+ var newButtons = new ArrayList<Button>();
|
|
|
|
|
+
|
|
|
|
|
+ for (Action action : Session.getActionProcessor().getActions()) {
|
|
|
|
|
+ var actionButton = new Button(action.getName());
|
|
|
|
|
|
|
|
- for (int i = 0; i < 50; i++) {
|
|
|
|
|
- Text fragment1 = new Text("Hello, ");
|
|
|
|
|
- Text fragment2 = new Text("favourite boy! ");
|
|
|
|
|
- Text fragment3 = new Text("Welcome back. ");
|
|
|
|
|
|
|
+ actionButton.setUserData(new ButtonData(action.getId()));
|
|
|
|
|
+ actionButton.setOnAction(this::exectuteAction);
|
|
|
|
|
|
|
|
- output.getChildren().addAll(fragment1, fragment2, fragment3);
|
|
|
|
|
|
|
+ actionButton.setMaxWidth(Double.MAX_VALUE);
|
|
|
|
|
+
|
|
|
|
|
+ newButtons.add(actionButton);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ inputButtonContainer.getChildren().addAll(newButtons);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void update() {
|
|
|
|
|
+ renderActionButtons();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|