|
1
|
|
|
package de.kleiner3.lasertag.client.screen; |
|
2
|
|
|
|
|
3
|
|
|
import de.kleiner3.lasertag.lasertaggame.gamemode.GameModes; |
|
4
|
|
|
import de.kleiner3.lasertag.networking.NetworkingConstants; |
|
5
|
|
|
import io.netty.buffer.Unpooled; |
|
6
|
|
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; |
|
7
|
|
|
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; |
|
8
|
|
|
import net.minecraft.client.gui.widget.ButtonWidget; |
|
9
|
|
|
import net.minecraft.client.gui.widget.CyclingButtonWidget; |
|
10
|
|
|
import net.minecraft.entity.player.PlayerEntity; |
|
11
|
|
|
import net.minecraft.network.PacketByteBuf; |
|
12
|
|
|
import net.minecraft.text.Text; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The main screen of the lasertag game manager |
|
16
|
|
|
* |
|
17
|
|
|
* @author Étienne Muser |
|
18
|
|
|
*/ |
|
19
|
|
|
public class LasertagGameManagerScreen extends GameManagerScreen { |
|
20
|
|
|
|
|
21
|
|
|
private CyclingButtonWidget<String> gameModeButton; |
|
22
|
|
|
|
|
23
|
|
|
public LasertagGameManagerScreen(PlayerEntity player) { |
|
24
|
|
|
super(null, "gui.game_manager.overview_screen_title", player); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public void reloadGameMode() { |
|
28
|
|
|
|
|
29
|
|
|
// Get the game managers |
|
30
|
|
|
var gameManager = client.world.getClientLasertagManager(); |
|
31
|
|
|
var gameModeManager = gameManager.getGameModeManager(); |
|
32
|
|
|
|
|
33
|
|
|
this.gameModeButton.setValue(gameModeManager.getGameMode().getTranslatableName()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
@Override |
|
37
|
|
|
protected void init() { |
|
38
|
|
|
super.init(); |
|
39
|
|
|
|
|
40
|
|
|
// Get the game managers |
|
41
|
|
|
var gameManager = client.world.getClientLasertagManager(); |
|
42
|
|
|
var gameModeManager = gameManager.getGameModeManager(); |
|
43
|
|
|
|
|
44
|
|
|
this.gameModeButton = this.addListedWidget((x, y, width, height) -> CyclingButtonWidget |
|
45
|
|
|
.builder(this::getGameModeText) |
|
46
|
|
|
.values(GameModes.GAME_MODES.keySet()) |
|
47
|
|
|
.initially(gameModeManager.getGameMode().getTranslatableName()) |
|
48
|
|
|
.build(x, y, width, height, Text.translatable("gui.game_manager.game_mode_button"), |
|
49
|
|
|
(button, gameModeTranslatableName) -> { |
|
50
|
|
|
|
|
51
|
|
|
// Send event to server |
|
52
|
|
|
var buf = new PacketByteBuf(Unpooled.buffer()); |
|
53
|
|
|
buf.writeString(gameModeTranslatableName); |
|
54
|
|
|
ClientPlayNetworking.send(NetworkingConstants.CLIENT_TRIGGER_GAME_MODE_CHANGE, buf); |
|
55
|
|
|
})); |
|
56
|
|
|
this.gameModeButton.active = this.player.hasPermissionLevel(4); |
|
57
|
|
|
|
|
58
|
|
|
this.addListedButton("gui.game_manager.settings_button", this::onSettingsClick); |
|
59
|
|
|
|
|
60
|
|
|
if (this.player.hasPermissionLevel(4)) { |
|
61
|
|
|
this.addListedButton("gui.game_manager.map_button", this::onMapClick); |
|
62
|
|
|
} |
|
63
|
|
|
if (this.player.hasPermissionLevel(4)) { |
|
64
|
|
|
this.addListedButton("gui.game_manager.teams_button", this::onTeamsClick); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (this.player.hasPermissionLevel(4)) { |
|
68
|
|
|
this.addListedButton("gui.game_manager.reset_team_config_button", this::onResetTeamConfigClick); |
|
69
|
|
|
} |
|
70
|
|
|
if (this.player.hasPermissionLevel(4)) { |
|
71
|
|
|
this.addListedButton("gui.game_manager.reload_team_config_button", this::onReloadTeamConfigClick); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private void onSettingsClick(ButtonWidget button) { |
|
76
|
|
|
this.client.setScreen(new LasertagGameManagerSettingsScreen(this, player)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private void onMapClick(ButtonWidget button) { |
|
80
|
|
|
this.client.setScreen(new LasertaGameManagerArenaScreen(this, player)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private void onTeamsClick(ButtonWidget button) { |
|
84
|
|
|
this.client.setScreen(new LasertagGameManagerTeamsScreen(this, player)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
private void onResetTeamConfigClick(ButtonWidget button) { |
|
88
|
|
|
ClientPlayNetworking.send(NetworkingConstants.CLIENT_TRIGGER_RESET_TEAM_CONFIG, PacketByteBufs.empty()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private void onReloadTeamConfigClick(ButtonWidget button) { |
|
92
|
|
|
ClientPlayNetworking.send(NetworkingConstants.CLIENT_TRIGGER_RELOAD_TEAM_CONFIG, PacketByteBufs.empty()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private Text getGameModeText(String gameModeTranslatableName) { |
|
96
|
|
|
return Text.translatable(gameModeTranslatableName); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|