Skip to content

Commit b2bc8d7

Browse files
committed
Implemented auto close
1 parent 3e153a9 commit b2bc8d7

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

client.lua

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ function createDialog(title, text, ...)
1111
dialogs[id] = {
1212
title = title,
1313
text = text,
14-
columns = {},
14+
columns = { { inputs = {}, buttons = {} } },
1515
buttons = {...},
16-
variables = {}
16+
variables = {},
17+
autoclose = "true"
1718
}
1819
return id
1920
end
@@ -122,6 +123,16 @@ function setVariable(dialog, name, value)
122123
end
123124
dialogs[dialog].variables[name] = value
124125
end
126+
function setDialogAutoclose(dialog, autoclose)
127+
if dialogs[dialog] == nil then
128+
return
129+
end
130+
if autoclose then
131+
dialogs[dialog].autoclose = "true"
132+
else
133+
dialogs[dialog].autoclose = "false"
134+
end
135+
end
125136
function replaceVariables(text, variables)
126137
for k,v in pairs(variables) do
127138
text = text:gsub("{"..k.."}", v)
@@ -148,9 +159,9 @@ function showDialog(dialog)
148159
end
149160
lastOpened = dialog
150161
local d = dialogs[dialog]
151-
local json = ""
162+
local json = "autoclose:"..d.autoclose..","
152163
if d.title ~= nil then
153-
json = "title:\""..replaceVariables(d.title, d.variables).."\","
164+
json = json.."title:\""..replaceVariables(d.title, d.variables).."\","
154165
end
155166
if d.text ~= nil then
156167
json = json.."text:\""..replaceVariables(d.text, d.variables).."\","
@@ -221,7 +232,6 @@ function showDialog(dialog)
221232
json = json.."\""..replaceVariables(d.buttons[i], d.variables).."\""
222233
end
223234
end
224-
print("SetDialog("..dialog..",{"..json.."]});")
225235
ExecuteWebJS(web, "SetDialog("..dialog..",{"..json.."]});")
226236
SetIgnoreLookInput(true)
227237
SetIgnoreMoveInput(true)
@@ -245,4 +255,5 @@ AddFunctionExport("show", showDialog)
245255
AddFunctionExport("close", closeDialog)
246256
AddFunctionExport("destroy", destroyDialog)
247257
AddFunctionExport("setSelectOptions", setDialogSelectOptions)
248-
AddFunctionExport("setSelectLabeledOptions", setDialogSelectOptionsWithLabels)
258+
AddFunctionExport("setSelectLabeledOptions", setDialogSelectOptionsWithLabels)
259+
AddFunctionExport("setAutoClose", setDialogAutoclose)

dialog.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ body {
124124
margin-bottom: 5px;
125125
}
126126

127+
.menu-input-slider {
128+
width: calc(100% - 8px);
129+
background-color: #262626;
130+
color: white;
131+
outline: none;
132+
margin-bottom: 5px;
133+
}
134+
127135
.menu-checkbox {
128136

129137
}

dialog.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ function SetDialog(id, json) {
66
while (menuDiv.firstChild !== null) {
77
menuDiv.removeChild(menuDiv.firstChild);
88
}
9+
let boxWidth = json.columns.length;
10+
if(boxWidth < 1){
11+
boxWidth = 1;
12+
}
913
let menuContentDiv = document.createElement("div");
10-
menuContentDiv.style.width = (json.columns.length*300)+"px";;
14+
menuContentDiv.style.width = (boxWidth*300)+"px";
1115
if (json.title !== undefined) {
1216
if(json.title.length > 0){
1317
let titleH = document.createElement("h1");
@@ -28,7 +32,7 @@ function SetDialog(id, json) {
2832
}
2933
let gridElement = document.createElement("div");
3034
gridElement.className = "row";
31-
gridElement.style.width = (json.columns.length*300)+"px";
35+
gridElement.style.width = (boxWidth*300)+"px";
3236
gridElement.style.marginLeft = "0px";
3337
let rendered = 0;
3438
for(let colId=0; colId<json.columns.length; colId++){
@@ -117,7 +121,7 @@ function SetDialog(id, json) {
117121
}
118122
gridElement = document.createElement("div");
119123
gridElement.className = "row";
120-
gridElement.style.width = (json.columns.length*300)+"px";
124+
gridElement.style.width = (boxWidth*300)+"px";
121125
gridElement.style.marginLeft = "0px";
122126
for(let colId=0; colId<json.columns.length; colId++){
123127
let column = json.columns[colId];

0 commit comments

Comments
 (0)