diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java index 12285090..f74060eb 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java @@ -1,6 +1,7 @@ package pp.mdga.client; import com.jme3.app.SimpleApplication; +import com.jme3.renderer.RenderManager; import com.simsilica.lemur.GuiGlobals; import pp.mdga.client.acoustic.AcousticHandler; import pp.mdga.client.animation.AnimationHandler; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java index b338fd4b..fcc48eae 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java @@ -1,6 +1,7 @@ package pp.mdga.client.board; import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; import com.jme3.renderer.queue.RenderQueue; @@ -31,19 +32,25 @@ public class BoardHandler { private Map> waitingNodesMap; private Map> waitingPiecesMap; private Map pieceColor; + private Set outlineControls; private Node node; private final FilterPostProcessor fpp; - private boolean init; + private boolean isInitialised; + + private boolean scheduleInit = false; + private boolean scheduleShutdown = false; public BoardHandler(MdgaApp app, FilterPostProcessor fpp) { if(app == null) throw new RuntimeException("app is null"); - this.init = false; + this.isInitialised = false; this.app = app; this.fpp = fpp; + + initMap(); } private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) { @@ -52,11 +59,10 @@ private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) { } private void initMap() { - if (init) return; + if (isInitialised) return; - this.init = true; + this.isInitialised = true; this.node = new Node("Asset Node"); - app.getRootNode().attachChild(node); this.pieces = new HashMap<>(); this.colorAssetsMap = new HashMap<>(); @@ -65,6 +71,7 @@ private void initMap() { this.waitingNodesMap = new HashMap<>(); this.waitingPiecesMap = new HashMap<>(); this.pieceColor = new HashMap<>(); + this.outlineControls = new HashSet<>(); @@ -115,7 +122,7 @@ private Spatial createModel(Asset asset, Vector3f pos, float rot) { mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName)); model.setMaterial(mat); node.attachChild(model); -// app.getRootNode().attachChild(model); + return model; } @@ -181,7 +188,7 @@ private List removeItemFromMapList(Map> map, E key, T item){ //public methods**************************************************************************************************** public void addPlayer(Color color, List uuid) { - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); List playerAssets = colorAssetsMap.get(color); if (playerAssets == null) throw new RuntimeException("Assets for Player color are not defined"); @@ -205,7 +212,7 @@ public void addPlayer(Color color, List uuid) { } public void moveHomePiece(UUID uuid, int index){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); Color color = pieceColor.get(uuid); if(color == null) throw new RuntimeException("uuid is not mapped to a color"); @@ -226,7 +233,7 @@ public void moveHomePiece(UUID uuid, int index){ } public void movePieceStart(UUID uuid, int nodeIndex){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); Color color = pieceColor.get(uuid); if(color == null) throw new RuntimeException("uuid is not mapped to a color"); @@ -238,13 +245,13 @@ public void movePieceStart(UUID uuid, int nodeIndex){ } public void movePiece(UUID uuid, int curIndex, int moveIndex){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); movePiece_rek(uuid, curIndex, moveIndex); } public void throwPiece(UUID uuid){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); Color color = pieceColor.get(uuid); if(color == null) throw new RuntimeException("uuid is not mapped to a color"); @@ -259,25 +266,25 @@ public void throwPiece(UUID uuid){ } public void shieldPiece(UUID uuid){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); pieces.get(uuid).activateShield(); } public void unshieldPiece(UUID uuid){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); pieces.get(uuid).deactivateShield(); } public void suppressShield(UUID uuid){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); pieces.get(uuid).suppressShield(); } public void swapPieces(UUID piece1, UUID piece2){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); PieceControl piece1_control = pieces.get(piece1); PieceControl piece2_control = pieces.get(piece2); @@ -298,37 +305,53 @@ public void swapPieces(UUID piece1, UUID piece2){ piece2_control.setLocation(pos1); } - public void init(){ - initMap(); + public void init() { + outlineControls.forEach((outlineControl) -> { + outlineControl.outline(outlineControl.getColor()); + }); + + isInitialised = true; + scheduleInit = false; + app.getRootNode().attachChild(node); } public void shutdown(){ - if (!init) return; + outlineControls.forEach((outlineControl) -> { + outlineControl.deOutline(); + }); - init = false; + isInitialised = false; + scheduleShutdown = false; app.getRootNode().detachChild(node); } - //List //List public void outline(UUID uuid, boolean bool){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); pieces.get(uuid).outline(bool); + + outlineControls.add(pieces.get(uuid)); } public void deOutline(UUID uuid){ - if (!init) throw new RuntimeException("BoardHandler is not initialized"); + if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); pieces.get(uuid).deOutline(); + + outlineControls.remove(pieces.get(uuid)); } public void outline(int index){ infield.get(index).outline(); + + outlineControls.add(infield.get(index)); } public void deOutline(int index){ infield.get(index).deOutline(); + + outlineControls.remove(infield.get(index)); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java index 3f326741..e010e03a 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java @@ -13,6 +13,8 @@ public class OutlineControl extends AbstractControl { private int thickness = 4; private final SelectObjectOutliner outlineOwn; + ColorRGBA color; + public OutlineControl(MdgaApp app, FilterPostProcessor fpp){ outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera()); } @@ -28,6 +30,8 @@ public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, int thic public void outline(ColorRGBA color){ outlineOwn.select(spatial, color); + + this.color = color; } public void deOutline(){ @@ -44,4 +48,7 @@ protected void controlRender(RenderManager rm, ViewPort vp) { } + public ColorRGBA getColor() { + return color; + } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/SingleButtonTopRight.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/SingleButtonTopRight.java new file mode 100644 index 00000000..df03df42 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/SingleButtonTopRight.java @@ -0,0 +1,66 @@ +package pp.mdga.client.dialog; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.HAlignment; +import com.simsilica.lemur.VAlignment; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class SingleButtonTopRight extends Dialog { + public SingleButtonTopRight(MdgaApp app, Node node, String label, Runnable action) { + super(app, node); + + createButton(label, action, new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); + } + + @Override + public void show() { + super.show(); + + float x = (14 * horitontal_step) - container.getPreferredSize().x; + float y = 8.5f * vertical_step; + + container.setLocalTranslation(x, y, 0); + } + + @Override + public void hide() { + super.hide(); + } + + protected void createButton(String label, Runnable action, Vector3f size) { + Button button = new Button(label); + button.addClickCommands(source -> action.run()); + button.setFontSize(fontSize); + button.setHighlightColor(ColorRGBA.White); + button.setColor(ColorRGBA.Black); + button.setPreferredSize(size); + button.setTextHAlignment(HAlignment.Center); + button.setTextVAlignment(VAlignment.Center); + + QuadBackgroundComponent background = new QuadBackgroundComponent(ColorRGBA.Red); + background.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); + button.setBackground(background); + + button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOn, (source) -> { + QuadBackgroundComponent hoverBackground = new QuadBackgroundComponent(ColorRGBA.Yellow); + hoverBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); + source.setBackground(hoverBackground); + button.setHighlightColor(ColorRGBA.White); + button.setColor(ColorRGBA.Black); + }); + + button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOff, (source) -> { + QuadBackgroundComponent normalBackground = new QuadBackgroundComponent(ColorRGBA.Red); + normalBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); + source.setBackground(normalBackground); + button.setHighlightColor(ColorRGBA.White); + button.setColor(ColorRGBA.Black); + }); + + container.addChild(button); + } +} diff --git a/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Outline.frag b/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Outline.frag index 48634b78..d38250b7 100644 --- a/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Outline.frag +++ b/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Outline.frag @@ -1,29 +1,40 @@ +// Samplers for textures uniform sampler2D m_Texture; uniform sampler2D m_OutlineDepthTexture; uniform sampler2D m_DepthTexture; -varying vec2 texCoord; +// Input texture coordinates from the vertex shader +in vec2 texCoord; + +// Resolution of the screen and outline settings uniform vec2 m_Resolution; uniform vec4 m_OutlineColor; uniform float m_OutlineWidth; +// Output color of the fragment +out vec4 fragColor; + void main() { - vec4 depth = texture2D(m_OutlineDepthTexture, texCoord); - vec4 depth1 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,m_OutlineWidth))/m_Resolution); - vec4 depth2 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,-m_OutlineWidth))/m_Resolution); - vec4 depth3 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,m_OutlineWidth))/m_Resolution); - vec4 depth4 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,-m_OutlineWidth))/m_Resolution); - vec4 depth5 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,m_OutlineWidth))/m_Resolution); - vec4 depth6 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,-m_OutlineWidth))/m_Resolution); - vec4 depth7 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,0.))/m_Resolution); - vec4 depth8 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,0.))/m_Resolution); - vec4 color = texture2D(m_Texture, texCoord); - //如果是背景 - if(depth==vec4(0.) && (depth1 != depth || depth2 != depth || depth3 != depth || depth4 != depth||depth5 != depth || depth6 != depth || depth7 != depth || depth8 != depth)){ - gl_FragColor = m_OutlineColor; - }else{ - gl_FragColor = color; - } - //debug - //gl_FragColor = vec4(0.,(1.-ratio),0.,1.); -} \ No newline at end of file + // Sample depth textures + vec4 depth = texture(m_OutlineDepthTexture, texCoord); + vec4 depth1 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(m_OutlineWidth, m_OutlineWidth)) / m_Resolution); + vec4 depth2 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(m_OutlineWidth, -m_OutlineWidth)) / m_Resolution); + vec4 depth3 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(-m_OutlineWidth, m_OutlineWidth)) / m_Resolution); + vec4 depth4 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(-m_OutlineWidth, -m_OutlineWidth)) / m_Resolution); + vec4 depth5 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(0.0, m_OutlineWidth)) / m_Resolution); + vec4 depth6 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(0.0, -m_OutlineWidth)) / m_Resolution); + vec4 depth7 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(m_OutlineWidth, 0.0)) / m_Resolution); + vec4 depth8 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(-m_OutlineWidth, 0.0)) / m_Resolution); + + // Sample the main texture + vec4 color = texture(m_Texture, texCoord); + + // Determine whether to apply the outline color + if (depth == vec4(0.0) && + (depth1 != depth || depth2 != depth || depth3 != depth || depth4 != depth || + depth5 != depth || depth6 != depth || depth7 != depth || depth8 != depth)) { + fragColor = m_OutlineColor; // Apply outline color + } else { + fragColor = color; // Use the original texture color + } +} diff --git a/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/OutlinePre.frag b/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/OutlinePre.frag index 4b9173dc..a814e693 100644 --- a/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/OutlinePre.frag +++ b/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/OutlinePre.frag @@ -1,10 +1,18 @@ -varying vec2 texCoord; +// Use 'in' instead of 'varying' for inputs from the vertex shader +in vec2 texCoord; + +// Declare a custom output variable for the fragment color +out vec4 fragColor; + +// Uniform samplers uniform sampler2D m_Texture; uniform sampler2D m_NormalsTexture; uniform sampler2D m_DepthTexture; -void main(){ - vec4 color = texture2D(m_Texture, texCoord); - gl_FragColor=color; -} \ No newline at end of file +void main() { + // Sample the texture at the given texture coordinates + vec4 color = texture(m_Texture, texCoord); + // Assign the color to the output variable + fragColor = color; +} diff --git a/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Post15.vert b/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Post15.vert index 16a78655..87b84987 100644 --- a/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Post15.vert +++ b/Projekte/mdga/client/src/main/resources/MatDefs/SelectObjectOutliner/Post15.vert @@ -1,10 +1,15 @@ -attribute vec4 inPosition; -attribute vec2 inTexCoord; +// Use 'in' for vertex attributes +in vec4 inPosition; +in vec2 inTexCoord; -varying vec2 texCoord; +// Use 'out' for passing data to the fragment shader +out vec2 texCoord; void main() { + // Transform position to clip space vec2 pos = inPosition.xy * 2.0 - 1.0; gl_Position = vec4(pos, 0.0, 1.0); + + // Pass texture coordinates to the fragment shader texCoord = inTexCoord; -} \ No newline at end of file +} diff --git a/Projekte/mdga/client/src/main/resources/audio_icon.png~ b/Projekte/mdga/client/src/main/resources/audio_icon.png~ deleted file mode 100644 index ef15a1ff..00000000 Binary files a/Projekte/mdga/client/src/main/resources/audio_icon.png~ and /dev/null differ diff --git a/Projekte/mdga/client/src/main/resources/monitor.png~ b/Projekte/mdga/client/src/main/resources/monitor.png~ deleted file mode 100644 index 1de46a61..00000000 Binary files a/Projekte/mdga/client/src/main/resources/monitor.png~ and /dev/null differ diff --git a/Projekte/mdga/client/src/main/resources/test.png~ b/Projekte/mdga/client/src/main/resources/test.png~ deleted file mode 100644 index 9a1a61b3..00000000 Binary files a/Projekte/mdga/client/src/main/resources/test.png~ and /dev/null differ diff --git a/Projekte/mdga/client/src/main/resources/zahnrad.png~ b/Projekte/mdga/client/src/main/resources/zahnrad.png~ deleted file mode 100644 index 4cc9d980..00000000 Binary files a/Projekte/mdga/client/src/main/resources/zahnrad.png~ and /dev/null differ