Advertisement
Western01

Untitled

Sep 6th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. --Set this to true while editing and false when you have finished
  2. disableSave = true
  3. --Remember to set this to false once you are done making changes
  4. --Then, after you save & apply it, save your game too
  5.  
  6. --Color information for button text (r,g,b, values of 0-1)
  7. buttonFontColor = {0,0,0}
  8. --Color information for button background
  9. buttonColor = {1,1,1}
  10. --Change scale of button (Avoid changing if possible)
  11. buttonScale = {1,1,1}
  12.  
  13. --This is the button placement information
  14. defaultButtonData = {
  15. --Add checkboxes
  16. checkbox = {
  17. --[[
  18. pos = the position (pasted from the helper tool)
  19. size = height/width/font_size for checkbox
  20. state = default starting value for checkbox (true=checked, false=not)
  21. ]]
  22. --First checkbox
  23. --End of checkboxes
  24. },
  25. --Add counters that have a + and - button
  26. counter = {
  27. --[[
  28. pos = the position (pasted from the helper tool)
  29. size = height/width/font_size for counter
  30. value = default starting value for counter
  31. hideBG = if background of counter is hidden (true=hidden, false=not)
  32. ]]
  33. --First counter
  34. {
  35. pos = {-1.325,0.1,-0.670},
  36. size = 200,
  37. value = 0,
  38. hideBG = true
  39. },
  40. {
  41. pos = {-0.02,0.1,-0.684},
  42. size = 200,
  43. value = 0,
  44. hideBG = true
  45. },
  46. {
  47. pos = {1.315,0.1,-0.670},
  48. size = 200,
  49. value = 0,
  50. hideBG = true
  51. },
  52. {
  53. pos = {-1.325,0.1,0.670},
  54. size = 200,
  55. value = 0,
  56. hideBG = true
  57. },
  58. {
  59. pos = {-0.02,0.1,0.670},
  60. size = 200,
  61. value = 0,
  62. hideBG = true
  63. },
  64. {
  65. pos = {1.315,0.1,0.670},
  66. size = 200,
  67. value = 0,
  68. hideBG = true
  69. },
  70.  
  71. --End of counters
  72. },
  73. --Add editable text boxes
  74. textbox = {
  75. --[[
  76. pos = the position (pasted from the helper tool)
  77. rows = how many lines of text you want for this box
  78. width = how wide the text box is
  79. font_size = size of text. This and "rows" effect overall height
  80. label = what is shown when there is no text. "" = nothing
  81. value = text entered into box. "" = nothing
  82. alignment = Number to indicate how you want text aligned
  83. (1=Automatic, 2=Left, 3=Center, 4=Right, 5=Justified)
  84. ]]
  85. --First textbox
  86. --End of textboxes
  87. }
  88. }
  89.  
  90. --Lua beyond this point, I recommend doing something more fun with your life
  91.  
  92. --Save function
  93. function updateSave()
  94. saved_data = JSON.encode(ref_buttonData)
  95. if disableSave==true then saved_data="" end
  96. self.script_state = saved_data
  97. end
  98.  
  99. --Startup procedure
  100. function onload(saved_data)
  101. if disableSave==true then saved_data="" end
  102. if saved_data ~= "" then
  103. local loaded_data = JSON.decode(saved_data)
  104. ref_buttonData = loaded_data
  105. else
  106. ref_buttonData = defaultButtonData
  107. end
  108.  
  109. spawnedButtonCount = 0
  110. createCheckbox()
  111. createCounter()
  112. createTextbox()
  113. end
  114.  
  115.  
  116.  
  117. --Click functions for buttons
  118.  
  119.  
  120.  
  121. --Checks or unchecks the given box
  122. function click_checkbox(tableIndex, buttonIndex)
  123. if ref_buttonData.checkbox[tableIndex].state == true then
  124. ref_buttonData.checkbox[tableIndex].state = false
  125. self.editButton({index=buttonIndex, label=""})
  126. else
  127. ref_buttonData.checkbox[tableIndex].state = true
  128. self.editButton({index=buttonIndex, label=string.char(10008)})
  129. end
  130. updateSave()
  131. end
  132.  
  133. --Applies value to given counter display
  134. function click_counter(tableIndex, buttonIndex, amount)
  135. ref_buttonData.counter[tableIndex].value = ref_buttonData.counter[tableIndex].value + amount
  136. self.editButton({index=buttonIndex, label=ref_buttonData.counter[tableIndex].value})
  137. updateSave()
  138. end
  139.  
  140. --Updates saved value for given text box
  141. function click_textbox(i, value, selected)
  142. if selected == false then
  143. ref_buttonData.textbox[i].value = value
  144. updateSave()
  145. end
  146. end
  147.  
  148. --Dud function for if you have a background on a counter
  149. function click_none() end
  150.  
  151. --Makes checkboxes
  152. function createCheckbox()
  153. for i, data in ipairs(ref_buttonData.checkbox) do
  154. --Sets up reference function
  155. local buttonNumber = spawnedButtonCount
  156. local funcName = "checkbox"..i
  157. local func = function() click_checkbox(i, buttonNumber) end
  158. self.setVar(funcName, func)
  159. --Sets up label
  160. local label = ""
  161. if data.state==true then label=string.char(10008) end
  162. --Creates button and counts it
  163. self.createButton({
  164. label=label, click_function=funcName, function_owner=self,
  165. position=data.pos, height=data.size, width=data.size,
  166. font_size=data.size, scale=buttonScale,
  167. color=buttonColor, font_color=buttonFontColor
  168. })
  169. spawnedButtonCount = spawnedButtonCount + 1
  170. end
  171. end
  172.  
  173. --Makes counters
  174. function createCounter()
  175. for i, data in ipairs(ref_buttonData.counter) do
  176. --Sets up display
  177. local displayNumber = spawnedButtonCount
  178. --Sets up label
  179. local label = data.value
  180. --Sets height/width for display
  181. local size = data.size
  182. if data.hideBG == true then size = 0 end
  183. --Creates button and counts it
  184. self.createButton({
  185. label=label, click_function="click_none", function_owner=self,
  186. position=data.pos, height=size, width=size,
  187. font_size=data.size, scale=buttonScale,
  188. color=buttonColor, font_color=buttonFontColor
  189. })
  190. spawnedButtonCount = spawnedButtonCount + 1
  191.  
  192. --Sets up add 1
  193. local funcName = "counterAdd"..i
  194. local func = function() click_counter(i, displayNumber, 1) end
  195. self.setVar(funcName, func)
  196. --Sets up label
  197. local label = "+"
  198. --Sets up position
  199. local offsetDistance = (data.size/2 + data.size/2) * (buttonScale[1] * 0.0020)
  200. local pos = {data.pos[1] + offsetDistance, data.pos[2], data.pos[3]}
  201. --Sets up size
  202. local size = data.size / 2
  203. --Creates button and counts it
  204. self.createButton({
  205. label=label, click_function=funcName, function_owner=self,
  206. position=pos, height=size, width=size,
  207. font_size=size, scale=buttonScale,
  208. color=buttonColor, font_color=buttonFontColor
  209. })
  210. spawnedButtonCount = spawnedButtonCount + 1
  211.  
  212. --Sets up subtract 1
  213. local funcName = "counterSub"..i
  214. local func = function() click_counter(i, displayNumber, -1) end
  215. self.setVar(funcName, func)
  216. --Sets up label
  217. local label = "-"
  218. --Set up position
  219. local pos = {data.pos[1] - offsetDistance, data.pos[2], data.pos[3]}
  220. --Creates button and counts it
  221. self.createButton({
  222. label=label, click_function=funcName, function_owner=self,
  223. position=pos, height=size, width=size,
  224. font_size=size, scale=buttonScale,
  225. color=buttonColor, font_color=buttonFontColor
  226. })
  227. spawnedButtonCount = spawnedButtonCount + 1
  228. end
  229. end
  230.  
  231. function createTextbox()
  232. for i, data in ipairs(ref_buttonData.textbox) do
  233. --Sets up reference function
  234. local funcName = "textbox"..i
  235. local func = function(_,_,val,sel) click_textbox(i,val,sel) end
  236. self.setVar(funcName, func)
  237.  
  238. self.createInput({
  239. input_function = funcName,
  240. function_owner = self,
  241. label = data.label,
  242. alignment = data.alignment,
  243. position = data.pos,
  244. scale = buttonScale,
  245. width = data.width,
  246. height = (data.font_size*data.rows)+32,
  247. font_size = data.font_size,
  248. color = buttonColor,
  249. font_color = buttonFontColor,
  250. value = data.value,
  251. })
  252. end
  253. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement