merge from koppe

This commit is contained in:
Cedric Beck
2024-11-26 16:47:24 +01:00
11 changed files with 172 additions and 51 deletions

View File

@@ -1,6 +1,7 @@
package pp.mdga.client; package pp.mdga.client;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import com.simsilica.lemur.GuiGlobals; import com.simsilica.lemur.GuiGlobals;
import pp.mdga.client.acoustic.AcousticHandler; import pp.mdga.client.acoustic.AcousticHandler;
import pp.mdga.client.animation.AnimationHandler; import pp.mdga.client.animation.AnimationHandler;

View File

@@ -1,6 +1,7 @@
package pp.mdga.client.board; package pp.mdga.client.board;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor; import com.jme3.post.FilterPostProcessor;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
@@ -31,19 +32,25 @@ public class BoardHandler {
private Map<Color, List<NodeControl>> waitingNodesMap; private Map<Color, List<NodeControl>> waitingNodesMap;
private Map<Color, List<PieceControl>> waitingPiecesMap; private Map<Color, List<PieceControl>> waitingPiecesMap;
private Map<UUID, Color> pieceColor; private Map<UUID, Color> pieceColor;
private Set<OutlineControl> outlineControls;
private Node node; private Node node;
private final FilterPostProcessor fpp; private final FilterPostProcessor fpp;
private boolean init; private boolean isInitialised;
private boolean scheduleInit = false;
private boolean scheduleShutdown = false;
public BoardHandler(MdgaApp app, FilterPostProcessor fpp) { public BoardHandler(MdgaApp app, FilterPostProcessor fpp) {
if(app == null) throw new RuntimeException("app is null"); if(app == null) throw new RuntimeException("app is null");
this.init = false; this.isInitialised = false;
this.app = app; this.app = app;
this.fpp = fpp; this.fpp = fpp;
initMap();
} }
private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) { private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
@@ -52,11 +59,10 @@ private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
} }
private void initMap() { private void initMap() {
if (init) return; if (isInitialised) return;
this.init = true; this.isInitialised = true;
this.node = new Node("Asset Node"); this.node = new Node("Asset Node");
app.getRootNode().attachChild(node);
this.pieces = new HashMap<>(); this.pieces = new HashMap<>();
this.colorAssetsMap = new HashMap<>(); this.colorAssetsMap = new HashMap<>();
@@ -65,6 +71,7 @@ private void initMap() {
this.waitingNodesMap = new HashMap<>(); this.waitingNodesMap = new HashMap<>();
this.waitingPiecesMap = new HashMap<>(); this.waitingPiecesMap = new HashMap<>();
this.pieceColor = 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)); mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName));
model.setMaterial(mat); model.setMaterial(mat);
node.attachChild(model); node.attachChild(model);
// app.getRootNode().attachChild(model);
return model; return model;
} }
@@ -181,7 +188,7 @@ private <T, E> List<T> removeItemFromMapList(Map<E,List<T>> map, E key, T item){
//public methods**************************************************************************************************** //public methods****************************************************************************************************
public void addPlayer(Color color, List<UUID> uuid) { public void addPlayer(Color color, List<UUID> uuid) {
if (!init) throw new RuntimeException("BoardHandler is not initialized"); if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized");
List<AssetOnMap> playerAssets = colorAssetsMap.get(color); List<AssetOnMap> playerAssets = colorAssetsMap.get(color);
if (playerAssets == null) throw new RuntimeException("Assets for Player color are not defined"); if (playerAssets == null) throw new RuntimeException("Assets for Player color are not defined");
@@ -205,7 +212,7 @@ public void addPlayer(Color color, List<UUID> uuid) {
} }
public void moveHomePiece(UUID uuid, int index){ 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); Color color = pieceColor.get(uuid);
if(color == null) throw new RuntimeException("uuid is not mapped to a color"); 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){ 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); Color color = pieceColor.get(uuid);
if(color == null) throw new RuntimeException("uuid is not mapped to a color"); 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){ 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); movePiece_rek(uuid, curIndex, moveIndex);
} }
public void throwPiece(UUID uuid){ 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); Color color = pieceColor.get(uuid);
if(color == null) throw new RuntimeException("uuid is not mapped to a color"); 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){ 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(); pieces.get(uuid).activateShield();
} }
public void unshieldPiece(UUID uuid){ 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(); pieces.get(uuid).deactivateShield();
} }
public void suppressShield(UUID uuid){ 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(); pieces.get(uuid).suppressShield();
} }
public void swapPieces(UUID piece1, UUID piece2){ 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 piece1_control = pieces.get(piece1);
PieceControl piece2_control = pieces.get(piece2); PieceControl piece2_control = pieces.get(piece2);
@@ -299,36 +306,52 @@ public void swapPieces(UUID piece1, UUID piece2){
} }
public void init() { public void init() {
initMap(); outlineControls.forEach((outlineControl) -> {
outlineControl.outline(outlineControl.getColor());
});
isInitialised = true;
scheduleInit = false;
app.getRootNode().attachChild(node);
} }
public void shutdown(){ public void shutdown(){
if (!init) return; outlineControls.forEach((outlineControl) -> {
outlineControl.deOutline();
});
init = false; isInitialised = false;
scheduleShutdown = false;
app.getRootNode().detachChild(node); app.getRootNode().detachChild(node);
} }
//List<Pieces> //List<Pieces>
//List<NodesIndexe> //List<NodesIndexe>
public void outline(UUID uuid, boolean bool){ 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); pieces.get(uuid).outline(bool);
outlineControls.add(pieces.get(uuid));
} }
public void deOutline(UUID 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(); pieces.get(uuid).deOutline();
outlineControls.remove(pieces.get(uuid));
} }
public void outline(int index){ public void outline(int index){
infield.get(index).outline(); infield.get(index).outline();
outlineControls.add(infield.get(index));
} }
public void deOutline(int index){ public void deOutline(int index){
infield.get(index).deOutline(); infield.get(index).deOutline();
outlineControls.remove(infield.get(index));
} }
} }

