Merge work #7
@@ -0,0 +1,81 @@
|
|||||||
|
package pp.mdga.client;
|
||||||
|
|
||||||
|
import com.jme3.input.InputManager;
|
||||||
|
import com.jme3.input.KeyInput;
|
||||||
|
import com.jme3.input.MouseInput;
|
||||||
|
import com.jme3.input.controls.*;
|
||||||
|
|
||||||
|
public class InputSyncronizer {
|
||||||
|
|
||||||
|
private MdgaApp app;
|
||||||
|
private InputManager inputManager;
|
||||||
|
|
||||||
|
protected boolean rightMousePressed = false;
|
||||||
|
private float rotationAngle = 0f;
|
||||||
|
private int scrollValue = 50;
|
||||||
|
|
||||||
|
InputSyncronizer(MdgaApp app) {
|
||||||
|
this.app = app;
|
||||||
|
|
||||||
|
this.inputManager = app.getInputManager();
|
||||||
|
|
||||||
|
setupInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
rotateModel();
|
||||||
|
updateScrollValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupInput() {
|
||||||
|
inputManager.addMapping("Settings", new KeyTrigger(KeyInput.KEY_ESCAPE));
|
||||||
|
|
||||||
|
inputManager.addMapping("RotateRightMouse", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
|
||||||
|
inputManager.addMapping("MouseLeft", new MouseAxisTrigger(MouseInput.AXIS_X, false)); // Left movement
|
||||||
|
inputManager.addMapping("MouseRight", new MouseAxisTrigger(MouseInput.AXIS_X, true)); // Right movement
|
||||||
|
inputManager.addMapping("MouseScrollUp", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false)); // Scroll up
|
||||||
|
inputManager.addMapping("MouseScrollDown", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true)); // Scroll down
|
||||||
|
|
||||||
|
inputManager.addListener(actionListener, "Settings", "RotateRightMouse");
|
||||||
|
inputManager.addListener(analogListener, "MouseLeft", "MouseRight", "MouseScrollUp", "MouseScrollDown");
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ActionListener actionListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void onAction(String name, boolean isPressed, float tpf) {
|
||||||
|
if (name.equals("Settings") && isPressed) {
|
||||||
|
app.getView().pressEscape();
|
||||||
|
}
|
||||||
|
if (name.equals("RotateRightMouse")) {
|
||||||
|
rightMousePressed = isPressed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final AnalogListener analogListener = new AnalogListener() {
|
||||||
|
@Override
|
||||||
|
public void onAnalog(String name, float value, float tpf) {
|
||||||
|
if (name.equals("MouseLeft") && rightMousePressed) {
|
||||||
|
rotationAngle -= value * 360f;
|
||||||
|
rotateModel();
|
||||||
|
} else if (name.equals("MouseRight") && rightMousePressed) {
|
||||||
|
rotationAngle += value * 360f;
|
||||||
|
rotateModel();
|
||||||
|
} else if (name.equals("MouseScrollUp")) {
|
||||||
|
scrollValue = Math.min(100, scrollValue + 1);
|
||||||
|
updateScrollValue();
|
||||||
|
} else if (name.equals("MouseScrollDown")) {
|
||||||
|
scrollValue = Math.max(1, scrollValue - 1);
|
||||||
|
updateScrollValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void rotateModel() {
|
||||||
|
//System.out.println("Rotation Angle: " + rotationAngle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateScrollValue() {
|
||||||
|
//System.out.println("Scroll Value: " + scrollValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ public class MdgaApp extends SimpleApplication {
|
|||||||
private AnimationHandler animationHandler;
|
private AnimationHandler animationHandler;
|
||||||
private AcousticHandler acousticHandler;
|
private AcousticHandler acousticHandler;
|
||||||
private NotificationSynchronizer notificationSynchronizer;
|
private NotificationSynchronizer notificationSynchronizer;
|
||||||
|
private InputSyncronizer inputSyncronizer;
|
||||||
|
|
||||||
MdgaView view = null;
|
MdgaView view = null;
|
||||||
private MdgaState state = MdgaState.MAIN;
|
private MdgaState state = MdgaState.MAIN;
|
||||||
@@ -41,7 +42,9 @@ public void simpleInitApp() {
|
|||||||
animationHandler = new AnimationHandler(this);
|
animationHandler = new AnimationHandler(this);
|
||||||
acousticHandler = new AcousticHandler(this);
|
acousticHandler = new AcousticHandler(this);
|
||||||
notificationSynchronizer = new NotificationSynchronizer(this);
|
notificationSynchronizer = new NotificationSynchronizer(this);
|
||||||
|
inputSyncronizer = new InputSyncronizer(this);
|
||||||
|
|
||||||
|
inputManager.deleteMapping("SIMPLEAPP_Exit");
|
||||||
GuiGlobals.initialize(this);
|
GuiGlobals.initialize(this);
|
||||||
|
|
||||||
enter(state);
|
enter(state);
|
||||||
@@ -49,6 +52,7 @@ public void simpleInitApp() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
|
inputSyncronizer.update();
|
||||||
view.update();
|
view.update();
|
||||||
acousticHandler.update();
|
acousticHandler.update();
|
||||||
}
|
}
|
||||||
@@ -95,4 +99,8 @@ public AcousticHandler getAcousticHandler() {
|
|||||||
public float getResolutionFactor() {
|
public float getResolutionFactor() {
|
||||||
return resolutionFactor;
|
return resolutionFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MdgaView getView() {
|
||||||
|
return view;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public MainView(MdgaApp app) {
|
|||||||
dialog = new InputButtonDialog(app, node);
|
dialog = new InputButtonDialog(app, node);
|
||||||
dialog.addButton("Spiel beitreten", () -> app.enter(MdgaState.LOBBY), size);
|
dialog.addButton("Spiel beitreten", () -> app.enter(MdgaState.LOBBY), size);
|
||||||
dialog.addButton("Spiel hosten", () -> app.enter(MdgaState.LOBBY), size);
|
dialog.addButton("Spiel hosten", () -> app.enter(MdgaState.LOBBY), size);
|
||||||
dialog.addButton("Einstellungen", () -> enterSettings(), size);
|
dialog.addButton("Einstellungen", () -> enterSettings(false), size);
|
||||||
dialog.addButton("Spiel beenden", () -> app.stop(), size);
|
dialog.addButton("Spiel beenden", () -> app.stop(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ public abstract class MdgaView {
|
|||||||
protected MdgaApp app;
|
protected MdgaApp app;
|
||||||
protected Node node;
|
protected Node node;
|
||||||
|
|
||||||
|
int depth = 0;
|
||||||
|
boolean isVideo = false;
|
||||||
|
boolean isAudio = false;
|
||||||
|
|
||||||
private Node settingsNode;
|
private Node settingsNode;
|
||||||
private Node audioNode;
|
private Node audioNode;
|
||||||
private Node videoNode;
|
private Node videoNode;
|
||||||
@@ -38,7 +42,7 @@ public MdgaView(MdgaApp app) {
|
|||||||
this.audioNode = new Node();
|
this.audioNode = new Node();
|
||||||
this.videoNode = new Node();
|
this.videoNode = new Node();
|
||||||
|
|
||||||
this.settingsButton = new SettingsButtonDialog(app, node, "", () -> enterSettings());
|
this.settingsButton = new SettingsButtonDialog(app, node, "", () -> enterSettings(false));
|
||||||
|
|
||||||
this.settingsBackground = createBackground("background/zahnräder.png");
|
this.settingsBackground = createBackground("background/zahnräder.png");
|
||||||
settingsNode.attachChild(settingsBackground);
|
settingsNode.attachChild(settingsBackground);
|
||||||
@@ -103,11 +107,15 @@ protected Geometry createBackground(String texturePath) {
|
|||||||
return background;
|
return background;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void enterSettings() {
|
protected void enterSettings(boolean soft) {
|
||||||
leave();
|
leave();
|
||||||
|
|
||||||
app.getGuiNode().attachChild(settingsNode);
|
app.getGuiNode().attachChild(settingsNode);
|
||||||
|
|
||||||
|
if(!soft) {
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
settings.show();
|
settings.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,12 +126,16 @@ protected void leaveSettings(boolean soft) {
|
|||||||
|
|
||||||
if(!soft) {
|
if(!soft) {
|
||||||
enter();
|
enter();
|
||||||
|
depth--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void enterAudio() {
|
protected void enterAudio() {
|
||||||
leaveSettings(true);
|
leaveSettings(true);
|
||||||
|
|
||||||
|
depth++;
|
||||||
|
isAudio = true;
|
||||||
|
|
||||||
app.getGuiNode().attachChild(audioNode);
|
app.getGuiNode().attachChild(audioNode);
|
||||||
|
|
||||||
audio.show();
|
audio.show();
|
||||||
@@ -134,7 +146,10 @@ protected void leaveAudio() {
|
|||||||
|
|
||||||
app.getGuiNode().detachChild(audioNode);
|
app.getGuiNode().detachChild(audioNode);
|
||||||
|
|
||||||
enterSettings();
|
isAudio = false;
|
||||||
|
depth--;
|
||||||
|
|
||||||
|
enterSettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void enterVideo() {
|
protected void enterVideo() {
|
||||||
@@ -142,6 +157,10 @@ protected void enterVideo() {
|
|||||||
|
|
||||||
app.getGuiNode().attachChild(videoNode);
|
app.getGuiNode().attachChild(videoNode);
|
||||||
|
|
||||||
|
depth++;
|
||||||
|
|
||||||
|
isVideo = true;
|
||||||
|
|
||||||
video.show();
|
video.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +169,27 @@ protected void leaveVideo() {
|
|||||||
|
|
||||||
app.getGuiNode().detachChild(videoNode);
|
app.getGuiNode().detachChild(videoNode);
|
||||||
|
|
||||||
enterSettings();
|
depth--;
|
||||||
|
isVideo = false;
|
||||||
|
|
||||||
|
enterSettings(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pressEscape() {
|
||||||
|
if(depth == 0) {
|
||||||
|
enterSettings(false);
|
||||||
|
} else if(depth == 1) {
|
||||||
|
leaveSettings(false);
|
||||||
|
}
|
||||||
|
else if (depth == 2){
|
||||||
|
if(isVideo) {
|
||||||
|
leaveVideo();
|
||||||
|
}
|
||||||
|
if(isAudio) {
|
||||||
|
leaveAudio();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user