This commit is contained in:
Felix
2024-11-26 16:18:33 +01:00
parent 7a482b74ab
commit 3e7d3dbc1b
13 changed files with 177 additions and 55 deletions

View File

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

View File

@@ -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<Color, List<NodeControl>> waitingNodesMap;
private Map<Color, List<PieceControl>> waitingPiecesMap;
private Map<UUID, Color> pieceColor;
private Set<OutlineControl> 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<>();
List<AssetOnMap> assetOnMaps = MapLoader.loadMap(MAP_NAME);
@@ -112,7 +119,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;
}
@@ -178,7 +185,7 @@ private <T, E> List<T> removeItemFromMapList(Map<E,List<T>> map, E key, T item){
//public methods****************************************************************************************************
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);
if (playerAssets == null) throw new RuntimeException("Assets for Player color are not defined");
@@ -202,7 +209,7 @@ public void addPlayer(Color color, List<UUID> 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");
@@ -223,7 +230,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");
@@ -235,13 +242,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");
@@ -256,25 +263,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);
@@ -295,37 +302,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<Pieces>
//List<NodesIndexe>
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));
}
}

View File

@@ -13,6 +13,8 @@ public class OutlineControl extends AbstractControl {
private static final int OUTLINE_THICKNESS = 4;
public final SelectObjectOutliner outlineOwn;
ColorRGBA color;
public OutlineControl(MdgaApp app, FilterPostProcessor fpp){
outlineOwn = new SelectObjectOutliner(OUTLINE_THICKNESS, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera());
}
@@ -24,6 +26,8 @@ public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){
public void outline(ColorRGBA color){
outlineOwn.select(spatial, color);
this.color = color;
}
public void deOutline(){
@@ -40,4 +44,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

@@ -88,4 +88,4 @@ public void deleteCard(Spatial spatial){
public Camera getOverlayCam(){
return overlayCam;
}
}
}

View File

@@ -16,6 +16,7 @@
import pp.mdga.client.dialog.SingleButtonRightDialog;
import pp.mdga.client.MdgaApp;
import pp.mdga.client.MdgaState;
import pp.mdga.client.dialog.SingleButtonTopRight;
import pp.mdga.client.gui.GuiHandler;
import pp.mdga.game.Color;
@@ -28,7 +29,7 @@ public class GameView extends MdgaView {
private CameraHandler camera;
private GuiHandler guiHandler;
private SingleButtonLeftDialog leaveButton;
private SingleButtonTopRight leaveButton;
private SingleButtonRightDialog continueButton;
public GameView(MdgaApp app) {
@@ -48,7 +49,7 @@ public GameView(MdgaApp app) {
this.guiHandler = new GuiHandler(app, backTexture);
leaveButton = new SingleButtonLeftDialog(app, settingsNode, "Verlassen", () -> leaveGame());
leaveButton = new SingleButtonTopRight(app, settingsNode, "Verlassen", () -> leaveGame());
continueButton = new SingleButtonRightDialog(app, node, "Weiter", () -> app.getModelSyncronizer().enter(MdgaState.CEREMONY));
}
@@ -71,7 +72,7 @@ public void onEnter() {
boardHandler.movePieceStart(player0, 0);
boardHandler.outline(player0, true);
boardHandler.outline(10);
//boardHandler.outline(10);
app.getInputManager().addMapping("Test", new KeyTrigger(KeyInput.KEY_J));
app.getInputManager().addListener(new ActionListener() {

View File

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

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_NormalsTexture;
uniform sampler2D m_DepthTexture;
void main(){
vec4 color = texture2D(m_Texture, texCoord);
gl_FragColor=color;
}
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;
}

View File

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

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