mirror of
https://github.com/tiennm99/caro.git
synced 2026-09-02 14:20:02 +00:00
优化大厅页面;添加READEME文档
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
## 介绍
|
||||
本项目是一个使用 `javafx` + `netty` 技术构建的一个桌面应用,
|
||||
是对ratel应用命令行客户端的扩展,为ratel应用提供可视化界面操作方式。
|
||||
|
||||
### 系统架构
|
||||
* 使用`netty`构建和**ratel**服务端的通讯
|
||||
* 使用`javafx`构建`GUI`界面
|
||||
|
||||
## 快速启动
|
||||
### 依赖
|
||||
* `jdk`
|
||||
本项目是一个`java`应用,所以运行需要`java`环境,前往[oracle](https://www.oracle.com/java/technologies/java-downloads.html)下载最新版本jdk进行安装
|
||||
|
||||
* `maven`
|
||||
本项目由maven构建,构建本应用需要先安装maven,前往[apache maven](https://maven.apache.org)下载最新版本maven进行安装
|
||||
|
||||
### 安装
|
||||
```powershell
|
||||
git clone https://github.com/ainilili/ratel.git
|
||||
cd ratel
|
||||
mvn install package
|
||||
```
|
||||
#### 启动服务器
|
||||
```shell
|
||||
java -jar landlords-server/target/landlords-server-#{version}.jar -p 1024
|
||||
```
|
||||
|
||||
#### 启动`javafx`客户端
|
||||
```shell
|
||||
java -jar landlords-client-javafx/target/landlords-client-javafx-#{version}.jar
|
||||
```
|
||||
|
||||
## 使用
|
||||
1. 选择服务器地址连接
|
||||
2. 输入昵称
|
||||
3. 选择模式
|
||||
4. 选择房间
|
||||
5. 开始游戏
|
||||
|
||||
## TODO List
|
||||
-[X] PVP模式
|
||||
-[] 优化界面
|
||||
-[] PVE模式
|
||||
-[] 页面切换
|
||||
-[] 挂机检测
|
||||
|
||||
## 反馈与贡献
|
||||
- 如果您想贡献代码,非常欢迎提``PR``,我们将会合并优秀的代码.
|
||||
- 如果您发现了``Bug``或想提问,非常欢迎提[issue](https://github.com/marmot-z/ratel/issues)给我们.
|
||||
|
||||
## 联系方式
|
||||
* [zhangxunweia@gmail.com](zhangxunweia@gmail.com)
|
||||
* [15870664270@163.com](15870664270@163.com)
|
||||
|
||||
## 参考
|
||||
* [NaiveChat](https://github.com/fuzhengwei/NaiveChat)
|
||||
* [ratel部分协议](https://github.com/ainilili/ratel/blob/master/PROTOCO_CN.md)
|
||||
+1
@@ -9,6 +9,7 @@ import org.nico.noson.util.string.StringUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.listener.ClientListenerUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.handler.DefaultChannelInitializer;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.UIService;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
+1
-7
@@ -1,12 +1,9 @@
|
||||
package priv.zxw.ratel.landlords.client.javafx;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
import org.nico.noson.Noson;
|
||||
import org.nico.noson.entity.NoType;
|
||||
import org.nico.ratel.landlords.utils.StreamUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -20,14 +17,11 @@ import priv.zxw.ratel.landlords.client.javafx.ui.view.index.IndexMethod;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.lobby.LobbyController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.login.LoginController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
public class SimpleClient extends Application {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package priv.zxw.ratel.landlords.client.javafx.event;
|
||||
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.IIndexEvent;
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import io.netty.channel.Channel;
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.listener.ClientListener;
|
||||
import priv.zxw.ratel.landlords.client.javafx.listener.ClientListenerUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.ILobbyEvent;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ package priv.zxw.ratel.landlords.client.javafx.event;
|
||||
import io.netty.channel.Channel;
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.ILoginEvent;
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.netty.channel.Channel;
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.IRoomEvent;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import io.netty.channel.Channel;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package priv.zxw.ratel.landlords.client.javafx.listener;
|
||||
import io.netty.channel.Channel;
|
||||
import javafx.application.Platform;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.AlertUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.AlertUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.Method;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.lobby.LobbyController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
|
||||
+2
-2
@@ -8,10 +8,10 @@ import javafx.scene.control.Label;
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomMethod;
|
||||
|
||||
|
||||
+2
-6
@@ -4,9 +4,9 @@ import io.netty.channel.Channel;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Label;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomMethod;
|
||||
|
||||
@@ -33,11 +33,7 @@ public class ClientPokerPlayListener extends AbstractClientListener {
|
||||
if (future == null || future.isDone()) {
|
||||
CountDownTask task = new CountDownTask(timer, 30,
|
||||
node -> {
|
||||
// 由于服务器查找挂机客户端响应太慢,此处直接模拟服务器发送 CODE_CLIENT_KICK 事件将玩家请出房间,
|
||||
// 然后由客户端模拟机器人代替用户进行出牌,从而规避长时间的无响应对游戏的影响。
|
||||
// 暨此处不使用服务器的机器人功能,而由客户端自己实现机器人功能来解决玩家挂机的问题。
|
||||
Platform.runLater(() -> roomMethod.hidePokerPlayButtons());
|
||||
ClientListenerUtils.getListener(ClientEventCode.CODE_CLIENT_KICK).handle(channel, null);
|
||||
},
|
||||
surplusTime -> Platform.runLater(() -> timer.setText(surplusTime.toString())));
|
||||
BeanUtil.addBean(user.getNickname(), task.start());
|
||||
|
||||
+15
-2
@@ -2,10 +2,15 @@ package priv.zxw.ratel.landlords.client.javafx.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Label;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomMethod;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
|
||||
public class ClientPokerPlayRedirectListener extends AbstractClientListener {
|
||||
@@ -21,11 +26,19 @@ public class ClientPokerPlayRedirectListener extends AbstractClientListener {
|
||||
|
||||
NettyClient nettyClient = BeanUtil.getBean("nettyClient");
|
||||
int sellClientId = jsonObject.getIntValue("sellClientId");
|
||||
String sellClientNickname = jsonObject.getString("sellClinetNickname");
|
||||
|
||||
// 通知下一个玩家出牌
|
||||
if (sellClientId == nettyClient.getId()) {
|
||||
ClientListenerUtils.getListener(ClientEventCode.CODE_GAME_POKER_PLAY).handle(channel, json);
|
||||
}
|
||||
// 为下一个出牌的玩家设置倒计时定时器
|
||||
else {
|
||||
RoomMethod method = (RoomMethod) uiService.getMethod(RoomController.METHOD_NAME);
|
||||
|
||||
LOGGER.info("下一个出牌玩家为 {} ", jsonObject.getString("sellClinetNickname"));
|
||||
Label timer = (Label) method.getTimer(sellClientNickname);
|
||||
CountDownTask task = new CountDownTask(timer, 30, n -> {}, i -> Platform.runLater(() -> timer.setText(i.toString())));
|
||||
BeanUtil.addBean(sellClientNickname, task.start());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import javafx.application.Platform;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomMethod;
|
||||
|
||||
+1
-7
@@ -3,13 +3,7 @@ package priv.zxw.ratel.landlords.client.javafx.listener;
|
||||
import io.netty.channel.Channel;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
|
||||
/**
|
||||
* @ClassName ClientShowOptionsPVEListener
|
||||
* @Desc TODO
|
||||
* @Author zxw
|
||||
* @Date 2020/8/7 10:14
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
public class ClientShowOptionsPVEListener extends AbstractClientListener {
|
||||
|
||||
public ClientShowOptionsPVEListener() {
|
||||
|
||||
+4
-7
@@ -2,17 +2,13 @@ package priv.zxw.ratel.landlords.client.javafx.listener;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import javafx.application.Platform;
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.lobby.LobbyController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.lobby.LobbyMethod;
|
||||
|
||||
/**
|
||||
* @ClassName ClientShowOptionsPVPListener
|
||||
* @Desc TODO
|
||||
* @Author zxw
|
||||
* @Date 2020/8/7 10:13
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
public class ClientShowOptionsPVPListener extends AbstractClientListener {
|
||||
|
||||
public ClientShowOptionsPVPListener() {
|
||||
@@ -24,5 +20,6 @@ public class ClientShowOptionsPVPListener extends AbstractClientListener {
|
||||
LobbyMethod lobbyMethod = (LobbyMethod) uiService.getMethod(LobbyController.METHOD_NAME);
|
||||
|
||||
Platform.runLater(lobbyMethod::toggleToPVPMenu);
|
||||
ChannelUtils.pushToServer(channel, ServerEventCode.CODE_GET_ROOMS, null);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -3,14 +3,13 @@ package priv.zxw.ratel.landlords.client.javafx.listener;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomController;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.room.RoomMethod;
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import javafx.application.Platform;
|
||||
import org.nico.ratel.landlords.entity.ClientSide;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.Method;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.NettyClient;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
-2
@@ -10,8 +10,6 @@ import priv.zxw.ratel.landlords.client.javafx.ui.event.IIndexEvent;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.EventRegister;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.UIObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IndexEventRegister implements EventRegister {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(IndexEventRegister.class);
|
||||
|
||||
|
||||
-2
@@ -11,8 +11,6 @@ public class ServerAddressLabel {
|
||||
label.setText(serverAddress);
|
||||
label.setLayoutY(index * 30);
|
||||
label.getStyleClass().add("remoteServerOption");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Label getLabel() {
|
||||
|
||||
+8
-7
@@ -8,7 +8,7 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.RoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.ILobbyEvent;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.AlertUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.AlertUtils;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.UIObject;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -52,14 +52,15 @@ public class LobbyController extends UIObject implements LobbyMethod {
|
||||
|
||||
@Override
|
||||
public void showRoomList(List<RoomInfo> roomInfoList) {
|
||||
Pane buttonsPane = $("buttonsPane", Pane.class);
|
||||
buttonsPane.setVisible(false);
|
||||
|
||||
Pane roomsPane = $("roomsPane", Pane.class);
|
||||
roomsPane.setVisible(true);
|
||||
|
||||
ObservableList<Node> children = roomsPane.getChildren();
|
||||
roomInfoList.forEach(roomInfo -> children.add(new RoomPane(roomInfo, lobbyEvent).getPane()));
|
||||
for (int i = 0, size = roomInfoList.size(); i < size; i++) {
|
||||
RoomInfo roomInfo = roomInfoList.get(i);
|
||||
Pane roomPane = new RoomPane(roomInfo, i).getPane();
|
||||
roomPane.setOnMouseClicked(e -> lobbyEvent.joinRoom(roomInfo.getRoomId()));
|
||||
|
||||
roomsPane.getChildren().add(roomPane);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-7
@@ -23,22 +23,17 @@ public class LobbyEventRegister implements EventRegister {
|
||||
selectPVPModal();
|
||||
selectPVEModal();
|
||||
createPVPRoom();
|
||||
showRooms();
|
||||
}
|
||||
|
||||
private void selectPVPModal() {
|
||||
uiObject.$("pvpButton", Button.class).setOnAction(e -> lobbyEvent.selectPVPModal());
|
||||
uiObject.$("pvpModalButton", Button.class).setOnAction(e -> lobbyEvent.selectPVPModal());
|
||||
}
|
||||
|
||||
private void selectPVEModal() {
|
||||
uiObject.$("pveButton", Button.class).setOnAction(e -> lobbyEvent.selectPVEModal());
|
||||
uiObject.$("pveModalButton", Button.class).setOnAction(e -> lobbyEvent.selectPVEModal());
|
||||
}
|
||||
|
||||
private void createPVPRoom() {
|
||||
uiObject.$("createRoomButton", Button.class).setOnAction(e -> lobbyEvent.createPVPRoom());
|
||||
}
|
||||
|
||||
private void showRooms() {
|
||||
uiObject.$("listRoomsButton", Button.class).setOnAction(e -> lobbyEvent.showRooms());
|
||||
}
|
||||
}
|
||||
|
||||
+37
-37
@@ -2,57 +2,57 @@ package priv.zxw.ratel.landlords.client.javafx.ui.view.lobby;
|
||||
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Cursor;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.Pane;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.RoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.ILobbyEvent;
|
||||
|
||||
public class RoomPane {
|
||||
private static final int MARGIN_TOP = 25;
|
||||
private static final int MARGIN_LEFT = 40;
|
||||
|
||||
private Pane pane;
|
||||
|
||||
private Label idLabel;
|
||||
private Label roomOwnerLabel;
|
||||
private Label modalLabel;
|
||||
private Label clientCountLabel;
|
||||
|
||||
public RoomPane(RoomInfo roomInfo, ILobbyEvent lobbyEvent) {
|
||||
public RoomPane(RoomInfo roomInfo, int index) {
|
||||
pane = new Pane();
|
||||
pane.setId("roomPane" + roomInfo.getRoomId());
|
||||
pane.setPrefSize(200, 150);
|
||||
pane.setStyle("-fx-border-color: black");
|
||||
pane.setCursor(Cursor.HAND);
|
||||
pane.setOnMouseClicked(e -> lobbyEvent.joinRoom(roomInfo.getRoomId()));
|
||||
ObservableList<Node> children = pane.getChildren();
|
||||
pane.getStyleClass().add("roomPane");
|
||||
pane.setLayoutX(35 + (index % 3) * (150 + MARGIN_LEFT));
|
||||
pane.setLayoutY(65 + ((index / 3) * (120 + MARGIN_TOP)));
|
||||
|
||||
// 房间id label
|
||||
idLabel = new Label();
|
||||
idLabel.setLayoutX(14);
|
||||
idLabel.setLayoutY(14);
|
||||
Label idLabel = new Label();
|
||||
idLabel.setLayoutX(6);
|
||||
idLabel.setLayoutY(3);
|
||||
idLabel.getStyleClass().add("idLabel");
|
||||
idLabel.setText(roomInfo.getRoomId().toString());
|
||||
|
||||
Label roomOwnerLabel = new Label();
|
||||
roomOwnerLabel.setLayoutX(0);
|
||||
roomOwnerLabel.setLayoutY(22);
|
||||
roomOwnerLabel.getStyleClass().add("roomOwnerLabel");
|
||||
|
||||
Label roomOwnerNameLabel = new Label();
|
||||
roomOwnerNameLabel.setLayoutX(34);
|
||||
roomOwnerNameLabel.setLayoutY(32);
|
||||
roomOwnerNameLabel.setText(roomInfo.getRoomOwner());
|
||||
|
||||
Label modalLabel = new Label();
|
||||
modalLabel.setLayoutX(54);
|
||||
modalLabel.setLayoutY(60);
|
||||
modalLabel.getStyleClass().add("modalLabel");
|
||||
modalLabel.setText(roomInfo.getRoomType());
|
||||
|
||||
Label playerCountLabel = new Label();
|
||||
playerCountLabel.setLayoutX(60);
|
||||
playerCountLabel.setLayoutY(100);
|
||||
playerCountLabel.getStyleClass().add("playerCountLabel");
|
||||
playerCountLabel.setText("当前人数:" + roomInfo.getRoomClientCount() + "/3");
|
||||
|
||||
ObservableList<Node> children = pane.getChildren();
|
||||
children.add(idLabel);
|
||||
|
||||
// 房主label
|
||||
roomOwnerLabel = new Label();
|
||||
roomOwnerLabel.setLayoutX(14);
|
||||
roomOwnerLabel.setLayoutY(40);
|
||||
roomOwnerLabel.setText("房主:" + roomInfo.getRoomOwner());
|
||||
children.add(roomOwnerLabel);
|
||||
|
||||
// 模式label
|
||||
modalLabel = new Label();
|
||||
modalLabel.setLayoutX(14);
|
||||
modalLabel.setLayoutY(112);
|
||||
modalLabel.setText(roomInfo.getRoomType() + "模式");
|
||||
children.add(roomOwnerNameLabel);
|
||||
children.add(modalLabel);
|
||||
|
||||
// 当前人数
|
||||
clientCountLabel = new Label();
|
||||
clientCountLabel.setLayoutX(136);
|
||||
clientCountLabel.setLayoutY(112);
|
||||
clientCountLabel.setText(roomInfo.getRoomClientCount() + "/3人");
|
||||
children.add(clientCountLabel);
|
||||
children.add(playerCountLabel);
|
||||
}
|
||||
|
||||
public Pane getPane() {
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import javafx.scene.text.Text;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.enums.PokerLevel;
|
||||
import org.nico.ratel.landlords.enums.PokerType;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
|
||||
public class PokerPane {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import javafx.scene.layout.Pane;
|
||||
import javafx.scene.text.Text;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.enums.ClientType;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.IRoomEvent;
|
||||
|
||||
+2
-3
@@ -1,14 +1,13 @@
|
||||
package priv.zxw.ratel.landlords.client.javafx.ui.view.room;
|
||||
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import priv.zxw.ratel.landlords.client.javafx.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.util.BeanUtil;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.CurrentRoomInfo;
|
||||
import priv.zxw.ratel.landlords.client.javafx.entity.User;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.event.IRoomEvent;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.util.CountDownTask;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.EventRegister;
|
||||
import priv.zxw.ratel.landlords.client.javafx.ui.view.UIObject;
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package priv.zxw.ratel.landlords.client.javafx.ui.view.util;
|
||||
|
||||
import javafx.scene.control.Alert;
|
||||
|
||||
public class AlertUtils {
|
||||
|
||||
public static void info(String headerText, String contentText) {
|
||||
createAndShowAlert(Alert.AlertType.INFORMATION, headerText, contentText);
|
||||
}
|
||||
|
||||
private static void createAndShowAlert(Alert.AlertType alertType,
|
||||
String headerText, String contentText) {
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle(Alert.AlertType.INFORMATION.equals(alertType) ? "信息" :
|
||||
Alert.AlertType.WARNING.equals(alertType) ? "警告" : "错误");
|
||||
alert.setHeaderText(headerText);
|
||||
alert.setContentText(contentText);
|
||||
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
public static void warn(String headerText, String contentText) {
|
||||
createAndShowAlert(Alert.AlertType.WARNING, headerText, contentText);
|
||||
}
|
||||
|
||||
public static void error(String headerText, String contentText) {
|
||||
createAndShowAlert(Alert.AlertType.ERROR, headerText, contentText);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package priv.zxw.ratel.landlords.client.javafx.ui.view.util;
|
||||
|
||||
|
||||
import javafx.scene.Node;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CountDownTask {
|
||||
public static final int DEFAULT_TIME_OUT = 30;
|
||||
|
||||
private Consumer<Node> finallyExecuteConsumer;
|
||||
private Consumer<Integer> preSecondExecuteConsumer;
|
||||
private Node targetElement;
|
||||
private int duration;
|
||||
|
||||
public CountDownTask(Node targetElement,
|
||||
Consumer<Node> finallyExecuteConsumer, Consumer<Integer> preSecondExecuteConsumer) {
|
||||
this.finallyExecuteConsumer = finallyExecuteConsumer;
|
||||
this.preSecondExecuteConsumer = preSecondExecuteConsumer;
|
||||
this.targetElement = targetElement;
|
||||
}
|
||||
|
||||
public CountDownTask(Node targetElement, int duration,
|
||||
Consumer<Node> finallyExecuteConsumer, Consumer<Integer> preSecondExecuteConsumer) {
|
||||
Objects.requireNonNull(finallyExecuteConsumer);
|
||||
|
||||
this.finallyExecuteConsumer = finallyExecuteConsumer;
|
||||
this.preSecondExecuteConsumer = preSecondExecuteConsumer;
|
||||
this.duration = duration < 0 ? DEFAULT_TIME_OUT : duration;
|
||||
this.targetElement = targetElement;
|
||||
}
|
||||
|
||||
public CountDownFuture start() {
|
||||
targetElement.setVisible(true);
|
||||
|
||||
CountDownFuture future = new CountDownFuture();
|
||||
future.start();
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public class CountDownFuture extends Thread {
|
||||
|
||||
private volatile boolean done = false;
|
||||
|
||||
private CountDownFuture() {
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long startTimeMillis = System.currentTimeMillis();
|
||||
|
||||
long interval;
|
||||
try {
|
||||
while (true) {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
interval = (currentTimeMillis - startTimeMillis) / 1000;
|
||||
|
||||
if (interval > duration) {
|
||||
break;
|
||||
}
|
||||
|
||||
preSecondExecuteConsumer.accept((int) (duration - interval));
|
||||
|
||||
sleep(1000L);
|
||||
}
|
||||
|
||||
finallyExecuteConsumer.accept(targetElement);
|
||||
} catch (InterruptedException cancelFlag) {
|
||||
// exit
|
||||
return;
|
||||
} finally {
|
||||
done = true;
|
||||
targetElement.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
|
||||
done = true;
|
||||
interrupt();
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package priv.zxw.ratel.landlords.client.javafx.util;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BeanUtil {
|
||||
private static final Map<String, Object> CACHE_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
public static void addBean(String name, Object object) {
|
||||
CACHE_MAP.put(name, object);
|
||||
}
|
||||
|
||||
public static <T> T getBean(String name) {
|
||||
return (T) CACHE_MAP.get(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#createRoomButton {
|
||||
-fx-pref-width: 30;
|
||||
-fx-pref-height: 30;
|
||||
-fx-background-color: #dbd9d8;
|
||||
-fx-border-width: 1;
|
||||
-fx-border-radius: 5;
|
||||
-fx-background-radius: 5;
|
||||
-fx-border-color: #dbd9d8;
|
||||
-fx-cursor: hand;
|
||||
-fx-background-image: url("../image/add_0.png");
|
||||
}
|
||||
|
||||
.title {
|
||||
-fx-pref-width: 600;
|
||||
-fx-pref-height: 40;
|
||||
-fx-border-color: black;
|
||||
-fx-border-width: 0 0 1 0;
|
||||
}
|
||||
|
||||
.roomListTitle {
|
||||
-fx-font-size: 20;
|
||||
}
|
||||
|
||||
.roomPane {
|
||||
-fx-pref-width: 150;
|
||||
-fx-pref-height: 120;
|
||||
-fx-border-color: #afadab;
|
||||
-fx-background-color: #dddbd8;
|
||||
-fx-background-radius: 10;
|
||||
-fx-border-radius: 10;
|
||||
-fx-cursor: hand;
|
||||
}
|
||||
|
||||
.roomPane:hover {
|
||||
-fx-border-color: #3f91af;
|
||||
}
|
||||
|
||||
.roomPane > .idLabel {
|
||||
-fx-font-size: 16;
|
||||
-fx-border-color: black;
|
||||
-fx-border-width: 0 0 1 0;
|
||||
}
|
||||
|
||||
.roomPane > .roomOwnerLabel {
|
||||
-fx-pref-width: 30;
|
||||
-fx-pref-height: 30;
|
||||
-fx-background-image: url("../image/face_0.png");
|
||||
}
|
||||
|
||||
.roomPane > .modalLabel {
|
||||
-fx-font-size: 30;
|
||||
-fx-text-fill: silver;
|
||||
-fx-opacity: 0.8;
|
||||
}
|
||||
|
||||
.roomPane > .playerCountLabel {
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
@import "./poker.css";
|
||||
|
||||
#waitingPane,
|
||||
#gameOverPane {
|
||||
-fx-background-color: silver;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -1,27 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<AnchorPane prefHeight="400.0" prefWidth="600.0"
|
||||
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" stylesheets="@assets/css/lobby.css">
|
||||
<children>
|
||||
<!-- 对战模式选择 -->
|
||||
<Pane fx:id="modalPane" visible="true">
|
||||
<Button fx:id="pvpButton" layoutX="80.0" layoutY="80" prefHeight="100.0" prefWidth="200.0">P v P</Button>
|
||||
<Button fx:id="pveButton" layoutX="350.0" layoutY="80" prefHeight="100.0" prefWidth="200.0">P v E</Button>
|
||||
<Button fx:id="pvpModalButton" layoutX="80.0" layoutY="80" prefHeight="100.0" prefWidth="200.0">P v P</Button>
|
||||
<Button fx:id="pveModalButton" layoutX="350.0" layoutY="80" prefHeight="100.0" prefWidth="200.0">P v E</Button>
|
||||
</Pane>
|
||||
|
||||
<!-- PVP菜单 -->
|
||||
<Pane fx:id="pvpMenuPane" visible="false">
|
||||
<children>
|
||||
<Pane fx:id="buttonsPane" visible="true">
|
||||
<Button fx:id="createRoomButton" layoutX="80.0" layoutY="80" prefHeight="100.0" prefWidth="200.0">创建房间</Button>
|
||||
<Button fx:id="listRoomsButton" layoutX="350.0" layoutY="80" prefHeight="100.0" prefWidth="200.0">房间列表</Button>
|
||||
<Pane fx:id="roomsPane" prefHeight="400.0" prefWidth="600.0">
|
||||
<Pane styleClass="title">
|
||||
<Label layoutX="5" layoutY="5" styleClass="roomListTitle">房间列表</Label>
|
||||
<Button fx:id="createRoomButton" layoutX="540" layoutY="5"/>
|
||||
</Pane>
|
||||
|
||||
<Pane fx:id="roomsPane" visible="false">
|
||||
</Pane>
|
||||
</children>
|
||||
</Pane>
|
||||
</Pane>
|
||||
|
||||
<!-- PVE菜单 -->
|
||||
|
||||
Reference in New Issue
Block a user