showDialog patch

This commit is contained in:
Michael Wain 2024-07-08 21:10:44 +03:00
parent 0eb0a91ec6
commit 78bf203d23
7 changed files with 48 additions and 10 deletions

View File

@ -5,9 +5,9 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public class ActionDialog<T> {
public class ActionDialog {
private String dialogTitle;
private String dialogDescription;
private ActionDialogType actionDialogType;
private T actionDialogBody;
private ActionDialogBody actionDialogBody;
}

View File

@ -0,0 +1,4 @@
package com.alterdekim.game.component.game;
public interface ActionDialogBody {
}

View File

@ -1,10 +1,13 @@
package com.alterdekim.game.component.game;
import com.alterdekim.game.websocket.message.WebSocketMessageType;
import lombok.AllArgsConstructor;
import java.util.List;
@AllArgsConstructor
public class DialogButton {
private String buttonText;
private String buttonColor;
private String onclickAction;
private DialogButtonColor buttonColor;
private List<WebSocketMessageType> onclickAction;
}

View File

@ -0,0 +1,9 @@
package com.alterdekim.game.component.game;
public enum DialogButtonColor {
GREEN,
RED,
BLUE,
PURPLE,
YELLOW
}

View File

@ -0,0 +1,13 @@
package com.alterdekim.game.component.game;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.List;
@Getter
@RequiredArgsConstructor
public class DialogButtonsList implements ActionDialogBody {
private final List<DialogButton> buttons;
}

View File

@ -13,9 +13,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@ -31,7 +29,9 @@ public class GameRoom {
private List<BoardField> boardFields;
private ObjectMapper om = new ObjectMapper();
private final ObjectMapper om = new ObjectMapper();
public GameRoom(List<RoomPlayer> players, UserServiceImpl userService) {
this.userService = userService;
@ -122,8 +122,9 @@ public class GameRoom {
sendMessage(message.getUid(), WebSocketMessageType.PlayerColor, new PlayerColor(2L, "#ff0000"));
List<DialogButton> buttons = new ArrayList<>();
buttons.add(new DialogButton("Button1", "#00ff00", ""));
sendMessage(message.getUid(), WebSocketMessageType.ShowDialog, new ActionDialog<>("Title!", "Description!", ActionDialogType.Buttons, buttons));
buttons.add(new DialogButton("Button1", DialogButtonColor.GREEN, Collections.singletonList(WebSocketMessageType.HideDialog)));
DialogButtonsList b = new DialogButtonsList(buttons);
sendMessage(message.getUid(), WebSocketMessageType.ShowDialog, new ActionDialog("Title!", "Description!", ActionDialogType.Buttons, b));
}
private void sendMessage(Long userId, WebSocketMessageType type, Object o) {

View File

@ -124,6 +124,9 @@ function showMessage(message) {
case 'PlayerColor':
playerColor(JSON.parse(message.body));
break;
case 'ShowDialog':
showDialog(JSON.parse(message.body));
break;
}
}
@ -139,6 +142,11 @@ function chipMove(body) {
moveChips();
}
function showDialog(body) {
console.log("Got showDialog message");
console.log(body);
}
function playerColor(body) {
$(".player").each(function() {
if( $(this).attr("data-pid") == body.playerId ) {