-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmationModal.java
More file actions
190 lines (157 loc) · 5 KB
/
Copy pathConfirmationModal.java
File metadata and controls
190 lines (157 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.hyperfactions.gui.shared.component;
import com.hyperfactions.gui.UIPaths;
import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
import com.hypixel.hytale.server.core.ui.builder.EventData;
import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Reusable confirmation modal component.
* Displays a yes/no prompt with custom title, message, and event data.
*/
public class ConfirmationModal {
private final String title;
private final String message;
private final String confirmEventName;
private final String cancelEventName;
private final EventData confirmEventData;
private final EventData cancelEventData;
/**
* Builder for ConfirmationModal.
*/
public static class Builder {
private String title = "Confirm Action";
private String message = "Are you sure?";
private String confirmEventName = "Confirm";
private String cancelEventName = "Cancel";
private EventData confirmEventData;
private EventData cancelEventData;
/** Title. */
public Builder title(@NotNull String title) {
this.title = title;
return this;
}
/** Message. */
public Builder message(@NotNull String message) {
this.message = message;
return this;
}
/** Confirm Event. */
public Builder confirmEvent(@NotNull String eventName) {
this.confirmEventName = eventName;
return this;
}
/** Confirm Event. */
public Builder confirmEvent(@NotNull String eventName, @NotNull EventData data) {
this.confirmEventName = eventName;
this.confirmEventData = data;
return this;
}
/** Checks if cel event. */
public Builder cancelEvent(@NotNull String eventName) {
this.cancelEventName = eventName;
return this;
}
public Builder cancelEvent(@NotNull String eventName, @NotNull EventData data) {
this.cancelEventName = eventName;
this.cancelEventData = data;
return this;
}
/** Builds . */
public ConfirmationModal build() {
if (confirmEventData == null) {
confirmEventData = EventData.of("Button", confirmEventName);
}
if (cancelEventData == null) {
cancelEventData = EventData.of("Button", cancelEventName);
}
return new ConfirmationModal(
title, message, confirmEventName, cancelEventName,
confirmEventData, cancelEventData
);
}
}
private ConfirmationModal(String title, String message,
String confirmEventName, String cancelEventName,
EventData confirmEventData, EventData cancelEventData) {
this.title = title;
this.message = message;
this.confirmEventName = confirmEventName;
this.cancelEventName = cancelEventName;
this.confirmEventData = confirmEventData;
this.cancelEventData = cancelEventData;
}
/** Builds er. */
public static Builder builder() {
return new Builder();
}
/**
* Renders the confirmation modal into the UI.
*
* @param cmd UI command builder
* @param events UI event builder
* @param targetId Target element ID where modal should be appended (e.g., "#ModalContainer")
*/
public void render(@NotNull UICommandBuilder cmd, @NotNull UIEventBuilder events,
@NotNull String targetId) {
// Append modal template
cmd.append(targetId, UIPaths.MODAL_CONFIRMATION);
// Set title and message
cmd.set(targetId + " #ModalTitle.Text", title);
cmd.set(targetId + " #ModalMessage.Text", message);
// Bind confirm button
events.addEventBinding(
CustomUIEventBindingType.Activating,
targetId + " #ConfirmBtn",
confirmEventData,
false
);
// Bind cancel button
events.addEventBinding(
CustomUIEventBindingType.Activating,
targetId + " #CancelBtn",
cancelEventData,
false
);
}
/**
* Quick helper for dangerous actions (disband, kick, war, etc.).
* Uses red styling for confirm button.
*/
public static ConfirmationModal dangerous(String title, String message, String confirmEvent) {
return builder()
.title(title)
.message(message)
.confirmEvent(confirmEvent)
.build();
}
/**
* Quick helper for safe confirmations (leave, neutral, etc.).
* Uses default styling.
*/
public static ConfirmationModal safe(String title, String message, String confirmEvent) {
return builder()
.title(title)
.message(message)
.confirmEvent(confirmEvent)
.build();
}
// Getters
/** Returns the title. */
public String getTitle() {
return title;
}
/** Returns the message. */
public String getMessage() {
return message;
}
/** Returns the confirm event name. */
public String getConfirmEventName() {
return confirmEventName;
}
/** Returns the cancel event name. */
public String getCancelEventName() {
return cancelEventName;
}
}