Skip to content

Commit ffcc255

Browse files
committed
Made some more adjustments
1 parent 3e91a95 commit ffcc255

3 files changed

Lines changed: 112 additions & 18 deletions

File tree

client.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ SetWebURL(web, "http://asset/dialogui/dialog.html")
55
local nextId = 1
66
local dialogs = {}
77
local lastOpened = -1
8-
function createDialog(title, text)
8+
function createDialog(title, text, ...)
99
local id = nextId
1010
nextId = nextId + 1
1111
dialogs[id] = {
1212
title = title,
1313
text = text,
1414
columns = {},
15+
buttons = {...},
1516
variables = {}
1617
}
1718
return id
@@ -20,6 +21,10 @@ function setDialogButtons(dialog, column, ...)
2021
if dialogs[dialog] == nil then
2122
return
2223
end
24+
if column == 0 then
25+
dialogs[dialog].buttons = {...}
26+
return
27+
end
2328
if dialogs[dialog].columns[column] == nil then
2429
dialogs[dialog].columns[column] = {
2530
inputs = {},
@@ -164,7 +169,10 @@ function showDialog(dialog)
164169
if i > 1 then
165170
json = json..","
166171
end
167-
json = json.."{type:\""..d.columns[j].inputs[i].type.."\",name:\""..replaceVariables(d.columns[j].inputs[i].name, d.variables).."\""
172+
json = json.."{type:\""..d.columns[j].inputs[i].type.."\""
173+
if d.columns[j].inputs[i].name ~= nil then
174+
json = json..",name:\""..replaceVariables(d.columns[j].inputs[i].name, d.variables).."\""
175+
end
168176
if d.columns[j].inputs[i].options ~= nil then
169177
if d.columns[j].inputs[i].labelMode then
170178
json = json..",options:{"
@@ -205,7 +213,15 @@ function showDialog(dialog)
205213
end
206214
json = json.."]}"
207215
end
216+
json = json.."],buttons:["
217+
for i=1,#d.buttons do
218+
if i > 1 then
219+
json = json..","
220+
end
221+
json = json.."\""..replaceVariables(d.buttons[i], d.variables).."\""
222+
end
208223
end
224+
print("SetDialog("..dialog..",{"..json.."]});")
209225
ExecuteWebJS(web, "SetDialog("..dialog..",{"..json.."]});")
210226
SetIgnoreLookInput(true)
211227
SetIgnoreMoveInput(true)

dialog.css

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,58 @@ body {
22
margin: 0px;
33
}
44

5-
.col-md-6 {
5+
.input-c2 {
66
padding-left: 1%;
77
padding-right: 1%;
88
width: 48%;
99
}
1010

11-
.col-md-12 {
11+
.input-c1 {
1212
padding: 0px;
1313
width: 100%;
1414
}
1515

16-
.col-md-4 {
16+
.input-c3 {
1717
padding-left: 1%;
1818
padding-right: 1%;
1919
width: 31.333333%;
2020
}
2121

22+
.spl-c1-1 {
23+
padding: 0px;
24+
width: 100%;
25+
}
26+
27+
.spl-c2-1 {
28+
padding-left: 0%;
29+
padding-right: 1%;
30+
width: 49%;
31+
}
32+
33+
.spl-c2-2 {
34+
padding-left: 1%;
35+
padding-right: 0%;
36+
width: 49%;
37+
}
38+
39+
.spl-c3-1 {
40+
padding-left:0%;
41+
padding-right: 1%;
42+
width: 32%;
43+
}
44+
45+
.spl-c3-2 {
46+
padding-left: 1%;
47+
padding-right: 1%;
48+
width: 32%;
49+
}
50+
51+
.spl-c3-3 {
52+
padding-left: 1%;
53+
padding-right: 0%;
54+
width: 32%;
55+
}
56+
2257
.wrapper {
2358
width: 100vw;
2459
height: 100vh;

dialog.js

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ function SetDialog(id, json) {
1010
menuContentDiv.style.width = (json.columns.length*300)+"px";;
1111
if (json.title !== undefined) {
1212
if(json.title.length > 0){
13-
menuContentDiv.appendChild(document.createElement("hr"));
1413
let titleH = document.createElement("h1");
1514
titleH.className = "menu-title";
1615
titleH.appendChild(document.createTextNode(json.title));
@@ -31,33 +30,30 @@ function SetDialog(id, json) {
3130
gridElement.className = "row";
3231
gridElement.style.width = (json.columns.length*300)+"px";
3332
gridElement.style.marginLeft = "0px";
33+
let rendered = 0;
3434
for(let colId=0; colId<json.columns.length; colId++){
3535
let column = json.columns[colId];
3636
let colElement = document.createElement("div");
3737
switch(json.columns.length){
3838
case 1:
39-
colElement.className = "col-md-12";
39+
colElement.className = "col-md-12 spl-c1-1";
4040
break;
4141
case 2:
42-
colElement.className = "col-md-6";
42+
colElement.className = "col-md-6 spl-c2-"+(colId+1);
4343
break;
4444
case 3:
45-
colElement.className = "col-md-4";
46-
break;
47-
case 4:
48-
colElement.className = "col-md-3";
45+
colElement.className = "col-md-4 spl-c3-"+(colId+1);
4946
break;
5047
}
5148
if (column.inputs !== undefined && column.inputs.length > 0) {
52-
let rendered = 0;
5349
for (let jsonInput of column.inputs){
5450
if (jsonInput.type === "text") {
5551
let inputElement = document.createElement("input");
5652
inputElement.className = "menu-input-text";
5753
if(jsonInput.name.length > 0){
5854
let labelElement = document.createElement("label");
5955
labelElement.className = "menu-label";
60-
labelElement.appendChild(document.createTextNode(jsonInput.name + ':'));
56+
labelElement.appendChild(document.createTextNode(jsonInput.name));
6157
colElement.appendChild(labelElement);
6258
colElement.appendChild(inputElement);
6359
rendered++;
@@ -88,7 +84,7 @@ function SetDialog(id, json) {
8884
if(jsonInput.name !== undefined){
8985
let labelElement = document.createElement("label");
9086
labelElement.className = "menu-label";
91-
labelElement.appendChild(document.createTextNode(jsonInput.name + ':'));
87+
labelElement.appendChild(document.createTextNode(jsonInput.name));
9288
colElement.appendChild(labelElement);
9389
}
9490
colElement.appendChild(selectElement);
@@ -112,9 +108,30 @@ function SetDialog(id, json) {
112108
inputs.push(checkboxElement);
113109
}
114110
}
115-
if(rendered > 0){
116-
colElement.appendChild(document.createElement("hr"));
117-
}
111+
}
112+
gridElement.appendChild(colElement);
113+
}
114+
menuContentDiv.appendChild(gridElement);
115+
if(rendered > 0){
116+
menuContentDiv.appendChild(document.createElement("hr"));
117+
}
118+
gridElement = document.createElement("div");
119+
gridElement.className = "row";
120+
gridElement.style.width = (json.columns.length*300)+"px";
121+
gridElement.style.marginLeft = "0px";
122+
for(let colId=0; colId<json.columns.length; colId++){
123+
let column = json.columns[colId];
124+
let colElement = document.createElement("div");
125+
switch(json.columns.length){
126+
case 1:
127+
colElement.className = "col-md-12 spl-c1-1";
128+
break;
129+
case 2:
130+
colElement.className = "col-md-6 spl-c2-"+(colId+1);
131+
break;
132+
case 3:
133+
colElement.className = "col-md-4 spl-c3-"+(colId+1);
134+
break;
118135
}
119136
for (let i = 0; i < column.buttons.length; i++){
120137
if(column.buttons[i].length == 0){
@@ -145,6 +162,32 @@ function SetDialog(id, json) {
145162
gridElement.appendChild(colElement);
146163
}
147164
menuContentDiv.appendChild(gridElement);
165+
for (let i = 0; i < json.buttons.length; i++){
166+
if(json.buttons[i].length == 0){
167+
continue;
168+
}
169+
let buttonElement = document.createElement("button");
170+
buttonElement.className = "menu-button";
171+
buttonElement.appendChild(document.createTextNode(json.buttons[i]));
172+
let buttonId = nextButtonId;
173+
nextButtonId++;
174+
buttonElement.onclick = function () {
175+
let params = [id, buttonId];
176+
for (let input of inputs) {
177+
if (input.type === "checkbox") {
178+
params.push(input.checked);
179+
} else {
180+
params.push(input.value);
181+
}
182+
}
183+
if(json.autoclose === undefined || json.autoclose){
184+
CloseDialog();
185+
ue.game.callevent("__dialog_system_closed", "[]");
186+
}
187+
ue.game.callevent("OnDialogSubmit", JSON.stringify(params));
188+
};
189+
menuContentDiv.appendChild(buttonElement);
190+
}
148191
menuDiv.appendChild(menuContentDiv);
149192
}
150193

0 commit comments

Comments
 (0)