View File

@@ -13,6 +13,8 @@ public class OutlineControl extends AbstractControl {
private int thickness = 4; private int thickness = 4;
private final SelectObjectOutliner outlineOwn; private final SelectObjectOutliner outlineOwn;
ColorRGBA color;
public OutlineControl(MdgaApp app, FilterPostProcessor fpp){ public OutlineControl(MdgaApp app, FilterPostProcessor fpp){
outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera()); 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){ public void outline(ColorRGBA color){
outlineOwn.select(spatial, color); outlineOwn.select(spatial, color);
this.color = color;
} }
public void deOutline(){ public void deOutline(){
@@ -44,4 +48,7 @@ protected void controlRender(RenderManager rm, ViewPort vp) {
} }
public ColorRGBA getColor() {
return color;
}
} }

View File

@@ -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);
}
}

View File

@@ -1,29 +1,40 @@
// Samplers for textures
uniform sampler2D m_Texture; uniform sampler2D m_Texture;
uniform sampler2D m_OutlineDepthTexture; uniform sampler2D m_OutlineDepthTexture;
uniform sampler2D m_DepthTexture; 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 vec2 m_Resolution;
uniform vec4 m_OutlineColor; uniform vec4 m_OutlineColor;
uniform float m_OutlineWidth; uniform float m_OutlineWidth;
// Output color of the fragment
out vec4 fragColor;
void main() { void main() {
vec4 depth = texture2D(m_OutlineDepthTexture, texCoord); // Sample depth textures
vec4 depth1 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,m_OutlineWidth))/m_Resolution); vec4 depth = texture(m_OutlineDepthTexture, texCoord);
vec4 depth2 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,-m_OutlineWidth))/m_Resolution); vec4 depth1 = texture(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 depth2 = texture(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 depth3 = texture(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 depth4 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(-m_OutlineWidth, -m_OutlineWidth)) / m_Resolution);
vec4 depth6 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(0.,-m_OutlineWidth))/m_Resolution); vec4 depth5 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(0.0, m_OutlineWidth)) / m_Resolution);
vec4 depth7 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(m_OutlineWidth,0.))/m_Resolution); vec4 depth6 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(0.0, -m_OutlineWidth)) / m_Resolution);
vec4 depth8 = texture2D(m_OutlineDepthTexture, ((texCoord*m_Resolution)+vec2(-m_OutlineWidth,0.))/m_Resolution); vec4 depth7 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(m_OutlineWidth, 0.0)) / m_Resolution);
vec4 color = texture2D(m_Texture, texCoord); vec4 depth8 = texture(m_OutlineDepthTexture, ((texCoord * m_Resolution) + vec2(-m_OutlineWidth, 0.0)) / m_Resolution);
//如果是背景
if(depth==vec4(0.) && (depth1 != depth || depth2 != depth || depth3 != depth || depth4 != depth||depth5 != depth || depth6 != depth || depth7 != depth || depth8 != depth)){ // Sample the main texture
gl_FragColor = m_OutlineColor; 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 { } else {
gl_FragColor = color; fragColor = color; // Use the original texture color
} }
//debug
//gl_FragColor = vec4(0.,(1.-ratio),0.,1.);
} }

View File

@@ -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_Texture;
uniform sampler2D m_NormalsTexture; uniform sampler2D m_NormalsTexture;
uniform sampler2D m_DepthTexture; uniform sampler2D m_DepthTexture;
void main() { void main() {
vec4 color = texture2D(m_Texture, texCoord); // Sample the texture at the given texture coordinates
gl_FragColor=color; vec4 color = texture(m_Texture, texCoord);
// Assign the color to the output variable
fragColor = color;
} }

View File

@@ -1,10 +1,15 @@
attribute vec4 inPosition; // Use 'in' for vertex attributes
attribute vec2 inTexCoord; in vec4 inPosition;
in vec2 inTexCoord;
varying vec2 texCoord; // Use 'out' for passing data to the fragment shader
out vec2 texCoord;
void main() { void main() {
// Transform position to clip space
vec2 pos = inPosition.xy * 2.0 - 1.0; vec2 pos = inPosition.xy * 2.0 - 1.0;
gl_Position = vec4(pos, 0.0, 1.0); gl_Position = vec4(pos, 0.0, 1.0);
// Pass texture coordinates to the fragment shader
texCoord = inTexCoord; texCoord = inTexCoord;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB