This commit is contained in:
Cedric Beck
2024-12-02 02:52:41 +01:00
21 changed files with 2195 additions and 71 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,15 +1,19 @@
package pp.mdga.client;
import com.jme3.app.SimpleApplication;
import com.jme3.system.JmeContext;
import com.simsilica.lemur.GuiGlobals;
import pp.mdga.client.acoustic.AcousticHandler;
import pp.mdga.client.animation.AnimationHandler;
import com.jme3.system.AppSettings;
import pp.mdga.client.dialog.JoinDialog;
import pp.mdga.client.view.*;
import pp.mdga.message.server.ServerInterpreter;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.prefs.Preferences;
/**
* Main application class for the MdgaApp game.
@@ -17,6 +21,8 @@
*/
public class MdgaApp extends SimpleApplication {
private static Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
/** Handles animations in the application. */
private AnimationHandler animationHandler;
@@ -39,7 +45,7 @@ public class MdgaApp extends SimpleApplication {
private MdgaState state = null;
/** Scale for rendering images. */
private static final float IMAGE_SCALE = 1.5f;
private float imageScale = prefs.getInt("scale", 1);
/** The main menu view. */
private MdgaView mainView;
@@ -74,9 +80,9 @@ private MdgaApp() {
public static void main(String[] args) {
AppSettings settings = new AppSettings(true);
settings.setSamples(128);
settings.setWidth(prefs.getInt("width", 1280));
settings.setHeight(prefs.getInt("height", 720));
settings.setCenterWindow(true);
settings.setWidth((int) (1920*0.9f));
settings.setHeight((int) (1080*0.9f));
settings.setVSync(false);
MdgaApp app = new MdgaApp();
@@ -190,7 +196,7 @@ public MdgaState getState() {
* @return the image scale as a float
*/
public float getImageScale() {
return IMAGE_SCALE;
return imageScale;
}
/**
@@ -249,8 +255,34 @@ public ExecutorService getExecutor() {
return this.executor;
}
public ServerConnection getNetworkSupport() {
public ServerConnection getNetworkSupport(){
return networkConnection;
}
public void updateResolution(int width, int height, float imageFactor) {
prefs.putInt("width", width);
prefs.putInt("height", height);
prefs.putFloat("scale", imageFactor);
try {
restartApp();
} catch (Exception e) {
//nothing
}
}
public static void restartApp() throws IOException {
String javaBin = System.getProperty("java.home") + "/bin/java";
String classPath = System.getProperty("java.class.path");
String className = System.getProperty("sun.java.command");
ProcessBuilder builder = new ProcessBuilder(
javaBin, "-cp", classPath, className
);
builder.start();
System.exit(0);
}
}

View File

@@ -158,4 +158,8 @@ protected void calculateRelative() {
heightStep = verticalStep / 2;
widthStep = horizontalStep / 2;
}
public Vector2f getPos() {
return pos;
}
}

View File

@@ -30,20 +30,9 @@ public SettingsButton(MdgaApp app, Node node, Runnable action) {
// Enable adjustment for positioning
adjust = true;
}
/**
* Displays the settings button by attaching it to the scene graph.
*/
@Override
public void show() {
release();
calculateRelative();
setRelative();
setImageRelative(pictureNormal);
node.attachChild(instance);
pictureNormal.setImage(app.getAssetManager(), "Images/Settings_Button_normal.png", true);
pictureHover.setImage(app.getAssetManager(), "Images/Settings_Button_hover.png", true);
}
/**
@@ -51,12 +40,6 @@ public void show() {
*/
@Override
public void onHover() {
icon = new IconComponent("Images/Settings_Button_hover.png");
icon.setIconScale(0.02f * app.getImageScale());
icon.setHAlignment(HAlignment.Center);
icon.setVAlignment(VAlignment.Center);
instance.setIcon(icon);
}
/**
@@ -64,12 +47,6 @@ public void onHover() {
*/
@Override
public void onUnHover() {
icon = new IconComponent("Images/Settings_Button_normal.png");
icon.setIconScale(0.02f * app.getImageScale());
icon.setHAlignment(HAlignment.Center);
icon.setVAlignment(VAlignment.Center);
instance.setIcon(icon);
}
}

View File

@@ -3,12 +3,21 @@
import com.jme3.math.Vector2f;
import com.jme3.scene.Node;
import pp.mdga.client.MdgaApp;
import pp.mdga.client.button.ButtonLeft;
import pp.mdga.client.button.ButtonRight;
import pp.mdga.client.button.MenuButton;
import pp.mdga.client.view.MdgaView;
public class VideoSettingsDialog extends Dialog {
private MenuButton backButton;
private ButtonLeft hdButton9;
private ButtonLeft fullHdButton9;
private ButtonLeft wqhdButton9;
private ButtonRight hdButton10;
private ButtonRight fullHdButton10;
private ButtonRight wqhdButton10;
private final MdgaView view;
private boolean active = false;
@@ -20,8 +29,30 @@ public VideoSettingsDialog(MdgaApp app, Node node, MdgaView view) {
backButton = new MenuButton(app, node, view::leaveVideoSettings, "Zurück");
// MenuButton für verschiedene Auflösungen erstellen
hdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(1280, 720, 1.0f), "hd 16:9", 10);
fullHdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(1920, 1080, 2.25f), "full hd 16:9", 10);
wqhdButton9 = new ButtonLeft(app, node, () -> app.updateResolution(2560, 1440, 4.0f), "wqhd 16:9", 10);
hdButton10 = new ButtonRight(app, node, () -> app.updateResolution(1280, 800, 1.0f), "hd 16:10", 10);
fullHdButton10 = new ButtonRight(app, node, () -> app.updateResolution(1920, 1200, 2.25f), "full hd 16:10", 10);
wqhdButton10 = new ButtonRight(app, node, () -> app.updateResolution(2560, 1600, 4.0f), "wqhd 16:10", 10);
float offset = 2.8f;
hdButton9.setPos(new Vector2f(hdButton9.getPos().x, MenuButton.VERTICAL - offset));
hdButton10.setPos(new Vector2f(hdButton10.getPos().x, MenuButton.VERTICAL - offset));
offset += 1.5f;
fullHdButton9.setPos(new Vector2f(fullHdButton9.getPos().x, MenuButton.VERTICAL - offset));
fullHdButton10.setPos(new Vector2f(fullHdButton10.getPos().x, MenuButton.VERTICAL - offset));
offset += 1.5f;
wqhdButton9.setPos(new Vector2f(wqhdButton9.getPos().x, MenuButton.VERTICAL - offset));
wqhdButton10.setPos(new Vector2f(wqhdButton10.getPos().x, MenuButton.VERTICAL - offset));
offset += 1.5f;
backButton.setPos(new Vector2f(0, 1.8f));
}
@@ -29,6 +60,14 @@ public VideoSettingsDialog(MdgaApp app, Node node, MdgaView view) {
protected void onShow() {
active = true;
hdButton9.show();
fullHdButton9.show();
wqhdButton9.show();
hdButton10.show();
fullHdButton10.show();
wqhdButton10.show();
backButton.show();
}
@@ -36,6 +75,14 @@ protected void onShow() {
protected void onHide() {
active = false;
hdButton9.hide();
fullHdButton9.hide();
wqhdButton9.hide();
hdButton10.hide();
fullHdButton10.hide();
wqhdButton10.hide();
backButton.hide();
}

View File

@@ -2,6 +2,7 @@
import com.jme3.network.*;
import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.EnumSerializer;
import pp.mdga.game.*;
import pp.mdga.message.client.*;
import pp.mdga.message.server.*;
@@ -12,7 +13,6 @@
import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.net.InetAddress;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;
@@ -130,6 +130,7 @@ private void initializeSerializables() {
Serializer.registerClass(ReconnectBriefingMessage.class);
Serializer.registerClass(ResumeGameMessage.class);
Serializer.registerClass(ServerStartGameMessage.class);
Serializer.registerClass(ShutdownMessage.class);
Serializer.registerClass(StartPieceMessage.class);
Serializer.registerClass(UpdateReadyMessage.class);
Serializer.registerClass(UpdateTSKMessage.class);
@@ -143,6 +144,8 @@ private void initializeSerializables() {
Serializer.registerClass(StartNode.class);
Serializer.registerClass(PlayerData.class);
Serializer.registerClass(HomeNode.class);
Serializer.registerClass(PieceState.class, new EnumSerializer());
Serializer.registerClass(ShieldState.class, new EnumSerializer());
}
private void registerListeners() {
@@ -199,6 +202,9 @@ private void messageReceived(HostedConnection source, ClientMessage message) {
public void connectionAdded(Server server, HostedConnection hostedConnection) {
System.out.println("new connection " + hostedConnection); //NON-NLS
LOGGER.log(Level.DEBUG, "new connection {0}", hostedConnection); //NON-NLS
if (this.myServer.getConnections().size() == 1) {
this.logic.getGame().setHost(hostedConnection.getId());
}
}
@Override

View File

@@ -32,8 +32,6 @@ public class GameView extends MdgaView {
private CameraHandler camera;
private GuiHandler guiHandler;
private ButtonRight cheatButton; //TODO
private ButtonLeft leaveButton;
private ButtonRight confirmButton;
@@ -44,7 +42,6 @@ public class GameView extends MdgaView {
public GameView(MdgaApp app) {
super(app);
cheatButton = new ButtonRight(app, overlayNode, () -> app.getModelSynchronize().enter(MdgaState.CEREMONY), "CHEAT", 1);
leaveButton = new ButtonLeft(app, overlayNode, () -> app.getModelSynchronize().leave(), "Spiel verlassen", 1);
confirmButton = new ButtonRight(app, guiNode, () -> app.getModelSynchronize().confirm(), "Bestätigen", 1);
@@ -90,7 +87,6 @@ public void onUpdate(float tpf) {
protected void onEnterOverlay(Overlay overlay) {
if(overlay == Overlay.SETTINGS) {
leaveButton.show();
cheatButton.show();
}
}
@@ -98,7 +94,6 @@ protected void onEnterOverlay(Overlay overlay) {
protected void onLeaveOverlay(Overlay overlay) {
if(overlay == Overlay.SETTINGS) {
leaveButton.hide();
cheatButton.hide();
}
}