Guest User

Character Sheet Template + Lock/Unlock functionality

a guest
Aug 26th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.27 KB | None | 0 0
  1. disableSave = true
  2. --Remember to set this to false once you are done making changes
  3. --Then, after you save & apply it, save your game too
  4.  
  5. --Color information for button text (r,g,b, values of 0-1)
  6. buttonFontColor = {0,0,0}
  7. --Color information for button background
  8. buttonColor = {1,1,1}
  9. --Change scale of button (Avoid changing if possible)
  10. buttonScale = {0.1,0.1,0.1}
  11.  
  12. --This is the button placement information
  13. defaultButtonData = {
  14. --Add checkboxes
  15. checkbox = {
  16. --[[
  17. pos = the position (pasted from the helper tool)
  18. size = height/width/font_size for checkbox
  19. state = default starting value for checkbox (true=checked, false=not)
  20. ]]
  21. {
  22. pos = {1.12,0.1,-1.78},
  23. size = 800,
  24. state = true
  25. },
  26. --First checkbox
  27. {
  28. pos = {-0.977,0.1,-0.589},
  29. size = 800,
  30. state = false
  31. },
  32. --Second checkbox
  33. {
  34. pos = {-0.163,0.1,-0.594},
  35. size = 800,
  36. state = false
  37. },
  38. --Third checkbox
  39. {
  40. pos = {0.735,0.1,-0.592},
  41. size = 800,
  42. state = false
  43. },
  44. --End of checkboxes
  45. },
  46. --Add counters that have a + and - button
  47. counter = {
  48. --[[
  49. pos = the position (pasted from the helper tool)
  50. size = height/width/font_size for counter
  51. value = default starting value for counter
  52. hideBG = if background of counter is hidden (true=hidden, false=not)
  53. ]]
  54. --First counter
  55. {
  56. pos = {-0.996,0.1,0.057},
  57. size = 800,
  58. value = 0,
  59. hideBG = true
  60. },
  61. --Second counter
  62. {
  63. pos = {-0.151,0.1,0.043},
  64. size = 800,
  65. value = 0,
  66. hideBG = false
  67. },
  68. --Third counter
  69. {
  70. pos = {0.736,0.1,0.051},
  71. size = 800,
  72. value = 0,
  73. hideBG = true
  74. },
  75. --End of counters
  76. },
  77. --Add editable text boxes
  78. textbox = {
  79. --[[
  80. pos = the position (pasted from the helper tool)
  81. rows = how many lines of text you want for this box
  82. width = how wide the text box is
  83. font_size = size of text. This and "rows" effect overall height
  84. label = what is shown when there is no text. "" = nothing
  85. value = text entered into box. "" = nothing
  86. alignment = Number to indicate how you want text aligned
  87. (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified)
  88. ]]
  89. --First textbox
  90. {
  91. pos = {-0.552,0.1,1.213},
  92. rows = 16,
  93. width = 4000,
  94. font_size = 300,
  95. label = "Empty",
  96. value = "",
  97. alignment = 2
  98. },
  99. --Second textbox
  100. {
  101. pos = {0.572,0.1,0.768},
  102. rows = 1,
  103. width = 3000,
  104. font_size = 600,
  105. label = "Broke",
  106. value = "",
  107. alignment = 3
  108. },
  109. --Third textbox
  110. {
  111. pos = {0.596,0.1,1.393},
  112. rows = 6,
  113. width = 4000,
  114. font_size = 400,
  115. label = "Brickabrackless",
  116. value = "",
  117. alignment = 4
  118. },
  119. --End of textboxes
  120. }
  121. }
  122.  
  123. --Save function
  124. function updateSave()
  125. saved_data = JSON.encode(ref_buttonData)
  126. if disableSave==true then saved_data="" end
  127. self.script_state = saved_data
  128. end
  129.  
  130. --Startup procedure
  131. function onload(saved_data)
  132. if disableSave==true then saved_data="" end
  133. if saved_data ~= "" then
  134. local loaded_data = JSON.decode(saved_data)
  135. ref_buttonData = loaded_data
  136. else
  137. ref_buttonData = defaultButtonData
  138. end
  139.  
  140. spawnedButtonCount = 0
  141. createCheckbox()
  142. createCounter()
  143. createTextbox()
  144. end
  145.  
  146.  
  147.  
  148. --Click functions for buttons
  149.  
  150.  
  151.  
  152. --Checks or unchecks the given box
  153. function click_checkbox(tableIndex, buttonIndex)
  154. if ref_buttonData.checkbox[1].state then
  155. if ref_buttonData.checkbox[tableIndex].state == true then
  156. ref_buttonData.checkbox[tableIndex].state = false
  157. self.editButton({index=buttonIndex, label=""})
  158. else
  159. ref_buttonData.checkbox[tableIndex].state = true
  160. self.editButton({index=buttonIndex, label=string.char(10008)})
  161. end
  162. updateSave()
  163. end
  164. end
  165. --Predefined special checkbox (to lock other controls)
  166. function click_checkboxE(tableIndex, buttonIndex)
  167. if ref_buttonData.checkbox[tableIndex].state == true then
  168. ref_buttonData.checkbox[tableIndex].state = false
  169. self.editButton({index=buttonIndex, label=""})
  170. else
  171. ref_buttonData.checkbox[tableIndex].state = true
  172. self.editButton({index=buttonIndex, label=string.char(10008)})
  173. for i, text in ipairs(ref_buttonData.textbox) do
  174. self.editInput({index=i-1,value=ref_buttonData.textbox[i].value})
  175. end
  176. end
  177. updateSave()
  178. end
  179.  
  180. --Applies value to given counter display
  181. function click_counter(tableIndex, buttonIndex, amount)
  182. if ref_buttonData.checkbox[1].state then
  183. ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount
  184. self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value})
  185. updateSave()
  186. end
  187. end
  188.  
  189. --Updates saved value for given text box
  190. function click_textbox(i, value, selected)
  191. if ref_buttonData.checkbox[1].state then
  192. if selected == false then
  193. ref_buttonData.textbox[i].value = value
  194. updateSave()
  195. end
  196. else
  197. if selected == false then
  198. Wait.time(function() self.editInput({index=i-1,value=ref_buttonData.textbox[i].value}) end,0.1)
  199. broadcastToAll("someone tried edit text field while not edible.")
  200. end
  201. end
  202. end
  203.  
  204. --Dud function for if you have a background on a counter
  205. function click_none() end
  206.  
  207.  
  208.  
  209. --Button creation
  210.  
  211.  
  212.  
  213. --Makes checkboxes
  214. function createCheckbox()
  215. for i, data in ipairs(ref_buttonData.checkbox) do
  216. --Sets up reference function
  217. local buttonNumber = spawnedButtonCount
  218. local funcName = "checkbox"..i
  219. local func
  220. if i == 1 then
  221. func = function() click_checkboxE(i, buttonnumber) end
  222. else
  223. func = function() click_checkbox(i, buttonNumber) end
  224. end
  225. self.setVar(funcName, func)
  226. --Sets up label
  227. local label = ""
  228. if data.state==true then label=string.char(10008) end
  229. --Creates button and counts it
  230. self.createButton({
  231. label=label, click_function=funcName, function_owner=self,
  232. position=data.pos, height=data.size, width=data.size,
  233. font_size=data.size, scale=buttonScale,
  234. color=buttonColor, font_color=buttonFontColor
  235. })
  236. spawnedButtonCount = spawnedButtonCount + 1
  237. end
  238. end
  239.  
  240. --Makes counters
  241. function createCounter()
  242. for i, data in ipairs(ref_buttonData.counter) do
  243. --Sets up display
  244. local displayNumber = spawnedButtonCount
  245. --Sets up label
  246. local label = data.value
  247. --Sets height/width for display
  248. local size = data.size
  249. if data.hideBG == true then size = 0 end
  250. --Creates button and counts it
  251. self.createButton({
  252. label=label, click_function="click_none", function_owner=self,
  253. position=data.pos, height=size, width=size,
  254. font_size=data.size, scale=buttonScale,
  255. color=buttonColor, font_color=buttonFontColor
  256. })
  257. spawnedButtonCount = spawnedButtonCount + 1
  258.  
  259. --Sets up add 1
  260. local funcName = "counterAdd"..i
  261. local func = function() click_counter(i, displayNumber, 1) end
  262. self.setVar(funcName, func)
  263. --Sets up label
  264. local label = "+"
  265. --Sets up position
  266. local offsetDistance = (data.size/2 + data.size/4) * (buttonScale[1] * 0.002)
  267. local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]}
  268. --Sets up size
  269. local size = data.size / 2
  270. --Creates button and counts it
  271. self.createButton({
  272. label=label, click_function=funcName, function_owner=self,
  273. position=pos, height=size, width=size,
  274. font_size=size, scale=buttonScale,
  275. color=buttonColor, font_color=buttonFontColor
  276. })
  277. spawnedButtonCount = spawnedButtonCount + 1
  278.  
  279. --Sets up subtract 1
  280. local funcName = "counterSub"..i
  281. local func = function() click_counter(i, displayNumber, -1) end
  282. self.setVar(funcName, func)
  283. --Sets up label
  284. local label = "-"
  285. --Set up position
  286. local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]}
  287. --Creates button and counts it
  288. self.createButton({
  289. label=label, click_function=funcName, function_owner=self,
  290. position=pos, height=size, width=size,
  291. font_size=size, scale=buttonScale,
  292. color=buttonColor, font_color=buttonFontColor
  293. })
  294. spawnedButtonCount = spawnedButtonCount + 1
  295. end
  296. end
  297.  
  298. function createTextbox()
  299. for i, data in ipairs(ref_buttonData.textbox) do
  300. --Sets up reference function
  301. local funcName = "textbox"..i
  302. local func = function(_,_,val,sel) click_textbox(i,val,sel) end
  303. self.setVar(funcName, func)
  304.  
  305. self.createInput({
  306. input_function = funcName,
  307. function_owner = self,
  308. label = data.label,
  309. alignment = data.alignment,
  310. position = data.pos,
  311. scale = buttonScale,
  312. width = data.width,
  313. height = (data.font_size*data.rows)+24,
  314. font_size = data.font_size,
  315. color = buttonColor,
  316. font_color = buttonFontColor,
  317. value = data.value,
  318. })
  319. end
  320. end
Advertisement
Add Comment
Please, Sign In to add comment