· 4 years ago · Jan 29, 2021, 12:12 PM
1-- Easy Graphical User Interface for CraftOS
2-- with interactive designer
3-- v.1.0, for CraftOS 1.8
4
5--Please read until line 75 if you are new to EasyGUI!
6--If you need help the designer, run it on a computer and get help to almost everything if you hold F1 and click on the specific thing you have questions about.
7
8--multiple monitor support: this array stores the wrapped peripherals, monitor sizes and text scales
9monitors = {}
10terminalScreen = nil
11
12--GUI Elements Clickable
13--dynamic text boxes include rectangles by using an empty string and buttons (even checkboxes) by assigning an onClick Function
14dynamicTextBoxes = {}
15sliders = {}
16dropDownMenus = {}
17navigationMenus = {}
18colorPickers = {}
19
20--unclickable
21--progressBars can also be used as bar charts by assigning the bg color to one of its colors
22progressBars = {}
23coordinateSystems = {}
24pictures = {}
25
26elements = {}
27
28--For GUI Elements to be rendered, they need to be added to a screen. A screen can then be saved and rendered on any advanced device.
29screens = {}
30
31--PLEASE READ THIS ABOUT FILE SYSTEM
32--You might want to change the following value if you are not running EasyGUI in a root directory.
33--For example: if you put EasyGUI.lua in a folder called apis, change to: 'root = "/apis/"'
34root = "/"
35
36--1 = DEBUG, 2 = INFO, 3 = WARNING, 4 = ERROR, 5 = FATAL
37--PLEASE READ THIS ABOUT LOGGING!
38--WARNING level 1 results in extremely large files. Use only when debugging.
39--Level 2 can also be rather big. Leave it at 3 if everything works ok.
40--Keep in mind that the size of log file over time depends on the refresh rate used.
41--Note that by default one cc computer only has 1mb of storage, can be changed in computercraft.cfg.
42--If less than 1kb is available, log won't be written to anymore.
43writingLogLevel = 3
44
45--Designer/Editor colors.
46--If you don't like the default settings, change the colors here: default text color, default background color and an accent color.
47colorPalette = {colors.white,colors.black,colors.green}
48
49-------- Changelog
50
51--29/01/20202 Release 1.1 pastebin:
52--implemented helping dialogue for many elements by holding f1 and clicking on it
53--implemented more hotkeys like Ctrl+Z for undo
54
55--16/01/2020: Release 1.0 pastebin: LxhGCu7F
56--fixed #1,#2 and #3
57--cleaned up adding a new screen while running designer on monitor
58--everything else appears very stable up to this point
59
60--25/12/2020: Release Beta v.0.1 pastebin: LGVzZLwK
61-- All features that were planned at this point have now been implemented.
62-- It took roughly half a year. An intensive testing phase is about to begin.
63-------
64
65-- Bugs
66--#1 designer not usable on turtle and pocket screen / fixed 16/01/2021
67--#2 wireless modems throw errors during monitor initialization sequence / fixed 16/01/2021
68--#3 when using only terminal and no monitors, will always try to find new monitors / fixed 16/01/2021
69
70--Future plans:
71--interactive helping page for everything related to using the api in a programm
72--feature that creates a generic EasyGUI implementation program
73
74----------------------------------
75--Technical stuff starting. Enjoy.
76refreshTimerID = nil
77refreshRate = nil
78
79IDlist = {}
80startTime = os.clock()
81logFile = nil
82lastLogString = nil
83
84refreshFunction = nil
85processClickEventFunc = nil
86processEventFunc = nil
87
88args = {...}
89
90--color arrays
91colorsArrayStrToNum = {}
92colorsArrayStrToNum["0"] = colors.white
93colorsArrayStrToNum["1"] = colors.orange
94colorsArrayStrToNum["2"] = colors.magenta
95colorsArrayStrToNum["3"] = colors.lightBlue
96colorsArrayStrToNum["4"] = colors.yellow
97colorsArrayStrToNum["5"] = colors.lime
98colorsArrayStrToNum["6"] = colors.pink
99colorsArrayStrToNum["7"] = colors.gray
100colorsArrayStrToNum["8"] = colors.lightGray
101colorsArrayStrToNum["9"] = colors.cyan
102colorsArrayStrToNum["a"] = colors.purple
103colorsArrayStrToNum["b"] = colors.blue
104colorsArrayStrToNum["c"] = colors.brown
105colorsArrayStrToNum["d"] = colors.green
106colorsArrayStrToNum["e"] = colors.red
107colorsArrayStrToNum["f"] = colors.black
108
109colorsArrayNumToNum = {colors.white,colors.orange,colors.magenta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.gray,colors.lightGray,colors.cyan,colors.purple,colors.blue,colors.brown,colors.green,colors.red,colors.black}
110
111colorsArrayNumToString = {}
112colorsArrayNumToString[colors.white] = "0"
113colorsArrayNumToString[colors.orange] = "1"
114colorsArrayNumToString[colors.magenta] = "2"
115colorsArrayNumToString[colors.lightBlue] = "3"
116colorsArrayNumToString[colors.yellow] = "4"
117colorsArrayNumToString[colors.lime] = "5"
118colorsArrayNumToString[colors.pink] = "6"
119colorsArrayNumToString[colors.gray] = "7"
120colorsArrayNumToString[colors.lightGray] = "8"
121colorsArrayNumToString[colors.cyan] = "9"
122colorsArrayNumToString[colors.purple] = "a"
123colorsArrayNumToString[colors.blue] = "b"
124colorsArrayNumToString[colors.brown] = "c"
125colorsArrayNumToString[colors.green] = "d"
126colorsArrayNumToString[colors.red] = "e"
127colorsArrayNumToString[colors.black] = "f"
128
129--designer stuff
130designerMonitor = nil
131designerScreen = nil
132designerX = nil
133designerY = nil
134lastSave = nil
135saveTimerID = nil
136selectedPart = ""
137F1Held = false
138CTRLHeld = false
139
140--hashes and help strings (md5)
141help = {}
142terminalID = "a8bcae0d70fdbf14c572156f8e31000a"
143
144initMonsSID = "cdac1a98818689af48db3b552851fc6f"
145initMonsSHeadingID = "890f2028b00a4579df6b48ad34d8a269"
146help[initMonsSHeadingID] = "EasyGUI needs to save your monitor configuration as pseudo-xml. This screen will guide you through the process."
147initMonsSLeftRectID = "ea24a45da7a8fbef8b236748907aa7fb"
148initMonsSTextID = "4900d0b145e8533b398b5e12dd7525e5"
149help[initMonsSTextID] = "You need to assign an ID to every monitor to tell them properly apart. IDs will be saved lower case and must not be longer than 31 characters."
150initMonsSPictureID = "694b8cec4ab3a26d01c68005ec8aa56c"
151initMonsSErrorID = "fb95b84d5b14a09ab93511fc6fb575f4"
152help[initMonsSErrorID] = "IDs need to be unique and must not be longer than 31 characters."
153
154changeMonSID = "c737dc7d97748d8b40963a95a0dc7861"
155help[changeMonSID] = "EasyGUI Designer/Editor can run on a computer terminal or on a monitor. On this screen you can choose to transfer the Designer. Note: you will have the best experience on a computer terminal because you can use your keyboard."
156changeMonSDDMenuID = "d73a60583fc13ea25db201571bca7301"
157help[changeMonSDDMenuID] = "Leave this at \"term\" if you want to run the designer on this computer screen. Otherwise, choose one of your monitors. Note: only computer screens are big enough to run EasyGUI Designer, turtle and pocket screens will not work."
158changeMonSApplyID = "c1eac4028ea88abba1e9fa2b5894a5ac"
159changeMonSScaleDDID = "0f76acbc91744387905e22aa7420e892"
160help[changeMonSScaleDDID] = "If running EasyGUI on a monitor, you may want to set the textScale higher. Standard 0.5 might result in very small letters on a big monitor."
161
162mainSID = "174e80d8ed22ac2287bf056b4e7c2c0a"
163mainSBorderID = "42adbd6df1cf676ed2cbf9040ff73d69"
164mainSButton1ID = "9d8692e9a7d29f1cea8ff0728b27ec15"
165help[mainSButton1ID] = "Elements are the essence of EasyGUI. On this menu you can add new elements and edit already existing ones. Right now, supports dynamicTextBoxes,sliders,dropDownMenus,navigationMenus,colorPickers,coordinateSystems,progressBars and pictures. All of them will be saved as pseudo-xml files."
166mainSButton2ID = "9ce00dc655e34d3e4ade16daa7267a12"
167help[mainSButton2ID] = "Elements alone can not be displayed, they need to be added to a screen which can then be displayed. On this menu you can add new screens and edit already existing ones. All of them will be saved as pseudo-xml files."
168mainSButton3ID = "a79fa19cb268b702bcbcaccbbb7ce8d3"
169mainSHeadingID = "0ede5fa492669473d6f765e957967296"
170
171screensSID = "c00d2f1c0bc784e4d9bd67f800a0e702"
172screensSHeadingID = "04f609cb0bf336e33b5ac887858f8a81"
173help[screensSHeadingID] = help[mainSButton1ID]
174screensSButton1ID = "aaa4cb31682f6968660ef882899b16b2"
175screensSButton2ID = "b10a959313edf31aa004faffcf905256"
176screensSButton3ID = "f2ca3bcbb6f6febcb3d73236ff285fb5"
177screensSDDMenuID = "a2f436771da5644c27a39d73b57fd29c"
178screensSMsgID = "b823cc4d92c1748967586c2878967248"
179
180elementsSID = "0ce4a8f25a81d19b9abf7cfcbd450a4d"
181elementsSHeadingID = "f34a17e23d41cffa1b9fbd6a33cd4f71"
182help[elementsSHeadingID] = help[mainSButton2ID]
183elementsSButton1ID = "c8a2c4a1a569bc97d659707bc42539fe"
184elementsSButton2ID = "650a9aef06bb8e99389773a9fd6ec2cd"
185elementsSDDMenu1ID = "bc9fc4bada884c28114d4bfb1783b8c7"
186elementsSDDMenu2ID = "030bbbca3d6cf0847f87feda6bf6a783"
187
188editorSID = "ba0832bc2dcb0adcf14b490ac6be2065"
189editorSElementID = nil
190editorSElementType = nil
191editorSElementX = nil
192editorSElementY = nil
193editorSRelocateButtonID = "ca5d5014d000faa233f4c58909e9ea21"
194help[editorSRelocateButtonID] = "Toggle on to relocate the current element to a place you click on the screen. Note: this has nothing to do with where the element will be rendered. It is purely for the sake of seeing things better."
195editorSLastSaveID = "70461177a186553350dbb333d5b2cde2"
196help[editorSLastSaveID] = "Shows when the element was last saved into the pseudo-xml file. Normally auto-saves every 3 minutes. You can also save with Ctrl+S."
197editorSExitID = "99f1eb11c00f5c188844a7311c879bac"
198editorSUndoID = "0f7132a19e8760f425c2eef5b386cc61"
199editorSRedoID = "fe21a08c7dffa4717d24593f7fcd0a0e"
200editorSPropsID = "e46d61c144903147e4cb5f136a0fecb8"
201help[editorSPropsID] = "Toggle to show/hide the properties menu."
202editorSPropsMenuID = "cbf856355edab7b830d36dec09857e0d"
203help[editorSPropsMenuID] = "Shows every non-technical property of the element. Almost all of them can be changed in the editor."
204editorSDescID = "06431f84d6b74e6796e52341a882e9a5"
205editorSHideUIID = "ad4e5a2c6c8b4995893cec8cd4e2f219"
206help[editorSHideUIID] = "Hide all UI elements for a few seconds to see your element better."
207editorSPropColorPickID = "25c276460958a39672b08d75baf86b4d"
208editorSPropResetButtonID = "6c04474a36beb72d7659bb0be1a07753"
209help[editorSPropResetButtonID] = "By clicking, the property will be set nil if it is non-essential or to a default value if it is essential. See property description for further details."
210editorSPropDDMenuID = "0603d9ac23d75d560d24cf76b2321882"
211help[editorSPropDDMenuID] = "This property can only have specific values. Select them in this menu. First (empty) can only be selected by hitting the default button."
212editorSPropDisplayID = "43c8ab35bc70361a89080b0e6c8d0dcc"
213editorSPropConsoleInputButtonID = "48066d14f326e44bc285eacea5953c53"
214help[editorSPropConsoleInputButtonID] = "This property can be changed via console input. To do so, click this button."
215editorSPropConsoleMsgID = "253177a56e1e679a671650ff660ac628"
216editorSPropColorsArrayDDID = "f786c674209bc58c63be21a9973a36a7"
217help[editorSPropColorsArrayDDID] = "You can choose a different color for every index. This menu indicates the current index."
218editorSPropStringArrayDDID = "873ab20d4a621beb75c4a288aafc4d9b"
219help[editorSPropStringArrayDDID] = "To change or remove an entry, select it in this menu and hit the change button. Hit the last entry (\"+add\") to add another one."
220editorSPropNavMenuID = "1a8bf4cb11854ddc7070fa988b6bd061"
221help[editorSPropNavMenuID] = "You can change the menuArray structure by using this menu. Add new entries: \"+add\" Change or remove: select it and then \"<- edit\" Add another menu level: \"add sub\""
222editorSPropNavMenuHintID = "5e192f2543b2955606ea876e5a0f5061"
223help[editorSPropNavMenuHintID] = help[editorSPropNavMenuID]
224editorSPropCSTableIndexDDID = "c0db47af6a31df0c8b5d6d93528e8789"
225help[editorSPropCSTableIndexDDID] = "Multiple graphs can be saved. This indicates the index of the graph to be edited. You can add another one by hitting the last entry (\"+add\"). To remove an entire graph, hit the Remove button."
226editorSPropCSTableDDID = "285065eb94ad1d28cc4256b2ba90313e"
227help[editorSPropCSTableDDID] = "This lists all the coordinates of the selected graph. To change/remove a point, select it and hit the change button. To add a new point, hit the last entry (\"+add\")"
228editorSPropCSChangeID = "69280395cc41074df3a851bd35dae7eb"
229help[editorSPropCSChangeID] = "Click to change or remove the selected coordinate/design property."
230editorSPropCSRemoveID = "947a332a5fd6e2f12cdee783584d7b2f"
231help[editorSPropCSRemoveID] = "Click to remove the selected graph."
232editorSPropCSDesignsIndexDDID = "6cc418ef452522709716091a3fee13b4"
233help[editorSPropCSDesignsIndexDDID] = "Every graph can have a different design. This indicates the index of the graph design to be edited."
234editorSPropCSDesignsDDID = "dcf4b18661fa3189e028cc5b9e3bb091"
235help[editorSPropCSDesignsDDID] = "Design consists of the character to be drawn at the point and the textcolor and backgroundcolor to be used. Select what to change in this menu."
236editorSPropCSDesignsDisplayID = "a911bd54fc2a722273349b86b7ba7e5b"
237editorSPropPicEditButtonID = "d4baa6b9a4165cd060adf01ac06413c1"
238
239pictureESID = "8c62478c73d841127d5cfee2ca0057f5"
240pictureESCurrentX = 1
241pictureESCurrentY = 1
242pictureESButtonBackID = "2b0706da3b5d426fa94dc2f8296b3163"
243pictureESCoordsDisplayID = "badf495b60b2dfbf16a6505fc5a6abea"
244help[pictureESCoordsDisplayID] = "Current selected coordinate on the picture."
245pictureESControlPicID = "8e30ae73df15a61c5031fbb303d0aacb"
246help[pictureESControlPicID] = "Click on the arrows to change selected coordinate. Click the middle circle to hide/show the selection indicator. Note: you can also use your arrow keys to change selected location."
247pictureESIndicatorID = "eedc3c41696a69f23da0afaa26966886"
248pictureESChangeID = "6fa7bc313ff09ed5ffe3a03eabd9f023"
249help[pictureESChangeID] = "Click to change the character at the selected location. Note: you can change characters without using this button simply by typing on your keyboard. You can also use paste (Ctrl+V)"
250pictureESColorPick1ID = "b35a1604be58560bed010a10814b9e96"
251help[pictureESColorPick1ID] = "Use to change textColor of current pixel."
252pictureESColorPick2ID = "f21f6272bc5b1fde77e1fae2b81a8cd2"
253help[pictureESColorPick2ID] = "Use to change backgroundColor of current pixel."
254pictureESUseDefault1ID = "544eede5770aab86e04abe55a69df30e"
255help[pictureESUseDefault1ID] = "Click to use default textcolor of current screen at selected location."
256pictureESUseDefault2ID = "6ecb339249a0d6fc15345a3a9678d801"
257help[pictureESUseDefault2ID] = "Click to use default backgroundcolor of current screen at selected location."
258pictureESTransparentID = "2273d20c36018b7d17dc3c2986581939"
259help[pictureESTransparentID] = "Click to make selected pixel entirely transparent so that other elements may be rendered behind it."
260
261newScreenSID = "4c87e69acef20548469e1739e668a0b2"
262newScreenSHeadingID = "d3b18e12b96639b9185abb60ba990ddb"
263help[newScreenSHeadingID] = "This screen guides you through the process of creating a new screen. Size and default colors need to be set."
264newScreenSTextID = "8413e43f729eccce6ae5ec696b90dbda"
265newScreenSDDM1ID = "5febc01add087220c728a65579e148f3"
266help[newScreenSDDM1ID] = "You can pick one of the first three options to use a screen size equivalent to the specific device screen. Choose the fourth option to adapt the screen size to one of your attached monitors. Choose the fifth to enter dimensions manually."
267newScreenSDDM2ID = "e5cc2beacfc426487c711c85deb2015d"
268help[newScreenSDDM2ID] = "Choose which monitor you want to adapt the screen size to."
269newScreenSDDM3ID = "1f2fae049f3e7a22afd512769a7b171d"
270help[newScreenSDDM3ID] = "You may want to set textScale higher on a bigger monitor to read things better. This will affect the screen size."
271newScreenSResultID = "bbdc5855b127608208219ecc1a275978"
272newScreenSColor1ID = "d43e48d259cd4baa3c209f590f912cbf"
273help[newScreenSColor1ID] = "Choose the default textcolor of the screen."
274newScreenSColor2ID = "0acbe4f69fa595fd123d03ad834cc50d"
275help[newScreenSColor2ID] = "Choose the default backgroundcolor of the screen."
276
277designerSID = nil
278designerSExitButtonID = "1d3b801e5d4f2c7226492cf2a66f9ebd"
279designerSHideUIID = "9818d56316ad57a0567c4076c26ae597"
280help[designerSHideUIID] = "Hide all UI elements for a few seconds to see your element better."
281designerSControlPicID = "71e90f74303d96e10277d15591add23e"
282help[designerSControlPicID] = "Click on the arrows to change the position of the selected element. You can also use your arrow keys, but may want to prefer relocating elements by dragging the indicator in the top left of the selected element."
283designerSSelectionID = "31cf20d5dd112d373b987ca97d7bec60"
284help[designerSSelectionID] = "Here you can see the position of the selected element, its ID and the selected part. Click to deselect."
285designerSAddID = "ebd3455e1d4cb26e3880b7ef5963ef55"
286help[designerSAddID] = "Click to show/hide a menu which shows all saved elements. Select one to add it to this screen."
287designerSRemoveID = "2a2abf50f7ca26032ee56471ead9ed46"
288help[designerSRemoveID] = "Click to remove selected element from the screen."
289designerSIndicatorID = "61a218bc9eadf687b5218d580c99d1c7"
290designerSLastSaveID = "5d7d14cce74cf0f0506a47557b2c49b7"
291help[designerSLastSaveID] = "Shows when the screen was last saved into the pseudo-xml file. Normally auto-saves every 3 minutes. You can also save with Ctrl+S."
292designerSSelection = ""
293designerSmaxX = nil
294designerSmaxY = nil
295designerSBox1ID = "d0dca4a2df75fbc538d26bf55f838068"
296designerSBox2ID = "dd5bd01b51b9dae60c4908954a25da05"
297designerSUndoID = "b690378913463294bc11c499bf032798"
298designerSRedoID = "25d97fd89146fa2a0378577fea852434"
299designerRefresh = false
300designerSButtonHeld = false
301
302helpSID = "a4b4970624f9e7db4a4b9a1cad861aaf"
303helpSBorderID = "a91d2b3ffc44366c5801ccd3bb5b8c2f"
304helpSOKID = "a3a59d8266d8b1e220773f0977e22726"
305
306undoRedoTable = {}
307undoRedoIndex = 0
308
309--property tables
310--width, height, content, variables, textColor, textAlignmentHorizontal, textAlignmentVertical, BGColor, borderColor, onActiveFunction, onInactiveFunction, onClickMode, activeDuration, activeContent, activeTextColor, activeBGColor, activeBorderColor, borderThickness, active, timerID, visible, enabled
311dynamicTextBoxProperties = {}
312dynamicTextBoxProperties["content"] = {}
313dynamicTextBoxProperties["content"]["input"] = "string"
314dynamicTextBoxProperties["content"]["essential"] = true
315dynamicTextBoxProperties["content"]["desc"] = "content (string): the text inside the dynamicTextBox. It automatically splits the text into different lines if necessary. Can also be an empty string."
316dynamicTextBoxProperties["content"]["default"] = "Your Text"
317
318dynamicTextBoxProperties["width"] = {}
319dynamicTextBoxProperties["width"]["input"] = "number"
320dynamicTextBoxProperties["width"]["essential"] = false
321dynamicTextBoxProperties["width"]["desc"] = "width (non-decimal number in pixels): how wide (x) the element should be. If unused (nil) the dynamicTextBox will take the space the text requires, but never run over the edge of the screen."
322
323dynamicTextBoxProperties["height"] = {}
324dynamicTextBoxProperties["height"]["input"] = "number"
325dynamicTextBoxProperties["height"]["essential"] = false
326dynamicTextBoxProperties["height"]["desc"] = "height (non-decimal number in pixels): how broad (y) the element should be. If unused (nil) the dynamicTextBox will take the space the text requires, but never run over the edge of the screen."
327
328dynamicTextBoxProperties["variables"] = {}
329dynamicTextBoxProperties["variables"]["input"] = "manual"
330dynamicTextBoxProperties["variables"]["essential"] = false
331dynamicTextBoxProperties["variables"]["desc"] = "variables (table): can be used thus: variables[\"name\"] = retrieveVarFunc, then put &name somewhere in content. Can only be set manually. (EasyGUI.changeProperty(ID,\"variables\",table))"
332
333dynamicTextBoxProperties["textColor"] = {}
334dynamicTextBoxProperties["textColor"]["input"] = "color"
335dynamicTextBoxProperties["textColor"]["essential"] = false
336dynamicTextBoxProperties["textColor"]["desc"] = "textColor (color): color of the text inside the dynamicTextBox. If unused (nil) defaultTextColor of the screen will be used."
337
338dynamicTextBoxProperties["BGColor"] = {}
339dynamicTextBoxProperties["BGColor"]["input"] = "color"
340dynamicTextBoxProperties["BGColor"]["essential"] = false
341dynamicTextBoxProperties["BGColor"]["desc"] = "BGColor (color): color of background of the dynamicTextBox. If unused (nil) defaultBGColor of the screen will be used."
342
343dynamicTextBoxProperties["borderColor"] = {}
344dynamicTextBoxProperties["borderColor"]["input"] = "color"
345dynamicTextBoxProperties["borderColor"]["essential"] = false
346dynamicTextBoxProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the dynamicTextBox. borderThickness needs to be greater than 0. If unused (nil) BGColor will be used."
347
348dynamicTextBoxProperties["activeContent"] = {}
349dynamicTextBoxProperties["activeContent"]["input"] = "string"
350dynamicTextBoxProperties["activeContent"]["essential"] = false
351dynamicTextBoxProperties["activeContent"]["desc"] = "activeContent (string): the text inside the dynamicTextBox if it's active. It automatically splits the text into different lines if necessary. Can also be an empty string. If unused (nil) will be content."
352
353dynamicTextBoxProperties["activeTextColor"] = {}
354dynamicTextBoxProperties["activeTextColor"]["input"] = "color"
355dynamicTextBoxProperties["activeTextColor"]["essential"] = false
356dynamicTextBoxProperties["activeTextColor"]["desc"] = "activeTextColor (color): color of the text inside the dynamicTextBox if it's active. If unused (nil) textColor will be used."
357
358dynamicTextBoxProperties["activeBGColor"] = {}
359dynamicTextBoxProperties["activeBGColor"]["input"] = "color"
360dynamicTextBoxProperties["activeBGColor"]["essential"] = false
361dynamicTextBoxProperties["activeBGColor"]["desc"] = "activeBGColor (color): color of background of the dynamicTextBox if it's active. If unused (nil) BGColor will be used."
362
363dynamicTextBoxProperties["activeBorderColor"] = {}
364dynamicTextBoxProperties["activeBorderColor"]["input"] = "color"
365dynamicTextBoxProperties["activeBorderColor"]["essential"] = false
366dynamicTextBoxProperties["activeBorderColor"]["desc"] = "activeBorderColor (color): color of the border of the dynamicTextBox if it's active. borderThickness needs to be greater then 0. If unused (nil) borderColor will be used."
367
368dynamicTextBoxProperties["textAlignmentHorizontal"] = {}
369dynamicTextBoxProperties["textAlignmentHorizontal"]["input"] = "DDM:left:center:right"
370dynamicTextBoxProperties["textAlignmentHorizontal"]["essential"] = false
371dynamicTextBoxProperties["textAlignmentHorizontal"]["desc"] = "textAlignmentHorizontal (left,center,right): where the text inside the dynamicTextBox shall be placed horizontally. If unused (nil) defaults to center."
372
373dynamicTextBoxProperties["textAlignmentVertical"] = {}
374dynamicTextBoxProperties["textAlignmentVertical"]["input"] = "DDM:top:center:bottom"
375dynamicTextBoxProperties["textAlignmentVertical"]["essential"] = false
376dynamicTextBoxProperties["textAlignmentVertical"]["desc"] = "textAlignmentVertical (top,center,bottom): where the text inside the dynamicTextBox shall be placed vertically. If unused (nil) defaults to center."
377
378dynamicTextBoxProperties["borderThickness"] = {}
379dynamicTextBoxProperties["borderThickness"]["input"] = "number"
380dynamicTextBoxProperties["borderThickness"]["essential"] = false
381dynamicTextBoxProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the dynamicTextBox shall be. If unused (nil) will be 0. (no border)"
382
383dynamicTextBoxProperties["onClickMode"] = {}
384dynamicTextBoxProperties["onClickMode"]["input"] = "DDM:flash:toggle"
385dynamicTextBoxProperties["onClickMode"]["essential"] = false
386dynamicTextBoxProperties["onClickMode"]["desc"] = "onClickMode (flash,toggle): whether the dynamicTextBox if clicked shall stay active until the next click (toggle) or turn inactive again after a specific amount of time. (flash) Also set activeDuration if using the second option."
387
388dynamicTextBoxProperties["activeDuration"] = {}
389dynamicTextBoxProperties["activeDuration"]["input"] = "decimal"
390dynamicTextBoxProperties["activeDuration"]["essential"] = false
391dynamicTextBoxProperties["activeDuration"]["desc"] = "activeDuration (decimal number in seconds): if onClickMode is set to flash, this value determines how long the dynamicTextBox stays active after clicked. Can only be as accurate as 1 in-game tick or 0.05s. If unused (nil) will be 0.05."
392
393dynamicTextBoxProperties["onActiveFunction"] = {}
394dynamicTextBoxProperties["onActiveFunction"]["input"] = "manual"
395dynamicTextBoxProperties["onActiveFunction"]["essential"] = false
396dynamicTextBoxProperties["onActiveFunction"]["desc"] = "onActiveFunction (function): to be called when the dynamicTextBox becomes active through a click. Can only be set manually. (EasyGUI.changeProperty(ID,\"onActiveFunction\",func)) Will be called with two arguments: ID of element (string), whether it's active (boolean)"
397
398dynamicTextBoxProperties["onInactiveFunction"] = {}
399dynamicTextBoxProperties["onInactiveFunction"]["input"] = "manual"
400dynamicTextBoxProperties["onInactiveFunction"]["essential"] = false
401dynamicTextBoxProperties["onInactiveFunction"]["desc"] = "onInactiveFunction (function): to be called when the dynamicTextBox becomes inactive through a click or when activeDuration has passed. Can only be set manually. (EasyGUI.changeProperty(ID,\"onInactiveFunction\",func)) Will be called with two arguments: ID of element (string), whether it's active (boolean)"
402
403--length, value, broadness, orientation, pixelsPerUnit, color, colorsArray, textPosition, textMargin, BGColor, borderColor, onChangeFunction, borderThickness, visible, enabled, mode, changeButtons
404sliderProperties = {}
405sliderProperties["length"] = {}
406sliderProperties["length"]["input"] = "number"
407sliderProperties["length"]["essential"] = true
408sliderProperties["length"]["desc"] = "length (number): the maximum value the slider shall take on. Not necessarily the length in pixels, for more info see pixelsPerUnit."
409sliderProperties["length"]["default"] = 5
410
411sliderProperties["value"] = {}
412sliderProperties["value"]["input"] = "number"
413sliderProperties["value"]["essential"] = true
414sliderProperties["value"]["desc"] = "value (number): the default value the slider shall take on."
415sliderProperties["value"]["default"] = 1
416
417sliderProperties["broadness"] = {}
418sliderProperties["broadness"]["input"] = "number"
419sliderProperties["broadness"]["essential"] = false
420sliderProperties["broadness"]["desc"] = "broadness (non-decimal number in pixels): how broad the slider shall be. Perpendicular to slider orientation. If unused (nil) will be 1."
421
422sliderProperties["pixelsPerUnit"] = {}
423sliderProperties["pixelsPerUnit"]["input"] = "number"
424sliderProperties["pixelsPerUnit"]["essential"] = false
425sliderProperties["pixelsPerUnit"]["desc"] = "pixelsPerUnit (non-decimal number in pixels): how many pixels one unit of the slider shall take up. If unused (nil) will be 1."
426
427sliderProperties["orientation"] = {}
428sliderProperties["orientation"]["input"] = "DDM:top-bottom:bottom-top:left-right:right-left"
429sliderProperties["orientation"]["essential"] = false
430sliderProperties["orientation"]["desc"] = "orientation (top-bottom,bottom-top,left-right,right-left): how the slider shall be oriented. 'start-end'. If unused (nil) will be left-right."
431
432sliderProperties["color"] = {}
433sliderProperties["color"]["input"] = "color"
434sliderProperties["color"]["essential"] = false
435sliderProperties["color"]["desc"] = "color (color): the color the bar of the slider shall take on. If unused (nil) will be the defaultTextColor of the screen."
436
437sliderProperties["BGColor"] = {}
438sliderProperties["BGColor"]["input"] = "color"
439sliderProperties["BGColor"]["essential"] = false
440sliderProperties["BGColor"]["desc"] = "BGColor (color): the background of the slider. If unused (nil) will be the defaultBGColor of the screen."
441
442sliderProperties["borderColor"] = {}
443sliderProperties["borderColor"]["input"] = "color"
444sliderProperties["borderColor"]["essential"] = false
445sliderProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the slider. borderThickness needs to be greater than 0. If unused (nil) will be BGColor."
446
447sliderProperties["borderThickness"] = {}
448sliderProperties["borderThickness"]["input"] = "number"
449sliderProperties["borderThickness"]["essential"] = false
450sliderProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the slider shall be. If unused (nil) will be 0. (no border)"
451
452sliderProperties["colorsArray"] = {}
453sliderProperties["colorsArray"]["input"] = "colorsArray"
454sliderProperties["colorsArray"]["essential"] = false
455sliderProperties["colorsArray"]["desc"] = "colorsArray (numerically-indexed table): this can be used if you want a different bar color for different values. Example: red for high values and green for low values."
456
457sliderProperties["mode"] = {}
458sliderProperties["mode"]["input"] = "DDM:fill:value"
459sliderProperties["mode"]["essential"] = false
460sliderProperties["mode"]["desc"] = "mode (fill,value): whether the slider shall be filled up to the current value (fill) or only display the current value (value). If unused (nil) will be fill."
461
462sliderProperties["textPosition"] = {}
463sliderProperties["textPosition"]["input"] = "DDM:top:bottom:left:right"
464sliderProperties["textPosition"]["essential"] = false
465sliderProperties["textPosition"]["desc"] = "textPosition (top,bottom,left,right): if this value is set will display the current value at the chosen position."
466
467sliderProperties["textMargin"] = {}
468sliderProperties["textMargin"]["input"] = "number"
469sliderProperties["textMargin"]["essential"] = false
470sliderProperties["textMargin"]["desc"] = "textMargin (non-decimal number in pixels): determines how many pixels away from the slider the value will be placed. Requires textPosition to be set. If unused (nil) will be 0."
471
472sliderProperties["changeButtons"] = {}
473sliderProperties["changeButtons"]["input"] = "string"
474sliderProperties["changeButtons"]["essential"] = false
475sliderProperties["changeButtons"]["desc"] = "changeButtons (2 characters): if set draws an increment button with the first character and a decrement button with the second character. Example: '+-'"
476
477sliderProperties["onChangeFunction"] = {}
478sliderProperties["onChangeFunction"]["input"] = "manual"
479sliderProperties["onChangeFunction"]["essential"] = false
480sliderProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the value of the slider changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), current value (number)"
481
482--entries,width,expandedMaxHeight, textColor, BGColor, borderColor, onChangeFunction, onExpandFunction, onCollapseFunction, highlightTextColor, highlightBGColor, borderThickness, expanded, visible, enabled,selectionID,scrollPositionIndex,highlightID,buttonsColor,buttonsBGColor
483dropDownMenuProperties = {}
484dropDownMenuProperties["entries"] = {}
485dropDownMenuProperties["entries"]["input"] = "stringArray"
486dropDownMenuProperties["entries"]["essential"] = true
487dropDownMenuProperties["entries"]["desc"] = "entries (numerically indexed table): all entries of the dropDownMenu."
488dropDownMenuProperties["entries"]["default"] = {"Entry 1","Entry 2","Entry 3"}
489
490dropDownMenuProperties["selectionID"] = {}
491dropDownMenuProperties["selectionID"]["input"] = "number"
492dropDownMenuProperties["selectionID"]["essential"] = true
493dropDownMenuProperties["selectionID"]["desc"] = "selectionID (non-decimal number): by default selected entry of dropDownMenu."
494dropDownMenuProperties["selectionID"]["default"] = 1
495
496dropDownMenuProperties["width"] = {}
497dropDownMenuProperties["width"]["input"] = "number"
498dropDownMenuProperties["width"]["essential"] = false
499dropDownMenuProperties["width"]["desc"] = "width (non-decimal number in pixels): how wide (x) the dropDownMenu shall be. Text will be shortened accordingly. If unused (nil) takes as much space as necessary but will not run over the edge of the screen."
500
501dropDownMenuProperties["expandedMaxHeight"] = {}
502dropDownMenuProperties["expandedMaxHeight"]["input"] = "number"
503dropDownMenuProperties["expandedMaxHeight"]["essential"] = false
504dropDownMenuProperties["expandedMaxHeight"]["desc"] = "expandedMaxHeight (non-decimal number in pixels): the maximum height of the dropDownMenu in its expanded state. Adds a scroll feature if necessary. If unused (nil) takes as much space as necessary but will not run over the edge of the screen."
505
506dropDownMenuProperties["textColor"] = {}
507dropDownMenuProperties["textColor"]["input"] = "color"
508dropDownMenuProperties["textColor"]["essential"] = false
509dropDownMenuProperties["textColor"]["desc"] = "textColor (color): color of the text of the entries. If unused (nil) defaultTextColor of the screen will be used."
510
511dropDownMenuProperties["BGColor"] = {}
512dropDownMenuProperties["BGColor"]["input"] = "color"
513dropDownMenuProperties["BGColor"]["essential"] = false
514dropDownMenuProperties["BGColor"]["desc"] = "BGColor (color): color of background of the dropDownMenu. If unused (nil) defaultBGColor of the screen will be used."
515
516dropDownMenuProperties["borderColor"] = {}
517dropDownMenuProperties["borderColor"]["input"] = "color"
518dropDownMenuProperties["borderColor"]["essential"] = false
519dropDownMenuProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the dropDownMenu. borderThickness needs to be greater than 0. If unused (nil) BGColor will be used."
520
521dropDownMenuProperties["highlightTextColor"] = {}
522dropDownMenuProperties["highlightTextColor"]["input"] = "color"
523dropDownMenuProperties["highlightTextColor"]["essential"] = false
524dropDownMenuProperties["highlightTextColor"]["desc"] = "highlightTextColor (color): color of the text of the highlighted entry. If unused (nil) textColor will be used."
525
526dropDownMenuProperties["highlightBGColor"] = {}
527dropDownMenuProperties["highlightBGColor"]["input"] = "color"
528dropDownMenuProperties["highlightBGColor"]["essential"] = false
529dropDownMenuProperties["highlightBGColor"]["desc"] = "highlightBGColor (color): color of background of the highlighted entry. If unused (nil) BGColor will be used."
530
531dropDownMenuProperties["buttonsColor"] = {}
532dropDownMenuProperties["buttonsColor"]["input"] = "color"
533dropDownMenuProperties["buttonsColor"]["essential"] = false
534dropDownMenuProperties["buttonsColor"]["desc"] = "buttonsColor (color): textColor of expand/collapse/scroll buttons. If unused (nil) textColor will be used."
535
536dropDownMenuProperties["buttonsBGColor"] = {}
537dropDownMenuProperties["buttonsBGColor"]["input"] = "color"
538dropDownMenuProperties["buttonsBGColor"]["essential"] = false
539dropDownMenuProperties["buttonsBGColor"]["desc"] = "buttonsBGColor (color): BGColor of expand/collapse/scroll buttons. If unused (nil) BGColor will be used."
540
541dropDownMenuProperties["borderThickness"] = {}
542dropDownMenuProperties["borderThickness"]["input"] = "number"
543dropDownMenuProperties["borderThickness"]["essential"] = false
544dropDownMenuProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the dropDownMenu shall be. If unused (nil) will be 0. (no border)"
545
546dropDownMenuProperties["onChangeFunction"] = {}
547dropDownMenuProperties["onChangeFunction"]["input"] = "manual"
548dropDownMenuProperties["onChangeFunction"]["essential"] = false
549dropDownMenuProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the selection of the dropDownMenu changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), current selection (number)"
550
551dropDownMenuProperties["onExpandFunction"] = {}
552dropDownMenuProperties["onExpandFunction"]["input"] = "manual"
553dropDownMenuProperties["onExpandFunction"]["essential"] = false
554dropDownMenuProperties["onExpandFunction"]["desc"] = "onExpandFunction (function): to be called if the dropDownMenu expands through a click event. Can only be set manually. (EasyGUI.ExpandProperty(ID,\"onExpandFunction\",func)) Will be called with two arguments: ID of element (string), whether it's expanded (boolean)"
555
556dropDownMenuProperties["onCollapseFunction"] = {}
557dropDownMenuProperties["onCollapseFunction"]["input"] = "manual"
558dropDownMenuProperties["onCollapseFunction"]["essential"] = false
559dropDownMenuProperties["onCollapseFunction"]["desc"] = "onCollapseFunction (function): to be called if the dropDownMenu collapses through a click event. Can only be set manually. (EasyGUI.CollapseProperty(ID,\"onCollapseFunction\",func)) Will be called with two arguments: ID of element (string), whether it's expanded (boolean)"
560
561--title,menuArray (text, submenu),titleTextColor,titleBGColor,titleTextColorExpanded,titleBGColorExpanded,textAlignmentHorizontal,textAlignmentVertical,entryWidth,entryHeight,entryTextColor,entryBGColor,borderColor,spaceBetweenEntries,borderThickness,highlightTextColor,highlightBGColor,expanded,highlightIDs,onChangeFunction,enabled,visible
562navigationMenuProperties = {}
563navigationMenuProperties["title"] = {}
564navigationMenuProperties["title"]["input"] = "string"
565navigationMenuProperties["title"]["essential"] = true
566navigationMenuProperties["title"]["desc"] = "title (string): the text of the title of the navigationMenu. Also displayed when the menu is collapsed."
567navigationMenuProperties["title"]["default"] = "Menu"
568
569navigationMenuProperties["menuArray"] = {}
570navigationMenuProperties["menuArray"]["input"] = "navMenuArray"
571navigationMenuProperties["menuArray"]["essential"] = true
572navigationMenuProperties["menuArray"]["desc"] = "menuArray (numerically indexed nested table): all entries of the navigationMenu with submenus if necessary. Structure: array[index]={[\"text\"]=\"text\",[\"submenu\"]=anotherMenuArray}"
573navigationMenuProperties["menuArray"]["default"] = {{["text"]="Entry 1"},{["text"]="Entry 2"},{["text"]="Entry 3"}}
574
575navigationMenuProperties["titleTextColor"] = {}
576navigationMenuProperties["titleTextColor"]["input"] = "color"
577navigationMenuProperties["titleTextColor"]["essential"] = false
578navigationMenuProperties["titleTextColor"]["desc"] = "titleTextColor (color): color of the text of title. If unused (nil) defaultTextColor of the screen will be used."
579
580navigationMenuProperties["titleBGColor"] = {}
581navigationMenuProperties["titleBGColor"]["input"] = "color"
582navigationMenuProperties["titleBGColor"]["essential"] = false
583navigationMenuProperties["titleBGColor"]["desc"] = "titleBGColor (color): color of the background of title. If unused (nil) defaultBGColor of the screen will be used."
584
585navigationMenuProperties["titleTextColorExpanded"] = {}
586navigationMenuProperties["titleTextColorExpanded"]["input"] = "color"
587navigationMenuProperties["titleTextColorExpanded"]["essential"] = false
588navigationMenuProperties["titleTextColorExpanded"]["desc"] = "titleTextColor (color): color of the text of title when menu is expanded. If unused (nil) titleTextColor will be used."
589
590navigationMenuProperties["titleBGColorExpanded"] = {}
591navigationMenuProperties["titleBGColorExpanded"]["input"] = "color"
592navigationMenuProperties["titleBGColorExpanded"]["essential"] = false
593navigationMenuProperties["titleBGColorExpanded"]["desc"] = "titleBGColor (color): color of the background of title when menu is expanded. If unused (nil) titleBGColor will be used."
594
595navigationMenuProperties["borderColor"] = {}
596navigationMenuProperties["borderColor"]["input"] = "color"
597navigationMenuProperties["borderColor"]["essential"] = false
598navigationMenuProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the navigationMenu. borderThickness needs to be greater than 0. If unused (nil) defaultBGColor of the screen will be used."
599
600navigationMenuProperties["entryTextColor"] = {}
601navigationMenuProperties["entryTextColor"]["input"] = "color"
602navigationMenuProperties["entryTextColor"]["essential"] = false
603navigationMenuProperties["entryTextColor"]["desc"] = "entryTextColor (color): color of the text of the entries of the expanded menu. If unused (nil) defaultTextColor of the screen will be used."
604
605navigationMenuProperties["entryBGColor"] = {}
606navigationMenuProperties["entryBGColor"]["input"] = "color"
607navigationMenuProperties["entryBGColor"]["essential"] = false
608navigationMenuProperties["entryBGColor"]["desc"] = "entryBGColor (color): color of the background of the entries of the expanded menu. If unused (nil) defaultBGColor of the screen will be used."
609
610navigationMenuProperties["highlightTextColor"] = {}
611navigationMenuProperties["highlightTextColor"]["input"] = "color"
612navigationMenuProperties["highlightTextColor"]["essential"] = false
613navigationMenuProperties["highlightTextColor"]["desc"] = "highlightTextColor (color): color of the text of a highlighted entry of the expanded menu. If unused (nil) entryTextColor will be used."
614
615navigationMenuProperties["highlightBGColor"] = {}
616navigationMenuProperties["highlightBGColor"]["input"] = "color"
617navigationMenuProperties["highlightBGColor"]["essential"] = false
618navigationMenuProperties["highlightBGColor"]["desc"] = "highlightBGColor (color): color of the background of a highlighted entry of the expanded menu. If unused (nil) entryBGColor will be used."
619
620navigationMenuProperties["entryWidth"] = {}
621navigationMenuProperties["entryWidth"]["input"] = "number"
622navigationMenuProperties["entryWidth"]["essential"] = false
623navigationMenuProperties["entryWidth"]["desc"] = "entryWidth (non-decimal number in pixels): how wide (x) every entry shall be including submenus. If unused (nil) will take as much space as needed."
624
625navigationMenuProperties["entryHeight"] = {}
626navigationMenuProperties["entryHeight"]["input"] = "number"
627navigationMenuProperties["entryHeight"]["essential"] = false
628navigationMenuProperties["entryHeight"]["desc"] = "entryHeight (non-decimal number in pixels): how broad (y) every entry shall be including submenus. If unused (nil) will be 1."
629
630navigationMenuProperties["textAlignmentHorizontal"] = {}
631navigationMenuProperties["textAlignmentHorizontal"]["input"] = "DDM:left:center:right"
632navigationMenuProperties["textAlignmentHorizontal"]["essential"] = false
633navigationMenuProperties["textAlignmentHorizontal"]["desc"] = "textAlignmentHorizontal (left,center,right): where the text inside every entry including submenus shall be placed horizontally. If unused (nil) defaults to center."
634
635navigationMenuProperties["textAlignmentVertical"] = {}
636navigationMenuProperties["textAlignmentVertical"]["input"] = "DDM:top:center:bottom"
637navigationMenuProperties["textAlignmentVertical"]["essential"] = false
638navigationMenuProperties["textAlignmentVertical"]["desc"] = "textAlignmentVertical (top,center,bottom): where the text inside every entry including submenus shall be placed vertically. If unused (nil) defaults to center."
639
640navigationMenuProperties["borderThickness"] = {}
641navigationMenuProperties["borderThickness"]["input"] = "number"
642navigationMenuProperties["borderThickness"]["essential"] = false
643navigationMenuProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the navigationMenu shall be. If unused (nil) will be 0. (no border)"
644
645navigationMenuProperties["spaceBetweenEntries"] = {}
646navigationMenuProperties["spaceBetweenEntries"]["input"] = "number"
647navigationMenuProperties["spaceBetweenEntries"]["essential"] = false
648navigationMenuProperties["spaceBetweenEntries"]["desc"] = "spaceBetweenEntries (non-decimal number in pixels): broadness (y) of a line to be placed between entries for separation. If unused (nil) will be 0. (no spaces)"
649
650navigationMenuProperties["onChangeFunction"] = {}
651navigationMenuProperties["onChangeFunction"]["input"] = "manual"
652navigationMenuProperties["onChangeFunction"]["essential"] = false
653navigationMenuProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the selection of the navigationMenu changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), selections of all submenus before menu closed. (number array)"
654
655--selection,borderColor,borderThickness,colorWidth,colorHeight,selectionCharacter,onChangeFunction,visible,enabled
656colorPickerProperties = {}
657colorPickerProperties["selection"] = {}
658colorPickerProperties["selection"]["input"] = "color"
659colorPickerProperties["selection"]["essential"] = false
660colorPickerProperties["selection"]["desc"] = "selection (color): by default selected color."
661
662colorPickerProperties["borderColor"] = {}
663colorPickerProperties["borderColor"]["input"] = "color"
664colorPickerProperties["borderColor"]["essential"] = false
665colorPickerProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the colorPicker. borderThickness needs to be greater than 0. If unused (nil) defaultBGColor of the screen will be used."
666
667colorPickerProperties["borderThickness"] = {}
668colorPickerProperties["borderThickness"]["input"] = "number"
669colorPickerProperties["borderThickness"]["essential"] = false
670colorPickerProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the colorPicker shall be. If unused (nil) will be 0. (no border)"
671
672colorPickerProperties["colorWidth"] = {}
673colorPickerProperties["colorWidth"]["input"] = "number"
674colorPickerProperties["colorWidth"]["essential"] = false
675colorPickerProperties["colorWidth"]["desc"] = "colorWidth (non-decimal number in pixels): how wide (x) every color shall be. If unused (nil) will be 1."
676
677colorPickerProperties["colorHeight"] = {}
678colorPickerProperties["colorHeight"]["input"] = "number"
679colorPickerProperties["colorHeight"]["essential"] = false
680colorPickerProperties["colorHeight"]["desc"] = "colorHeight (non-decimal number in pixels): how broad (y) every color shall be. If unused (nil) will be 1."
681
682colorPickerProperties["selectionCharacter"] = {}
683colorPickerProperties["selectionCharacter"]["input"] = "string"
684colorPickerProperties["selectionCharacter"]["essential"] = false
685colorPickerProperties["selectionCharacter"]["desc"] = "selectionCharacter (1 character): the character which shall indicate the currently selected color. If unused will be X."
686
687colorPickerProperties["onChangeFunction"] = {}
688colorPickerProperties["onChangeFunction"]["input"] = "manual"
689colorPickerProperties["onChangeFunction"]["essential"] = false
690colorPickerProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the selection of the colorPicker changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), selected color. (color)"
691
692--length, value, valueType, broadness, orientation, textPosition, textMargin, color, colorsArray, BGColor, borderColor, borderThickness, visible
693progressBarProperties = {}
694progressBarProperties["length"] = {}
695progressBarProperties["length"]["input"] = "number"
696progressBarProperties["length"]["essential"] = true
697progressBarProperties["length"]["desc"] = "length (non-decimal number in pixels): the length of the progressBar."
698progressBarProperties["length"]["default"] = 5
699
700progressBarProperties["value"] = {}
701progressBarProperties["value"]["input"] = "number"
702progressBarProperties["value"]["essential"] = false
703progressBarProperties["value"]["desc"] = "value (non-decimal number): the default value the progressBar shall take on, either in percent or absolute, see valueType. Defaults to 0."
704
705progressBarProperties["valueType"] = {}
706progressBarProperties["valueType"]["input"] = "DDM:relative:absolute"
707progressBarProperties["valueType"]["essential"] = false
708progressBarProperties["valueType"]["desc"] = "valueType (relative,absolute): whether value shall be an absolute value or a percentage. Defaults to absolute."
709
710progressBarProperties["color"] = {}
711progressBarProperties["color"]["input"] = "color"
712progressBarProperties["color"]["essential"] = false
713progressBarProperties["color"]["desc"] = "color (color): the color the bar of the progressBar shall take on. If unused (nil) will be the defaultTextColor of the screen."
714
715progressBarProperties["BGColor"] = {}
716progressBarProperties["BGColor"]["input"] = "color"
717progressBarProperties["BGColor"]["essential"] = false
718progressBarProperties["BGColor"]["desc"] = "BGColor (color): the background of the progressBar. If unused (nil) will be the defaultBGColor of the screen."
719
720progressBarProperties["borderColor"] = {}
721progressBarProperties["borderColor"]["input"] = "color"
722progressBarProperties["borderColor"]["essential"] = false
723progressBarProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the progressBar. borderThickness needs to be greater than 0. If unused (nil) will be BGColor."
724
725progressBarProperties["borderThickness"] = {}
726progressBarProperties["borderThickness"]["input"] = "number"
727progressBarProperties["borderThickness"]["essential"] = false
728progressBarProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the progressBar shall be. If unused (nil) will be 0. (no border)"
729
730progressBarProperties["colorsArray"] = {}
731progressBarProperties["colorsArray"]["input"] = "colorsArray"
732progressBarProperties["colorsArray"]["essential"] = false
733progressBarProperties["colorsArray"]["desc"] = "colorsArray (numerically-indexed table): this can be used if you want a different bar color for different values. Example: red for high values and green for low values."
734
735progressBarProperties["broadness"] = {}
736progressBarProperties["broadness"]["input"] = "number"
737progressBarProperties["broadness"]["essential"] = false
738progressBarProperties["broadness"]["desc"] = "broadness (non-decimal number in pixels): how broad the progressBar shall be. Perpendicular to progressBar orientation. If unused (nil) will be 1."
739
740progressBarProperties["orientation"] = {}
741progressBarProperties["orientation"]["input"] = "DDM:top-bottom:bottom-top:left-right:right-left"
742progressBarProperties["orientation"]["essential"] = false
743progressBarProperties["orientation"]["desc"] = "orientation (top-bottom,bottom-top,left-right,right-left): how the progressBar shall be oriented. 'start-end'. If unused (nil) will be left-right."
744
745progressBarProperties["textPosition"] = {}
746progressBarProperties["textPosition"]["input"] = "DDM:top:bottom:left:right"
747progressBarProperties["textPosition"]["essential"] = false
748progressBarProperties["textPosition"]["desc"] = "textPosition (top,bottom,left,right): if this value is set will display the current value at the chosen position."
749
750progressBarProperties["textMargin"] = {}
751progressBarProperties["textMargin"]["input"] = "number"
752progressBarProperties["textMargin"]["essential"] = false
753progressBarProperties["textMargin"]["desc"] = "textMargin (non-decimal number in pixels): determines how many pixels away from the progressBar the value will be placed. Requires textPosition to be set. If unused (nil) will be 0."
754
755--width,height,graphTables,graphDesigns(color,BGColor,character),unitsPerPixelX,unitsPerPixelY,axesColor,numbersColor,labelX,labelY,startX,startY,stepX,stepY
756coordinateSystemProperties = {}
757coordinateSystemProperties["width"] = {}
758coordinateSystemProperties["width"]["input"] = "number"
759coordinateSystemProperties["width"]["essential"] = true
760coordinateSystemProperties["width"]["desc"] = "width (non-decimal number in pixels): how long the x axis shall be."
761coordinateSystemProperties["width"]["default"] = 10
762
763coordinateSystemProperties["height"] = {}
764coordinateSystemProperties["height"]["input"] = "number"
765coordinateSystemProperties["height"]["essential"] = true
766coordinateSystemProperties["height"]["desc"] = "height (non-decimal number in pixels): how long the y axis shall be."
767coordinateSystemProperties["height"]["default"] = 10
768
769coordinateSystemProperties["graphTables"] = {}
770coordinateSystemProperties["graphTables"]["input"] = "CSTable"
771coordinateSystemProperties["graphTables"]["essential"] = false
772coordinateSystemProperties["graphTables"]["desc"] = "graphTables (numerically-indexed nested table) all graphs to be displayed. Structure: array[index]={[x]=y}"
773
774coordinateSystemProperties["graphDesigns"] = {}
775coordinateSystemProperties["graphDesigns"]["input"] = "CSDesignsTable"
776coordinateSystemProperties["graphDesigns"]["essential"] = false
777coordinateSystemProperties["graphDesigns"]["desc"] = "graphDesigns (numerically-indexed nested table): each graph can have a different display character, color and background color, stored in this table. Structure: array[index]={[\"character\"]=\"x\",[\"color\"]=color,[\"BGColor\"]=BGColor}"
778
779coordinateSystemProperties["numbersColor"] = {}
780coordinateSystemProperties["numbersColor"]["input"] = "color"
781coordinateSystemProperties["numbersColor"]["essential"] = false
782coordinateSystemProperties["numbersColor"]["desc"] = "numbersColor (color): color of the numbers next to the axes. If unused (nil) will be defaultTextColor of the screen."
783
784coordinateSystemProperties["axesColor"] = {}
785coordinateSystemProperties["axesColor"]["input"] = "color"
786coordinateSystemProperties["axesColor"]["essential"] = false
787coordinateSystemProperties["axesColor"]["desc"] = "axesColor (color): color of the axes. If unused (nil) will be defaultTextColor of the screen."
788
789coordinateSystemProperties["unitsPerPixelX"] = {}
790coordinateSystemProperties["unitsPerPixelX"]["input"] = "decimal"
791coordinateSystemProperties["unitsPerPixelX"]["essential"] = false
792coordinateSystemProperties["unitsPerPixelX"]["desc"] = "unitsPerPixelX (decimal number): how many units one pixel equals on the x axis. If unused (nil) will be 1."
793
794coordinateSystemProperties["unitsPerPixelY"] = {}
795coordinateSystemProperties["unitsPerPixelY"]["input"] = "decimal"
796coordinateSystemProperties["unitsPerPixelY"]["essential"] = false
797coordinateSystemProperties["unitsPerPixelY"]["desc"] = "unitsPerPixelY (decimal number): how many units one pixel equals on the y axis. If unused (nil) will be 1."
798
799coordinateSystemProperties["labelX"] = {}
800coordinateSystemProperties["labelX"]["input"] = "string"
801coordinateSystemProperties["labelX"]["essential"] = false
802coordinateSystemProperties["labelX"]["desc"] = "labelX (string): label of the x axis to be placed next to it. If unused (nil) will be X."
803
804coordinateSystemProperties["labelY"] = {}
805coordinateSystemProperties["labelY"]["input"] = "string"
806coordinateSystemProperties["labelY"]["essential"] = false
807coordinateSystemProperties["labelY"]["desc"] = "labelY (string): label of the y axis to be placed next to it. If unused (nil) will be Y."
808
809coordinateSystemProperties["startX"] = {}
810coordinateSystemProperties["startX"]["input"] = "decimal"
811coordinateSystemProperties["startX"]["essential"] = false
812coordinateSystemProperties["startX"]["desc"] = "startX (decimal number): what x coordinate shall be at the origin of the system. If unused (nil) will be 0."
813
814coordinateSystemProperties["startY"] = {}
815coordinateSystemProperties["startY"]["input"] = "decimal"
816coordinateSystemProperties["startY"]["essential"] = false
817coordinateSystemProperties["startY"]["desc"] = "startY (decimal number): what y coordinate shall be at the origin of the system. If unused (nil) will be 0."
818
819coordinateSystemProperties["stepX"] = {}
820coordinateSystemProperties["stepX"]["input"] = "number"
821coordinateSystemProperties["stepX"]["essential"] = false
822coordinateSystemProperties["stepX"]["desc"] = "stepX (non-decimal number in pixels): every how many pixels a number label shall be placed next to the x axis. If unused (nil) will be as small as possible while maintaining 1 pixel space."
823
824coordinateSystemProperties["stepY"] = {}
825coordinateSystemProperties["stepY"]["input"] = "number"
826coordinateSystemProperties["stepY"]["essential"] = false
827coordinateSystemProperties["stepY"]["desc"] = "stepY (non-decimal number in pixels): every how many pixels a number label shall be placed next to the y axis. If unused (nil) will be as small as possible while maintaining 1 pixel space."
828
829--linesArray
830pictureProperties = {}
831pictureProperties["linesArray"] = {}
832pictureProperties["linesArray"]["input"] = "picArray"
833pictureProperties["linesArray"]["essential"] = true
834pictureProperties["linesArray"]["desc"] = "linesArray (numerically indexed string table) this array defines the whole picture. One entry equals one line. Colors are defined with one character 0-f. String structure: \";\"=transparent pixel, \"color;\"=pixel without character, \"color:bgcolor:character;\"=pixel with character."
835pictureProperties["linesArray"]["default"] = {"#;#;#;#;#;#;#;#;#;#;","#;*:#:Y;*:#:o;*:#:u;*:#:r;#;*:#:P;*:#:i;*:#:c;#;","#;#;#;#;#;#;#;#;#;#;"}
836
837pictureProperties["width"] = {}
838pictureProperties["width"]["input"] = "number"
839pictureProperties["width"]["essential"] = true
840pictureProperties["width"]["desc"] = "width (non-decimal number in pixels): how wide the picture shall be. Even if more information is stored in linesArray, will not overrun this property."
841pictureProperties["width"]["default"] = 10
842
843pictureProperties["height"] = {}
844pictureProperties["height"]["input"] = "number"
845pictureProperties["height"]["essential"] = true
846pictureProperties["height"]["desc"] = "height (non-decimal number in pixels): how high the picture shall be. Even if more information is stored in linesArray, will not overrun this property."
847pictureProperties["height"]["default"] = 3
848
849--elementProperties
850elementProperties = {}
851elementProperties["dynTextBox"] = dynamicTextBoxProperties
852elementProperties["slider"] = sliderProperties
853elementProperties["dropDownMenu"] = dropDownMenuProperties
854elementProperties["navMenu"] = navigationMenuProperties
855elementProperties["colorPicker"] = colorPickerProperties
856elementProperties["progressBar"] = progressBarProperties
857elementProperties["coordsSystem"] = coordinateSystemProperties
858elementProperties["picture"] = pictureProperties
859
860elements = {}
861elements["dynTextBox"] = dynamicTextBoxes
862elements["slider"] = sliders
863elements["dropDownMenu"] = dropDownMenus
864elements["navMenu"] = navigationMenus
865elements["colorPicker"] = colorPickers
866elements["progressBar"] = progressBars
867elements["coordsSystem"] = coordinateSystems
868elements["picture"] = pictures
869
870--string to boolean
871function toBool(var)
872 if type(var)=="string" then
873 if var=="true" then
874 return true
875 else
876 return false
877 end
878 end
879end
880
881--this is used to avoid ID conflicts
882function trackID(ID)
883 ID = string.lower(ID)
884 local found = false
885 for i,current in ipairs(IDlist) do
886 if current==ID then
887 found = true
888 break
889 end
890 end
891 if found then
892 writeToLog("Potential ID conflict: "..ID..". Ignore if designer.",3)
893 else
894 if ID~=nil then
895 table.insert(IDlist,ID)
896 writeToLog("ID "..ID.." added to list.",1)
897 else
898 writeToLog("ID can't be nil!",4)
899 return false
900 end
901 end
902 return not found
903end
904
905function IDExists(ID)
906 ID = string.lower(ID)
907 for i,current in ipairs(IDlist) do
908 if ID==current then
909 return true
910 end
911 end
912 return false
913end
914
915--function to turn a percentage into an absolute coordinate
916function relX(perc,screenID)
917 if math.floor(((screens[screenID]["sizeX"])/100)*perc)>0 then
918 return math.floor(((screens[screenID]["sizeX"])/100)*perc+0.5)
919 else
920 return 1
921 end
922end
923
924function relY(perc,screenID)
925 if math.floor(((screens[screenID]["sizeY"])/100)*perc)>0 then
926 return math.floor(((screens[screenID]["sizeY"])/100)*perc+0.5)
927 else
928 return 1
929 end
930end
931
932--writeToLog function with 5 different levels and time since program start
933function writeToLog(text,level)
934 local levels = {"DEBUG","INFO","WARNING","ERROR","FATAL"}
935 if level == nil then
936 level = 2
937 end
938 if level>=writingLogLevel then
939 if fs.getFreeSpace(fs.combine(root,"EasyGUI/"))>1000 then
940 local timeNumber = os.clock() - startTime
941 local hours = 0
942 local minutes = 0
943 local seconds = 0
944 local milliseconds = 0
945 while timeNumber>=3600 do
946 hours = hours + 1
947 timeNumber = timeNumber - 3600
948 end
949 while timeNumber>=60 do
950 minutes = minutes + 1
951 timeNumber = timeNumber - 60
952 end
953 seconds = timeNumber
954
955 local hours = tostring(hours)
956 local minutes = tostring(minutes)
957 local seconds = tostring(seconds)
958 if string.len(hours)==1 then
959 hours = "0"..hours
960 end
961 if string.len(minutes)==1 then
962 minutes = "0"..minutes
963 end
964 if lastLogString~="[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text then
965 logFile.writeLine("[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text)
966 logFile.flush()
967 lastLogString = "[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text
968 end
969 end
970 end
971end
972
973--save and load functions from here:
974--monitors,screens,dynamicTextBoxes,sliders,dropDownMenus,navigationMenus,colorPickers,progressBars,coordinateSystem,picture
975
976function saveMonitors()
977 writeToLog("Saving monitors to monitors.xml...",2)
978 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
979 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
980 end
981 local stream = fs.open(fs.combine(root,"EasyGUI/monitors.xml"),"a")
982 stream.writeLine("<monitors>")
983
984 for sMonitor,data in pairs(monitors) do
985 writeToLog("Saving monitor "..sMonitor.." to monitors.xml...",1)
986 stream.writeLine("\t<monitor>")
987 stream.writeLine("\t\t<name>"..sMonitor.."</name>")
988 writeToLog("Saving side "..data["side"]..".",1)
989 stream.writeLine("\t\t<side>"..data["side"].."</side>")
990 writeToLog("Saving networkID "..data["networkID"]..".",1)
991 stream.writeLine("\t\t<networkID>"..data["networkID"].."</networkID>")
992 stream.writeLine("\t</monitor>")
993 writeToLog("Done saving monitor "..sMonitor.." to monitors.xml.",1)
994 end
995
996 stream.writeLine("</monitors>")
997 stream.close()
998 writeToLog("Done saving monitors to monitors.xml.",2)
999end
1000
1001function loadMonitors()
1002 writeToLog("Loading monitors from monitors.xml...",2)
1003 local stream = fs.open(fs.combine(root,"EasyGUI/monitors.xml"),"r")
1004
1005 local line = stream.readLine()
1006 local mon = nil
1007 while line~=nil do
1008 if string.match(line,"<monitor>") then
1009 if mon==nil then
1010 mon = {}
1011 writeToLog("Reading new monitor tag...",1)
1012 else
1013 writeToLog("Found monitor tag even though previous monitor tag was not closed. Did someone mess around with the xml?",4)
1014 mon = {}
1015 end
1016 end
1017 if string.match(line,"<name>") and string.match(line,"</name>") then
1018 a,start = string.find(line,"<name>")
1019 sEnd,b = string.find(line,"</name>")
1020 name = string.sub(line,start+1,sEnd-1)
1021 if mon~=nil then
1022 writeToLog("Reading monitor name: "..name,1)
1023 mon["name"] = name
1024 else
1025 writeToLog("Found name tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
1026 end
1027 end
1028 if string.match(line,"<side>") and string.match(line,"</side>") then
1029 a,start = string.find(line,"<side>")
1030 sEnd,b = string.find(line,"</side>")
1031 side = string.sub(line,start+1,sEnd-1)
1032 if mon~=nil then
1033 writeToLog("Reading monitor side: "..side,1)
1034 mon["side"] = side
1035 else
1036 writeToLog("Found side tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
1037 end
1038 end
1039 if string.match(line,"<networkID>") and string.match(line,"</networkID>") then
1040 a,start = string.find(line,"<networkID>")
1041 sEnd,b = string.find(line,"</networkID>")
1042 networkID = string.sub(line,start+1,sEnd-1)
1043 if mon~=nil then
1044 writeToLog("Reading monitor networkID: "..networkID,1)
1045 mon["networkID"] = networkID
1046 else
1047 writeToLog("Found networkID tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
1048 end
1049 end
1050 if string.match(line,"</monitor>") then
1051 if mon~=nil then
1052 name = mon["name"]
1053 mon["name"] = nil
1054 if mon["side"]~=nil and mon["networkID"]~=nil then
1055 monitors[name] = mon
1056 trackID(name)
1057 if mon["networkID"]=="NONE" then
1058 monitors[name]["peripheral"] = peripheral.wrap(mon["side"])
1059 if monitors[name]["peripheral"]==nil then
1060 monitors[name]=nil
1061 writeToLog("A saved monitor is missing. Reinitializing search.",4)
1062 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
1063 findMonitors()
1064 saveMonitors()
1065 break
1066 else
1067 writeToLog("Successfully read information for monitor "..name.." and added to the system.",1)
1068 end
1069 else
1070 monitors[name]["peripheral"] = peripheral.wrap(mon["networkID"])
1071 if monitors[name]["peripheral"]==nil then
1072 monitors[name]=nil
1073 writeToLog("A saved monitor is missing. Reinitializing search.",4)
1074 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
1075 findMonitors()
1076 saveMonitors()
1077 break
1078 else
1079 writeToLog("Successfully read information for monitor "..name.." and added to the system.",1)
1080 end
1081 end
1082 else
1083 writeToLog("Information for monitor "..name.." is faulty. Did someone mess around with the xml?",4)
1084 end
1085 mon = nil
1086 else
1087 writeToLog("Found monitor closing tag even though it was not opened. Did someone mess around with the xml?",4)
1088 end
1089 end
1090
1091 line = stream.readLine()
1092 end
1093
1094 writeToLog("Done loading monitors from monitors.xml.",2)
1095 stream.close()
1096end
1097
1098function saveScreen(ID)
1099 if screens[ID]~=nil then
1100 writeToLog("Saving screen "..ID.."...",2)
1101 if fs.exists(fs.combine(root,"EasyGUI/screens/"..ID..".xml")) then
1102 fs.delete(fs.combine(root,"EasyGUI/screens/"..ID..".xml"))
1103 end
1104
1105 local handle = fs.open(fs.combine(root,"EasyGUI/screens/"..ID..".xml"),"a")
1106
1107 local data = screens[ID]
1108
1109 handle.writeLine("<screen>")
1110 saveProp(handle,"sizeX",data)
1111 saveProp(handle,"sizeY",data)
1112 saveProp(handle,"defaultTextColor",data)
1113 saveProp(handle,"defaultBGColor",data)
1114
1115 handle.writeLine("\t<elements>")
1116 for i,element in ipairs(data["elements"]) do
1117 if string.len(element["ID"])<32 then
1118 handle.writeLine("\t\t<element>")
1119 handle.writeLine("\t\t\t<type>"..element["type"].."</type>")
1120 handle.writeLine("\t\t\t<ID>"..element["ID"].."</ID>")
1121 handle.writeLine("\t\t\t<x>"..element["x"].."</x>")
1122 handle.writeLine("\t\t\t<y>"..element["y"].."</y>")
1123 saveElement(element["ID"],element["type"])
1124 handle.writeLine("\t\t</element>")
1125 end
1126 end
1127 handle.writeLine("\t</elements>")
1128
1129 handle.writeLine("</screen>")
1130 handle.close()
1131 writeToLog("Done saving screen "..ID..".",2)
1132 else
1133 writeToLog("Could not save screen "..ID.." because it was not found.",3)
1134 end
1135end
1136
1137function loadScreen(ID)
1138 if fs.exists(fs.combine(root,"EasyGUI/screens/"..ID..".xml")) then
1139 local handle = fs.open(fs.combine(root,"EasyGUI/screens/"..ID..".xml"),"r")
1140 local temp = {}
1141 local line = handle.readLine()
1142 while line~=nil do
1143 readPropNumber(line,"sizeX",temp)
1144 readPropNumber(line,"sizeY",temp)
1145 readPropNumber(line,"defaultTextColor",temp)
1146 readPropNumber(line,"defaultBGColor",temp)
1147 if string.match(line,"<elements>") then
1148 local temp2 = {}
1149 line = handle.readLine()
1150 while not string.match(line,"</elements>") do
1151 if string.match(line,"<element>") then
1152 local temp3 = {}
1153 line = handle.readLine()
1154 while not string.match(line,"</element>") do
1155 if string.match(line,"<type>") and string.match(line,"</type>") then
1156 a,start = string.find(line,"<type>")
1157 sEnd,b = string.find(line,"</type>")
1158 type_ = string.sub(line,start+1,sEnd-1)
1159 temp3["type"] = type_
1160 end
1161 if string.match(line,"<ID>") and string.match(line,"</ID>") then
1162 a,start = string.find(line,"<ID>")
1163 sEnd,b = string.find(line,"</ID>")
1164 ID_ = string.sub(line,start+1,sEnd-1)
1165 temp3["ID"] = ID_
1166 end
1167 if string.match(line,"<x>") and string.match(line,"</x>") then
1168 a,start = string.find(line,"<x>")
1169 sEnd,b = string.find(line,"</x>")
1170 x_ = string.sub(line,start+1,sEnd-1)
1171 temp3["x"] = tonumber(x_)
1172 end
1173 if string.match(line,"<y>") and string.match(line,"</y>") then
1174 a,start = string.find(line,"<y>")
1175 sEnd,b = string.find(line,"</y>")
1176 y_ = string.sub(line,start+1,sEnd-1)
1177 temp3["y"] = tonumber(y_)
1178 end
1179
1180 line = handle.readLine()
1181 end
1182 loadElement(temp3["ID"],temp3["type"])
1183 table.insert(temp2,temp3)
1184 end
1185 line = handle.readLine()
1186 end
1187 temp["elements"] = temp2
1188 end
1189 line = handle.readLine()
1190 end
1191 if temp["sizeX"]~=nil and temp["sizeY"]~=nil and temp["defaultTextColor"]~=nil and temp["defaultBGColor"]~=nil and temp["elements"]~=nil then
1192 temp["pixelMatrix"] = {}
1193 screens[ID] = temp
1194 trackID(ID)
1195 writeToLog("Succesfully loaded screen "..ID..".",2)
1196 else
1197 writeToLog("Information for screen "..ID.." is faulty. Did someone mess around with the xml?",4)
1198 end
1199 handle.close()
1200 else
1201 writeToLog("Could not load screen "..ID.." because the file was not found.",3)
1202 end
1203end
1204
1205function tryLoadAllScreens()
1206 if fs.exists(fs.combine(root,"/EasyGUI/screens/")) then
1207 for i,name in ipairs(fs.list(fs.combine(root,"/EasyGUI/screens/"))) do
1208 if string.sub(name,-4)==".xml" then
1209 if screens[string.sub(name,1,-5)]==nil then
1210 loadScreen(string.sub(name,1,-5))
1211 end
1212 end
1213 end
1214 end
1215end
1216
1217function tryLoadAllElements()
1218 for type_,data in pairs(elements) do
1219 if fs.exists(fs.combine(root,"/EasyGUI/"..type_.."/")) then
1220 for i,name in ipairs(fs.list(fs.combine(root,"/EasyGUI/"..type_.."/"))) do
1221 if string.sub(name,-4)==".xml" then
1222 if elements[type_][string.sub(name,1,-5)]==nil then
1223 loadElement(string.sub(name,1,-5),type_)
1224 end
1225 end
1226 end
1227 end
1228 end
1229end
1230
1231function saveProp(handle,prop,data)
1232 if data[prop]~=nil then
1233 handle.writeLine("\t<"..prop..">"..data[prop].."</"..prop..">")
1234 writeToLog("Saving "..prop.." "..data[prop]..".",1)
1235 end
1236end
1237
1238function readPropString(line,prop,temp)
1239 if string.match(line,"<"..prop..">") and string.match(line,"</"..prop..">") then
1240 local a,start = string.find(line,"<"..prop..">")
1241 local sEnd,b = string.find(line,"</"..prop..">")
1242 local value = string.sub(line,start+1,sEnd-1)
1243 temp[prop] = value
1244 writeToLog("Reading "..prop..": "..value,1)
1245 end
1246end
1247
1248function readPropNumber(line,prop,temp)
1249 if string.match(line,"<"..prop..">") and string.match(line,"</"..prop..">") then
1250 local a,start = string.find(line,"<"..prop..">")
1251 local sEnd,b = string.find(line,"</"..prop..">")
1252 local value = string.sub(line,start+1,sEnd-1)
1253 temp[prop] = tonumber(value)
1254 writeToLog("Reading "..prop..": "..value,1)
1255 end
1256end
1257
1258function saveArray(handle,prop,data)
1259 if data[prop]~=nil then
1260 handle.writeLine("\t<"..prop..">")
1261 writeToLog("Saving "..prop..".",1)
1262 for i,entry in ipairs(data[prop]) do
1263 handle.writeLine("\t\t<"..i..">"..entry.."</"..i..">")
1264 end
1265 handle.writeLine("\t</"..prop..">")
1266 end
1267end
1268
1269function readNumberArray(line,prop,temp,handle)
1270 if string.match(line,"<"..prop..">") then
1271 line = handle.readLine()
1272 local temp2 = {}
1273 while not (string.match(line,"</"..prop..">")) do
1274 if string.match(line,"<%d+>") and string.match(line,"</%d+>") then
1275 local a,start = string.find(line,"<%d+>")
1276 local sEnd,b = string.find(line,"</%d+>")
1277 local currentValue = tonumber(string.sub(line,start+1,sEnd-1))
1278 local index = tonumber(string.sub(line,a+1,start-1))
1279 temp2[index] = currentValue
1280 end
1281
1282 line = handle.readLine()
1283 end
1284 temp[prop] = temp2
1285 writeToLog("Reading "..prop..".",1)
1286 end
1287end
1288
1289function readStringArray(line,prop,temp,handle)
1290 if string.match(line,"<"..prop..">") then
1291 line = handle.readLine()
1292 local temp2 = {}
1293 while not (string.match(line,"</"..prop..">")) do
1294 if string.match(line,"<%d+>") and string.match(line,"</%d+>") then
1295 local a,start = string.find(line,"<%d+>")
1296 local sEnd,b = string.find(line,"</%d+>")
1297 local currentValue = (string.sub(line,start+1,sEnd-1))
1298 local index = tonumber(string.sub(line,a+1,start-1))
1299 temp2[index] = currentValue
1300 end
1301
1302 line = handle.readLine()
1303 end
1304 temp[prop] = temp2
1305 writeToLog("Reading "..prop..".",1)
1306 end
1307end
1308
1309--helper function for writing navMenu arrays (recursive)
1310function writeSubmenu(handle,array,level)
1311 local tabs = "\t\t"
1312 for i=1,level-1 do
1313 tabs = tabs.."\t\t"
1314 end
1315 for i,entry in ipairs(array) do
1316 handle.writeLine(tabs.."<"..i..">")
1317 handle.writeLine(tabs.."\t<text>"..entry["text"].."</text>")
1318 if entry["submenu"]~=nil then
1319 handle.writeLine(tabs.."\t<submenu>")
1320 writeSubmenu(handle,entry["submenu"],level+1)
1321 handle.writeLine(tabs.."\t</submenu>")
1322 end
1323 handle.writeLine(tabs.."</"..i..">")
1324 end
1325end
1326
1327function saveNavMenu(handle,prop,data)
1328 handle.writeLine("\t<"..prop..">")
1329 writeSubmenu(handle,data[prop],1)
1330 handle.writeLine("\t</"..prop..">")
1331end
1332
1333function readNavMenu(line,prop,temp,handle)
1334 if string.match(line,"<"..prop..">") then
1335 line = handle.readLine()
1336 local temp2 = {}
1337 local currentPos = {}
1338 local indexTagOpen = 0
1339 local submenuTagOpen = 0
1340 local currentIndex = nil
1341 while not string.match(line,"</"..prop..">") do
1342 if string.match(line,"<%d+>") then
1343 a,start = string.find(line,"<%d+>")
1344 sEnd,b = string.find(line,"</%d+>")
1345 index = tonumber(string.sub(line,a+1,start-1))
1346
1347 local currentArray = temp2
1348 for i=1,table.getn(currentPos) do
1349 currentArray = currentArray[currentPos[i]]
1350 end
1351
1352 currentIndex = index
1353 currentArray[currentIndex] = {}
1354 indexTagOpen = indexTagOpen + 1
1355 end
1356 if string.match(line,"</%d+>") then
1357 if indexTagOpen==0 then
1358 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1359 end
1360 currentIndex = nil
1361 indexTagOpen = indexTagOpen - 1
1362 end
1363 if string.match(line,"<text>") and string.match(line,"</text>") then
1364 a,start = string.find(line,"<text>")
1365 sEnd,b = string.find(line,"</text>")
1366 text = string.sub(line,start+1,sEnd-1)
1367 writeToLog("Reading text: "..text,1)
1368 if indexTagOpen==0 or currentIndex==nil then
1369 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1370 else
1371 local currentArray = temp2
1372 for i=1,table.getn(currentPos) do
1373 currentArray = currentArray[currentPos[i]]["submenu"]
1374 end
1375 currentArray[currentIndex] = {}
1376 currentArray[currentIndex]["text"] = text
1377 end
1378 end
1379 if string.match(line,"<submenu>") then
1380 if indexTagOpen==0 or currentIndex==nil then
1381 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1382 else
1383 local currentArray = temp2
1384 for i=1,table.getn(currentPos) do
1385 currentArray = currentArray[currentPos[i]]["submenu"]
1386 end
1387 table.insert(currentPos,currentIndex)
1388 currentArray[currentIndex]["submenu"] = {}
1389 end
1390 submenuTagOpen = submenuTagOpen + 1
1391 end
1392 if string.match(line,"</submenu>") then
1393 if submenuTagOpen == 0 then
1394 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1395 else
1396 currentPos[table.getn(currentPos)] = nil
1397 end
1398
1399 submenuTagOpen = submenuTagOpen - 1
1400 end
1401 line = handle.readLine()
1402 end
1403 if submenuTagOpen~=0 or indexTagOpen~=0 then
1404 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1405 else
1406 temp["menuArray"] = temp2
1407 end
1408 end
1409end
1410
1411function saveCSTable(handle,prop,data)
1412 if data[prop]~=nil then
1413 handle.writeLine("\t<"..prop..">")
1414 for i,currentTable in ipairs(data[prop]) do
1415 handle.writeLine("\t\t<"..i..">")
1416 for name,currentNumber in pairs(currentTable) do
1417 handle.writeLine("\t\t\t<"..name..">"..currentNumber.."</"..name..">")
1418 end
1419 handle.writeLine("\t\t</"..i..">")
1420 end
1421 handle.writeLine("\t</"..prop..">")
1422 end
1423end
1424
1425function saveCSDesignsTable(handle,prop,data)
1426 if data[prop]~=nil then
1427 handle.writeLine("\t<"..prop..">")
1428 for i,design in ipairs(data[prop]) do
1429 handle.writeLine("\t\t<"..i..">")
1430 if design["color"]~=nil then
1431 handle.writeLine("\t\t\t<color>"..design["color"].."</color>")
1432 end
1433 if design["BGColor"]~=nil then
1434 handle.writeLine("\t\t\t<BGColor>"..design["BGColor"].."</BGColor>")
1435 end
1436 if design["character"]~=nil then
1437 handle.writeLine("\t\t\t<character>"..design["character"].."</character>")
1438 end
1439 handle.writeLine("\t\t</"..i..">")
1440 end
1441 handle.writeLine("\t</"..prop..">")
1442 end
1443end
1444
1445function readCSTable(line,prop,temp,handle)
1446 if string.match(line,"<"..prop..">") then
1447 line = handle.readLine()
1448 local temp2 = {}
1449 local tableOpen = nil
1450 while not string.match(line,"</"..prop..">") do
1451 if string.match(line,"<[%d.-]+>") then
1452 a,start = string.find(line,"<[%d.-]+>")
1453 index = tonumber(string.sub(line,a+1,start-1))
1454 if tableOpen==nil then
1455 tableOpen = index
1456 temp2[tableOpen] = {}
1457 else
1458 if string.match(line,"</[%d.-]+>") then
1459 sEnd,b = string.find(line,"</[%d.-]+>")
1460 currentNumber = tonumber(string.sub(line,start+1,sEnd-1))
1461 temp2[tableOpen][index] = currentNumber
1462 end
1463 end
1464 else if string.match(line,"</[%d.-]+>") then
1465 tableOpen = nil
1466 end
1467 end
1468 line = handle.readLine()
1469 end
1470 temp[prop] = temp2
1471 end
1472end
1473
1474function readCSDesignsTable(line,prop,temp,handle)
1475 if string.match(line,"<"..prop..">") then
1476 line = handle.readLine()
1477 local temp2 = {}
1478 local tableOpen = nil
1479 while not string.match(line,"</"..prop..">") do
1480 if string.match(line,"<%d+>") then
1481 a,start = string.find(line,"<%d+>")
1482 index = tonumber(string.sub(line,a+1,start-1))
1483 if tableOpen==nil then
1484 tableOpen = index
1485 temp2[tableOpen] = {}
1486 else
1487 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1488 end
1489 end
1490 if string.match(line,"</%d+>") then
1491 tableOpen = nil
1492 end
1493 if string.match(line,"<color>") and string.match(line,"</color>") then
1494 a,start = string.find(line,"<color>")
1495 sEnd,b = string.find(line,"</color>")
1496 color = string.sub(line,start+1,sEnd-1)
1497 if tableOpen==nil then
1498 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1499 else
1500 temp2[tableOpen]["color"] = tonumber(color)
1501 end
1502 end
1503 if string.match(line,"<BGColor>") and string.match(line,"</BGColor>") then
1504 a,start = string.find(line,"<BGColor>")
1505 sEnd,b = string.find(line,"</BGColor>")
1506 BGColor = string.sub(line,start+1,sEnd-1)
1507 if tableOpen==nil then
1508 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1509 else
1510 temp2[tableOpen]["BGColor"] = tonumber(BGColor)
1511 end
1512 end
1513 if string.match(line,"<character>") and string.match(line,"</character>") then
1514 a,start = string.find(line,"<character>")
1515 sEnd,b = string.find(line,"</character>")
1516 character = string.sub(line,start+1,sEnd-1)
1517 if tableOpen==nil then
1518 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1519 else
1520 temp2[tableOpen]["character"] = character
1521 end
1522 end
1523 line = handle.readLine()
1524 end
1525 temp[prop] = temp2
1526 end
1527end
1528
1529function saveElement(ID,type_)
1530 if elements[type_][ID]~=nil then
1531 writeToLog("Saving "..type_.." "..ID.."...",2)
1532 if fs.exists(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml")) then
1533 fs.delete(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"))
1534 end
1535
1536 local handle = fs.open(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"),"a")
1537
1538 local data = elements[type_][ID]
1539
1540 handle.writeLine("<"..type_..">")
1541
1542 for name,data2 in pairs(elementProperties[type_]) do
1543 if data2["input"]=="number" or data2["input"]=="string" or data2["input"]=="decimal" or data2["input"]=="color" or string.sub(data2["input"],1,3)=="DDM" then
1544 saveProp(handle,name,data)
1545 end
1546 if data2["input"]=="colorsArray" or data2["input"]=="stringArray" or data2["input"]=="picArray" then
1547 saveArray(handle,name,data)
1548 end
1549 if data2["input"]=="navMenuArray" then
1550 saveNavMenu(handle,name,data)
1551 end
1552 if data2["input"]=="CSTable" then
1553 saveCSTable(handle,name,data)
1554 end
1555 if data2["input"]=="CSDesignsTable" then
1556 saveCSDesignsTable(handle,name,data)
1557 end
1558 end
1559
1560 handle.writeLine("</"..type_..">")
1561 handle.close()
1562 writeToLog("Done saving "..type_.." "..ID..".",2)
1563 else
1564 writeToLog("Could not save "..type_.." "..ID.." because it was not found.",3)
1565 end
1566end
1567
1568function loadElement(ID,type_)
1569 if fs.exists(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml")) then
1570 local handle = fs.open(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"),"r")
1571 local temp = {}
1572 local line = handle.readLine()
1573 while line~=nil do
1574 for name,data2 in pairs(elementProperties[type_]) do
1575 if data2["input"]=="number" or data2["input"]=="decimal" or data2["input"]=="color" then
1576 readPropNumber(line,name,temp)
1577 end
1578 if data2["input"]=="string" or string.sub(data2["input"],1,3)=="DDM" then
1579 readPropString(line,name,temp)
1580 end
1581 if data2["input"]=="stringArray" or data2["input"]=="picArray" then
1582 readStringArray(line,name,temp,handle)
1583 end
1584 if data2["input"]=="colorsArray" then
1585 readNumberArray(line,name,temp,handle)
1586 end
1587 if data2["input"]=="navMenuArray" then
1588 readNavMenu(line,name,temp,handle)
1589 end
1590 if data2["input"]=="CSTable" then
1591 readCSTable(line,name,temp,handle)
1592 end
1593 if data2["input"]=="CSDesignsTable" then
1594 readCSDesignsTable(line,name,temp,handle)
1595 end
1596 end
1597
1598 line = handle.readLine()
1599 end
1600 local valid = true
1601 for name,data2 in pairs(elementProperties[type_]) do
1602 if data2["essential"] then
1603 if temp[name]==nil then
1604 valid = false
1605 break
1606 end
1607 end
1608 end
1609 if valid then
1610 temp["visible"] = true
1611 temp["enabled"] = true
1612 temp["expanded"] = false
1613 elements[type_][ID] = temp
1614 trackID(ID)
1615 writeToLog("Succesfully loaded "..type_.." "..ID..".",2)
1616 else
1617 writeToLog("Information for "..type_.." "..ID.." is faulty. Did someone mess around with the xml?",4)
1618 end
1619 handle.close()
1620 else
1621 writeToLog("Could not load "..type_.." "..ID.." because the file was not found.",3)
1622 end
1623end
1624
1625--screens and pixel matrices from here
1626--this functions adds a screen
1627function addScreen(id,sizeX,sizeY,defaultTextColor,defaultBGColor)
1628 if trackID(id) then
1629 screens[id] = {}
1630 screens[id]["sizeX"] = sizeX
1631 screens[id]["sizeY"] = sizeY
1632 screens[id]["defaultTextColor"] = defaultTextColor
1633 screens[id]["defaultBGColor"] = defaultBGColor
1634 screens[id]["elements"] = {}
1635 screens[id]["pixelMatrix"] = {}
1636 writeToLog("Added screen "..id..".",2)
1637 else
1638 writeToLog("Did not add screen because of ID conflict.",3)
1639 end
1640end
1641
1642--this is an essential function which adds pixels to screen matrices accordingly
1643function writeToPixelMatrix(screenID,s,x,y,textColor,BGColor,elementID,elementType,sPart)
1644 if string.len(s)==1 then
1645 if x<=screens[screenID]["sizeX"] and y<=screens[screenID]["sizeY"] and x>=1 and y>=1 then
1646 writeToLog("Drawing "..sPart.." of "..elementType.." "..elementID..".",1)
1647 screens[screenID]["pixelMatrix"][x..":"..y] = {}
1648 screens[screenID]["pixelMatrix"][x..":"..y]["character"] = s
1649 screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] = textColor
1650 screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] = BGColor
1651 screens[screenID]["pixelMatrix"][x..":"..y]["elementID"] = elementID
1652 screens[screenID]["pixelMatrix"][x..":"..y]["elementType"] = elementType
1653 screens[screenID]["pixelMatrix"][x..":"..y]["part"] = sPart
1654 else
1655 writeToLog("Part "..sPart.." of "..elementType.." "..elementID.." tried to draw outside of screen "..screenID..".",3)
1656 end
1657 else
1658 for i=1,string.len(s) do
1659 writeToPixelMatrix(screenID,string.sub(s,i,i),x+i-1,y,textColor,BGColor,elementID,elementType,sPart)
1660 end
1661 end
1662end
1663
1664function fullRefresh()
1665 clearTerminal()
1666 clearMonitors()
1667 for name,data in pairs(screens) do
1668 screens[name]["pixelMatrix"] = {}
1669 end
1670 refresh()
1671end
1672
1673function restartTimer(nRefreshRate)
1674 if nRefreshRate~=nil then
1675 refreshRate = nRefreshRate
1676 refreshTimerID = os.startTimer(refreshRate)
1677 writeToLog("Restarting refresh timer with refreshRate "..refreshRate.." seconds.",1)
1678 end
1679end
1680
1681--this function adds an element to the screen
1682function addElementToScreen(elementID, screenID, x,y)
1683 if x==nil then
1684 x = 1
1685 end
1686 if y==nil then
1687 y = 1
1688 end
1689 if screens[screenID]~=nil then
1690 local elements = screens[screenID]["elements"]
1691 local element = {}
1692 local exists = false
1693
1694 for i,current in ipairs(elements) do
1695 if current["ID"]==elementID then
1696 exists = true
1697 end
1698 end
1699
1700 if not exists then
1701 if getType(elementID)~=nil then
1702 element["type"] = getType(elementID)
1703 element["ID"] = elementID
1704 element["x"] = x
1705 element["y"] = y
1706
1707 table.insert(elements, element)
1708 screens[screenID]["elements"] = elements
1709 writeToLog("Successfully added element "..elementID.." to screen "..screenID..".",2)
1710 else
1711 writeToLog("Could not add element to the screen. Element was not found or nil.",3)
1712 end
1713 else
1714 writeToLog("Did not add element to the screen because the element is already on that screen.",2)
1715 end
1716 else
1717 writeToLog("Could not add the element to the screen. Screen was not found or nil.",3)
1718 end
1719end
1720
1721function removeElementFromScreen(elementID,screenID)
1722 if screens[screenID]~=nil then
1723 for i,data in ipairs(screens[screenID]["elements"]) do
1724 if data["ID"]==elementID then
1725 table.remove(screens[screenID]["elements"],i)
1726 break
1727 end
1728 end
1729 else
1730 writeToLog("Could not remove the element from the screen. Screen was not found or nil.",3)
1731 end
1732end
1733
1734function changePos(elementID,screenID,x,y)
1735 if x==nil then
1736 x = 1
1737 end
1738 if y==nil then
1739 y = 1
1740 end
1741 if screens[screenID]~=nil then
1742 local elements = screens[screenID]["elements"]
1743 local found = false
1744
1745 for name,data in pairs(screens[screenID]["elements"]) do
1746 if data["ID"]==elementID then
1747 found = true
1748 data["x"] = x
1749 data["y"] = y
1750 break
1751 end
1752 end
1753
1754 if found then
1755 writeToLog("Successfully changed pos of element "..elementID.." on screen "..screenID..".",2)
1756 else
1757 writeToLog("Could not change pos of element. Element was not found or nil.",3)
1758 end
1759 else
1760 writeToLog("Could not change pos of element. Screen was not found or nil.",3)
1761 end
1762end
1763
1764function getPos(elementID,screenID)
1765 if screens[screenID]~=nil then
1766 local elements = screens[screenID]["elements"]
1767
1768 for name,data in pairs(screens[screenID]["elements"]) do
1769 if data["ID"]==elementID then
1770 return data["x"],data["y"]
1771 end
1772 end
1773 end
1774end
1775
1776--this function updates the pixel matrix of a certain screen
1777function updatePixelMatrix(screenID,str)
1778 writeToLog("Updating pixel matrix of screen "..screenID..".",2)
1779 --write elements to pixel matrix
1780 for i,element in ipairs(screens[screenID]["elements"]) do
1781 if str==nil or (string.len(element["ID"])>31 and str=="ONLYHASH") or (string.len(element["ID"])<32 and str=="ONLYNONHASH") then
1782 if elements[element["type"]][element["ID"]]["visible"] then
1783 writeToLog("Writing "..element["type"].." "..element["ID"].." to pixel matrix.",1)
1784 success,msg = pcall(writeElementToPixelMatrix,screenID,element["ID"],element["x"],element["y"],element["type"])
1785 if success then
1786 writeToLog("Done writing "..element["type"].." "..element["ID"].." to pixel matrix.",1)
1787 else
1788 writeToLog("There was an error writing "..element["type"].." "..element["ID"].." to pixel matrix. Error message: "..msg,4)
1789 end
1790 end
1791 end
1792 end
1793 writeToLog("Done updating pixel matrix.",2)
1794end
1795
1796function writeElementToPixelMatrix(screenID,ID,x,y,type_)
1797 if type_=="dynTextBox" then
1798 writeDynamicTextBoxToPixelMatrix(screenID,ID,x,y)
1799 end
1800 if type_=="slider" then
1801 writeSliderToPixelMatrix(screenID,ID,x,y)
1802 end
1803 if type_=="dropDownMenu" then
1804 writeDropDownMenuToPixelMatrix(screenID,ID,x,y)
1805 end
1806 if type_=="navMenu" then
1807 writeNavigationMenuToPixelMatrix(screenID,ID,x,y)
1808 end
1809 if type_=="colorPicker" then
1810 writeColorPickerToPixelMatrix(screenID,ID,x,y)
1811 end
1812 if type_=="progressBar" then
1813 writeProgressBarToPixelMatrix(screenID,ID,x,y)
1814 end
1815 if type_=="coordsSystem" then
1816 writeCoordinateSystemToPixelMatrix(screenID,ID,x,y)
1817 end
1818 if type_=="picture" then
1819 writePictureToPixelMatrix(screenID,ID,x,y)
1820 end
1821end
1822
1823function setScreenToRenderOnMon(screenID,monID,textScale,offsetX,offsetY)
1824 if offsetX ==nil then
1825 offsetX = 0
1826 end
1827 if offsetY ==nil then
1828 offsetY = 0
1829 end
1830 if monitors[monID]~=nil then
1831 if screens[screenID]~=nil then
1832 clearMonitor(monID)
1833 screens[screenID]["pixelMatrix"] = {}
1834 monitors[monID]["screen"] = screenID
1835 monitors[monID]["offsetX"] = offsetX
1836 monitors[monID]["offsetY"] = offsetY
1837 monitors[monID]["textScale"] = textScale
1838 writeToLog("Set screen "..screenID.." to be rendered on monitor "..monID..".",2)
1839 else
1840 writeToLog("Could not set screen to be rendered on monitor. Screen was not found or nil.",3)
1841 end
1842 else
1843 writeToLog("Could not set the screen to be rendered on monitor. Monitor was not found or nil.",3)
1844 end
1845end
1846
1847function setScreenToRenderOnTerminal(screenID)
1848 if screens[screenID]~=nil then
1849 clearTerminal()
1850 screens[screenID]["pixelMatrix"] = {}
1851 terminalScreen = screenID
1852 writeToLog("Set screen "..screenID.." to be rendered on terminal.")
1853 else
1854 terminalScreen = nil
1855 writeToLog("Could not set screen to be rendered on terminal. Screen was not found or nil.")
1856 end
1857end
1858
1859function setRefreshFunction(func)
1860 refreshFunction = func
1861 writeToLog("Changed refresh function.",2)
1862end
1863
1864function setProcessClickEventFunction(func)
1865 processClickEventFunc = func
1866 writeToLog("Changed processClickEvent function.",2)
1867end
1868
1869function setProcessEventFunction(func)
1870 processEventFunc = func
1871 writeToLog("Changed processEvent function.",2)
1872end
1873
1874function drawPixels(x,y,textColor,BGColor,str,monID)
1875 if monID~=nil then
1876 monitors[monID]["peripheral"].setBackgroundColor(BGColor)
1877 monitors[monID]["peripheral"].setTextColor(textColor)
1878 monitors[monID]["peripheral"].setCursorPos(x+monitors[monID]["offsetX"],y+monitors[monID]["offsetY"])
1879 monitors[monID]["peripheral"].write(str)
1880 else
1881 term.setBackgroundColor(BGColor)
1882 term.setTextColor(textColor)
1883 term.setCursorPos(x,y)
1884 term.write(str)
1885 end
1886end
1887
1888function drawOnMonitors(x,y,textColor,BGColor,str,monitorList)
1889 for i,monID in ipairs(monitorList) do
1890 if monID==terminalID then
1891 success,msg = pcall(drawPixels,x,y,textColor,BGColor,str)
1892 else
1893 success,msg = pcall(drawPixels,x,y,textColor,BGColor,str,monID)
1894 end
1895 if success then
1896 writeToLog("Drew "..str.." at "..x..":"..y..".",1)
1897 else
1898 writeToLog("There was an error drawing "..str.." at "..x..":"..y..". Error message: "..msg,4)
1899 end
1900 end
1901end
1902
1903function refresh()
1904 writeToLog("Refreshing all monitors...",2)
1905 local startTime = os.clock()
1906 for screenID,screenData in pairs(screens) do
1907 monitorList = {}
1908 for monID,data in pairs(monitors) do
1909 if screenID==data["screen"] then
1910 table.insert(monitorList,monID)
1911 end
1912 end
1913 if screenID==terminalScreen then
1914 table.insert(monitorList,terminalID)
1915 end
1916 if table.getn(monitorList)~=0 then
1917 --store previous pixels in this array
1918 local previousMatrix = {}
1919 for name,data in pairs(screens[screenID]["pixelMatrix"]) do
1920 previousMatrix[name] = data
1921 end
1922 screens[screenID]["pixelMatrix"] = {}
1923
1924 if designerRefresh then
1925 updatePixelMatrix(screenID,"ONLYNONHASH")
1926 screens[screenID]["sizeX"] = designerX
1927 screens[screenID]["sizeY"] = designerY
1928 updatePixelMatrix(screenID,"ONLYHASH")
1929 else
1930 updatePixelMatrix(screenID)
1931 end
1932
1933 writeToLog("Drawing pixels of screen "..screenID.." on monitors.",2)
1934 --render pixel matrix
1935 for y=1,screens[screenID]["sizeY"] do
1936 --this is a system which is performance optimized
1937 --instead of drawing each pixel separately, it collects all the pixels which use the same colors and writes it as a whole string
1938 local currStr = ""
1939 local currTextColor = nil
1940 local currBGColor = nil
1941 local currX = nil
1942 for x=1,screens[screenID]["sizeX"] do
1943 if screens[screenID]["pixelMatrix"][x..":"..y]~=nil then
1944 --only draw it if something changed about the pixel
1945 --performance
1946 local draw = true
1947 if previousMatrix[x..":"..y]~=nil then
1948 if previousMatrix[x..":"..y]["BGColor"]==screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] and previousMatrix[x..":"..y]["textColor"]==screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] and previousMatrix[x..":"..y]["character"]==screens[screenID]["pixelMatrix"][x..":"..y]["character"] then
1949 draw = false
1950 end
1951 else
1952 if screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"]==screens[screenID]["defaultBGColor"] and screens[screenID]["pixelMatrix"][x..":"..y]["character"]==" " then
1953 draw = false
1954 end
1955 end
1956 if draw then
1957 if currTextColor==screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] and currBGColor==screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] then
1958 currStr = currStr ..screens[screenID]["pixelMatrix"][x..":"..y]["character"]
1959 else
1960 if currStr~="" and currStr~=nil then
1961 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1962 end
1963 currStr = screens[screenID]["pixelMatrix"][x..":"..y]["character"]
1964 currTextColor = screens[screenID]["pixelMatrix"][x..":"..y]["textColor"]
1965 currBGColor = screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"]
1966 currX = x
1967 end
1968 else
1969 if currStr~="" and currStr~=nil then
1970 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1971 end
1972 currStr = ""
1973 currTextColor = nil
1974 currBGColor = nil
1975 currX = nil
1976 end
1977 previousMatrix[x..":"..y] = nil
1978 else
1979 if currStr~="" and currStr~=nil then
1980 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1981 end
1982 currStr = ""
1983 currTextColor = nil
1984 currBGColor = nil
1985 currX = nil
1986 end
1987 end
1988 if currStr~="" and currStr~=nil then
1989 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1990 end
1991 end
1992 writeToLog("Done drawing pixels of screen "..screenID.. " on monitors.",2)
1993
1994 --clean up using backup array. this procedure is necessary because clearing the monitor all the time (manually or with mon.clear()) creates too much lag with big screens
1995 --this is a clever way to increase performance
1996 writeToLog("Cleaning up monitors. (screen "..screenID..")",2)
1997 for y=1,screens[screenID]["sizeY"] do
1998 local str = ""
1999 local currX = nil
2000 for x=1,screens[screenID]["sizeX"] do
2001 if previousMatrix[x..":"..y]~=nil then
2002 if currX==nil then
2003 currX = x
2004 end
2005 str = str .." "
2006 else
2007 if str~="" then
2008 drawOnMonitors(currX,y,screens[screenID]["defaultTextColor"],screens[screenID]["defaultBGColor"],str,monitorList)
2009 end
2010 str = ""
2011 currX = nil
2012 end
2013 end
2014 if str~="" then
2015 drawOnMonitors(currX,y,screens[screenID]["defaultTextColor"],screens[screenID]["defaultBGColor"],str,monitorList)
2016 end
2017 end
2018 writeToLog("Done cleaning up monitors. (screen "..screenID..")",2)
2019
2020 if designerRefresh then
2021 screens[screenID]["sizeX"] = designerSmaxX
2022 screens[screenID]["sizeY"] = designerSmaxY
2023 end
2024 end
2025 end
2026 writeToLog("Done refreshing all monitors. Took "..(os.clock()-startTime).."seconds.",2)
2027end
2028
2029function clearMonitor(monID)
2030 local data = monitors[monID]
2031 if data["screen"]~=nil then
2032 local screenID = data["screen"]
2033 local offsetX = data["offsetX"]
2034 local offsetY = data["offsetY"]
2035 local textScale = data["textScale"]
2036 screens[screenID]["pixelMatrix"] = {}
2037 --check sizes
2038 monitors[monID]["peripheral"].setBackgroundColor(colors.black)
2039 monitors[monID]["peripheral"].clear()
2040 monX,monY = monitors[monID]["peripheral"].getSize()
2041 monitors[monID]["peripheral"].setTextScale(textScale)
2042 if (screens[screenID]["sizeX"] + offsetX)>monX or (screens[screenID]["sizeY"] + offsetY)>monY then
2043 writeToLog("Screen "..screenID.." cannot be displayed completely with given offset and textScale.",3)
2044 end
2045 monitors[monID]["peripheral"].setBackgroundColor(screens[screenID]["defaultBGColor"])
2046 --custom clear
2047 writeToLog("Clearing monitor "..monID.."...",1)
2048 local s = ""
2049 for i=1,screens[screenID]["sizeX"] do
2050 s = s.." "
2051 end
2052 for i=1,screens[screenID]["sizeY"] do
2053 monitors[monID]["peripheral"].setCursorPos(offsetX+1,offsetY+i)
2054 monitors[monID]["peripheral"].write(s)
2055 end
2056 writeToLog("Done clearing monitor "..monID..".",2)
2057 end
2058end
2059
2060function clearMonitors()
2061 for monID,data in pairs(monitors) do
2062 clearMonitor(monID)
2063 end
2064end
2065
2066function clearTerminal()
2067 if terminalScreen~=nil then
2068 local screenID = terminalScreen
2069 screens[screenID]["pixelMatrix"] = {}
2070 --check sizes
2071 sizeX,sizeY = term.getSize()
2072 if (screens[screenID]["sizeX"])>sizeX or (screens[screenID]["sizeY"])>sizeY then
2073 writeToLog("Screen "..screenID.." cannot be displayed completely on terminal.",3)
2074 end
2075 term.setBackgroundColor(colors.black)
2076 term.clear()
2077 term.setBackgroundColor(screens[screenID]["defaultBGColor"])
2078 --custom clear
2079 writeToLog("Clearing terminal.",1)
2080 local s = ""
2081 for i=1,screens[screenID]["sizeX"] do
2082 s = s.." "
2083 end
2084 for i=1,screens[screenID]["sizeY"] do
2085 term.setCursorPos(1,i)
2086 term.write(s)
2087 end
2088 writeToLog("Done clearing terminal.",2)
2089 end
2090end
2091
2092function run(nRefreshRate)
2093 writeToLog("Starting program, clearing all monitors...")
2094 clearMonitors()
2095 clearTerminal()
2096 writeToLog("Done clearing all monitors.")
2097
2098 refresh()
2099 if nRefreshRate~=nil then
2100 refreshRate = nRefreshRate
2101 refreshTimerID = os.startTimer(refreshRate)
2102 writeToLog("Starting refresh timer with refreshRate "..refreshRate.." seconds.",1)
2103 end
2104 local running = true
2105 while running do
2106 event,var1,var2,var3,var4,var5 = os.pullEventRaw()
2107 writeToLog("Caught "..event.." event.",2)
2108 if event=="timer" then
2109 processTimerEvent(var1)
2110 end
2111 if event=="monitor_resize" then
2112 fullRefresh()
2113 end
2114 if event=="mouse_click" then
2115 if var1==1 then
2116 processClickEvent(terminalID,var2,var3)
2117 end
2118 end
2119 if event=="monitor_touch" then
2120 processClickEvent(var1,var2,var3)
2121 end
2122 if event=="mouse_drag" then
2123 processDragEvent(var2,var3)
2124 end
2125 if event=="mouse_scroll" then
2126 processScrollEvent(var1,var2,var3)
2127 end
2128 if shell~=nil then
2129 if event=="key" then
2130 if var1==59 then
2131 F1Held = true
2132 end
2133 end
2134 if event=="key_up" then
2135 if var1==59 then
2136 F1Held = false
2137 end
2138 end
2139 if event=="key" then
2140 if var1==29 then
2141 CTRLHeld = true
2142 end
2143 end
2144 if event=="key_up" then
2145 if var1==29 then
2146 CTRLHeld = false
2147 end
2148 end
2149 end
2150 if event=="terminate" then
2151 writeToLog("User terminated. Exiting.",2)
2152 logFile.writeLine("")
2153 logFile.flush()
2154 for sMonitor,data in pairs(monitors) do
2155 data["peripheral"].setBackgroundColor(colors.black)
2156 data["peripheral"].clear()
2157 end
2158 term.setBackgroundColor(colors.black)
2159 term.setTextColor(colors.white)
2160 term.clear()
2161 term.setCursorPos(1,1)
2162 running = false
2163 end
2164 if event=="easygui_interrupt" then
2165 running = false
2166 end
2167 if processEventFunc~=nil then
2168 success,msg = pcall(processEventFunc,event,var1,var2,var3,var4,var5)
2169 if success then
2170 writeToLog("Successfully called processEventFunc.",2)
2171 else
2172 writeToLog("There was an error calling processEventFunc. Msg: "..msg)
2173 end
2174 end
2175 end
2176end
2177
2178function processScrollEvent(direction,x,y)
2179 if terminalScreen~=nil then
2180 local s = x..":"..y
2181 local screenID = terminalScreen
2182
2183 local data = screens[screenID]["pixelMatrix"][s]
2184 if data~=nil then
2185 local elementType = data["elementType"]
2186 local ID = data["elementID"]
2187 local part = data["part"]
2188
2189 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] and (part=="expandButton" or part=="BG" or part=="text") and not dropDownMenus[ID]["expanded"] then
2190 if direction==-1 then
2191 if dropDownMenus[ID]["selectionID"]~=1 then
2192 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of scroll event.",2)
2193 dropDownMenus[ID]["selectionID"] = dropDownMenus[ID]["selectionID"]-1
2194 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2195 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2196 if success then
2197 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2198 else
2199 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2200 end
2201 end
2202 refresh()
2203 end
2204 else
2205 if dropDownMenus[ID]["selectionID"]~=table.getn(dropDownMenus[ID]["entries"]) then
2206 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of scroll event.",2)
2207 dropDownMenus[ID]["selectionID"] = dropDownMenus[ID]["selectionID"]+1
2208 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2209 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2210 if success then
2211 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2212 else
2213 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2214 end
2215 end
2216 refresh()
2217 end
2218 end
2219 end
2220
2221 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] and dropDownMenus[ID]["expanded"] and (string.match(part,"entry") or string.match(part,"scroll")) then
2222 if dropDownMenus[ID]["scrollPositionIndex"]~=nil then
2223 if direction==-1 then
2224 if dropDownMenus[ID]["scrollPositionIndex"]~=1 then
2225 writeToLog("Scrolled up dropDownMenu "..ID.." because of scroll event.",2)
2226 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]-1
2227 refresh()
2228 end
2229 else
2230 if dropDownMenus[ID]["scrollPositionIndex"]~=table.getn(dropDownMenus[ID]["entries"])-dropDownMenus[ID]["spaceY"]+1 then
2231 writeToLog("Scrolled down dropDownMenu "..ID.." because of scroll event.",2)
2232 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]+1
2233 refresh()
2234 end
2235 end
2236 end
2237 end
2238
2239 if elementType=="slider" and sliders[ID]["enabled"] and string.match(part,"bar") then
2240 if direction==1 then
2241 if sliders[ID]["value"]~=sliders[ID]["length"] then
2242 sliders[ID]["value"] = sliders[ID]["value"] + 1
2243 writeToLog("Incremented value of slider "..ID.." because of scroll event.",2)
2244 if sliders[ID]["onChangeFunction"]~=nil then
2245 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2246 if success then
2247 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2248 else
2249 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2250 end
2251 end
2252 refresh()
2253 end
2254 else
2255 if sliders[ID]["value"]~=1 then
2256 sliders[ID]["value"] = sliders[ID]["value"] - 1
2257 writeToLog("Decremented value of slider "..ID.." because of scroll event.",2)
2258 if sliders[ID]["onChangeFunction"]~=nil then
2259 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2260 if success then
2261 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2262 else
2263 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2264 end
2265 end
2266 refresh()
2267 end
2268 end
2269 end
2270 end
2271 end
2272end
2273
2274function processDragEvent(x,y)
2275 if terminalScreen~=nil then
2276 local s = x..":"..y
2277 local screenID = terminalScreen
2278
2279 local data = screens[screenID]["pixelMatrix"][s]
2280 if data~=nil then
2281 local elementType = data["elementType"]
2282 local ID = data["elementID"]
2283 local part = data["part"]
2284
2285 if elementType=="slider" and sliders[ID]["enabled"] and string.match(part,"bar") then
2286 processClickEvent(terminalID,x,y)
2287 end
2288 end
2289 end
2290end
2291
2292function processTimerEvent(timerID)
2293 writeToLog("Processing timerEvent with ID "..timerID.."...",2)
2294 if timerID==refreshTimerID then
2295 if refreshFunction~=nil then
2296 success,msg = pcall(refreshFunction)
2297 if success then
2298 writeToLog("Successfully called refresh function.",1)
2299 else
2300 writeToLog("There was an error calling the refresh function. Error message: "..msg,4)
2301 end
2302 end
2303 refresh()
2304 writeToLog("Restarting refresh timer.",2)
2305 refreshTimerID = os.startTimer(refreshRate)
2306 end
2307
2308 for name,data in pairs(dynamicTextBoxes) do
2309 if data["timerID"]==timerID then
2310 writeToLog("Processing timer of dynamicTextBox "..name..".",1)
2311 dynamicTextBoxes[name]["active"] = false
2312 dynamicTextBoxes[name]["timerID"] = nil
2313 if dynamicTextBoxes[name]["onInactiveFunction"]~=nil then
2314 success,msg = pcall(dynamicTextBoxes[name]["onInactiveFunction"],name,dynamicTextBoxes[name]["active"])
2315 if success then
2316 writeToLog("Successfully called onInactiveFunction of dynamicTextBox "..name..".",1)
2317 else
2318 writeToLog("There was an error calling the onInactiveFunction of dynamicTextBox "..name..". Error message: "..msg,4)
2319 end
2320 end
2321 refresh()
2322 end
2323 end
2324
2325 writeToLog("Done processing timerEvent with ID "..timerID..".",2)
2326end
2327
2328function processClickEvent(monitorName,x,y)
2329 writeToLog("Processing click event.",2)
2330 local monID
2331 for name,data in pairs(monitors) do
2332 if monitorName==data["networkID"] then
2333 monID = name
2334 break
2335 end
2336 if monitorName==data["side"] and data["networkID"]=="NONE" then
2337 monID = name
2338 break
2339 end
2340 end
2341 if (monitorName==terminalID and terminalScreen~=nil) or (monitors[monID]~=nil and monitors[monID]["screen"]~=nil) then
2342 local s = nil
2343 local screenID = nil
2344 if monitorName==terminalID then
2345 s = x..":"..y
2346 screenID = terminalScreen
2347 else
2348 s = x-monitors[monID]["offsetX"]..":"..y-monitors[monID]["offsetY"]
2349 screenID = monitors[monID]["screen"]
2350 end
2351
2352 local data = screens[screenID]["pixelMatrix"][s]
2353 if data~=nil then
2354 local elementType = data["elementType"]
2355 local ID = data["elementID"]
2356 local part = data["part"]
2357
2358 if shell~=nil and F1Held then
2359 if help[ID]~=nil then
2360 changeProperty(helpSBorderID,"content",help[ID])
2361 setScreenToRenderOnTerminal(helpSID)
2362 fullRefresh()
2363 end
2364 else
2365 --button
2366 if elementType=="dynamicTextBox" and dynamicTextBoxes[ID]["enabled"] and dynamicTextBoxes[ID]["onClickMode"]=="toggle" then
2367 dynamicTextBoxes[ID]["active"] = not dynamicTextBoxes[ID]["active"]
2368 writeToLog("Changed status of dynamicTextBox "..ID.."because of click event.",2)
2369 if dynamicTextBoxes[ID]["active"] then
2370 if dynamicTextBoxes[ID]["onActiveFunction"]~=nil then
2371 success,msg = pcall(dynamicTextBoxes[ID]["onActiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2372 if success then
2373 writeToLog("Successfully called onActiveFunction of dynamicTextBox "..ID..".",1)
2374 else
2375 writeToLog("There was an error calling the onActiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2376 end
2377 end
2378 end
2379 if not dynamicTextBoxes[ID]["active"] then
2380 if dynamicTextBoxes[ID]["onInactiveFunction"]~=nil then
2381 success,msg = pcall(dynamicTextBoxes[ID]["onInactiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2382 if success then
2383 writeToLog("Successfully called onInactiveFunction of dynamicTextBox "..ID..".",1)
2384 else
2385 writeToLog("There was an error calling the onInactiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2386 end
2387 end
2388 end
2389 refresh()
2390 end
2391 if elementType=="dynamicTextBox" and dynamicTextBoxes[ID]["enabled"] and dynamicTextBoxes[ID]["onClickMode"]=="flash" and not dynamicTextBoxes[ID]["active"] then
2392 dynamicTextBoxes[ID]["active"] = true
2393 writeToLog("Changed status of dynamicTextBox "..ID.."because of click event.",2)
2394 if dynamicTextBoxes[ID]["onActiveFunction"]~=nil then
2395 success,msg = pcall(dynamicTextBoxes[ID]["onActiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2396 if success then
2397 writeToLog("Successfully called onActiveFunction of dynamicTextBox "..ID..".",1)
2398 else
2399 writeToLog("There was an error calling the onActiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2400 end
2401 end
2402 refresh()
2403 if dynamicTextBoxes[ID]["activeDuration"]~=nil then
2404 writeToLog("Starting timer of dynamicTextBox "..ID..".",1)
2405 dynamicTextBoxes[ID]["timerID"] = os.startTimer(dynamicTextBoxes[ID]["activeDuration"])
2406 else
2407 writeToLog("Even though mode of dynamicTextBox "..ID.." is 'flash', activeDuration is not defined!",2)
2408 dynamicTextBoxes[ID]["timerID"] = os.startTimer(0)
2409 end
2410 end
2411
2412 --slider
2413 if elementType=="slider" and sliders[ID]["enabled"] then
2414 if part=="incrementButton" then
2415 if sliders[ID]["value"]~=sliders[ID]["length"] then
2416 sliders[ID]["value"] = sliders[ID]["value"] + 1
2417 writeToLog("Incremented value of slider "..ID.." because of click event.",2)
2418 if sliders[ID]["onChangeFunction"]~=nil then
2419 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2420 if success then
2421 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2422 else
2423 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2424 end
2425 end
2426 refresh()
2427 end
2428 end
2429 if part=="decrementButton" then
2430 if sliders[ID]["value"]~=1 then
2431 sliders[ID]["value"] = sliders[ID]["value"] - 1
2432 writeToLog("Decremented value of slider "..ID.." because of click event.",2)
2433 if sliders[ID]["onChangeFunction"]~=nil then
2434 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2435 if success then
2436 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2437 else
2438 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2439 end
2440 end
2441 refresh()
2442 end
2443 end
2444 if string.match(part,"bar") then
2445 local index = tonumber(string.sub(part,5))
2446 if index~=sliders[ID]["value"] then
2447 sliders[ID]["value"] = index
2448 writeToLog("Changed value of slider "..ID.." because of click event.",2)
2449 if sliders[ID]["onChangeFunction"]~=nil then
2450 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2451 if success then
2452 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2453 else
2454 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2455 end
2456 end
2457 refresh()
2458 end
2459 end
2460 end
2461
2462 --dropdownmenus
2463 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] then
2464 if part=="collapseButton" then
2465 dropDownMenus[ID]["expanded"] = false
2466 dropDownMenus[ID]["scrollPositionIndex"] = nil
2467 dropDownMenus[ID]["highlightID"] = nil
2468 writeToLog("Collapsed dropDownMenu "..ID.." because of click event.",2)
2469 if dropDownMenus[ID]["onCollapseFunction"]~=nil then
2470 success,msg = pcall(dropDownMenus[ID]["onCollapseFunction"],ID,dropDownMenus[ID]["expanded"])
2471 if success then
2472 writeToLog("Successfully called onCollapseFunction of dropDownMenu "..ID..".",1)
2473 else
2474 writeToLog("There was an error calling the onCollapseFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2475 end
2476 end
2477 refresh()
2478 end
2479 if (part=="expandButton" or part=="BG" or part=="text") and not dropDownMenus[ID]["expanded"] then
2480 dropDownMenus[ID]["expanded"] = true
2481 writeToLog("Expanded dropDownMenu "..ID.." because of click event.",2)
2482 if dropDownMenus[ID]["onExpandFunction"]~=nil then
2483 success,msg = pcall(dropDownMenus[ID]["onExpandFunction"],ID,dropDownMenus[ID]["expanded"])
2484 if success then
2485 writeToLog("Successfully called onExpandFunction of dropDownMenu "..ID..".",1)
2486 else
2487 writeToLog("There was an error calling the onExpandFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2488 end
2489 end
2490 refresh()
2491 end
2492 if part=="scrollUpButton" then
2493 if dropDownMenus[ID]["scrollPositionIndex"]~=1 then
2494 writeToLog("Scrolled up dropDownMenu "..ID.." because of click event.",2)
2495 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]-1
2496 refresh()
2497 end
2498 end
2499 if part=="scrollDownButton" then
2500 if dropDownMenus[ID]["scrollPositionIndex"]~=table.getn(dropDownMenus[ID]["entries"])-dropDownMenus[ID]["spaceY"]+1 then
2501 writeToLog("Scrolled down dropDownMenu "..ID.." because of click event.",2)
2502 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]+1
2503 refresh()
2504 end
2505 end
2506 if string.match(part,"entry") then
2507 local index = tonumber(string.sub(part,7))
2508 if index==dropDownMenus[ID]["highlightID"] then
2509 dropDownMenus[ID]["selectionID"] = index
2510 dropDownMenus[ID]["highlightID"] = nil
2511 dropDownMenus[ID]["scrollPositionIndex"] = nil
2512 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of click event.",2)
2513 dropDownMenus[ID]["expanded"] = false
2514 writeToLog("Collapsed dropDownMenu "..ID.." because of selection.",2)
2515 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2516 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2517 if success then
2518 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2519 else
2520 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2521 end
2522 end
2523
2524 if dropDownMenus[ID]["onCollapseFunction"]~=nil then
2525 success,msg = pcall(dropDownMenus[ID]["onCollapseFunction"],ID,dropDownMenus[ID]["expanded"])
2526 if success then
2527 writeToLog("Successfully called onCollapseFunction of dropDownMenu "..ID..".",1)
2528 else
2529 writeToLog("There was an error calling the onCollapseFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2530 end
2531 end
2532 refresh()
2533 else
2534 if dropDownMenus[ID]["highlightID"]~=index then
2535 dropDownMenus[ID]["highlightID"] = index
2536 writeToLog("Changed highlightID of dropDownMenu "..ID.." because of click event.",2)
2537 refresh()
2538 end
2539 end
2540 end
2541 end
2542
2543 --navMenus
2544 if elementType=="navigationMenu" and navigationMenus[ID]["enabled"] then
2545 if string.match(part,"title") then
2546 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2547 navigationMenus[ID]["highlightIDs"] = nil
2548 writeToLog("Expanded navMenu "..ID.." because of click event.",2)
2549 refresh()
2550 end
2551 if string.match(part,"entry") then
2552 local s = string.sub(part,7)
2553 local level = string.sub(s,1,string.find(s,":")-1)
2554 local entry = string.sub(s,string.find(s,":")+1)
2555 if tonumber(level)==1 then
2556 if navigationMenus[ID]["menuArray"][tonumber(entry)]["submenu"]~=nil then
2557 navigationMenus[ID]["highlightIDs"] = {tonumber(entry)}
2558 local i = 1
2559 while navigationMenus[ID]["highlightIDs"][tonumber(level)+i]~=nil do
2560 navigationMenus[ID]["highlightIDs"][tonumber(level)+i] = nil
2561 i = i + 1
2562 end
2563 writeToLog("Opened submenu on level 2 for navMenu "..ID..".",2)
2564 else
2565 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2566 writeToLog("Collapsed navMenu "..ID.." because of click event.",2)
2567 navigationMenus[ID]["highlightIDs"] = {tonumber(entry)}
2568 if navigationMenus[ID]["onChangeFunction"]~=nil then
2569 success,msg = pcall(navigationMenus[ID]["onChangeFunction"],ID,navigationMenus[ID]["highlightIDs"])
2570 if success then
2571 writeToLog("Successfully called onChangeFunction of navMenu "..ID..".",1)
2572 else
2573 writeToLog("There was an error calling onChangeFunction of navMenu "..ID..". Error message: "..msg,4)
2574 end
2575 end
2576 navigationMenus[ID]["highlightIDs"] = nil
2577 end
2578 else
2579 array = navigationMenus[ID]["menuArray"]
2580
2581 for i=1,tonumber(level)-1 do
2582 array = array[navigationMenus[ID]["highlightIDs"][i]]["submenu"]
2583 end
2584
2585 if array[tonumber(entry)]["submenu"]~=nil then
2586 navigationMenus[ID]["highlightIDs"][tonumber(level)] = tonumber(entry)
2587 local i = 1
2588 while navigationMenus[ID]["highlightIDs"][tonumber(level)+i]~=nil do
2589 navigationMenus[ID]["highlightIDs"][tonumber(level)+i] = nil
2590 i = i + 1
2591 end
2592 writeToLog("Opened submenu on level "..(tonumber(level)+1).." for navMenu "..ID..".",2)
2593 else
2594 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2595 writeToLog("Collapsed navMenu "..ID.." because of click event.",2)
2596 navigationMenus[ID]["highlightIDs"][tonumber(level)] = tonumber(entry)
2597 if navigationMenus[ID]["onChangeFunction"]~=nil then
2598 success,msg = pcall(navigationMenus[ID]["onChangeFunction"],ID,navigationMenus[ID]["highlightIDs"])
2599 if success then
2600 writeToLog("Successfully called onChangeFunction of navMenu "..ID..".",1)
2601 else
2602 writeToLog("There was an error calling onChangeFunction of navMenu "..ID..". Error message: "..msg,4)
2603 end
2604 end
2605 navigationMenus[ID]["highlightIDs"] = nil
2606 end
2607 end
2608 refresh()
2609 end
2610 end
2611
2612 --colorpicker
2613 if elementType=="colorPicker" and colorPickers[ID]["enabled"] then
2614 if part~="border" then
2615 if colorPickers[ID]["selection"]~=part then
2616 colorPickers[ID]["selection"] = part
2617 writeToLog("Changed selection of colorPicker "..ID.." because of clickEvent.",2)
2618 refresh()
2619 if colorPickers[ID]["onChangeFunction"]~=nil then
2620 success,msg = pcall(colorPickers[ID]["onChangeFunction"],ID,colorPickers[ID]["selection"])
2621 if success then
2622 writeToLog("Successfully called onChangeFunction of colorPicker "..ID..".",1)
2623 else
2624 writeToLog("There was an error calling onChangeFunction of colorPicker "..ID..". Error message: "..msg,4)
2625 end
2626 end
2627 end
2628 end
2629 end
2630
2631 if processClickEventFunc~=nil then
2632 success,msg = pcall(processClickEventFunc,elementType,ID,part)
2633 if success then
2634 writeToLog("Successfully called processClickEventFunction.",1)
2635 else
2636 writeToLog("There was an error calling the processClickEventFunction. Error message: "..msg,4)
2637 end
2638 end
2639 end
2640 end
2641 end
2642 writeToLog("Done processing click event.",2)
2643end
2644
2645--function to change any property from any element
2646function changeProperty(ID, propName, propValue)
2647 if elements[getType(ID)]~=nil then
2648 if elements[getType(ID)][ID]~=nil then
2649 elements[getType(ID)][ID][propName] = propValue
2650 writeToLog("Changed property of element "..ID..".",2)
2651 else
2652 writeToLog("Could not change property of element "..ID..". Element was not found. ",3)
2653 end
2654 end
2655end
2656
2657--function to get any property from any element
2658function getProperty(ID, propName)
2659 if elements[getType(ID)]~=nil then
2660 if elements[getType(ID)][ID]~=nil then
2661 return elements[getType(ID)][ID][propName]
2662 end
2663 end
2664end
2665
2666function getType(elementID)
2667 for name,data in pairs(dynamicTextBoxes) do
2668 if elementID==name then
2669 return "dynTextBox"
2670 end
2671 end
2672
2673 for name,data in pairs(sliders) do
2674 if elementID==name then
2675 return "slider"
2676 end
2677 end
2678
2679 for name,data in pairs(dropDownMenus) do
2680 if elementID==name then
2681 return "dropDownMenu"
2682 end
2683 end
2684
2685 for name,data in pairs(navigationMenus) do
2686 if elementID==name then
2687 return "navMenu"
2688 end
2689 end
2690
2691 for name,data in pairs(colorPickers) do
2692 if elementID==name then
2693 return "colorPicker"
2694 end
2695 end
2696
2697 for name,data in pairs(progressBars) do
2698 if elementID==name then
2699 return "progressBar"
2700 end
2701 end
2702
2703 for name,data in pairs(coordinateSystems) do
2704 if elementID==name then
2705 return "coordsSystem"
2706 end
2707 end
2708
2709 for name,data in pairs(pictures) do
2710 if elementID==name then
2711 return "picture"
2712 end
2713 end
2714
2715 return ""
2716end
2717
2718--DynamicTextBoxes from here
2719--DynamicTextBoxes all properties: width, height, content, variables, textColor, textAlignmentHorizontal, textAlignmentVertical, BGColor, borderColor, onActiveFunction, onInactiveFunction, onClickMode, activeDuration, activeContent, activeTextColor, activeBGColor, activeBorderColor, borderThickness, active, timerID, visible, enabled
2720function addDynamicTextBox(id, content)
2721 if trackID(id) then
2722 dynamicTextBoxes[id] = {}
2723 dynamicTextBoxes[id]["content"] = content
2724 dynamicTextBoxes[id]["visible"] = true
2725 dynamicTextBoxes[id]["enabled"] = true
2726 writeToLog("Added dynamicTextBox "..id..".",2)
2727 else
2728 writeToLog("Did not add dynamicTextBox because of ID conflict.",3)
2729 end
2730end
2731
2732--internal function used to draw a dynamic text box on a monitor
2733function writeDynamicTextBoxToPixelMatrix(screenID,dynamicTextBoxID,x,y)
2734 local data = dynamicTextBoxes[dynamicTextBoxID]
2735
2736 local content
2737 local textLines = {}
2738 local nTextLines
2739 local textColor
2740 local BGColor
2741 local borderColor
2742 local borderThickness
2743 local textAlignmentHorizontal
2744 local textAlignmentVertical
2745
2746 --standard value for horizontal alignment is center
2747 if data["textAlignmentHorizontal"]~=nil then
2748 textAlignmentHorizontal = data["textAlignmentHorizontal"]
2749 else
2750 textAlignmentHorizontal = "center"
2751 end
2752
2753 --standard value for vertical alignment is center
2754 if data["textAlignmentVertical"]~=nil then
2755 textAlignmentVertical = data["textAlignmentVertical"]
2756 else
2757 textAlignmentVertical = "center"
2758 end
2759
2760 --if no borderThickness is specified, assign the variable a zero value
2761 if data["borderThickness"]~=nil then
2762 borderThickness = data["borderThickness"]
2763 else
2764 borderThickness = 0
2765 end
2766
2767 --take care of all of the colors
2768 --if the button is active, colors might be different
2769 if data["active"] then
2770 if data["activeContent"]~=nil then
2771 content = data["activeContent"]
2772 else
2773 content = data["content"]
2774 end
2775 if data["activeTextColor"]~=nil then
2776 textColor = data["activeTextColor"]
2777 else
2778 textColor = data["textColor"]
2779 end
2780 if data["activeBGColor"]~=nil then
2781 BGColor = data["activeBGColor"]
2782 else
2783 BGColor = data["BGColor"]
2784 end
2785 if data["activeBorderColor"]~=nil then
2786 borderColor = data["activeBorderColor"]
2787 else
2788 borderColor = data["borderColor"]
2789 end
2790 else
2791 content = data["content"]
2792 textColor = data["textColor"]
2793 BGColor = data["BGColor"]
2794 borderColor = data["borderColor"]
2795 end
2796
2797 --if no colors are specified, use default colors of the corresponding screen
2798 if BGColor==nil then
2799 BGColor = screens[screenID]["defaultBGColor"]
2800 end
2801 if textColor==nil then
2802 textColor = screens[screenID]["defaultTextColor"]
2803 end
2804
2805 --if no bordercolor is specified, use the background color
2806 if borderColor==nil then
2807 borderColor = BGColor
2808 end
2809
2810 --replace variable placeholder with values
2811 if data["variables"]~=nil then
2812 for name, variableData in pairs(data["variables"]) do
2813 if data["variables"][name]~=nil then
2814 if type(data["variables"][name])=="function" then
2815 success,text = pcall(data["variables"][name],dynamicTextBoxID,name)
2816 if success then
2817 content = string.gsub(content,"$"..name,text)
2818 else
2819 writeToLog("There was an error retrieving variable "..name.." for dynamicTextBox "..dynamicTextBoxID..". Error message: "..text,4)
2820 end
2821 else if type(data["variables"][name])=="string" or type(data["variables"][name])=="number" then
2822 content = string.gsub(content,"$"..name,data["variables"][name])
2823 end end
2824 end
2825 end
2826 end
2827
2828 local maxX
2829 local maxY
2830
2831 if data["width"]~=nil then
2832 --if a width is specified the following variable is the maxX value
2833 maxX = x + data["width"] - 1
2834 --check if the content fits in one line with the specified width
2835 if string.len(content)<=(data["width"] - borderThickness*2) then
2836 textLines[1] = content
2837 nTextLines = 1
2838 end
2839 --if it does not fit, text will be split down below
2840 else
2841 --check if it fits in one line, assuming maxX is the monitors sizeX
2842 if string.len(content)<=(screens[screenID]["sizeX"]-x+1-(borderThickness*2)) then
2843 textLines[1] = content
2844 nTextLines = 1
2845 maxX = x + string.len(content) + borderThickness*2 - 1
2846 else
2847 --if it does not fit, text will be split down below
2848 maxX = screens[screenID]["sizeX"]
2849 end
2850 end
2851
2852 --variable used to determine the space for text on the dynamicTextBox
2853 local spaceX = maxX - x + 1 - borderThickness*2
2854
2855 --split text into lines
2856 if nTextLines~=1 then
2857 local words = {}
2858 --find spaces in the content string and use string.sub accordingly to create a list of words only
2859 local index = string.find(content," ")
2860 if index~=nil then
2861 repeat
2862 --insert the word into the table
2863 table.insert(words,string.sub(content,1,index-1))
2864 --remove the content that is already dealt with
2865 content = string.sub(content,index+1)
2866 index = string.find(content," ")
2867 until index==nil
2868 table.insert(words,content)
2869 else
2870 --in this case the content is one word alone
2871 table.insert(words,content)
2872 end
2873
2874 --create lines out of the words
2875 local sBuffer = ""
2876 for i,word in ipairs(words) do
2877 --the line is complete under three conditions: buffer not empty, current word added would be too long, current word is not longer than spaceX
2878 --it is also complete when it has the same length as spaceX or one less (space at the end) and the buffer is not empty
2879 --if the current word is longer than spaceX anyway, it can start in the current line and break subsequently
2880 if sBuffer~="" and ((string.len(sBuffer.." "..word)>spaceX and string.len(word)<=spaceX) or string.len(sBuffer)>=spaceX-1) then
2881 table.insert(textLines,sBuffer)
2882 sBuffer = ""
2883 end
2884
2885 --split down too long words
2886 while string.len(word)>spaceX do
2887 if sBuffer == "" then
2888 --if the buffer is empty, simply insert the first 'spaceX' letters of the word
2889 table.insert(textLines,string.sub(word,1,spaceX))
2890 word = string.sub(word,spaceX+1)
2891 sBuffer = ""
2892 else
2893 --otherwise, add as many letters as still fit in the line (spaceX-lengthOfBuffer-space)
2894 table.insert(textLines,sBuffer.." "..string.sub(word,1,spaceX-string.len(sBuffer)-1))
2895 word = string.sub(word,spaceX-string.len(sBuffer)-1+1)
2896 sBuffer = ""
2897 end
2898 end
2899
2900 --add the word to the buffer accordingly
2901 if sBuffer=="" then
2902 sBuffer = word
2903 else
2904 sBuffer = sBuffer.." "..word
2905 end
2906 end
2907
2908 --there can be one bit left at the end if it was a too long word
2909 if sBuffer~="" then
2910 table.insert(textLines,sBuffer)
2911 end
2912
2913 nTextLines = table.getn(textLines)
2914 end
2915
2916 if data["height"]~=nil then
2917 --if a height is specified, calculate maxY in the following variable
2918 maxY = y + data["height"] - 1
2919 --check if the lines fit with the given height
2920 if nTextLines>(data["height"] - borderThickness*2) then
2921 --in this case they don't, therefore use as many lines as there is space
2922 nTextLines = data["height"] - borderThickness*2
2923 end
2924 else
2925 --no height is specified therefore calculate maxY with as many lines as needed
2926 maxY = y + nTextLines + borderThickness*2 - 1
2927 --check if maxY is now bigger than the actual monitor's maxY
2928 if maxY>screens[screenID]["sizeY"] then
2929 --in this case it is bigger therefore maxY needs to be adjusted as well as the number of textLines
2930 maxY = screens[screenID]["sizeY"]
2931 nTextLines = maxY - y + 1 - borderThickness*2
2932 end
2933 end
2934
2935 --calculate the space for the text in y direction to be used later on
2936 local spaceY = maxY - y + 1 - borderThickness*2
2937
2938 --start drawing
2939 --border
2940 for currentOffset=0,borderThickness-1 do
2941 --this draws two horizontal lines
2942 for currentX=(x+currentOffset),(maxX-currentOffset) do
2943 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2944 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2945 end
2946
2947 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
2948 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
2949 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2950 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2951 end
2952 end
2953
2954 --draw the BGColor, offset by the borderThickness
2955 for currentX=(x+borderThickness),(maxX-borderThickness) do
2956 for currentY=(y+borderThickness),(maxY-borderThickness) do
2957 writeToPixelMatrix(screenID," ",currentX,currentY,textColor,BGColor,dynamicTextBoxID,"dynamicTextBox","BG")
2958 end
2959 end
2960
2961 --draw the text
2962 --calculate vertical offset
2963 local startOffsetY
2964 if textAlignmentVertical=="center" then
2965 --if vertical alignment is center, calculate the corresponding offset
2966 startOffsetY = math.floor((spaceY-nTextLines)/2)
2967 else
2968 if textAlignmentVertical=="top" then
2969 --no offset for top alignment
2970 startOffsetY = 0
2971 else
2972 if textAlignmentVertical=="bottom" then
2973 --calculate offsetY if alignment is bottom
2974 startOffsetY = spaceY - nTextLines
2975 end
2976 end
2977 end
2978
2979 local startOffsetX = {}
2980 --deal with horizontal alignment, calculate an offset for each line
2981 if textAlignmentHorizontal=="right" then
2982 for i,line in ipairs(textLines) do
2983 --calculate number for right alignment
2984 startOffsetX[i] = spaceX-string.len(line)
2985 end
2986 else
2987 if textAlignmentHorizontal=="center" then
2988 for i,line in ipairs(textLines) do
2989 --calculate number for center horizontal alignment
2990 startOffsetX[i] = math.floor((spaceX-string.len(line))/2)
2991 end
2992 else
2993 for i,line in ipairs(textLines) do
2994 --no offset needed for left alignment
2995 startOffsetX[i] = 0
2996 end
2997 end
2998 end
2999
3000 --write text, offset by borderThickness
3001 for i=1,nTextLines do
3002 writeToPixelMatrix(screenID,textLines[i],x+borderThickness+startOffsetX[i],y+borderThickness+startOffsetY+i-1,textColor,BGColor,dynamicTextBoxID,"dynamicTextBox","text")
3003 end
3004end
3005
3006--Sliders from here
3007--Sliders all properties: length, value, broadness, orientation, pixelsPerUnit, color, colorsArray, textPosition, textMargin, BGColor, borderColor, onChangeFunction, borderThickness, visible, enabled, mode, changeButtons
3008function addSlider(id,length, value)
3009 if trackID(id) then
3010 sliders[id] = {}
3011 sliders[id]["length"] = length
3012 sliders[id]["value"] = value
3013 sliders[id]["visible"] = true
3014 sliders[id]["enabled"] = true
3015 writeToLog("Added slider "..id..".",2)
3016 else
3017 writeToLog("Did not add slider because of ID conflict.",3)
3018 end
3019end
3020
3021--function which draws a slider in the pixel matrix
3022function writeSliderToPixelMatrix(screenID,sliderID,x,y)
3023 local data = sliders[sliderID]
3024
3025 local length = data["length"]
3026 local value = math.floor(tonumber(data["value"]))
3027 local broadness
3028 local orientation
3029 local pixelsPerUnit
3030 local color
3031 local colorsArray
3032 local textPosition = data["textPosition"]
3033 local textMargin
3034 local BGColor
3035 local borderColor
3036 local borderThickness
3037 local mode
3038 local changeButtons
3039
3040 --take care of all variable defaults
3041 if data["broadness"]~=nil then
3042 broadness = data["broadness"]
3043 else
3044 broadness = 1
3045 end
3046
3047 if data["orientation"]~=nil then
3048 orientation = data["orientation"]
3049 else
3050 orientation = "left-right"
3051 end
3052
3053 if data["pixelsPerUnit"]~=nil then
3054 pixelsPerUnit = data["pixelsPerUnit"]
3055 else
3056 pixelsPerUnit = 1
3057 end
3058
3059 if data["color"]~=nil then
3060 color = data["color"]
3061 else
3062 color = screens[screenID]["defaultTextColor"]
3063 end
3064
3065 if data["colorsArray"]~=nil then
3066 if data["colorsArray"][value]~=nil then
3067 color = data["colorsArray"][value]
3068 end
3069 end
3070
3071 if data["textMargin"]~=nil then
3072 textMargin = data["textMargin"]
3073 else
3074 textMargin = 0
3075 end
3076
3077 if data["BGColor"]~=nil then
3078 BGColor = data["BGColor"]
3079 else
3080 BGColor = screens[screenID]["defaultBGColor"]
3081 end
3082
3083 if data["borderColor"]~=nil then
3084 borderColor = data["borderColor"]
3085 else
3086 borderColor = BGColor
3087 end
3088
3089 if data["borderThickness"]~=nil then
3090 borderThickness = data["borderThickness"]
3091 else
3092 borderThickness = 0
3093 end
3094
3095 if data["mode"]~=nil then
3096 mode = data["mode"]
3097 else
3098 mode = "fill"
3099 end
3100
3101 changeButtons = data["changeButtons"]
3102
3103 local maxX
3104 local maxY
3105
3106 --calculate maxX and maxY based on the orientation of slider
3107 if orientation=="left-right" or orientation=="right-left" then
3108 maxX = x + borderThickness*2 + length*pixelsPerUnit - 1
3109 maxY = y + borderThickness*2 + broadness - 1
3110 else
3111 maxX = x + borderThickness*2 + broadness - 1
3112 maxY = y + borderThickness*2 + length*pixelsPerUnit - 1
3113 end
3114
3115 --start drawing
3116 --border
3117 for currentOffset=0,borderThickness-1 do
3118 --this draws two horizontal lines
3119 for currentX=(x+currentOffset),(maxX-currentOffset) do
3120 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,color,borderColor,sliderID,"slider","border")
3121 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,color,borderColor,sliderID,"slider","border")
3122 end
3123
3124 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3125 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3126 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,color,borderColor,sliderID,"slider","border")
3127 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,color,borderColor,sliderID,"slider","border")
3128 end
3129 end
3130
3131 --draw bar case horizontal
3132 if orientation=="left-right" or orientation=="right-left" then
3133 --this makes things easier
3134 local s = ""
3135 for i=1,pixelsPerUnit do
3136 s = s.." "
3137 end
3138 --loop for x coordinate (length)
3139 for i=1,length do
3140 --change color according to slider value
3141 --check mode
3142 local currentColor
3143 if mode=="fill" then
3144 if i<=value then
3145 currentColor = color
3146 else
3147 currentColor = BGColor
3148 end
3149 end
3150 if mode=="value" then
3151 if i==value then
3152 currentColor = color
3153 else
3154 currentColor = BGColor
3155 end
3156 end
3157 --loop for y coordinate (broadness)
3158 for currentY=y+borderThickness,maxY-borderThickness do
3159 --take pixelsPerUnit into account for calculations
3160 if orientation=="left-right" then
3161 writeToPixelMatrix(screenID,s,x+borderThickness+(i-1)*pixelsPerUnit,currentY,currentColor,currentColor,sliderID,"slider","bar:"..i)
3162 end
3163 if orientation=="right-left" then
3164 writeToPixelMatrix(screenID,s,maxX-borderThickness-pixelsPerUnit+1-(i-1)*pixelsPerUnit,currentY,currentColor,currentColor,sliderID,"slider","bar:"..i)
3165 end
3166 end
3167 end
3168 else
3169 --this makes things easier
3170 local s = ""
3171 for i=1,broadness do
3172 s = s.." "
3173 end
3174 --draw bar case vertical
3175 --loop for y coordinate (length)
3176 for i=1,length do
3177 local currentColor
3178 if mode=="fill" then
3179 if i<=value then
3180 currentColor = color
3181 else
3182 currentColor = BGColor
3183 end
3184 end
3185 if mode=="value" then
3186 if i==value then
3187 currentColor = color
3188 else
3189 currentColor = BGColor
3190 end
3191 end
3192 --loop for x coordinate (broadness)
3193 for j=1,pixelsPerUnit do
3194 if orientation=="top-bottom" then
3195 writeToPixelMatrix(screenID,s,x+borderThickness,y+borderThickness+(i-1)*pixelsPerUnit+j-1,currentColor,currentColor,sliderID,"slider","bar:"..i)
3196 end
3197 if orientation=="bottom-top" then
3198 writeToPixelMatrix(screenID,s,x+borderThickness,maxY-borderThickness-pixelsPerUnit+1-(i-1)*pixelsPerUnit+j-1,currentColor,currentColor,sliderID,"slider","bar:"..i)
3199 end
3200 end
3201 end
3202 end
3203
3204 --this fixes rounding issue
3205 value = tostring(value)
3206 --draw text
3207 if textPosition~=nil then
3208 --calculations to center the text
3209 if textPosition=="right" then
3210 writeToPixelMatrix(screenID,value,maxX+1+textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3211 end
3212 if textPosition=="left" then
3213 writeToPixelMatrix(screenID,value,x-string.len(value)-textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3214 end
3215 if textPosition=="top" then
3216 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),y-1-textMargin,color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3217 end
3218 if textPosition=="bottom" then
3219 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),maxY+1+textMargin,color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3220 end
3221 end
3222
3223 --if defined, draws an increment and decrement button according to slider orientation
3224 if changeButtons~=nil then
3225 if orientation=="left-right" then
3226 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),maxX+1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3227 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x-1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3228 end
3229 if orientation=="right-left" then
3230 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),maxX+1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3231 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x-1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3232 end
3233 if orientation=="bottom-top" then
3234 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x+math.floor((maxX-x+1-1)/2),y-1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3235 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x+math.floor((maxX-x+1-1)/2),maxY+1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3236 end
3237 if orientation=="top-bottom" then
3238 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x+math.floor((maxX-x+1-1)/2),y-1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3239 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x+math.floor((maxX-x+1-1)/2),maxY+1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3240 end
3241 end
3242end
3243
3244--Dropdownmenus from here
3245--All properties: entries,width,expandedMaxHeight, textColor, BGColor, borderColor, onChangeFunction, onExpandFunction, onCollapseFunction, highlightTextColor, highlightBGColor, borderThickness, expanded, visible, enabled,selectionID,scrollPositionIndex,highlightID,buttonsColor,buttonsBGColor
3246function addDropDownMenu(id,entries,selectionID)
3247 if trackID(id) then
3248 dropDownMenus[id] = {}
3249 dropDownMenus[id]["entries"] = entries
3250 dropDownMenus[id]["selectionID"] = selectionID
3251 dropDownMenus[id]["visible"] = true
3252 dropDownMenus[id]["enabled"] = true
3253 dropDownMenus[id]["expanded"] = false
3254 writeToLog("Added dropDownMenu "..id..".",2)
3255 else
3256 writeToLog("Did not add dropDownMenu because of ID conflict.",3)
3257 end
3258end
3259
3260function writeDropDownMenuToPixelMatrix(screenID,dropDownMenuID,x,y)
3261 local data = dropDownMenus[dropDownMenuID]
3262
3263 local entries = data["entries"]
3264 local selectionID = data["selectionID"]
3265 local expanded = data["expanded"]
3266 local width
3267 local textColor
3268 local BGColor
3269 local borderColor
3270 local borderThickness
3271 local highlightTextColor
3272 local highlightBGColor
3273 local highlightID = data["highlightID"]
3274 local scrollPositionIndex = data["scrollPositionIndex"]
3275 local buttonsColor
3276 local buttonsBGColor
3277
3278 --take care of the colors and set other default values
3279 if data["textColor"]~=nil then
3280 textColor = data["textColor"]
3281 else
3282 textColor = screens[screenID]["defaultTextColor"]
3283 end
3284
3285 if data["BGColor"]~=nil then
3286 BGColor = data["BGColor"]
3287 else
3288 BGColor = screens[screenID]["defaultBGColor"]
3289 end
3290
3291 if data["borderColor"]~=nil then
3292 borderColor = data["borderColor"]
3293 else
3294 borderColor = BGColor
3295 end
3296
3297 if data["borderThickness"]~=nil then
3298 borderThickness = data["borderThickness"]
3299 else
3300 borderThickness = 0
3301 end
3302
3303 if data["highlightTextColor"]~=nil then
3304 highlightTextColor = data["highlightTextColor"]
3305 else
3306 highlightTextColor = textColor
3307 end
3308
3309 if data["highlightBGColor"]~=nil then
3310 highlightBGColor = data["highlightBGColor"]
3311 else
3312 highlightBGColor = BGColor
3313 end
3314
3315 if data["buttonsColor"]~=nil then
3316 buttonsColor = data["buttonsColor"]
3317 else
3318 buttonsColor = textColor
3319 end
3320
3321 if data["buttonsBGColor"]~=nil then
3322 buttonsBGColor = data["buttonsBGColor"]
3323 else
3324 buttonsBGColor = BGColor
3325 end
3326
3327 --calculate greatestTextLength to later define a width if its not specified
3328 local greatestTextLength = 0
3329 for name,entry in pairs(entries) do
3330 if string.len(entry)>greatestTextLength then
3331 greatestTextLength = string.len(entry)
3332 end
3333 end
3334
3335 --fill this array with entries and manipulate later
3336 local shortenedEntries = {}
3337 for i,entry in ipairs(entries) do
3338 shortenedEntries[i] = entry
3339 end
3340 local nEntries = table.getn(entries)
3341 if data["width"]~=nil then
3342 width = data["width"]
3343 --two pixel space: one for v and one for a space (or space + scrollbar)
3344 if greatestTextLength>width-borderThickness*2-2 then
3345 --shorten entries if necessary
3346 for i,entry in ipairs(entries) do
3347 shortenedEntries[i] = string.sub(entry,1,width-borderThickness*2-2)
3348 end
3349 end
3350 else
3351 if greatestTextLength>screens[screenID]["sizeX"]-x-borderThickness*2+1-2 then
3352 --shorten entries if necessary
3353 for i,entry in ipairs(entries) do
3354 shortenedEntries[i] = string.sub(entry,1,screens[screenID]["sizeX"]-x-borderThickness*2+1-2)
3355 end
3356 width = screens[screenID]["sizeX"]-x+1
3357 else
3358 --as wide as it needs
3359 width = borderThickness*2+greatestTextLength + 2
3360 end
3361 end
3362
3363 local maxX = x + width - 1
3364
3365 --draw collapsed menu
3366 if not expanded then
3367 local maxY = y + borderThickness*2
3368 --start drawing
3369 --border
3370 for currentOffset=0,borderThickness-1 do
3371 --this draws two horizontal lines
3372 for currentX=(x+currentOffset),(maxX-currentOffset) do
3373 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3374 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3375 end
3376
3377 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3378 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3379 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3380 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3381 end
3382 end
3383
3384 --draw the BGColor, offset by the borderThickness
3385 for currentX=(x+borderThickness),(maxX-borderThickness) do
3386 writeToPixelMatrix(screenID," ",currentX,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","BG")
3387 end
3388
3389 --draw text
3390 writeToPixelMatrix(screenID,shortenedEntries[selectionID],x+borderThickness,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","text")
3391
3392 --draw v (expandbutton)
3393 writeToPixelMatrix(screenID,"v",maxX-borderThickness,y+borderThickness,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","expandButton")
3394 else
3395 --determine if a scrollbar is necessary
3396 local scrollBar
3397 local maxY
3398 if highlightID ==nil then
3399 highlightID = selectionID
3400 end
3401 dropDownMenus[dropDownMenuID]["highlightID"] = highlightID
3402 if data["expandedMaxHeight"]~=nil then
3403 local expandedMaxHeight = data["expandedMaxHeight"]
3404 --check if all entries fit with the given height
3405 if borderThickness*2 + 1 + nEntries > expandedMaxHeight then
3406 maxY = y+expandedMaxHeight-1
3407 scrollBar = true
3408 else
3409 --as wide as it needs
3410 maxY = y + borderThickness*2 + 1 + nEntries -1
3411 scrollBar = false
3412 end
3413 else
3414 --with no specified height, check if the full list would be greater than screen size
3415 if y + borderThickness*2 +1 + nEntries - 1>screens[screenID]["sizeY"] then
3416 maxY = screens[screenID]["sizeY"]
3417 scrollBar = true
3418 else
3419 maxY = y + borderThickness*2 + 1 + nEntries - 1
3420 scrollBar = false
3421 end
3422 end
3423
3424 --draw the BGColor, offset by the borderThickness
3425 for currentX=(x+borderThickness),(maxX-borderThickness) do
3426 writeToPixelMatrix(screenID," ",currentX,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","BG")
3427 end
3428
3429 --draw text
3430 writeToPixelMatrix(screenID,shortenedEntries[selectionID],x+borderThickness,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","text")
3431
3432 --draw v
3433 writeToPixelMatrix(screenID,"v",maxX-borderThickness,y+borderThickness,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","collapseButton")
3434
3435 --draw list without scrollbar
3436 if not scrollBar then
3437 --entries need to be spaced in order to fill the whole line
3438 local spacedEntries = {}
3439 for i,entry in ipairs(shortenedEntries) do
3440 local s = ""
3441 for j=1,width-borderThickness*2-string.len(entry) do
3442 s = s.." "
3443 end
3444 spacedEntries[i] = entry..s
3445 end
3446 for i,entry in ipairs(spacedEntries) do
3447 --change color accordingly
3448 local currentTextColor
3449 local currentBGColor
3450 if i==highlightID then
3451 currentTextColor = highlightTextColor
3452 currentBGColor = highlightBGColor
3453 else
3454 currentTextColor = textColor
3455 currentBGColor = BGColor
3456 end
3457 writeToPixelMatrix(screenID,entry,x+borderThickness,y+borderThickness+i,currentTextColor,currentBGColor,dropDownMenuID,"dropDownMenu","entry:"..i)
3458 end
3459 else
3460 local spacedEntries = {}
3461 for i,entry in ipairs(shortenedEntries) do
3462 local s = ""
3463 --this time -1 because of scrollbar
3464 for j=1,width-borderThickness*2-string.len(entry)-1 do
3465 s = s.." "
3466 end
3467 spacedEntries[i] = entry..s
3468 end
3469 local spaceY = maxY-y+1-borderThickness*2-1
3470 dropDownMenus[dropDownMenuID]["spaceY"] = spaceY
3471 --set scrollposition if menu was just opened
3472 if scrollPositionIndex==nil then
3473 --make sure not to overrun
3474 if selectionID>nEntries-spaceY then
3475 scrollPositionIndex = nEntries-spaceY+1
3476 else
3477 scrollPositionIndex = selectionID
3478 end
3479
3480 --set for next time
3481 dropDownMenus[dropDownMenuID]["scrollPositionIndex"] = scrollPositionIndex
3482 end
3483
3484 for i=1,spaceY do
3485 local currentTextColor
3486 local currentBGColor
3487 if i+scrollPositionIndex-1==highlightID then
3488 currentTextColor = highlightTextColor
3489 currentBGColor = highlightBGColor
3490 else
3491 currentTextColor = textColor
3492 currentBGColor = BGColor
3493 end
3494
3495 --this is a workaround for a very special case where one dropDownMenu is displayed on different screens with different space
3496 if spacedEntries[i+scrollPositionIndex-1]==nil then
3497 maxY = y+borderThickness+i
3498 break
3499 else
3500 writeToPixelMatrix(screenID,spacedEntries[i+scrollPositionIndex-1],x+borderThickness,y+borderThickness+i,currentTextColor,currentBGColor,dropDownMenuID,"dropDownMenu","entry:"..i+scrollPositionIndex-1)
3501 end
3502 end
3503
3504 --draw scrollbar buttons and bg
3505 local scrollBarX = maxX-1
3506 for currentY=y+borderThickness+1,maxY-1 do
3507 if currentY==y+borderThickness+1 then
3508 writeToPixelMatrix(screenID,"^",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollUpButton")
3509 else if currentY==maxY-1 then
3510 writeToPixelMatrix(screenID,"v",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollDownButton")
3511 else
3512 writeToPixelMatrix(screenID," ",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollBarBG")
3513 end
3514 end
3515 end
3516 end
3517
3518 --draw border
3519 for currentOffset=0,borderThickness-1 do
3520 --this draws two horizontal lines
3521 for currentX=(x+currentOffset),(maxX-currentOffset) do
3522 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3523 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3524 end
3525
3526 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3527 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3528 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3529 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3530 end
3531 end
3532 end
3533end
3534
3535--navMenus from here
3536-- all props: title,menuArray (text, submenu),titleTextColor,titleBGColor,titleTextColorExpanded,titleBGColorExpanded,textAlignmentHorizontal,textAlignmentVertical,entryWidth,entryHeight,entryTextColor,entryBGColor,borderColor,spaceBetweenEntries,borderThickness,highlightTextColor,highlightBGColor,expanded,highlightIDs,onChangeFunction,enabled,visible
3537function addNavigationMenu(id,title,menuArray)
3538 if trackID(id) then
3539 navigationMenus[id] = {}
3540 navigationMenus[id]["title"] = title
3541 navigationMenus[id]["menuArray"] = menuArray
3542 navigationMenus[id]["visible"] = true
3543 navigationMenus[id]["enabled"] = true
3544 navigationMenus[id]["expanded"] = false
3545 navigationMenus[id]["highlightIDs"] = nil
3546 writeToLog("Added navMenu "..id..".",2)
3547 else
3548 writeToLog("Did not add navMenu because of ID conflict.",3)
3549 end
3550end
3551
3552function writeNavigationMenuToPixelMatrix(screenID,navigationMenuID,x,y)
3553 local data = navigationMenus[navigationMenuID]
3554
3555 local title = data["title"]
3556 local menuArray = data["menuArray"]
3557 local expanded = data["expanded"]
3558 local entryWidth = data["entryWidth"]
3559 local entryHeight
3560 local titleTextColor
3561 local titleBGColor
3562 local titleTextColorExpanded
3563 local titleBGColorExpanded
3564 local entryTextColor
3565 local entryBGColor
3566 local borderColor
3567 local borderThickness
3568 local spaceBetweenEntries
3569 local highlightIDs = data["highlightIDs"]
3570 local highlightTextColor
3571 local highlightBGColor
3572 local expanded = data["expanded"]
3573 local textAlignmentHorizontal
3574 local textAlignmentVertical
3575
3576 --take care of the colors and set other default values
3577 if data["entryTextColor"]~=nil then
3578 entryTextColor = data["entryTextColor"]
3579 else
3580 entryTextColor = screens[screenID]["defaultTextColor"]
3581 end
3582
3583 if data["entryBGColor"]~=nil then
3584 entryBGColor = data["entryBGColor"]
3585 else
3586 entryBGColor = screens[screenID]["defaultBGColor"]
3587 end
3588
3589 if data["titleTextColor"]~=nil then
3590 titleTextColor = data["titleTextColor"]
3591 else
3592 titleTextColor = screens[screenID]["defaultTextColor"]
3593 end
3594
3595 if data["titleBGColor"]~=nil then
3596 titleBGColor = data["titleBGColor"]
3597 else
3598 titleBGColor = screens[screenID]["defaultBGColor"]
3599 end
3600
3601 if data["titleTextColorExpanded"]~=nil then
3602 titleTextColorExpanded = data["titleTextColorExpanded"]
3603 else
3604 titleTextColorExpanded = titleTextColor
3605 end
3606
3607 if data["titleBGColorExpanded"]~=nil then
3608 titleBGColorExpanded = data["titleBGColorExpanded"]
3609 else
3610 titleBGColorExpanded = titleBGColor
3611 end
3612
3613 if data["borderColor"]~=nil then
3614 borderColor = data["borderColor"]
3615 else
3616 borderColor = screens[screenID]["defaultBGColor"]
3617 end
3618
3619 if data["borderThickness"]~=nil then
3620 borderThickness = data["borderThickness"]
3621 else
3622 borderThickness = 0
3623 end
3624
3625 if data["spaceBetweenEntries"]~=nil then
3626 spaceBetweenEntries = data["spaceBetweenEntries"]
3627 else
3628 spaceBetweenEntries = 0
3629 end
3630
3631 if data["highlightTextColor"]~=nil then
3632 highlightTextColor = data["highlightTextColor"]
3633 else
3634 highlightTextColor = entryTextColor
3635 end
3636
3637 if data["highlightBGColor"]~=nil then
3638 highlightBGColor = data["highlightBGColor"]
3639 else
3640 highlightBGColor = entryBGColor
3641 end
3642
3643 if data["entryHeight"]~=nil then
3644 entryHeight = data["entryHeight"]
3645 else
3646 entryHeight = 1
3647 end
3648
3649 --standard value for horizontal alignment is center
3650 if data["textAlignmentHorizontal"]~=nil then
3651 textAlignmentHorizontal = data["textAlignmentHorizontal"]
3652 else
3653 textAlignmentHorizontal = "center"
3654 end
3655
3656 --standard value for vertical alignment is center
3657 if data["textAlignmentVertical"]~=nil then
3658 textAlignmentVertical = data["textAlignmentVertical"]
3659 else
3660 textAlignmentVertical = "center"
3661 end
3662
3663 local greatestRootTextLength = string.len(title)
3664 local rootEntryCount = 0
3665 for name,entry in pairs(menuArray) do
3666 rootEntryCount = rootEntryCount + 1
3667 if string.len(entry["text"])>greatestRootTextLength then
3668 greatestRootTextLength = string.len(entry["text"])
3669 end
3670 end
3671
3672 --fill this array with entries and manipulate later
3673 local nRootEntries = 0
3674 local shortenedEntries = {}
3675 for i,entry in ipairs(menuArray) do
3676 nRootEntries = nRootEntries + 1
3677 shortenedEntries[i] = entry
3678 end
3679
3680 local rootMaxX
3681 if entryWidth~=nil then
3682 rootMaxX = x+borderThickness*2+entryWidth-1
3683 --shorten text
3684 if greatestRootTextLength>entryWidth then
3685 title = string.sub(title,1,entryWidth)
3686 for i,entry in ipairs(shortenedEntries) do
3687 shortenedEntries[i]["text"] = string.sub(entry["text"],1,entryWidth)
3688 end
3689 end
3690 else
3691 rootMaxX = x+borderThickness*2+greatestRootTextLength-1
3692 entryWidth = greatestRootTextLength
3693 end
3694
3695 local currentTextColor
3696 local currentBGColor
3697
3698 if expanded then
3699 currentTextColor = titleTextColorExpanded
3700 currentBGColor = titleBGColorExpanded
3701 else
3702 currentTextColor = titleTextColor
3703 currentBGColor = titleBGColor
3704 end
3705
3706 --titleBG
3707 for currentX=(x+borderThickness),(rootMaxX-borderThickness) do
3708 for currentY=(y+borderThickness),(y+borderThickness+entryHeight-1) do
3709 writeToPixelMatrix(screenID," ",currentX,currentY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","titleBG")
3710 end
3711 end
3712
3713 local rootMaxY
3714 if not expanded then
3715 rootMaxY = y+borderThickness*2+entryHeight-1
3716 else
3717 rootMaxY = y+borderThickness*2+entryHeight+((entryHeight+spaceBetweenEntries)*rootEntryCount)-1
3718 end
3719
3720 --draw border
3721 for currentOffset=0,borderThickness-1 do
3722 --this draws two horizontal lines
3723 for currentX=(x+currentOffset),(rootMaxX-currentOffset) do
3724 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3725 writeToPixelMatrix(screenID," ",currentX,rootMaxY-currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3726 end
3727
3728 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3729 for currentY=(y+currentOffset+1),(rootMaxY-currentOffset-1) do
3730 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3731 writeToPixelMatrix(screenID," ",rootMaxX-currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3732 end
3733 end
3734
3735 --calculate vertical offset
3736 local startOffsetY
3737 if textAlignmentVertical=="center" then
3738 --if vertical alignment is center, calculate the corresponding offset
3739 startOffsetY = math.floor((entryHeight-1)/2)
3740 else
3741 if textAlignmentVertical=="top" then
3742 --no offset for top alignment
3743 startOffsetY = 0
3744 else
3745 if textAlignmentVertical=="bottom" then
3746 --calculate offsetY if alignment is bottom
3747 startOffsetY = entryHeight - 1
3748 end
3749 end
3750 end
3751
3752 local startOffsetX = 0
3753 --deal with horizontal alignment, calculate an offset
3754 if textAlignmentHorizontal=="right" then
3755 startOffsetX = entryWidth-string.len(title)
3756 else
3757 if textAlignmentHorizontal=="center" then
3758 --calculate number for center horizontal alignment
3759 startOffsetX = math.floor((entryWidth-string.len(title))/2)
3760 end
3761 end
3762
3763 --write title text
3764 writeToPixelMatrix(screenID,title,x+borderThickness+startOffsetX,y+borderThickness+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","title")
3765
3766 local nextY
3767 if expanded then
3768 -- this makes things easier
3769 local s = ""
3770 for i=1,entryWidth do
3771 s = s.." "
3772 end
3773 --draw entries
3774 for i=1,nRootEntries do
3775 for j=0,spaceBetweenEntries-1 do
3776 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+((i-1)*(spaceBetweenEntries+entryHeight)),titleTextColor,borderColor,navigationMenuID,"navigationMenu","spaceBorder")
3777 end
3778 local currentTextColor = entryTextColor
3779 local currentBGColor = entryBGColor
3780 if highlightIDs~=nil then
3781 if highlightIDs[1]==i then
3782 currentTextColor = highlightTextColor
3783 currentBGColor = highlightBGColor
3784 --for next submenu
3785 nextY = y+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight))
3786 end
3787 end
3788 for j=0,entryHeight-1 do
3789 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight)),currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:1:"..i)
3790 end
3791 --calculate vertical offset
3792 local startOffsetY
3793 if textAlignmentVertical=="center" then
3794 --if vertical alignment is center, calculate the corresponding offset
3795 startOffsetY = math.floor((entryHeight-1)/2)
3796 else
3797 if textAlignmentVertical=="top" then
3798 --no offset for top alignment
3799 startOffsetY = 0
3800 else
3801 if textAlignmentVertical=="bottom" then
3802 --calculate offsetY if alignment is bottom
3803 startOffsetY = entryHeight - 1
3804 end
3805 end
3806 end
3807
3808 local startOffsetX = 0
3809 --deal with horizontal alignment, calculate an offset
3810 if textAlignmentHorizontal=="right" then
3811 startOffsetX = entryWidth-string.len(shortenedEntries[i]["text"])
3812 else
3813 if textAlignmentHorizontal=="center" then
3814 --calculate number for center horizontal alignment
3815 startOffsetX = math.floor((entryWidth-string.len(shortenedEntries[i]["text"]))/2)
3816 end
3817 end
3818
3819 --write title text
3820 writeToPixelMatrix(screenID,shortenedEntries[i]["text"],x+borderThickness+startOffsetX,y+borderThickness+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight))+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:1:"..i)
3821 end
3822
3823 --draw submenus
3824 if highlightIDs~=nil then
3825 --like this a lot of code is reused
3826 x = x + borderThickness + entryWidth
3827 y = nextY
3828 local subTable = menuArray[highlightIDs[1]]["submenu"]
3829 for k=1,table.getn(highlightIDs) do
3830 local greatestTextLength = 0
3831 local nEntries = 0
3832 for name,entry in pairs(subTable) do
3833 nEntries = nEntries + 1
3834 if string.len(entry["text"])>greatestTextLength then
3835 greatestTextLength = string.len(entry["text"])
3836 end
3837 end
3838
3839 --fill this array with entries and manipulate later
3840 local shortenedEntries = {}
3841 for i,entry in ipairs(subTable) do
3842 shortenedEntries[i] = entry
3843 end
3844
3845 entryWidth = data["entryWidth"]
3846 local maxX
3847 if entryWidth~=nil then
3848 maxX = x+borderThickness*2+entryWidth-1
3849 --shorten text
3850 if greatestTextLength>entryWidth then
3851 for i,entry in ipairs(shortenedEntries) do
3852 shortenedEntries[i]["text"] = string.sub(entry["text"],1,entryWidth)
3853 end
3854 end
3855 else
3856 maxX = x+borderThickness*2+greatestTextLength-1
3857 entryWidth = greatestTextLength
3858 end
3859
3860 -- this makes things easier
3861 local s = ""
3862 for i=1,entryWidth do
3863 s = s.." "
3864 end
3865
3866 local maxY = y + borderThickness*2 + (nEntries)*entryHeight + (nEntries-1)*spaceBetweenEntries - 1
3867
3868 --border
3869 for currentOffset=0,borderThickness-1 do
3870 --this draws two horizontal lines
3871 for currentX=(x+currentOffset),(maxX-currentOffset) do
3872 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3873 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3874 end
3875
3876 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3877 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3878 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3879 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3880 end
3881 end
3882
3883 for i=1,nEntries do
3884 if i~=nEntries then
3885 for j=0,spaceBetweenEntries-1 do
3886 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+((i-1)*(spaceBetweenEntries+entryHeight)),titleTextColor,borderColor,navigationMenuID,"navigationMenu","spaceBorder")
3887 end
3888 end
3889
3890 local currentTextColor = entryTextColor
3891 local currentBGColor = entryBGColor
3892 if highlightIDs[k+1]==i then
3893 currentTextColor = highlightTextColor
3894 currentBGColor = highlightBGColor
3895 nextY = y+((i-1)*(spaceBetweenEntries+entryHeight))
3896 end
3897 for j=0,entryHeight-1 do
3898 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+((i-1)*(spaceBetweenEntries+entryHeight)),currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:"..(k+1)..":"..i)
3899 end
3900 --calculate vertical offset
3901 local startOffsetY
3902 if textAlignmentVertical=="center" then
3903 --if vertical alignment is center, calculate the corresponding offset
3904 startOffsetY = math.floor((entryHeight-1)/2)
3905 else
3906 if textAlignmentVertical=="top" then
3907 --no offset for top alignment
3908 startOffsetY = 0
3909 else
3910 if textAlignmentVertical=="bottom" then
3911 --calculate offsetY if alignment is bottom
3912 startOffsetY = entryHeight - 1
3913 end
3914 end
3915 end
3916
3917 local startOffsetX = 0
3918 --deal with horizontal alignment, calculate an offset
3919 if textAlignmentHorizontal=="right" then
3920 startOffsetX = entryWidth-string.len(shortenedEntries[i]["text"])
3921 else
3922 if textAlignmentHorizontal=="center" then
3923 --calculate number for center horizontal alignment
3924 startOffsetX = math.floor((entryWidth-string.len(shortenedEntries[i]["text"]))/2)
3925 end
3926 end
3927
3928 --write title text
3929 writeToPixelMatrix(screenID,shortenedEntries[i]["text"],x+borderThickness+startOffsetX,y+borderThickness+((i-1)*(spaceBetweenEntries+entryHeight))+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:"..(k+1)..":"..i)
3930 end
3931
3932 if highlightIDs[k+1]~=nil then
3933 x = x + borderThickness + entryWidth
3934 y = nextY
3935 subTable = subTable[highlightIDs[k+1]]["submenu"]
3936 end
3937 end
3938 end
3939 end
3940end
3941
3942--colorPickers from here
3943--all props: selection,borderColor,borderThickness,colorWidth,colorHeight,selectionCharacter,onChangeFunction,visible,enabled
3944function addColorPicker(id,default)
3945 if trackID(id) then
3946 colorPickers[id] = {}
3947 colorPickers[id]["selection"] = default
3948 colorPickers[id]["visible"] = true
3949 colorPickers[id]["enabled"] = true
3950 writeToLog("Added colorPicker "..id..".",2)
3951 else
3952 writeToLog("Did not add colorPicker because of ID conflict.",3)
3953 end
3954end
3955
3956function writeColorPickerToPixelMatrix(screenID,colorPickerID,x,y)
3957 data = colorPickers[colorPickerID]
3958
3959 local selection = data["selection"]
3960 local colorWidth
3961 local colorHeight
3962 local borderColor
3963 local borderThickness
3964 local selectionCharacter
3965
3966 if data["colorWidth"]~=nil then
3967 colorWidth = data["colorWidth"]
3968 else
3969 colorWidth = 1
3970 end
3971
3972 if data["colorHeight"]~=nil then
3973 colorHeight = data["colorHeight"]
3974 else
3975 colorHeight = 1
3976 end
3977
3978 if data["borderColor"]~=nil then
3979 borderColor = data["borderColor"]
3980 else
3981 borderColor = screens[screenID]["defaultBGColor"]
3982 end
3983
3984 if data["borderThickness"]~=nil then
3985 borderThickness = data["borderThickness"]
3986 else
3987 borderThickness = 0
3988 end
3989
3990 if data["selectionCharacter"]~=nil then
3991 selectionCharacter = string.sub(data["selectionCharacter"],1,1)
3992 else
3993 selectionCharacter = "X"
3994 end
3995
3996 local maxX = x + borderThickness*2 + 4*colorWidth -1
3997 local maxY = y + borderThickness*2 + 4*colorHeight -1
3998
3999 --border
4000 for currentOffset=0,borderThickness-1 do
4001 --this draws two horizontal lines
4002 for currentX=(x+currentOffset),(maxX-currentOffset) do
4003 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,borderColor,borderColor,colorPickerID,"colorPicker","border")
4004 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,borderColor,borderColor,colorPickerID,"colorPicker","border")
4005 end
4006
4007 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
4008 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
4009 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,borderColor,borderColor,colorPickerID,"colorPicker","border")
4010 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,borderColor,borderColor,colorPickerID,"colorPicker","border")
4011 end
4012 end
4013
4014 for i=0,3 do
4015 for j=1,4 do
4016 local text = " "
4017 if selection==colorsArrayNumToNum[i*4+j] then
4018 text = selectionCharacter
4019 end
4020 local s = ""
4021 for h=1,colorWidth do
4022 s = s.. text
4023 end
4024
4025 for k=1,colorHeight do
4026 if selection==colors.black then
4027 writeToPixelMatrix(screenID,s,x+borderThickness+i*colorWidth,y+borderThickness+(j-1)*colorHeight+k-1,colors.white,colorsArrayNumToNum[i*4+j],colorPickerID,"colorPicker",colorsArrayNumToNum[i*4+j])
4028 else
4029 writeToPixelMatrix(screenID,s,x+borderThickness+i*colorWidth,y+borderThickness+(j-1)*colorHeight+k-1,colors.black,colorsArrayNumToNum[i*4+j],colorPickerID,"colorPicker",colorsArrayNumToNum[i*4+j])
4030 end
4031 end
4032 end
4033 end
4034end
4035
4036--Progressbars from here
4037-- all properties: length, value, valueType, broadness, orientation, textPosition, textMargin, color, colorsArray, BGColor, borderColor, borderThickness, visible
4038function addProgressBar(id,length)
4039 if trackID(id) then
4040 progressBars[id] = {}
4041 progressBars[id]["length"] = length
4042 progressBars[id]["visible"] = true
4043 writeToLog("Added progressBar "..id..".",2)
4044 else
4045 writeToLog("Did not add progressBar because of ID conflict.",3)
4046 end
4047end
4048
4049function writeProgressBarToPixelMatrix(screenID,progressBarID,x,y)
4050 data = progressBars[progressBarID]
4051
4052 local length = data["length"]
4053 local value = data["value"]
4054 local valueType
4055 local broadness
4056 local orientation
4057 local color
4058 local colorsArray
4059 local textPosition = data["textPosition"]
4060 local textMargin
4061 local BGColor
4062 local borderColor
4063 local borderThickness
4064
4065 --take care of all variable defaults
4066 if value==nil then
4067 value = 0
4068 end
4069
4070 if data["valueType"]~=nil then
4071 valueType = data["valueType"]
4072 else
4073 valueType = "absolute"
4074 end
4075
4076 local originalValue = value
4077 if valueType == "relative" then
4078 value = math.floor((length/100)*value)
4079 end
4080
4081 if data["broadness"]~=nil then
4082 broadness = data["broadness"]
4083 else
4084 broadness = 1
4085 end
4086
4087 if data["orientation"]~=nil then
4088 orientation = data["orientation"]
4089 else
4090 orientation = "left-right"
4091 end
4092
4093 if data["color"]~=nil then
4094 color = data["color"]
4095 else
4096 color = screens[screenID]["defaultTextColor"]
4097 end
4098
4099 if data["colorsArray"]~=nil then
4100 color = data["colorsArray"][value]
4101 end
4102
4103 if data["textMargin"]~=nil then
4104 textMargin = data["textMargin"]
4105 else
4106 textMargin = 0
4107 end
4108
4109 if data["BGColor"]~=nil then
4110 BGColor = data["BGColor"]
4111 else
4112 BGColor = screens[screenID]["defaultBGColor"]
4113 end
4114
4115 if data["borderColor"]~=nil then
4116 borderColor = data["borderColor"]
4117 else
4118 borderColor = color
4119 end
4120
4121 if data["borderThickness"]~=nil then
4122 borderThickness = data["borderThickness"]
4123 else
4124 borderThickness = 1
4125 end
4126
4127 local maxX
4128 local maxY
4129
4130 --calculate maxX and maxY based on the orientation of progressBar
4131 if orientation=="left-right" or orientation=="right-left" then
4132 maxX = x + borderThickness*2 + length - 1
4133 maxY = y + borderThickness*2 + broadness - 1
4134 else
4135 maxX = x + borderThickness*2 + broadness - 1
4136 maxY = y + borderThickness*2 + length - 1
4137 end
4138
4139 --start drawing
4140 --border
4141 for currentOffset=0,borderThickness-1 do
4142 --this draws two horizontal lines
4143 for currentX=(x+currentOffset),(maxX-currentOffset) do
4144 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,color,borderColor,progressBarID,"progressBar","border")
4145 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,color,borderColor,progressBarID,"progressBar","border")
4146 end
4147
4148 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
4149 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
4150 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,color,borderColor,progressBarID,"progressBar","border")
4151 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,color,borderColor,progressBarID,"progressBar","border")
4152 end
4153 end
4154
4155 --draw bar case horizontal
4156 if orientation=="left-right" or orientation=="right-left" then
4157 --this makes things easier
4158 local s = " "
4159
4160 --loop for x coordinate (length)
4161 for i=1,length do
4162 --change color according to slider value
4163 --check mode
4164 local currentColor
4165 if i<=value then
4166 currentColor = color
4167 else
4168 currentColor = BGColor
4169 end
4170 --loop for y coordinate (broadness)
4171 for currentY=y+borderThickness,maxY-borderThickness do
4172 --take pixelsPerUnit into account for calculations
4173 if orientation=="left-right" then
4174 writeToPixelMatrix(screenID,s,x+borderThickness+(i-1),currentY,currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4175 end
4176 if orientation=="right-left" then
4177 writeToPixelMatrix(screenID,s,maxX-borderThickness-(i-1),currentY,currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4178 end
4179 end
4180 end
4181 else
4182 --this makes things easier
4183 local s = ""
4184 for i=1,broadness do
4185 s = s.." "
4186 end
4187 --draw bar case vertical
4188 --loop for y coordinate (length)
4189 for i=1,length do
4190 local currentColor
4191 if i<=value then
4192 currentColor = color
4193 else
4194 currentColor = BGColor
4195 end
4196 if orientation=="top-bottom" then
4197 writeToPixelMatrix(screenID,s,x+borderThickness,y+borderThickness+(i-1),currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4198 end
4199 if orientation=="bottom-top" then
4200 writeToPixelMatrix(screenID,s,x+borderThickness,maxY-borderThickness-(i-1),currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4201 end
4202 end
4203 end
4204
4205 value = originalValue
4206 if valueType == "relative" then
4207 value = value .."%"
4208 end
4209 --draw text
4210 if textPosition~=nil then
4211 --calculations to center the text
4212 if textPosition=="right" then
4213 writeToPixelMatrix(screenID,value,maxX+1+textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4214 end
4215 if textPosition=="left" then
4216 writeToPixelMatrix(screenID,value,x-string.len(value)-textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4217 end
4218 if textPosition=="top" then
4219 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),y-1-textMargin,color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4220 end
4221 if textPosition=="bottom" then
4222 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),maxY+1+textMargin,color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4223 end
4224 end
4225end
4226
4227--coordinateSystems from here
4228-- all props: width,height,graphTables,graphDesigns(color,BGColor,character),unitsPerPixelX,unitsPerPixelY,axesColor,numbersColor,labelX,labelY,startX,startY,stepsX,stepsY
4229function addCoordinateSystem(id,width,height)
4230 if trackID(id) then
4231 coordinateSystems[id] = {}
4232 coordinateSystems[id]["width"] = width
4233 coordinateSystems[id]["height"] = height
4234 coordinateSystems[id]["visible"] = true
4235 writeToLog("Added coordinateSystem "..id..".",2)
4236 else
4237 writeToLog("Did not add coordinateSystem because of ID conflict.",3)
4238 end
4239end
4240
4241function writeCoordinateSystemToPixelMatrix(screenID,coordinateSystemID,x,y)
4242 data = coordinateSystems[coordinateSystemID]
4243
4244 local width = data["width"]
4245 local height = data["height"]
4246 local graphTables = data["graphTables"]
4247 local graphDesigns = data["graphDesigns"]
4248 local unitsPerPixelX
4249 local unitsPerPixelY
4250 local axesColor
4251 local numbersColor
4252 local labelX
4253 local labelY
4254 local startX
4255 local startY
4256 local numbersOffset
4257 local stepX = data["stepX"]
4258 local stepY
4259
4260 if data["stepY"]~=nil then
4261 stepY = data["stepY"]
4262 else
4263 stepY = 2
4264 end
4265
4266 if data["unitsPerPixelX"]~=nil then
4267 unitsPerPixelX = data["unitsPerPixelX"]
4268 else
4269 unitsPerPixelX = 1
4270 end
4271
4272 if data["unitsPerPixelY"]~=nil then
4273 unitsPerPixelY = data["unitsPerPixelY"]
4274 else
4275 unitsPerPixelY = 1
4276 end
4277
4278 if data["axesColor"]~=nil then
4279 axesColor = data["axesColor"]
4280 else
4281 axesColor = screens[screenID]["defaultTextColor"]
4282 end
4283
4284 if data["numbersColor"]~=nil then
4285 numbersColor = data["numbersColor"]
4286 else
4287 numbersColor = screens[screenID]["defaultTextColor"]
4288 end
4289
4290 if data["labelX"]~=nil then
4291 labelX = data["labelX"]
4292 else
4293 labelX = "X"
4294 end
4295
4296 if data["labelY"]~=nil then
4297 labelY = data["labelY"]
4298 else
4299 labelY = "Y"
4300 end
4301
4302 if data["startX"]~=nil then
4303 startX = data["startX"]
4304 else
4305 startX = 0
4306 end
4307
4308 if data["startY"]~=nil then
4309 startY = data["startY"]
4310 else
4311 startY = 0
4312 end
4313
4314 if data["numbersOffset"]~=nil then
4315 numbersOffset = data["numbersOffset"]
4316 else
4317 numbersOffset = 0
4318 end
4319
4320 --draw coordinateSystem
4321 --draw origin
4322 writeToPixelMatrix(screenID,"+",x,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisOrigin")
4323
4324 --draw start numbers around origin
4325 if startX == startY then
4326 writeToPixelMatrix(screenID,tostring(startX),x-string.len(startX)-numbersOffset,y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginXY")
4327 else
4328 writeToPixelMatrix(screenID,tostring(startX),x-math.floor(string.len(startX)/2),y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginX")
4329 writeToPixelMatrix(screenID,tostring(startY),x-string.len(startY)-numbersOffset,y,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginY")
4330 end
4331
4332 --draw axes
4333 for i=1,width-2 do
4334 writeToPixelMatrix(screenID,"-",x+i,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisX")
4335 end
4336 writeToPixelMatrix(screenID,">",x+width-1,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisXEnd")
4337
4338 for i=1,height-2 do
4339 writeToPixelMatrix(screenID,"|",x,y-i,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4340 end
4341 writeToPixelMatrix(screenID,"^",x,y-height+1,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4342
4343 --draw numbers
4344 if stepX==nil then
4345 local greatestTextLength = string.len(startX)
4346 if string.len(startX + (width-1)*unitsPerPixelX)>greatestTextLength then
4347 greatestTextLength = string.len(startX + (width-1)*unitsPerPixelX)
4348 end
4349 stepX = greatestTextLength + 1
4350 end
4351
4352 local currentX = x+stepX
4353 local currentValue = startX+(stepX*unitsPerPixelX)
4354 local maxX = x + width-1
4355 while currentX<maxX do
4356 writeToPixelMatrix(screenID,"+",currentX,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisX")
4357
4358 writeToPixelMatrix(screenID,tostring(currentValue),currentX-math.floor(string.len(currentValue)/2),y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numbersX")
4359
4360 currentX = currentX + stepX
4361 currentValue = currentValue + (stepX*unitsPerPixelX)
4362 end
4363
4364 local currentY = y-stepY
4365 local currentValue = startY+(stepY*unitsPerPixelY)
4366 local maxY = y - height+1
4367 while currentY>maxY do
4368 writeToPixelMatrix(screenID,"+",x,currentY,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4369
4370 writeToPixelMatrix(screenID,tostring(currentValue),x-numbersOffset-string.len(currentValue),currentY,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numbersY")
4371
4372 currentY = currentY - stepY
4373 currentValue = currentValue + (stepY*unitsPerPixelY)
4374 end
4375
4376 --draw labels
4377 writeToPixelMatrix(screenID,labelX,x+width-math.floor(string.len(labelX)/2)-1,y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","labelX")
4378 writeToPixelMatrix(screenID,labelY,x-string.len(labelY)-numbersOffset,y-height+1,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","labelY")
4379
4380 --draw graphs
4381 if graphTables~=nil then
4382 for i,graph in ipairs(graphTables) do
4383 local color = numbersColor
4384 local BGColor = screens[screenID]["defaultBGColor"]
4385 local character = "X"
4386 if graphDesigns~=nil then
4387 if graphDesigns[i]~=nil then
4388 if graphDesigns[i]["color"]~=nil then
4389 color = graphDesigns[i]["color"]
4390 end
4391 if graphDesigns[i]["BGColor"]~=nil then
4392 BGColor = graphDesigns[i]["BGColor"]
4393 end
4394 if graphDesigns[i]["character"]~=nil then
4395 character = graphDesigns[i]["character"]
4396 end
4397 end
4398 end
4399
4400 for currentX=x,maxX do
4401 if graph[((currentX-x)*unitsPerPixelX)+startX]~=nil then
4402 if y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5)>=y-height+1 and y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5)<=y then
4403 writeToPixelMatrix(screenID,character,currentX,y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5),color,BGColor,coordinateSystemID,"coordinateSystem","graph:"..i)
4404 end
4405 end
4406 end
4407 end
4408 end
4409end
4410
4411--pictures from here
4412-- all props: linesArray
4413function addPicture(id,width,height,linesArray)
4414 if trackID(id) then
4415 pictures[id] = {}
4416 pictures[id]["width"] = width
4417 pictures[id]["height"] = height
4418 pictures[id]["linesArray"] = linesArray
4419 pictures[id]["visible"] = true
4420 writeToLog("Added picture "..id..".",2)
4421 else
4422 writeToLog("Did not add picture because of ID conflict.",3)
4423 end
4424end
4425
4426function writePictureToPixelMatrix(screenID,pictureID,x,y)
4427 data = pictures[pictureID]
4428 colorsArrayStrToNum["*"]=screens[screenID]["defaultTextColor"]
4429 colorsArrayStrToNum["#"]=screens[screenID]["defaultBGColor"]
4430
4431 local linesArray = data["linesArray"]
4432 local width = data["width"]
4433 local height = data["height"]
4434
4435 for i=1,height do
4436 local j = 1
4437 local line = linesArray[i]
4438 local correct = true
4439 if line~=nil then
4440 while string.find(line,";")~=nil do
4441 local currentLetter = string.sub(line,1,string.find(line,";")-1)
4442 line = string.sub(line,string.find(line,";")+1)
4443
4444 if string.len(currentLetter)==5 and string.sub(currentLetter,2,2)==":" and string.sub(currentLetter,4,4)==":" then
4445 local textColor = string.sub(currentLetter,1,1)
4446 local BGColor = string.sub(currentLetter,3,3)
4447 local character = string.sub(currentLetter,5,5)
4448
4449 writeToPixelMatrix(screenID,character,x+j-1,y+i-1,colorsArrayStrToNum[textColor],colorsArrayStrToNum[BGColor],pictureID,"picture",j..":"..i)
4450 end
4451
4452 if string.len(currentLetter)==1 then
4453 writeToPixelMatrix(screenID," ",x+j-1,y+i-1,colorsArrayStrToNum[currentLetter],colorsArrayStrToNum[currentLetter],pictureID,"picture",j..":"..i)
4454 end
4455
4456 if j == width then correct = false break end
4457 j = j + 1
4458 end
4459 else
4460 linesArray[i] = ""
4461 end
4462 --correct mistakes
4463 if correct then
4464 for k=1,width-j+1 do
4465 linesArray[i] = linesArray[i].."#;"
4466 end
4467 end
4468 end
4469end
4470
4471--initalizing function searching for all monitors and adding them
4472function findMonitors()
4473 local nMonitorCount = 0
4474 monitors = {}
4475 writeToLog("Searching for monitors...",2)
4476 designerScreen = initMonsSID
4477 setScreenToRenderOnTerminal(initMonsSID)
4478 refresh()
4479 local sides = {"front","back","left","right","top","bottom"}
4480 --search for monitors and modems
4481 for i,side in ipairs(sides) do
4482 --check if there is a monitor
4483 if peripheral.isPresent(side) then
4484 if peripheral.getType(side)=="monitor" then
4485 --check if monitor is advanced
4486 if peripheral.call(side,"isColor") then
4487 -- initialize monitor
4488 monitor = peripheral.wrap(side)
4489 monitor.setBackgroundColor(colors.red)
4490 monitor.clear()
4491 changeProperty(initMonsSTextID,"content","Advanced monitor number "..(nMonitorCount+1).." was found on side "..side..". It has turned completely red for your identification. Please give this monitor a unique ID!")
4492
4493 writeToLog("Found monitor on side "..side..".",2)
4494 local sID
4495 local success = false
4496 repeat
4497 refresh()
4498 local x,y = term.getSize()
4499 term.setCursorPos(relX(20,initMonsSID)+2,y-1)
4500 term.setTextColor(colorPalette[1])
4501 term.write(">")
4502 sID = read()
4503 term.setCursorPos(relX(20,initMonsSID)+3,y-1)
4504 for i=1,string.len(sID) do
4505 term.write(" ")
4506 end
4507 if sID=="" then
4508 changeProperty(initMonsSErrorID,"content","Cannot be empty!")
4509 refresh()
4510 else
4511 if trackID(sID) then
4512 success = true
4513 else
4514 changeProperty(initMonsSErrorID,"content","ID already taken!")
4515 refresh()
4516 end
4517 end
4518 until success==true
4519 monitors[sID] = {}
4520 monitors[sID]["peripheral"] = monitor
4521 monitors[sID]["side"] = side
4522 monitors[sID]["networkID"] = "NONE"
4523 monitor.setBackgroundColor(colors.black)
4524 monitor.clear()
4525 nMonitorCount = nMonitorCount + 1
4526 writeToLog("Added monitor "..sID.." to the system.",2)
4527 changeProperty(initMonsSErrorID,"content","")
4528 end
4529 else
4530 --check monitors connected via modems
4531 if peripheral.getType(side)=="modem" then
4532 local modem = peripheral.wrap(side)
4533 if not modem.isWireless() then
4534 for i,sPeripheral in ipairs(modem.getNamesRemote()) do
4535 if string.match(sPeripheral,"monitor") then
4536 if modem.callRemote(sPeripheral,"isColor") then
4537 -- initialize monitor
4538 monitor = peripheral.wrap(sPeripheral)
4539 monitor.setBackgroundColor(colors.red)
4540 monitor.clear()
4541 changeProperty(initMonsSTextID,"content","Advanced monitor number "..(nMonitorCount+1).." was found via modem on side "..side..". It has turned red for your identification. Please give this monitor a unique ID!")
4542
4543 writeToLog("Found monitor on side "..side.." through modem.",2)
4544 local sID
4545 local success = false
4546 repeat
4547 refresh()
4548 local x,y = term.getSize()
4549 term.setCursorPos(relX(20,initMonsSID)+2,y-1)
4550 term.setTextColor(colorPalette[1])
4551 term.write(">")
4552 sID = read()
4553 term.setCursorPos(relX(20,initMonsSID)+3,y-1)
4554 for i=1,string.len(sID) do
4555 term.write(" ")
4556 end
4557 if sID=="" then
4558 changeProperty(initMonsSErrorID,"content","Cannot be empty!")
4559 refresh()
4560 else
4561 if trackID(sID) then
4562 success = true
4563 else
4564 changeProperty(initMonsSErrorID,"content","ID already taken!")
4565 refresh()
4566 end
4567 end
4568 until success==true
4569 monitors[sID] = {}
4570 monitors[sID]["peripheral"] = monitor
4571 monitors[sID]["side"] = side
4572 monitors[sID]["networkID"] = sPeripheral
4573 monitor.setBackgroundColor(colors.black)
4574 monitor.clear()
4575 nMonitorCount = nMonitorCount + 1
4576 writeToLog("Added monitor "..sID.." to the system.",2)
4577 changeProperty(initMonsSErrorID,"content","")
4578 end
4579 end
4580 end
4581 end
4582 end
4583 end
4584 end
4585 end
4586
4587 if nMonitorCount == 0 then
4588 writeToLog("Did not find any advanced monitors.",2)
4589 else
4590 writeToLog("Found "..nMonitorCount.." monitors.",2)
4591 end
4592end
4593
4594function setupStuff()
4595 local x,y = term.getSize()
4596 addScreen(initMonsSID,x,y,colorPalette[1],colorPalette[2])
4597 addDynamicTextBox(initMonsSLeftRectID,"")
4598 changeProperty(initMonsSLeftRectID,"width",relX(20,initMonsSID))
4599 changeProperty(initMonsSLeftRectID,"height",relY(100,initMonsSID))
4600 changeProperty(initMonsSLeftRectID,"BGColor",colorPalette[3])
4601 addElementToScreen(initMonsSLeftRectID,initMonsSID,1,1)
4602
4603 addDynamicTextBox(initMonsSHeadingID,"EasyGUI Monitor Initialization")
4604 changeProperty(initMonsSHeadingID,"width",relX(80,initMonsSID))
4605 changeProperty(initMonsSHeadingID,"borderThickness",1)
4606 addElementToScreen(initMonsSHeadingID,initMonsSID,relX(20,initMonsSID)+1,1)
4607
4608 addDynamicTextBox(initMonsSTextID,"Searching for monitors...")
4609 changeProperty(initMonsSTextID,"width",relX(80,initMonsSID))
4610 changeProperty(initMonsSTextID,"borderThickness",1)
4611 addElementToScreen(initMonsSTextID,initMonsSID,relX(20,initMonsSID)+1,relY(30,initMonsSID))
4612
4613 local picArray = {}
4614 for i=1,y do
4615 if (i%3)==1 then
4616 table.insert(picArray,"*;;;")
4617 end
4618 if (i%3)==2 then
4619 table.insert(picArray,";*;;")
4620 end
4621 if (i%3)==0 then
4622 table.insert(picArray,";;*;")
4623 end
4624 end
4625 addPicture(initMonsSPictureID,3,y,picArray)
4626 addElementToScreen(initMonsSPictureID,initMonsSID,relX(10,initMonsSID)-1,1)
4627
4628 addDynamicTextBox(initMonsSErrorID,"")
4629 changeProperty(initMonsSErrorID,"width",relX(80,initMonsSID))
4630 changeProperty(initMonsSErrorID,"textColor",colors.red)
4631 addElementToScreen(initMonsSErrorID,initMonsSID,relX(20,initMonsSID)+1,y)
4632
4633 addScreen(helpSID,x,y,colorPalette[1],colorPalette[3])
4634 addDynamicTextBox(helpSBorderID,"")
4635 changeProperty(helpSBorderID,"width",x-2)
4636 changeProperty(helpSBorderID,"height",y-2)
4637 changeProperty(helpSBorderID,"borderThickness",1)
4638 changeProperty(helpSBorderID,"textAlignmentHorizontal","left")
4639 changeProperty(helpSBorderID,"textAlignmentVertical","top")
4640 changeProperty(helpSBorderID,"BGColor",colorPalette[2])
4641 addElementToScreen(helpSBorderID,helpSID,2,2)
4642
4643 addDynamicTextBox(helpSOKID,"Okay")
4644 changeProperty(helpSOKID,"BGColor",colorPalette[1])
4645 changeProperty(helpSOKID,"textColor",colorPalette[2])
4646 changeProperty(helpSOKID,"onClickMode","flash")
4647 changeProperty(helpSOKID,"onActiveFunction",function()
4648 setScreenToRenderOnTerminal(designerScreen)
4649 fullRefresh()
4650 end)
4651 addElementToScreen(helpSOKID,helpSID,relX(50,initMonsSID),y-3)
4652end
4653
4654function setDesignerScreen(ID)
4655 designerScreen = ID
4656 if designerMonitor==terminalID then
4657 setScreenToRenderOnTerminal(ID)
4658 else
4659 setScreenToRenderOnMon(ID,designerMonitor,tonumber(getProperty(changeMonSScaleDDID,"entries")[getProperty(changeMonSScaleDDID,"selectionID")]),0,0)
4660 end
4661end
4662
4663function transferDesigner()
4664 local array = {"term"}
4665 for name,data in pairs(monitors) do
4666 table.insert(array,name)
4667 end
4668 if table.getn(array)~=1 then
4669 local x,y = term.getSize()
4670 addScreen(changeMonSID,x,y,colorPalette[1],colorPalette[2])
4671 setScreenToRenderOnTerminal(changeMonSID)
4672 designerScreen = changeMonSID
4673 addElementToScreen(initMonsSLeftRectID,changeMonSID,1,1)
4674 addElementToScreen(initMonsSPictureID,changeMonSID,relX(10,changeMonSID)-1,1)
4675 changeProperty(initMonsSHeadingID,"content","EasyGUI Designer transfer")
4676 addElementToScreen(initMonsSHeadingID,changeMonSID,relX(20,changeMonSID)+1,1)
4677 changeProperty(initMonsSTextID,"content","Would you like to transfer the designer on a monitor? You can also adjust textScale.")
4678 addElementToScreen(initMonsSTextID,changeMonSID,relX(20,changeMonSID)+1,relY(30,changeMonSID))
4679
4680 addDropDownMenu(changeMonSScaleDDID,{"0.5","1","1.5","2"},1)
4681 changeProperty(changeMonSScaleDDID,"borderThickness",1)
4682 changeProperty(changeMonSScaleDDID,"borderColor",colorPalette[3])
4683 changeProperty(changeMonSScaleDDID,"highlightTextColor",colorPalette[2])
4684 changeProperty(changeMonSScaleDDID,"highlightBGColor",colorPalette[1])
4685 changeProperty(changeMonSScaleDDID,"width",relX(40,changeMonSID)-2)
4686 addElementToScreen(changeMonSScaleDDID,changeMonSID,relX(20,changeMonSID)+2,relY(70,changeMonSID)+2)
4687
4688 addDropDownMenu(changeMonSDDMenuID,array,1)
4689 changeProperty(changeMonSDDMenuID,"borderThickness",1)
4690 changeProperty(changeMonSDDMenuID,"borderColor",colorPalette[3])
4691 changeProperty(changeMonSDDMenuID,"highlightTextColor",colorPalette[2])
4692 changeProperty(changeMonSDDMenuID,"highlightBGColor",colorPalette[1])
4693 changeProperty(changeMonSDDMenuID,"width",relX(40,changeMonSID)-2)
4694 addElementToScreen(changeMonSDDMenuID,changeMonSID,relX(20,changeMonSID)+2,relY(70,changeMonSID)-2)
4695
4696 addDynamicTextBox(changeMonSApplyID,"Apply")
4697 changeProperty(changeMonSApplyID,"width",relX(40,changeMonSID)-2)
4698 changeProperty(changeMonSApplyID,"textColor",colorPalette[3])
4699 changeProperty(changeMonSApplyID,"BGColor",colorPalette[1])
4700 changeProperty(changeMonSApplyID,"borderThickness",1)
4701 changeProperty(changeMonSApplyID,"onClickMode","flash")
4702 changeProperty(changeMonSApplyID,"onActiveFunction",function()
4703 os.queueEvent("easygui_interrupt") end)
4704 addElementToScreen(changeMonSApplyID,changeMonSID,relX(60,changeMonSID)+2,relY(70,changeMonSID))
4705
4706 run()
4707
4708 if getProperty(changeMonSDDMenuID,"selectionID")==1 then
4709 designerMonitor = terminalID
4710 else
4711 designerMonitor = array[getProperty(changeMonSDDMenuID,"selectionID")]
4712 end
4713 else
4714 designerMonitor = terminalID
4715 end
4716end
4717
4718function onLoadScreensS()
4719 tryLoadAllScreens()
4720 local array = {}
4721 for name,data in pairs(screens) do
4722 if string.len(name)<32 then
4723 table.insert(array,name)
4724 end
4725 end
4726 if table.getn(array)~=0 then
4727 changeProperty(screensSDDMenuID,"entries",array)
4728 else
4729 changeProperty(screensSButton2ID,"visible",false)
4730 changeProperty(screensSDDMenuID,"visible",false)
4731 end
4732end
4733
4734function onLoadElementsS()
4735 tryLoadAllElements()
4736 local array = {}
4737 for name,data in pairs(elements) do
4738 for name2,data2 in pairs(elements[name]) do
4739 if string.len(name2)<32 then
4740 table.insert(array,name2)
4741 end
4742 end
4743 end
4744 if table.getn(array)~=0 then
4745 changeProperty(elementsSDDMenu2ID,"entries",array)
4746 else
4747 changeProperty(elementsSButton2ID,"visible",false)
4748 changeProperty(elementsSDDMenu2ID,"visible",false)
4749 end
4750end
4751
4752function newElement(type_)
4753 local ID = nil
4754
4755 changeProperty(elementsSButton1ID,"visible",false)
4756 changeProperty(elementsSButton2ID,"visible",false)
4757 changeProperty(elementsSDDMenu1ID,"visible",false)
4758 changeProperty(elementsSDDMenu2ID,"visible",false)
4759 changeProperty(screensSButton3ID,"visible",false)
4760 changeProperty(screensSMsgID,"visible",true)
4761 refresh()
4762 term.setTextColor(colorPalette[1])
4763 term.setBackgroundColor(colorPalette[2])
4764 term.clear()
4765 term.setCursorPos(1,1)
4766 print("Please enter an unique ID for the new element:")
4767 repeat
4768 local input = read()
4769 if input~="" and input~=nil then
4770 if string.len(input)<32 then
4771 if not IDExists(input) then
4772 ID = input
4773 else
4774 print("ID already taken!")
4775 end
4776 else
4777 print("Must be less than 32 characters!")
4778 end
4779 else
4780 print("Cannot be an empty string.")
4781 end
4782 until ID~=nil
4783
4784 changeProperty(elementsSButton1ID,"visible",true)
4785 changeProperty(elementsSButton2ID,"visible",true)
4786 changeProperty(elementsSDDMenu1ID,"visible",true)
4787 changeProperty(elementsSDDMenu2ID,"visible",true)
4788 changeProperty(screensSButton3ID,"visible",true)
4789 changeProperty(screensSMsgID,"visible",false)
4790 fullRefresh()
4791
4792 elements[type_][ID] = {["enabled"]=true,["visible"]=true,["expanded"]=false}
4793
4794 for name,data in pairs(elementProperties[type_]) do
4795 if data["essential"] then
4796 changeProperty(ID,name,data["default"])
4797 end
4798 end
4799 return ID,type_
4800end
4801
4802function startEditor(ID,type_)
4803 editorSElementID = ID
4804 editorSElementType = type_
4805 saveElement(editorSElementID,editorSElementType)
4806 lastSave = os.clock()
4807 saveTimerID = os.startTimer(180)
4808 setProcessEventFunction(processEditorEvents)
4809 term.setTextColor(colorPalette[1])
4810 term.setBackgroundColor(colorPalette[2])
4811 term.clear()
4812 term.setCursorPos(1,1)
4813 term.write("EasyGUI Editor running on monitor.")
4814 addScreen(editorSID,designerX,designerY,colorPalette[1],colorPalette[2])
4815 addElementToScreen(editorSElementID,editorSID,relX(20,editorSID),relY(20,editorSID))
4816 editorSElementX = relX(20,editorSID)
4817 editorSElementY = relY(20,editorSID)
4818 undoRedoTable = {}
4819 undoRedoIndex = 0
4820
4821 addDynamicTextBox(editorSRelocateButtonID,"<Relocate>")
4822 changeProperty(editorSRelocateButtonID,"onClickMode","toggle")
4823 changeProperty(editorSRelocateButtonID,"activeTextColor",colorPalette[2])
4824 changeProperty(editorSRelocateButtonID,"activeBGColor",colorPalette[1])
4825 changeProperty(editorSRelocateButtonID,"onActiveFunction",relocateOn)
4826 changeProperty(editorSRelocateButtonID,"onInactiveFunction",relocateOff)
4827 addElementToScreen(editorSRelocateButtonID,editorSID,1,1)
4828
4829 addDynamicTextBox(editorSLastSaveID,"Last save: $time min ago.")
4830 changeProperty(editorSLastSaveID,"variables",{["time"]=function () return math.floor((os.clock()-lastSave)/60) end})
4831 addElementToScreen(editorSLastSaveID,editorSID,designerX-9,1)
4832
4833 addDynamicTextBox(editorSExitID,"<Save&Exit>")
4834 changeProperty(editorSExitID,"onClickMode","flash")
4835 changeProperty(editorSExitID,"onActiveFunction",function() saveElement(editorSElementID,editorSElementType)
4836 lastSave = os.clock()
4837 removeElementFromScreen(editorSElementID,editorSID)
4838 removeElementFromScreen(editorSDescID,editorSID)
4839 removeElementFromScreen(editorSExitID,editorSID)
4840 removeElementFromScreen(editorSHideUIID,editorSID)
4841 removeElementFromScreen(editorSLastSaveID,editorSID)
4842 removeElementFromScreen(editorSPropColorPickID,editorSID)
4843 removeElementFromScreen(editorSPropsID,editorSID)
4844 removeElementFromScreen(editorSPropsMenuID,editorSID)
4845 removeElementFromScreen(editorSRedoID,editorSID)
4846 removeElementFromScreen(editorSRelocateButtonID,editorSID)
4847 removeElementFromScreen(editorSUndoID,editorSID)
4848 removeElementFromScreen(editorSPropResetButtonID,editorSID)
4849 removeElementFromScreen(editorSPropDDMenuID,editorSID)
4850 removeElementFromScreen(editorSPropDisplayID,editorSID)
4851 removeElementFromScreen(editorSPropConsoleInputButtonID,editorSID)
4852 removeElementFromScreen(editorSPropConsoleMsgID,editorSID)
4853 removeElementFromScreen(editorSPropColorsArrayDDID,editorSID)
4854 removeElementFromScreen(editorSPropStringArrayDDID,editorSID)
4855 removeElementFromScreen(editorSPropNavMenuID,editorSID)
4856 removeElementFromScreen(editorSPropNavMenuHintID,editorSID)
4857 removeElementFromScreen(editorSPropCSTableIndexDDID,editorSID)
4858 removeElementFromScreen(editorSPropCSTableDDID,editorSID)
4859 removeElementFromScreen(editorSPropCSChangeID,editorSID)
4860 removeElementFromScreen(editorSPropCSRemoveID,editorSID)
4861 removeElementFromScreen(editorSPropCSDesignsDDID,editorSID)
4862 removeElementFromScreen(editorSPropCSDesignsDisplayID,editorSID)
4863 removeElementFromScreen(editorSPropCSDesignsIndexDDID,editorSID)
4864 removeElementFromScreen(editorSPropPicEditButtonID,editorSID)
4865 setProcessEventFunction(nil)
4866 editorSElementID = nil
4867 setDesignerScreen(elementsSID)
4868 refresh() end)
4869 addElementToScreen(editorSExitID,editorSID,designerX-10,designerY)
4870
4871 addDynamicTextBox(editorSPropsID,"<Properties>")
4872 changeProperty(editorSPropsID,"onClickMode","toggle")
4873 changeProperty(editorSPropsID,"activeTextColor",colorPalette[2])
4874 changeProperty(editorSPropsID,"activeBGColor",colorPalette[1])
4875 changeProperty(editorSPropsID,"onActiveFunction",function() changeProperty(editorSPropsMenuID,"visible",true)
4876 changeProperty(editorSDescID,"visible",true)
4877 changeProperty(editorSExitID,"visible",false)
4878 changeProperty(editorSRelocateButtonID,"visible",false)
4879 changeProperty(editorSHideUIID,"visible",false)
4880 refreshPropsMenu()
4881 pcall(getProperty(editorSPropsMenuID,"onChangeFunction")) end)
4882 changeProperty(editorSPropsID,"onInactiveFunction",function() changeProperty(editorSPropsMenuID,"visible",false)
4883 changeProperty(editorSDescID,"visible",false)
4884 changeProperty(editorSRelocateButtonID,"visible",true)
4885 changeProperty(editorSHideUIID,"visible",true)
4886 changeProperty(editorSExitID,"visible",true)
4887 changeProperty(editorSPropColorPickID,"visible",false)
4888 changeProperty(editorSPropResetButtonID,"visible",false)
4889 changeProperty(editorSPropDisplayID,"visible",false)
4890 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
4891 changeProperty(editorSPropDDMenuID,"visible",false)
4892 changeProperty(editorSPropConsoleMsgID,"visible",false)
4893 changeProperty(editorSPropColorsArrayDDID,"visible",false)
4894 changeProperty(editorSPropStringArrayDDID,"visible",false)
4895 changeProperty(editorSPropNavMenuID,"visible",false)
4896 changeProperty(editorSPropNavMenuHintID,"visible",false)
4897 changeProperty(editorSPropCSTableIndexDDID,"visible",false)
4898 changeProperty(editorSPropCSTableDDID,"visible",false)
4899 changeProperty(editorSPropCSChangeID,"visible",false)
4900 changeProperty(editorSPropCSRemoveID,"visible",false)
4901 changeProperty(editorSPropCSDesignsDDID,"visible",false)
4902 changeProperty(editorSPropCSDesignsIndexDDID,"visible",false)
4903 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
4904 changeProperty(editorSPropPicEditButtonID,"visible",false) end)
4905 addElementToScreen(editorSPropsID,editorSID,1,designerY)
4906
4907 addDynamicTextBox(editorSUndoID,"<Undo>")
4908 changeProperty(editorSUndoID,"onClickMode","flash")
4909 changeProperty(editorSUndoID,"activeTextColor",colorPalette[2])
4910 changeProperty(editorSUndoID,"activeBGColor",colorPalette[1])
4911 changeProperty(editorSUndoID,"onActiveFunction",function()
4912 if undoRedoIndex~=0 then
4913 if type(undoRedoTable[undoRedoIndex]["undo"])=="function" then
4914 pcall(undoRedoTable[undoRedoIndex]["undo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
4915 if getProperty(editorSPropsID,"active") then
4916 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4917 end
4918 onPixelSelecChange()
4919 refresh()
4920 else
4921 changeProperty(editorSElementID,undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["undo"])
4922 if getProperty(editorSPropsID,"active") then
4923 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4924 end
4925 onPixelSelecChange()
4926 refresh()
4927 end
4928 undoRedoIndex = undoRedoIndex - 1
4929 end
4930 end)
4931 addElementToScreen(editorSUndoID,editorSID,relX(50,editorSID)-6,designerY)
4932
4933 addDynamicTextBox(editorSRedoID,"<Redo>")
4934 changeProperty(editorSRedoID,"onClickMode","flash")
4935 changeProperty(editorSRedoID,"activeTextColor",colorPalette[2])
4936 changeProperty(editorSRedoID,"activeBGColor",colorPalette[1])
4937 changeProperty(editorSRedoID,"onActiveFunction",function()
4938 if undoRedoIndex~=table.getn(undoRedoTable) then
4939 undoRedoIndex = undoRedoIndex + 1
4940 if type(undoRedoTable[undoRedoIndex]["redo"])=="function" then
4941 pcall(undoRedoTable[undoRedoIndex]["redo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
4942 if getProperty(editorSPropsID,"active") then
4943 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4944 end
4945 onPixelSelecChange()
4946 refresh()
4947 else
4948 changeProperty(editorSElementID,undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["redo"])
4949 if getProperty(editorSPropsID,"active") then
4950 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4951 end
4952 onPixelSelecChange()
4953 refresh()
4954 end
4955 end
4956 end)
4957 addElementToScreen(editorSRedoID,editorSID,relX(50,editorSID)+1,designerY)
4958
4959 addDynamicTextBox(editorSDescID,nil)
4960 changeProperty(editorSDescID,"visible",false)
4961 changeProperty(editorSDescID,"height",designerY - 5)
4962 changeProperty(editorSDescID,"textAlignmentHorizontal","left")
4963 changeProperty(editorSDescID,"textAlignmentVertical","top")
4964 addElementToScreen(editorSDescID,editorSID,relX(50,editorSID)+1,4)
4965
4966 addDynamicTextBox(editorSPropResetButtonID,"Set default or unused")
4967 changeProperty(editorSPropResetButtonID,"BGColor",colorPalette[3])
4968 changeProperty(editorSPropResetButtonID,"textColor",colorPalette[2])
4969 changeProperty(editorSPropResetButtonID,"borderColor",colorPalette[1])
4970 changeProperty(editorSPropResetButtonID,"borderThickness",1)
4971 changeProperty(editorSPropResetButtonID,"width",relX(50,editorSID)-1)
4972 changeProperty(editorSPropResetButtonID,"onClickMode","flash")
4973 changeProperty(editorSPropResetButtonID,"activeBGColor",colorPalette[2])
4974 changeProperty(editorSPropResetButtonID,"activeTextColor",colorPalette[3])
4975 changeProperty(editorSPropResetButtonID,"visible",false)
4976 changeProperty(editorSPropResetButtonID,"onActiveFunction",function()
4977 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["essential"] then
4978 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "string" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "color" or string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],1,3)=="DDM" then
4979 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4980 else
4981 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "stringArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "colorsArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "picArray" then
4982 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4983 else
4984 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSTable" then
4985 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4986 else
4987 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSDesignsTable" then
4988 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSDesignsTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4989 else
4990 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "navMenuArray" then
4991 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4992 end
4993 end
4994 end
4995 end
4996 end
4997 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4998 changeProperty(editorSPropStringArrayDDID,"selectionID",1)
4999 changeProperty(editorSPropStringArrayDDID,"entries",{"Entry 1","Entry 2","Entry 3","+add"})
5000 else
5001 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "string" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "color" or string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],1,3)=="DDM" then
5002 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),nil)
5003 else
5004 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "stringArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "colorsArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "picArray" then
5005 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
5006 else
5007 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSTable" then
5008 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
5009 else
5010 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSDesignsTable" then
5011 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSDesignsTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
5012 else
5013 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "navMenuArray" then
5014 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
5015 end
5016 end
5017 end
5018 end
5019 end
5020 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil)
5021 changeProperty(editorSPropDDMenuID,"selectionID",1)
5022 changeProperty(editorSPropColorPickID,"selection",nil)
5023 changeProperty(editorSPropColorsArrayDDID,"entries",{"Use"})
5024 changeProperty(editorSPropCSTableIndexDDID,"entries",{"Use"})
5025 changeProperty(editorSPropCSDesignsIndexDDID,"entries",{"Use"})
5026 changeProperty(editorSPropCSDesignsDDID,"visible",false)
5027 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5028 changeProperty(editorSPropCSTableDDID,"visible",false)
5029 changeProperty(editorSPropColorsArrayDDID,"selectionID",1)
5030 changeProperty(editorSPropCSTableIndexDDID,"selectionID",1)
5031 changeProperty(editorSPropCSDesignsIndexDDID,"selectionID",1)
5032 changeProperty(editorSPropColorsArrayDDID,"expanded",false)
5033 changeProperty(editorSPropColorsArrayDDID,"highlightID",nil)
5034 changeProperty(editorSPropCSChangeID,"visible",false)
5035 changeProperty(editorSPropCSRemoveID,"visible",false)
5036 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="colorsArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
5037 changeProperty(editorSPropColorPickID,"visible",false)
5038 end
5039 end end)
5040 addElementToScreen(editorSPropResetButtonID,editorSID,1,designerY-4)
5041
5042 --input color
5043 addColorPicker(editorSPropColorPickID,nil)
5044 changeProperty(editorSPropColorPickID,"borderThickness",1)
5045 changeProperty(editorSPropColorPickID,"borderColor",colorPalette[3])
5046 changeProperty(editorSPropColorPickID,"visible",false)
5047 changeProperty(editorSPropColorPickID,"onChangeFunction", function(ID,selection)
5048 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="color" then
5049 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),selection)
5050 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),selection)
5051 end
5052 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="colorsArray" then
5053 --for colorsArray
5054 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var1 end,function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropColorsArrayDDID,"selectionID")],selection,getProperty(editorSPropColorsArrayDDID,"selectionID"))
5055 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropColorsArrayDDID,"selectionID")] = selection
5056 end
5057 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
5058 --for graphDesigns
5059 local string_ = ""
5060 if getProperty(editorSPropCSDesignsDDID,"selectionID")==1 then
5061 string_ = "color"
5062 else
5063 string_ = "BGColor"
5064 end
5065 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3,var4) getProperty(editorSElementID,prop)[var3][var4] = var1 end,function(prop,var1,var2,var3,var4) getProperty(editorSElementID,prop)[var3][var4] = var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")][string_],selection,getProperty(editorSPropCSDesignsIndexDDID,"selectionID"),string_)
5066 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")][string_] = selection
5067 end
5068 refresh()
5069 end)
5070 addElementToScreen(editorSPropColorPickID,editorSID,1,7)
5071
5072 --input ddmenu
5073 addDropDownMenu(editorSPropDDMenuID,nil,1)
5074 changeProperty(editorSPropDDMenuID,"selectionID",1)
5075 changeProperty(editorSPropDDMenuID,"borderThickness",1)
5076 changeProperty(editorSPropDDMenuID,"borderColor",colorPalette[3])
5077 changeProperty(editorSPropDDMenuID,"highlightTextColor",colorPalette[2])
5078 changeProperty(editorSPropDDMenuID,"highlightBGColor",colorPalette[1])
5079 changeProperty(editorSPropDDMenuID,"visible",false)
5080 changeProperty(editorSPropDDMenuID,"width",relX(50,editorSID)-1)
5081 changeProperty(editorSPropDDMenuID,"expandedMaxHeight",designerY-8)
5082 changeProperty(editorSPropDDMenuID,"onChangeFunction",function(ID,selection)
5083 if getProperty(editorSPropDDMenuID,"selectionID")==1 then
5084 changeProperty(editorSPropDDMenuID,"selectionID",2)
5085 end
5086 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),(getProperty(editorSPropDDMenuID,"entries")[getProperty(editorSPropDDMenuID,"selectionID")]))
5087 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),(getProperty(editorSPropDDMenuID,"entries")[getProperty(editorSPropDDMenuID,"selectionID")]))
5088 end)
5089 addElementToScreen(editorSPropDDMenuID,editorSID,1,7)
5090
5091 --input console (string,number,decimal)
5092 addDynamicTextBox(editorSPropDisplayID,"Current value: $value")
5093 changeProperty(editorSPropDisplayID,"width",relX(50,editorSID)-1)
5094 changeProperty(editorSPropDisplayID,"variables",{["value"]=function() return getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])) or "nil" end})
5095 changeProperty(editorSPropDisplayID,"textAlignmentHorizontal","center")
5096 changeProperty(editorSPropDisplayID,"visible",false)
5097 addElementToScreen(editorSPropDisplayID,editorSID,1,7)
5098
5099 addDynamicTextBox(editorSPropConsoleInputButtonID,"Change")
5100 changeProperty(editorSPropConsoleInputButtonID,"BGColor",colorPalette[3])
5101 changeProperty(editorSPropConsoleInputButtonID,"textColor",colorPalette[2])
5102 changeProperty(editorSPropConsoleInputButtonID,"borderColor",colorPalette[1])
5103 changeProperty(editorSPropConsoleInputButtonID,"borderThickness",1)
5104 changeProperty(editorSPropConsoleInputButtonID,"width",relX(50,editorSID)-1)
5105 changeProperty(editorSPropConsoleInputButtonID,"onClickMode","flash")
5106 changeProperty(editorSPropConsoleInputButtonID,"activeBGColor",colorPalette[2])
5107 changeProperty(editorSPropConsoleInputButtonID,"activeTextColor",colorPalette[3])
5108 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
5109 changeProperty(editorSPropConsoleInputButtonID,"onActiveFunction",function()
5110 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]~="stringArray" then
5111 changeProperty(editorSPropsID,"visible",false)
5112 changeProperty(editorSPropsMenuID,"enabled",false)
5113 changeProperty(editorSUndoID,"visible",false)
5114 changeProperty(editorSRedoID,"visible",false)
5115 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
5116 changeProperty(editorSPropResetButtonID,"visible",false)
5117 changeProperty(editorSPropConsoleMsgID,"visible",true)
5118 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5119 changeProperty(editorSPropCSTableDDID,"enabled",false)
5120 refresh()
5121 term.setBackgroundColor(colorPalette[2])
5122 term.setTextColor(colorPalette[1])
5123 term.clear()
5124 term.setCursorPos(1,1)
5125 local valid = false
5126 repeat
5127 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..")")
5128 input = read()
5129 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="string" then
5130 valid = true
5131 end
5132 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" then
5133 if tonumber(input)~=nil then
5134 input = math.floor(tonumber(input))
5135 valid = true
5136 else
5137 print("Must be a number!")
5138 end
5139 end
5140 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" then
5141 if tonumber(input)~=nil then
5142 input = (tonumber(input))
5143 valid = true
5144 else
5145 print("Must be a number!")
5146 end
5147 end
5148 until valid
5149 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),input)
5150 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),input)
5151
5152 changeProperty(editorSPropsID,"visible",true)
5153 changeProperty(editorSPropsMenuID,"enabled",true)
5154 changeProperty(editorSUndoID,"visible",true)
5155 changeProperty(editorSRedoID,"visible",true)
5156 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
5157 changeProperty(editorSPropResetButtonID,"visible",true)
5158 changeProperty(editorSPropConsoleMsgID,"visible",false)
5159 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5160 changeProperty(editorSPropCSTableDDID,"enabled",true)
5161 fullRefresh()
5162 else
5163 changeProperty(editorSPropsID,"visible",false)
5164 changeProperty(editorSPropsMenuID,"enabled",false)
5165 changeProperty(editorSUndoID,"visible",false)
5166 changeProperty(editorSRedoID,"visible",false)
5167 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
5168 changeProperty(editorSPropResetButtonID,"visible",false)
5169 changeProperty(editorSPropConsoleMsgID,"visible",true)
5170 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5171 changeProperty(editorSPropCSTableDDID,"enabled",false)
5172 refresh()
5173 term.setBackgroundColor(colorPalette[2])
5174 term.setTextColor(colorPalette[1])
5175 term.clear()
5176 term.setCursorPos(1,1)
5177 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..") entry number "..getProperty(editorSPropStringArrayDDID,"selectionID")..". To remove this entry press enter.")
5178 input = read()
5179 if input~="" then
5180 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var1 end, function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries"))[getProperty(editorSPropsMenuID,"selectionID")])[getProperty(editorSPropStringArrayDDID,"selectionID")],input,getProperty(editorSPropStringArrayDDID,"selectionID"))
5181 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropStringArrayDDID,"selectionID")] = input
5182 getProperty(editorSPropStringArrayDDID,"entries")[getProperty(editorSPropStringArrayDDID,"selectionID")] = input
5183 else
5184 local old = copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5185 table.remove(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),getProperty(editorSPropStringArrayDDID,"selectionID"))
5186 table.remove(getProperty(editorSPropStringArrayDDID,"entries"),getProperty(editorSPropStringArrayDDID,"selectionID"))
5187 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5188 end
5189 changeProperty(editorSPropsID,"visible",true)
5190 changeProperty(editorSPropsMenuID,"enabled",true)
5191 changeProperty(editorSUndoID,"visible",true)
5192 changeProperty(editorSRedoID,"visible",true)
5193 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
5194 changeProperty(editorSPropResetButtonID,"visible",true)
5195 changeProperty(editorSPropConsoleMsgID,"visible",false)
5196 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5197 changeProperty(editorSPropCSTableDDID,"enabled",true)
5198 fullRefresh()
5199 end
5200 end)
5201 addElementToScreen(editorSPropConsoleInputButtonID,editorSID,1,designerY-8)
5202
5203 addDynamicTextBox(editorSPropConsoleMsgID,"Please check term!")
5204 changeProperty(editorSPropConsoleMsgID,"borderThickness",1)
5205 changeProperty(editorSPropConsoleMsgID,"width",relX(50,editorSID)-1)
5206 changeProperty(editorSPropConsoleMsgID,"visible",false)
5207 addElementToScreen(editorSPropConsoleMsgID,editorSID,1,designerY-8)
5208
5209 --advanced types: colorsArray,stringArray,navMenuArray,CSTable,CSDesignsTable,picArray
5210
5211 --type colorsArray
5212 addDropDownMenu(editorSPropColorsArrayDDID,{"Use"},1)
5213 changeProperty(editorSPropColorsArrayDDID,"selectionID",1)
5214 changeProperty(editorSPropColorsArrayDDID,"expanded",false)
5215 changeProperty(editorSPropColorsArrayDDID,"highlightID",nil)
5216 changeProperty(editorSPropColorsArrayDDID,"borderThickness",1)
5217 changeProperty(editorSPropColorsArrayDDID,"borderColor",colorPalette[3])
5218 changeProperty(editorSPropColorsArrayDDID,"highlightTextColor",colorPalette[2])
5219 changeProperty(editorSPropColorsArrayDDID,"highlightBGColor",colorPalette[1])
5220 changeProperty(editorSPropColorsArrayDDID,"visible",false)
5221 changeProperty(editorSPropColorsArrayDDID,"expandedMaxHeight",designerY-8)
5222 changeProperty(editorSPropColorsArrayDDID,"onExpandFunction",function()
5223 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))==nil then
5224 local array = {}
5225 local entries = {}
5226 for i=1,getProperty(editorSElementID,"length") do
5227 array[i] = colors.white
5228 entries[i] = i
5229 end
5230 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil,copyOfSimpleArray(array))
5231 changeProperty(editorSPropColorsArrayDDID,"entries",entries)
5232 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),array)
5233 end end)
5234 changeProperty(editorSPropColorsArrayDDID,"onChangeFunction",function(ID,selection)
5235 changeProperty(editorSPropColorPickID,"visible",true)
5236 changeProperty(editorSPropColorPickID,"selection",getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropColorsArrayDDID,"selectionID")])
5237 end)
5238 addElementToScreen(editorSPropColorsArrayDDID,editorSID,8,7)
5239
5240 --type stringArray
5241 addDropDownMenu(editorSPropStringArrayDDID,nil,1)
5242 changeProperty(editorSPropStringArrayDDID,"selectionID",1)
5243 changeProperty(editorSPropStringArrayDDID,"expanded",false)
5244 changeProperty(editorSPropStringArrayDDID,"highlightID",nil)
5245 changeProperty(editorSPropStringArrayDDID,"borderThickness",1)
5246 changeProperty(editorSPropStringArrayDDID,"borderColor",colorPalette[3])
5247 changeProperty(editorSPropStringArrayDDID,"highlightTextColor",colorPalette[2])
5248 changeProperty(editorSPropStringArrayDDID,"highlightBGColor",colorPalette[1])
5249 changeProperty(editorSPropStringArrayDDID,"visible",false)
5250 changeProperty(editorSPropStringArrayDDID,"expandedMaxHeight",designerY-8)
5251 changeProperty(editorSPropStringArrayDDID,"onChangeFunction",function(ID,selection)
5252 if selection==table.getn(getProperty(editorSPropStringArrayDDID,"entries")) then
5253 pcall(getProperty(editorSPropConsoleInputButtonID,"onActiveFunction"))
5254 table.insert(getProperty(editorSPropStringArrayDDID,"entries"),"+add")
5255 end
5256 end)
5257 addElementToScreen(editorSPropStringArrayDDID,editorSID,1,7)
5258
5259 --type navMenuArray
5260 addDynamicTextBox(editorSPropNavMenuHintID,"Click on any entry to change its text or add entries.")
5261 changeProperty(editorSPropNavMenuHintID,"width",relX(50,editorSID)-1)
5262 changeProperty(editorSPropNavMenuHintID,"visible",false)
5263 addElementToScreen(editorSPropNavMenuHintID,editorSID,1,designerY-8)
5264
5265 addNavigationMenu(editorSPropNavMenuID,"Entries",{})
5266 changeProperty(editorSPropNavMenuID,"expanded",false)
5267 changeProperty(editorSPropNavMenuID,"highlightIDs",nil)
5268 changeProperty(editorSPropNavMenuID,"borderColor",colorPalette[3])
5269 changeProperty(editorSPropNavMenuID,"textAlignmentHorizontal","left")
5270 changeProperty(editorSPropNavMenuID,"borderThickness",1)
5271 changeProperty(editorSPropNavMenuID,"visible",false)
5272 changeProperty(editorSPropNavMenuID,"onChangeFunction",function(ID,numbers)
5273 local temp = getProperty(editorSPropNavMenuID,"menuArray")
5274 local old = copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5275 for i=1,table.getn(numbers)-1 do
5276 temp = temp[numbers[i]]["submenu"]
5277 end
5278 if temp[numbers[table.getn(numbers)]]["text"] == "+add" then
5279 local offset = 0
5280 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5281 for i=1,table.getn(numbers)-1 do
5282 temp2 = temp2[numbers[i]-offset]["submenu"]
5283 offset = 1
5284 end
5285 temp2[numbers[table.getn(numbers)]-offset] = {}
5286 temp2[numbers[table.getn(numbers)]-offset]["text"] = "New"
5287 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5288 end
5289 if temp[numbers[table.getn(numbers)]]["text"] == "+add sub" then
5290 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5291 local offset = 0
5292 for i=1,table.getn(numbers)-2 do
5293 temp2 = temp2[numbers[i]-offset]["submenu"]
5294 offset = 1
5295 end
5296 temp2[numbers[table.getn(numbers)-1]-offset]["submenu"] = {}
5297 temp2[numbers[table.getn(numbers)-1]-offset]["submenu"][1] = {}
5298 temp2[numbers[table.getn(numbers)-1]-offset]["submenu"][1]["text"] = "New"
5299 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5300 end
5301 if temp[numbers[table.getn(numbers)]]["text"] == "<- edit" then
5302 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5303 local highlightIDsString = "entry"
5304 local offset = 0
5305 for i=1,table.getn(numbers)-2 do
5306 temp2 = temp2[numbers[i]-offset]["submenu"]
5307 highlightIDsString = highlightIDsString .. "-"..numbers[i]-offset
5308 offset = 1
5309 end
5310 highlightIDsString = highlightIDsString .. "-"..(numbers[table.getn(numbers)-1]-offset)
5311
5312 local input = "Entry"
5313 changeProperty(editorSPropNavMenuID,"enabled",false)
5314 changeProperty(editorSPropNavMenuHintID,"visible",false)
5315 changeProperty(editorSPropsID,"visible",false)
5316 changeProperty(editorSPropsMenuID,"enabled",false)
5317 changeProperty(editorSUndoID,"visible",false)
5318 changeProperty(editorSRedoID,"visible",false)
5319 changeProperty(editorSPropResetButtonID,"visible",false)
5320 changeProperty(editorSPropConsoleMsgID,"visible",true)
5321 refresh()
5322
5323 term.setBackgroundColor(colorPalette[2])
5324 term.setTextColor(colorPalette[1])
5325 term.clear()
5326 term.setCursorPos(1,1)
5327 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..", "..highlightIDsString.." ) To remove entry press enter.")
5328 input = read()
5329
5330 if input~="" then
5331 temp2[numbers[table.getn(numbers)-1]-offset]["text"] = input
5332 else
5333 if not (temp2==getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])) and numbers[1]==1) then
5334 temp2[numbers[table.getn(numbers)-1]-offset] = ""
5335 table.remove(temp2,numbers[table.getn(numbers)-1]-offset)
5336 end
5337
5338 local count = 0
5339 for name,data in pairs(temp2) do
5340 count = count + 1
5341 break
5342 end
5343
5344 if count==0 then
5345 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5346 local offset = 0
5347 for i=1,table.getn(numbers)-3 do
5348 if i~=1 then
5349 temp2 = temp2[numbers[i]-1]["submenu"]
5350 else
5351 temp2 = temp2[numbers[i]]["submenu"]
5352 end
5353 offset = 1
5354 end
5355 temp2[numbers[table.getn(numbers)-2]-offset]["submenu"] = nil
5356 end
5357 end
5358
5359 changeProperty(editorSPropNavMenuID,"enabled",true)
5360 changeProperty(editorSPropNavMenuHintID,"visible",true)
5361 changeProperty(editorSPropsID,"visible",true)
5362 changeProperty(editorSPropsMenuID,"enabled",true)
5363 changeProperty(editorSUndoID,"visible",true)
5364 changeProperty(editorSRedoID,"visible",true)
5365 changeProperty(editorSPropResetButtonID,"visible",true)
5366 changeProperty(editorSPropConsoleMsgID,"visible",false)
5367
5368 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5369 fullRefresh()
5370 end
5371 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5372 end)
5373 addElementToScreen(editorSPropNavMenuID,editorSID,1,7)
5374
5375 -- type CSTable
5376 addDynamicTextBox(editorSPropCSChangeID,"Change")
5377 changeProperty(editorSPropCSChangeID,"BGColor",colorPalette[3])
5378 changeProperty(editorSPropCSChangeID,"textColor",colorPalette[2])
5379 changeProperty(editorSPropCSChangeID,"borderColor",colorPalette[1])
5380 changeProperty(editorSPropCSChangeID,"borderThickness",1)
5381 changeProperty(editorSPropCSChangeID,"onClickMode","flash")
5382 changeProperty(editorSPropCSChangeID,"activeBGColor",colorPalette[2])
5383 changeProperty(editorSPropCSChangeID,"activeTextColor",colorPalette[3])
5384 changeProperty(editorSPropCSChangeID,"visible",false)
5385 changeProperty(editorSPropCSChangeID,"onActiveFunction",function()
5386 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSTable" then
5387 changeProperty(editorSPropsID,"visible",false)
5388 changeProperty(editorSPropsMenuID,"enabled",false)
5389 changeProperty(editorSUndoID,"visible",false)
5390 changeProperty(editorSRedoID,"visible",false)
5391 changeProperty(editorSPropResetButtonID,"visible",false)
5392 changeProperty(editorSPropConsoleMsgID,"visible",true)
5393 changeProperty(editorSPropCSChangeID,"visible",false)
5394 changeProperty(editorSPropCSRemoveID,"visible",false)
5395 changeProperty(editorSPropCSTableDDID,"enabled",false)
5396 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5397
5398 refresh()
5399
5400 term.setBackgroundColor(colorPalette[2])
5401 term.setTextColor(colorPalette[1])
5402 term.clear()
5403 term.setCursorPos(1,1)
5404
5405 local index = tonumber(string.sub(getProperty(editorSPropCSTableDDID,"entries")[getProperty(editorSPropCSTableDDID,"selectionID")],1,string.find(getProperty(editorSPropCSTableDDID,"entries")[getProperty(editorSPropCSTableDDID,"selectionID")],":")-1))
5406 local _string = "graph "..getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")].." coordinate x="..index
5407 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..", ".._string..") To remove coordinate press enter.")
5408 print("Enter a new Y Coordinate:")
5409
5410 local input
5411 local valid = false
5412 repeat
5413 input = read()
5414 if input~="" then
5415 if tonumber(input)~=nil then
5416 input = (tonumber(input))
5417 valid = true
5418 else
5419 print("Must be a number!")
5420 end
5421 else
5422 valid = true
5423 end
5424 until valid
5425
5426 if input~="" then
5427 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3,var4,var5) getProperty(editorSElementID,prop)[var3][var4] = var1 end, function(prop,var1,var2,var3,var4,var5) getProperty(editorSElementID,prop)[var3][var4] = var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])][index],input,tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")]),index)
5428 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])][index] = input
5429 else
5430 local old = copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5431 table.remove(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])],index)
5432 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5433 end
5434 changeProperty(editorSPropsID,"visible",true)
5435 changeProperty(editorSPropsMenuID,"enabled",true)
5436 changeProperty(editorSUndoID,"visible",true)
5437 changeProperty(editorSRedoID,"visible",true)
5438 changeProperty(editorSPropResetButtonID,"visible",true)
5439 changeProperty(editorSPropConsoleMsgID,"visible",false)
5440 changeProperty(editorSPropCSChangeID,"visible",true)
5441 changeProperty(editorSPropCSRemoveID,"visible",true)
5442 changeProperty(editorSPropCSTableDDID,"enabled",true)
5443 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5444 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5445 fullRefresh()
5446 end
5447 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
5448 changeProperty(editorSPropsID,"visible",false)
5449 changeProperty(editorSPropsMenuID,"enabled",false)
5450 changeProperty(editorSUndoID,"visible",false)
5451 changeProperty(editorSRedoID,"visible",false)
5452 changeProperty(editorSPropResetButtonID,"visible",false)
5453 changeProperty(editorSPropConsoleMsgID,"visible",true)
5454 changeProperty(editorSPropCSChangeID,"visible",false)
5455 changeProperty(editorSPropCSDesignsDDID,"enabled",false)
5456 changeProperty(editorSPropCSDesignsIndexDDID,"enabled",false)
5457
5458 refresh()
5459
5460 term.setBackgroundColor(colorPalette[2])
5461 term.setTextColor(colorPalette[1])
5462 term.clear()
5463 term.setCursorPos(1,1)
5464 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..", graph number "..getProperty(editorSPropCSDesignsIndexDDID,"selectionID")..", character)")
5465
5466 local input = read()
5467
5468 if input~="" then
5469 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]["character"] = var1 end,function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]["character"] = var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["character"],string.sub(input,1,1),getProperty(editorSPropCSDesignsIndexDDID,"selectionID"))
5470 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["character"] = string.sub(input,1,1)
5471 end
5472
5473 changeProperty(editorSPropsID,"visible",true)
5474 changeProperty(editorSPropsMenuID,"enabled",true)
5475 changeProperty(editorSUndoID,"visible",true)
5476 changeProperty(editorSRedoID,"visible",true)
5477 changeProperty(editorSPropResetButtonID,"visible",true)
5478 changeProperty(editorSPropConsoleMsgID,"visible",false)
5479 changeProperty(editorSPropCSChangeID,"visible",true)
5480 changeProperty(editorSPropCSDesignsDDID,"enabled",true)
5481 changeProperty(editorSPropCSDesignsIndexDDID,"enabled",true)
5482 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5483 fullRefresh()
5484 end
5485 end)
5486 addElementToScreen(editorSPropCSChangeID,editorSID,1,designerY-8)
5487
5488 addDynamicTextBox(editorSPropCSRemoveID,"Remove")
5489 changeProperty(editorSPropCSRemoveID,"BGColor",colorPalette[3])
5490 changeProperty(editorSPropCSRemoveID,"textColor",colorPalette[2])
5491 changeProperty(editorSPropCSRemoveID,"borderColor",colorPalette[1])
5492 changeProperty(editorSPropCSRemoveID,"borderThickness",1)
5493 changeProperty(editorSPropCSRemoveID,"onClickMode","flash")
5494 changeProperty(editorSPropCSRemoveID,"activeBGColor",colorPalette[2])
5495 changeProperty(editorSPropCSRemoveID,"activeTextColor",colorPalette[3])
5496 changeProperty(editorSPropCSRemoveID,"visible",false)
5497 changeProperty(editorSPropCSRemoveID,"onActiveFunction",function()
5498 if table.getn(getProperty(editorSPropCSTableIndexDDID,"entries"))>2 then
5499 local old = copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5500 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSTableIndexDDID,"selectionID")] = ""
5501 table.remove(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5502 table.remove(getProperty(editorSPropCSTableIndexDDID,"entries"),getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5503 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5504 changeProperty(editorSPropCSTableIndexDDID,"selectionID",getProperty(editorSPropCSTableIndexDDID,"selectionID")-1)
5505 pcall(getProperty(editorSPropCSTableIndexDDID,"onChangeFunction"),editorSPropCSTableIndexDDID,getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5506 end
5507 end)
5508 addElementToScreen(editorSPropCSRemoveID,editorSID,relX(50,editorSID)+1-9,designerY-8)
5509
5510 addDropDownMenu(editorSPropCSTableIndexDDID,{"Use"},1)
5511 changeProperty(editorSPropCSTableIndexDDID,"selectionID",1)
5512 changeProperty(editorSPropCSTableIndexDDID,"expanded",false)
5513 changeProperty(editorSPropCSTableIndexDDID,"highlightID",nil)
5514 changeProperty(editorSPropCSTableIndexDDID,"borderThickness",1)
5515 changeProperty(editorSPropCSTableIndexDDID,"borderColor",colorPalette[3])
5516 changeProperty(editorSPropCSTableIndexDDID,"highlightTextColor",colorPalette[2])
5517 changeProperty(editorSPropCSTableIndexDDID,"highlightBGColor",colorPalette[1])
5518 changeProperty(editorSPropCSTableIndexDDID,"visible",false)
5519 changeProperty(editorSPropCSTableIndexDDID,"width",8)
5520 changeProperty(editorSPropCSTableIndexDDID,"expandedMaxHeight",designerY-8)
5521 changeProperty(editorSPropCSTableIndexDDID,"onExpandFunction",function(ID)
5522 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))==nil then
5523 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),{[1]={}})
5524 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil,copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5525 changeProperty(editorSPropCSTableDDID,"entries",{"+add"})
5526 changeProperty(editorSPropCSTableIndexDDID,"entries",{"1","+add"})
5527 changeProperty(editorSPropCSTableDDID,"selectionID",1)
5528 changeProperty(editorSPropCSTableDDID,"visible",true)
5529 changeProperty(editorSPropCSChangeID,"visible",true)
5530 changeProperty(editorSPropCSRemoveID,"visible",true)
5531 end
5532 end)
5533 changeProperty(editorSPropCSTableIndexDDID,"onChangeFunction",function(ID,selection)
5534 if selection~=table.getn(getProperty(editorSPropCSTableIndexDDID,"entries")) then
5535 local array = {}
5536 for name,data in pairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[selection]) do
5537 table.insert(array,name..":"..data)
5538 end
5539 table.insert(array,"+add")
5540 changeProperty(editorSPropCSTableDDID,"entries",array)
5541 changeProperty(editorSPropCSTableDDID,"selectionID",1)
5542 changeProperty(editorSPropCSTableDDID,"visible",true)
5543 changeProperty(editorSPropCSChangeID,"visible",true)
5544 changeProperty(editorSPropCSRemoveID,"visible",true)
5545 else
5546 local old = copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5547 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[selection] = {}
5548 getProperty(editorSPropCSTableIndexDDID,"entries")[selection] = ""..selection
5549 getProperty(editorSPropCSTableIndexDDID,"entries")[selection+1] = "+add"
5550 pcall(editorSPropCSTableIndexDDID,"onChangeFunction",ID,selection)
5551 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5552 end
5553 end)
5554 addElementToScreen(editorSPropCSTableIndexDDID,editorSID,relX(50,editorSID)+1-9,7)
5555
5556 addDropDownMenu(editorSPropCSTableDDID,{},1)
5557 changeProperty(editorSPropCSTableDDID,"selectionID",1)
5558 changeProperty(editorSPropCSTableDDID,"expanded",false)
5559 changeProperty(editorSPropCSTableDDID,"highlightID",nil)
5560 changeProperty(editorSPropCSTableDDID,"borderThickness",1)
5561 changeProperty(editorSPropCSTableDDID,"borderColor",colorPalette[3])
5562 changeProperty(editorSPropCSTableDDID,"highlightTextColor",colorPalette[2])
5563 changeProperty(editorSPropCSTableDDID,"highlightBGColor",colorPalette[1])
5564 changeProperty(editorSPropCSTableDDID,"visible",false)
5565 changeProperty(editorSPropCSTableDDID,"expandedMaxHeight",designerY-8)
5566 changeProperty(editorSPropCSTableDDID,"onChangeFunction",function(ID,selection)
5567 if selection==table.getn(getProperty(editorSPropCSTableDDID,"entries")) then
5568 changeProperty(editorSPropsID,"visible",false)
5569 changeProperty(editorSPropsMenuID,"enabled",false)
5570 changeProperty(editorSUndoID,"visible",false)
5571 changeProperty(editorSRedoID,"visible",false)
5572 changeProperty(editorSPropResetButtonID,"visible",false)
5573 changeProperty(editorSPropConsoleMsgID,"visible",true)
5574 changeProperty(editorSPropCSChangeID,"visible",false)
5575 changeProperty(editorSPropCSRemoveID,"visible",false)
5576 changeProperty(editorSPropCSTableDDID,"enabled",false)
5577 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5578
5579 refresh()
5580
5581 term.setBackgroundColor(colorPalette[2])
5582 term.setTextColor(colorPalette[1])
5583 term.clear()
5584 term.setCursorPos(1,1)
5585 print("Enter a new x coordinate:")
5586
5587 local input
5588 local valid = false
5589 repeat
5590 input = read()
5591 if tonumber(input)~=nil then
5592 input = (tonumber(input))
5593 valid = true
5594 else
5595 print("Must be a number!")
5596 end
5597 until valid
5598
5599 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])][input] = 0
5600
5601 changeProperty(editorSPropsID,"visible",true)
5602 changeProperty(editorSPropsMenuID,"enabled",true)
5603 changeProperty(editorSUndoID,"visible",true)
5604 changeProperty(editorSRedoID,"visible",true)
5605 changeProperty(editorSPropResetButtonID,"visible",true)
5606 changeProperty(editorSPropConsoleMsgID,"visible",false)
5607 changeProperty(editorSPropCSChangeID,"visible",true)
5608 changeProperty(editorSPropCSRemoveID,"visible",true)
5609 changeProperty(editorSPropCSTableDDID,"enabled",true)
5610 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5611
5612 getProperty(editorSPropCSTableDDID,"entries")[selection] = input..":0"
5613
5614 pcall(getProperty(editorSPropCSChangeID,"onActiveFunction"))
5615 end
5616 end)
5617 addElementToScreen(editorSPropCSTableDDID,editorSID,1,7)
5618
5619 --type CSDesigns
5620 addDropDownMenu(editorSPropCSDesignsIndexDDID,{"Use"})
5621 changeProperty(editorSPropCSDesignsIndexDDID,"selectionID",1)
5622 changeProperty(editorSPropCSDesignsIndexDDID,"expanded",false)
5623 changeProperty(editorSPropCSDesignsIndexDDID,"highlightID",nil)
5624 changeProperty(editorSPropCSDesignsIndexDDID,"borderThickness",1)
5625 changeProperty(editorSPropCSDesignsIndexDDID,"borderColor",colorPalette[3])
5626 changeProperty(editorSPropCSDesignsIndexDDID,"highlightTextColor",colorPalette[2])
5627 changeProperty(editorSPropCSDesignsIndexDDID,"highlightBGColor",colorPalette[1])
5628 changeProperty(editorSPropCSDesignsIndexDDID,"visible",false)
5629 changeProperty(editorSPropCSDesignsIndexDDID,"width",8)
5630 changeProperty(editorSPropCSDesignsIndexDDID,"expandedMaxHeight",designerY-8)
5631 changeProperty(editorSPropCSDesignsIndexDDID,"onExpandFunction",function()
5632 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))==nil then
5633 local array = {}
5634 local array2 = {}
5635 for name,data in ipairs(getProperty(editorSElementID,"graphTables")) do
5636 array[name] = name..""
5637 array2[name] = {}
5638 end
5639 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),array2)
5640 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil,copyOfCSDesignsTable(array2))
5641 changeProperty(editorSPropCSDesignsIndexDDID,"entries",array)
5642 end
5643 end)
5644 changeProperty(editorSPropCSDesignsIndexDDID,"onChangeFunction",function(id,selection)
5645 changeProperty(editorSPropCSDesignsDDID,"visible",true)
5646 pcall(getProperty(editorSPropCSDesignsDDID,"onChangeFunction"))
5647 end)
5648 addElementToScreen(editorSPropCSDesignsIndexDDID,editorSID,relX(50,editorSID)+1-9,7)
5649
5650 addDropDownMenu(editorSPropCSDesignsDDID,{"color","BG","char"})
5651 changeProperty(editorSPropCSDesignsDDID,"selectionID",1)
5652 changeProperty(editorSPropCSDesignsDDID,"expanded",false)
5653 changeProperty(editorSPropCSDesignsDDID,"highlightID",nil)
5654 changeProperty(editorSPropCSDesignsDDID,"borderThickness",1)
5655 changeProperty(editorSPropCSDesignsDDID,"borderColor",colorPalette[3])
5656 changeProperty(editorSPropCSDesignsDDID,"highlightTextColor",colorPalette[2])
5657 changeProperty(editorSPropCSDesignsDDID,"highlightBGColor",colorPalette[1])
5658 changeProperty(editorSPropCSDesignsDDID,"visible",false)
5659 changeProperty(editorSPropCSDesignsDDID,"width",9)
5660 changeProperty(editorSPropCSDesignsDDID,"expandedMaxHeight",designerY-8)
5661 changeProperty(editorSPropCSDesignsDDID,"onChangeFunction",function(id,selection)
5662 if selection==nil then
5663 selection = getProperty(editorSPropCSDesignsDDID,"selectionID")
5664 end
5665 if selection~=3 then
5666 changeProperty(editorSPropCSChangeID,"visible",false)
5667 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5668 changeProperty(editorSPropColorPickID,"visible",true)
5669 local color = nil
5670 if selection==1 then
5671 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["color"]~=nil then
5672 color = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["color"]
5673 end
5674 else
5675 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["BGColor"]~=nil then
5676 color = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["BGColor"]
5677 end
5678 end
5679 changeProperty(editorSPropColorPickID,"selection",color)
5680 else
5681 changeProperty(editorSPropCSChangeID,"visible",true)
5682 changeProperty(editorSPropCSDesignsDisplayID,"visible",true)
5683 changeProperty(editorSPropColorPickID,"visible",false)
5684 end
5685 end)
5686 addElementToScreen(editorSPropCSDesignsDDID,editorSID,relX(50,editorSID)+1-10,designerY-8)
5687
5688 addDynamicTextBox(editorSPropCSDesignsDisplayID,"Current char: $var")
5689 changeProperty(editorSPropCSDesignsDisplayID,"width",relX(50,editorSID)-1-9)
5690 changeProperty(editorSPropCSDesignsDisplayID,"variables",{["var"]=function() return getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["character"] or "nil" end})
5691 changeProperty(editorSPropCSDesignsDisplayID,"textAlignmentHorizontal","center")
5692 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5693 addElementToScreen(editorSPropCSDesignsDisplayID,editorSID,1,7)
5694
5695 --type linesArray
5696 addDynamicTextBox(editorSPropPicEditButtonID,"Edit")
5697 changeProperty(editorSPropPicEditButtonID,"BGColor",colorPalette[3])
5698 changeProperty(editorSPropPicEditButtonID,"textColor",colorPalette[2])
5699 changeProperty(editorSPropPicEditButtonID,"borderColor",colorPalette[1])
5700 changeProperty(editorSPropPicEditButtonID,"borderThickness",1)
5701 changeProperty(editorSPropPicEditButtonID,"onClickMode","flash")
5702 changeProperty(editorSPropPicEditButtonID,"width",relX(50,editorSID)-1)
5703 changeProperty(editorSPropPicEditButtonID,"activeBGColor",colorPalette[2])
5704 changeProperty(editorSPropPicEditButtonID,"activeTextColor",colorPalette[3])
5705 changeProperty(editorSPropPicEditButtonID,"visible",false)
5706 changeProperty(editorSPropPicEditButtonID,"onActiveFunction",function()
5707 addElementToScreen(editorSElementID,pictureESID,editorSElementX,editorSElementY)
5708 addElementToScreen(editorSUndoID,pictureESID,relX(50,editorSID)-6,designerY)
5709 addElementToScreen(editorSRedoID,pictureESID,relX(50,editorSID)+1,designerY)
5710 addElementToScreen(pictureESButtonBackID,pictureESID,1,designerY)
5711 addElementToScreen(pictureESCoordsDisplayID,pictureESID,designerX-11,designerY)
5712 addElementToScreen(pictureESControlPicID,pictureESID,designerX-5,designerY-5)
5713 addElementToScreen(pictureESIndicatorID,pictureESID,editorSElementX,editorSElementY)
5714 addElementToScreen(pictureESUseDefault2ID,pictureESID,designerX-8,designerY-7)
5715 addElementToScreen(pictureESColorPick2ID,pictureESID,designerX-5,designerY-11)
5716 addElementToScreen(pictureESUseDefault1ID,pictureESID,designerX-8,designerY-12)
5717 addElementToScreen(pictureESColorPick1ID,pictureESID,designerX-5,designerY-16)
5718 addElementToScreen(pictureESChangeID,pictureESID,designerX-7,designerY-18)
5719 addElementToScreen(pictureESTransparentID,pictureESID,designerX-12,designerY-1)
5720 pictureESCurrentX = 1
5721 pictureESCurrentY = 1
5722 setProcessClickEventFunction(function(type_,id,part)
5723 if id==editorSElementID then
5724 pictureESCurrentX = tonumber(string.sub(part,1,string.find(part,":")-1))
5725 pictureESCurrentY = tonumber(string.sub(part,string.find(part,":")+1))
5726 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5727 onPixelSelecChange()
5728 refresh()
5729 end
5730 if id==pictureESControlPicID then
5731 --y gets smaller
5732 if part=="3:1" then
5733 pictureESCurrentY = math.max(pictureESCurrentY-1,1)
5734 end
5735 --y gets bigger
5736 if part=="3:3" then
5737 pictureESCurrentY = math.min(pictureESCurrentY+1,getProperty(editorSElementID,"height"))
5738 end
5739 --x gets smaller
5740 if part=="1:2" then
5741 pictureESCurrentX = math.max(pictureESCurrentX-1,1)
5742 end
5743 --x gets bigger
5744 if part=="5:2" then
5745 pictureESCurrentX = math.min(pictureESCurrentX+1,getProperty(editorSElementID,"width"))
5746 end
5747 if part=="3:2" then
5748 changeProperty(pictureESIndicatorID,"visible",not getProperty(pictureESIndicatorID,"visible"))
5749 end
5750
5751 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5752 onPixelSelecChange()
5753 refresh()
5754 end
5755 end)
5756
5757 setProcessEventFunction(function(event,var1)
5758 if name=="timer" then
5759 if var1==saveTimerID then
5760 saveElement(editorSElementID,editorSElementType)
5761 saveTimerID = os.startTimer(180)
5762 lastSave = os.clock()
5763 end
5764 end
5765 if event=="key" then
5766 if var1==200 then
5767 pictureESCurrentY = math.max(pictureESCurrentY-1,1)
5768 end
5769 if var1==208 then
5770 pictureESCurrentY = math.min(pictureESCurrentY+1,getProperty(editorSElementID,"height"))
5771 end
5772 if var1==203 then
5773 pictureESCurrentX = math.max(pictureESCurrentX-1,1)
5774 end
5775 if var1==205 then
5776 pictureESCurrentX = math.min(pictureESCurrentX+1,getProperty(editorSElementID,"width"))
5777 end
5778 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5779 onPixelSelecChange()
5780 refresh()
5781 end
5782 if event=="char" then
5783 local new = var1
5784 local s = getPixelString()
5785 if string.len(s)==0 then
5786 writePixelString("*:#:"..new)
5787 end
5788 if string.len(s)==1 then
5789 writePixelString("*:"..s..":"..new)
5790 end
5791 if string.len(s)==5 then
5792 writePixelString(string.sub(s,1,4)..new)
5793 end
5794 pictureESCurrentX = math.min(pictureESCurrentX+1,getProperty(editorSElementID,"width"))
5795 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5796 onPixelSelecChange()
5797 refresh()
5798 end
5799 if event=="paste" then
5800 for i=1,string.len(var1) do
5801 os.queueEvent("char",string.sub(var1,i,i))
5802 end
5803 end
5804 end)
5805
5806 setDesignerScreen(pictureESID)
5807 onPixelSelecChange()
5808 fullRefresh()
5809 end)
5810 addElementToScreen(editorSPropPicEditButtonID,editorSID,1,7)
5811
5812 addScreen(pictureESID,designerX,designerY,colorPalette[1],colorPalette[2])
5813 addDynamicTextBox(pictureESButtonBackID,"<Back>")
5814 changeProperty(pictureESButtonBackID,"onClickMode","flash")
5815 changeProperty(pictureESButtonBackID,"onActiveFunction",function()
5816 removeElementFromScreen(editorSElementID,pictureESID)
5817 removeElementFromScreen(editorSUndoID,pictureESID)
5818 removeElementFromScreen(editorSRedoID,pictureESID)
5819 removeElementFromScreen(pictureESButtonBackID,pictureESID)
5820 removeElementFromScreen(pictureESCoordsDisplayID,pictureESID)
5821 removeElementFromScreen(pictureESControlPicID,pictureESID)
5822 removeElementFromScreen(pictureESIndicatorID,pictureESID)
5823 removeElementFromScreen(pictureESColorPick2ID,pictureESID)
5824 removeElementFromScreen(pictureESUseDefault2ID,pictureESID)
5825 removeElementFromScreen(pictureESColorPick1ID,pictureESID)
5826 removeElementFromScreen(pictureESUseDefault1ID,pictureESID)
5827 removeElementFromScreen(pictureESTransparentID,pictureESID)
5828 removeElementFromScreen(pictureESChangeID,pictureESID)
5829 setProcessEventFunction(processEditorEvents)
5830 setProcessClickEventFunction(nil)
5831
5832 setDesignerScreen(editorSID)
5833 fullRefresh()
5834 end)
5835
5836 local c = colorsArrayNumToString[colorPalette[3]]
5837 addDynamicTextBox(pictureESCoordsDisplayID,"Pixel: $x:$y")
5838 changeProperty(pictureESCoordsDisplayID,"textAlignmentHorizontal","right")
5839 changeProperty(pictureESCoordsDisplayID,"width",12)
5840 changeProperty(pictureESCoordsDisplayID,"variables",{["x"]=function() return pictureESCurrentX end,["y"]=function() return pictureESCurrentY end})
5841
5842 addPicture(pictureESControlPicID,5,3,{";;*:#:^;;;","*:#:<;;"..c..":#:+;;*:#:>;",";;*:#:v;;;"})
5843 addDynamicTextBox(pictureESIndicatorID," ")
5844 changeProperty(pictureESIndicatorID,"BGColor",colorPalette[3])
5845
5846 addDynamicTextBox(pictureESUseDefault1ID,"<Default>")
5847 changeProperty(pictureESUseDefault1ID,"onClickMode","toggle")
5848 changeProperty(pictureESUseDefault1ID,"activeBGColor",colorPalette[1])
5849 changeProperty(pictureESUseDefault1ID,"activeTextColor",colorPalette[2])
5850 changeProperty(pictureESUseDefault1ID,"onActiveFunction",function()
5851 changeProperty(pictureESTransparentID,"active",false)
5852 changeProperty(pictureESColorPick1ID,"selection",nil)
5853 local s = getPixelString()
5854 if string.len(s)==0 then
5855 writePixelString("*:#: ")
5856 end
5857 if string.len(s)==1 then
5858 writePixelString("*:"..s..": ")
5859 end
5860 if string.len(s)==5 then
5861 writePixelString("*"..string.sub(s,2))
5862 end
5863 refresh()
5864 end)
5865 changeProperty(pictureESUseDefault1ID,"onInactiveFunction",function()
5866 changeProperty(pictureESUseDefault1ID,"active",true)
5867 refresh()
5868 end)
5869
5870 addDynamicTextBox(pictureESUseDefault2ID,"<Default>")
5871 changeProperty(pictureESUseDefault2ID,"onClickMode","toggle")
5872 changeProperty(pictureESUseDefault2ID,"activeBGColor",colorPalette[1])
5873 changeProperty(pictureESUseDefault2ID,"activeTextColor",colorPalette[2])
5874 changeProperty(pictureESUseDefault2ID,"onActiveFunction",function()
5875 changeProperty(pictureESTransparentID,"active",false)
5876 changeProperty(pictureESColorPick2ID,"selection",nil)
5877 local s = getPixelString()
5878 if string.len(s)==0 or string.len(s)==1 then
5879 writePixelString("#")
5880 end
5881 if string.len(s)==5 then
5882 writePixelString(string.sub(s,1,2).."#"..string.sub(s,4,5))
5883 end
5884 refresh()
5885 end)
5886 changeProperty(pictureESUseDefault2ID,"onInactiveFunction",function()
5887 changeProperty(pictureESUseDefault2ID,"active",true)
5888 refresh()
5889 end)
5890
5891 addColorPicker(pictureESColorPick1ID,nil)
5892 changeProperty(pictureESColorPick1ID,"onChangeFunction",function(ID,selection)
5893 changeProperty(pictureESUseDefault1ID,"active",false)
5894 changeProperty(pictureESTransparentID,"active",false)
5895 local s = getPixelString()
5896 if string.len(s)==0 then
5897 writePixelString(colorsArrayNumToString[selection]..":#: ")
5898 end
5899 if string.len(s)==1 then
5900 writePixelString(colorsArrayNumToString[selection]..":"..s..": ")
5901 end
5902 if string.len(s)==5 then
5903 writePixelString(colorsArrayNumToString[selection]..string.sub(s,2))
5904 end
5905 refresh()
5906 end)
5907
5908 addColorPicker(pictureESColorPick2ID,nil)
5909 changeProperty(pictureESColorPick2ID,"onChangeFunction",function(ID,selection)
5910 changeProperty(pictureESUseDefault2ID,"active",false)
5911 changeProperty(pictureESTransparentID,"active",false)
5912 local s = getPixelString()
5913 if string.len(s)==0 or string.len(s)==1 then
5914 writePixelString(colorsArrayNumToString[selection])
5915 end
5916 if string.len(s)==5 then
5917 writePixelString(string.sub(s,1,2)..colorsArrayNumToString[selection]..string.sub(s,4,5))
5918 end
5919 refresh()
5920 end)
5921
5922 addDynamicTextBox(pictureESChangeID,"Char: $c <Change>")
5923 changeProperty(pictureESChangeID,"onClickMode","flash")
5924 changeProperty(pictureESChangeID,"variables",{["c"]=function() return " " end})
5925 changeProperty(pictureESChangeID,"onActiveFunction",function()
5926 changeProperty(pictureESChangeID,"content","Check term!")
5927
5928 term.setBackgroundColor(colorPalette[2])
5929 term.setTextColor(colorPalette[1])
5930 term.clear()
5931 term.setCursorPos(1,1)
5932
5933 print("Enter a new character for coordinate "..pictureESCurrentX..":"..pictureESCurrentY)
5934
5935 local new = read()
5936 if new=="" then new = " " end
5937 new = string.sub(new,1,1)
5938
5939 local s = getPixelString()
5940 if string.len(s)==0 then
5941 writePixelString("*:#:"..new)
5942 end
5943 if string.len(s)==1 then
5944 writePixelString("*:"..s..":"..new)
5945 end
5946 if string.len(s)==5 then
5947 writePixelString(string.sub(s,1,4)..new)
5948 end
5949
5950 changeProperty(pictureESChangeID,"content","Char: $c <Change>")
5951 onPixelSelecChange()
5952 fullRefresh()
5953 end)
5954
5955 addDynamicTextBox(pictureESTransparentID,"<Transparent>")
5956 changeProperty(pictureESTransparentID,"onClickMode","toggle")
5957 changeProperty(pictureESTransparentID,"activeBGColor",colorPalette[1])
5958 changeProperty(pictureESTransparentID,"activeTextColor",colorPalette[2])
5959 changeProperty(pictureESTransparentID,"onActiveFunction",function()
5960 writePixelString("")
5961 changeProperty(pictureESUseDefault1ID,"active",false)
5962 changeProperty(pictureESUseDefault2ID,"active",false)
5963 end)
5964 changeProperty(pictureESTransparentID,"onInactiveFunction",function()
5965 writePixelString("#")
5966 changeProperty(pictureESUseDefault1ID,"active",false)
5967 changeProperty(pictureESUseDefault2ID,"active",true)
5968 end)
5969
5970 addDropDownMenu(editorSPropsMenuID,nil,1)
5971 changeProperty(editorSPropsMenuID,"selectionID",1)
5972 changeProperty(editorSPropsMenuID,"expanded",false)
5973 changeProperty(editorSPropsMenuID,"highlightID",nil)
5974 changeProperty(editorSPropsMenuID,"borderThickness",1)
5975 changeProperty(editorSPropsMenuID,"borderColor",colorPalette[3])
5976 changeProperty(editorSPropsMenuID,"highlightTextColor",colorPalette[2])
5977 changeProperty(editorSPropsMenuID,"highlightBGColor",colorPalette[1])
5978 changeProperty(editorSPropsMenuID,"visible",false)
5979 changeProperty(editorSPropsMenuID,"width",relX(50,editorSID)-1)
5980 changeProperty(editorSPropsMenuID,"expandedMaxHeight",designerY-4)
5981 changeProperty(editorSPropsMenuID,"onChangeFunction",function() changeProperty(editorSDescID,"content",elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["desc"])
5982 changeProperty(editorSPropColorPickID,"visible",false)
5983 changeProperty(editorSPropDDMenuID,"visible",false)
5984 changeProperty(editorSPropDisplayID,"visible",false)
5985 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
5986 changeProperty(editorSPropColorPickID,"selection",nil)
5987 changeProperty(editorSPropColorsArrayDDID,"visible",false)
5988 changeProperty(editorSPropStringArrayDDID,"visible",false)
5989 changeProperty(editorSPropNavMenuID,"visible",false)
5990 changeProperty(editorSPropNavMenuHintID,"visible",false)
5991 changeProperty(editorSPropCSTableIndexDDID,"visible",false)
5992 changeProperty(editorSPropCSTableDDID,"visible",false)
5993 changeProperty(editorSPropCSChangeID,"visible",false)
5994 changeProperty(editorSPropCSRemoveID,"visible",false)
5995 changeProperty(editorSPropCSDesignsDDID,"visible",false)
5996 changeProperty(editorSPropCSDesignsIndexDDID,"visible",false)
5997 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5998 changeProperty(editorSPropPicEditButtonID,"visible",false)
5999
6000 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]~="manual" then
6001 changeProperty(editorSPropResetButtonID,"visible",true)
6002 else
6003 changeProperty(editorSPropResetButtonID,"visible",false)
6004 end
6005 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="color" then
6006 changeProperty(editorSPropColorPickID,"visible",true)
6007 changeProperty(editorSPropColorPickID,"selection",getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
6008 end
6009 if string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],1,3)=="DDM" then
6010 changeProperty(editorSPropDDMenuID,"visible",true)
6011 local array = {""}
6012 local menusS = string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],5)
6013 while string.find(menusS,":") do
6014 table.insert(array,string.sub(menusS,1,string.find(menusS,":")-1))
6015 menusS = string.sub(menusS,string.find(menusS,":")+1)
6016 end
6017 table.insert(array,menusS)
6018 changeProperty(editorSPropDDMenuID,"entries",array)
6019 changeProperty(editorSPropDDMenuID,"selectionID",1)
6020 for i,entry in ipairs(array) do
6021 if entry==getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])) then
6022 changeProperty(editorSPropDDMenuID,"selectionID",i)
6023 end
6024 end
6025 end
6026 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="string" then
6027 changeProperty(editorSPropDisplayID,"visible",true)
6028 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
6029 end
6030 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="colorsArray" then
6031 changeProperty(editorSPropColorsArrayDDID,"visible",true)
6032 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))~=nil then
6033 local array = {}
6034 for i=1,table.getn(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
6035 array[i] = i
6036 end
6037 changeProperty(editorSPropColorsArrayDDID,"entries",array)
6038 pcall(getProperty(editorSPropColorsArrayDDID,"onChangeFunction"),editorSPropColorsArrayDDID,1)
6039 else
6040 changeProperty(editorSPropColorsArrayDDID,"entries",{"Use"})
6041 end
6042 end
6043 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="stringArray" then
6044 changeProperty(editorSPropStringArrayDDID,"visible",true)
6045 local array = {}
6046 for i,current in ipairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
6047 table.insert(array,current)
6048 end
6049 table.insert(array,"+add")
6050 changeProperty(editorSPropStringArrayDDID,"entries",array)
6051 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
6052 end
6053 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="navMenuArray" then
6054 changeProperty(editorSPropNavMenuID,"menuArray",prepNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),{}))
6055 changeProperty(editorSPropNavMenuID,"visible",true)
6056 changeProperty(editorSPropNavMenuID,"expanded",false)
6057 changeProperty(editorSPropNavMenuHintID,"visible",true)
6058 end
6059 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSTable" then
6060 changeProperty(editorSPropCSTableIndexDDID,"visible",true)
6061 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))~=nil then
6062 local array = {}
6063 for i,data in ipairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
6064 array[i] = ""..i
6065 end
6066 table.insert(array,"+add")
6067 changeProperty(editorSPropCSTableIndexDDID,"entries",array)
6068 pcall(getProperty(editorSPropCSTableIndexDDID,"onChangeFunction"),editorSPropCSTableIndexDDID,getProperty(editorSPropCSTableIndexDDID,"selectionID"))
6069 else
6070 changeProperty(editorSPropCSTableIndexDDID,"entries",{"Use"})
6071 end
6072 end
6073 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
6074 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))~=nil then
6075 local array = {}
6076 for i,data in ipairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
6077 array[i] = ""..i
6078 end
6079 changeProperty(editorSPropCSDesignsIndexDDID,"entries",array)
6080 changeProperty(editorSPropCSDesignsIndexDDID,"visible",true)
6081 pcall(getProperty(editorSPropCSDesignsIndexDDID,"onChangeFunction"))
6082 else
6083 if getProperty(editorSElementID,"graphTables")~=nil then
6084 changeProperty(editorSPropCSDesignsIndexDDID,"visible",true)
6085 changeProperty(editorSPropCSDesignsIndexDDID,"entries",{"Use"})
6086 end
6087 end
6088 end
6089 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="picArray" then
6090 changeProperty(editorSPropPicEditButtonID,"visible",true)
6091 end
6092 end)
6093 addElementToScreen(editorSPropsMenuID,editorSID,1,3)
6094
6095 addDynamicTextBox(editorSHideUIID,"<Hide UI>")
6096 changeProperty(editorSHideUIID,"onClickMode","flash")
6097 changeProperty(editorSHideUIID,"activeDuration",3)
6098 changeProperty(editorSHideUIID,"onActiveFunction",function()
6099 changeProperty(editorSExitID,"visible",false)
6100 changeProperty(editorSPropsID,"visible",false)
6101 changeProperty(editorSUndoID,"visible",false)
6102 changeProperty(editorSRelocateButtonID,"visible",false)
6103 changeProperty(editorSLastSaveID,"visible",false)
6104 changeProperty(editorSRedoID,"visible",false)
6105 changeProperty(editorSHideUIID,"visible",false) end)
6106 changeProperty(editorSHideUIID,"onInactiveFunction",function()
6107 changeProperty(editorSExitID,"visible",true)
6108 changeProperty(editorSPropsID,"visible",true)
6109 changeProperty(editorSUndoID,"visible",true)
6110 changeProperty(editorSRelocateButtonID,"visible",true)
6111 changeProperty(editorSLastSaveID,"visible",true)
6112 changeProperty(editorSRedoID,"visible",true)
6113 changeProperty(editorSHideUIID,"visible",true) end)
6114 addElementToScreen(editorSHideUIID,editorSID,12,1)
6115
6116 setDesignerScreen(editorSID)
6117 refresh()
6118end
6119
6120function getPixelString(x_,y_)
6121 local x
6122 local y
6123 if x_==nil then x = pictureESCurrentX else x = x_ end
6124 if y_==nil then y = pictureESCurrentY else y = y_ end
6125 local s = getProperty(editorSElementID,"linesArray")[y]
6126 for i=1,x-1 do
6127 s = string.sub(s,string.find(s,";")+1)
6128 end
6129 return string.sub(s,1,string.find(s,";")-1)
6130end
6131
6132function writePixelString(new,x_,y_,bool)
6133 local x
6134 local y
6135 if x_==nil then x = pictureESCurrentX else x = x_ end
6136 if y_==nil then y = pictureESCurrentY else y = y_ end
6137 if not bool then
6138 addToUndoRedoTable("linesArray",function(prop,var1,var2,var3,var4) writePixelString(var1,var3,var4,true) end, function(prop,var1,var2,var3,var4) writePixelString(var2,var3,var4,true) end,getPixelString(x,y),new,x,y)
6139 end
6140 local s = getProperty(editorSElementID,"linesArray")[y]
6141 local count = 0
6142 for i=1,x-1 do
6143 count = count + string.find(s,";")
6144 s = string.sub(s,string.find(s,";")+1)
6145 end
6146 s = string.sub(s,string.find(s,";")+1)
6147 getProperty(editorSElementID,"linesArray")[y] = string.sub(getProperty(editorSElementID,"linesArray")[y],1,count) ..new..";"..s
6148end
6149
6150function onPixelSelecChange()
6151 if editorSElementType == "picture" then
6152 local s = getPixelString()
6153 if string.len(s)==0 then
6154 changeProperty(pictureESColorPick1ID,"selection",nil)
6155 changeProperty(pictureESColorPick2ID,"selection",nil)
6156 changeProperty(pictureESUseDefault1ID,"active",false)
6157 changeProperty(pictureESUseDefault2ID,"active",false)
6158 changeProperty(pictureESTransparentID,"active",true)
6159 changeProperty(pictureESChangeID,"variables",{["c"]=function() return " " end})
6160 end
6161 if string.len(s)==1 then
6162 changeProperty(pictureESColorPick1ID,"selection",nil)
6163 changeProperty(pictureESUseDefault1ID,"active",false)
6164 changeProperty(pictureESTransparentID,"active",false)
6165 changeProperty(pictureESChangeID,"variables",{["c"]=function() return " " end})
6166
6167 if s =="#" then
6168 changeProperty(pictureESUseDefault2ID,"active",true)
6169 changeProperty(pictureESColorPick2ID,"selection",nil)
6170 else
6171 changeProperty(pictureESUseDefault2ID,"active",false)
6172 changeProperty(pictureESColorPick2ID,"selection",colorsArrayStrToNum[s])
6173 end
6174 end
6175 if string.len(s)==5 then
6176 changeProperty(pictureESTransparentID,"active",false)
6177 changeProperty(pictureESChangeID,"variables",{["c"]=function() return string.sub(s,5) end})
6178
6179 if string.sub(s,3,3) =="#" then
6180 changeProperty(pictureESUseDefault2ID,"active",true)
6181 changeProperty(pictureESColorPick2ID,"selection",nil)
6182 else
6183 changeProperty(pictureESUseDefault2ID,"active",false)
6184 changeProperty(pictureESColorPick2ID,"selection",colorsArrayStrToNum[string.sub(s,3,3)])
6185 end
6186
6187 if string.sub(s,1,1) =="*" then
6188 changeProperty(pictureESUseDefault1ID,"active",true)
6189 changeProperty(pictureESColorPick1ID,"selection",nil)
6190 else
6191 changeProperty(pictureESUseDefault1ID,"active",false)
6192 changeProperty(pictureESColorPick1ID,"selection",colorsArrayStrToNum[string.sub(s,1,1)])
6193 end
6194 end
6195 end
6196end
6197
6198function prepNavMenu(array,new,first)
6199 local number
6200 if first==1 then
6201 new[1]={["text"]="<- edit"}
6202 else
6203 first = 0
6204 end
6205 for i,data in ipairs(array) do
6206 new[i+first] = {["text"]=data["text"]}
6207 if data["submenu"]~=nil then
6208 new[i+first]["submenu"] = {}
6209 prepNavMenu(data["submenu"],new[i+first]["submenu"],1)
6210 else
6211 new[i+first]["submenu"] = {[1]={["text"]="<- edit"},[2]={["text"]="+add sub"}}
6212 end
6213 number = i+first
6214 end
6215 new[number+1] = {["text"]="+add"}
6216 return new
6217end
6218
6219function copyOfSimpleArray(old,new)
6220 if new==nil then new = {} end
6221 for i,data in ipairs(old) do
6222 new[i] = data
6223 end
6224 return new
6225end
6226
6227function copyOfCSTable(old,new)
6228 if new==nil then new = {} end
6229 for i,data in ipairs(old) do
6230 new[i] = {}
6231 for x,y in pairs(old[i]) do
6232 new[i][x] = y
6233 end
6234 end
6235 return new
6236end
6237
6238function copyOfCSDesignsTable(old,new)
6239 if new==nil then new = {} end
6240 for i,data in ipairs(old) do
6241 new[i] = {}
6242 new[i]["color"] = old[i]["color"]
6243 new[i]["BGColor"] = old[i]["BGColor"]
6244 new[i]["character"] = old[i]["character"]
6245 end
6246 return new
6247end
6248
6249function copyOfNavMenu(old,new)
6250 if new==nil then new = {} end
6251 for i,data in ipairs(old) do
6252 new[i] = {["text"]=data["text"]}
6253 if data["submenu"]~=nil then
6254 new[i]["submenu"] = {}
6255 copyOfNavMenu(data["submenu"],new[i]["submenu"])
6256 end
6257 end
6258 return new
6259end
6260
6261function refreshPropsMenu()
6262 local array = {}
6263 for name,data in pairs(elementProperties[editorSElementType]) do
6264 table.insert(array,name)
6265 end
6266 changeProperty(editorSPropsMenuID,"entries",array)
6267 changeProperty(editorSDescID,"content",elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["desc"])
6268end
6269
6270function relocateOn()
6271 changeProperty(editorSElementID,"enabled",false)
6272 changeProperty(editorSExitID,"enabled",false)
6273 changeProperty(editorSPropsID,"enabled",false)
6274 changeProperty(editorSUndoID,"enabled",false)
6275 changeProperty(editorSRedoID,"enabled",false)
6276 changeProperty(editorSHideUIID,"enabled",false)
6277 setProcessEventFunction(relocate)
6278end
6279
6280function processEditorEvents(name,var1,var2,var3)
6281 if name=="timer" then
6282 if var1==saveTimerID then
6283 saveElement(editorSElementID,editorSElementType)
6284 saveTimerID = os.startTimer(180)
6285 lastSave = os.clock()
6286 end
6287 end
6288 if name=="key" then
6289 if var1==31 and CTRLHeld then
6290 saveElement(editorSElementID,editorSElementType)
6291 saveTimerID = os.startTimer(180)
6292 lastSave = os.clock()
6293 refresh()
6294 end
6295 if var1==44 and CTRLHeld then
6296 processClickEvent(terminalID,getPos(editorSUndoID,editorSID))
6297 end
6298 if var1==21 and CTRLHeld then
6299 processClickEvent(terminalID,getPos(editorSRedoID,editorSID))
6300 end
6301 end
6302end
6303
6304function relocate(name,var1,var2,var3)
6305 if name=="monitor_touch" or name=="mouse_click" or name=="mouse_drag" then
6306 changePos(editorSElementID,editorSID,var2,var3)
6307 editorSElementX = var2
6308 editorSElementY = var3
6309 refresh()
6310 end
6311 processEditorEvents(name,var1,var2,var3)
6312end
6313
6314function relocateOff()
6315 changeProperty(editorSElementID,"enabled",true)
6316 changeProperty(editorSExitID,"enabled",true)
6317 changeProperty(editorSPropsID,"enabled",true)
6318 changeProperty(editorSUndoID,"enabled",true)
6319 changeProperty(editorSRedoID,"enabled",true)
6320 changeProperty(editorSHideUIID,"enabled",true)
6321 setProcessEventFunction(processEditorEvents)
6322end
6323
6324function addToUndoRedoTable(prop,undo,redo,var1,var2,var3,var4,var5)
6325 local n = undoRedoIndex+1
6326 while undoRedoTable[n]~=nil do
6327 undoRedoTable[n]=nil
6328 n = n + 1
6329 end
6330 table.insert(undoRedoTable,{["prop"]=prop,["undo"]=undo,["redo"]=redo,["var1"]=var1,["var2"]=var2,["var3"]=var3,["var4"]=var4,["var5"]=var5})
6331 undoRedoIndex = table.getn(undoRedoTable)
6332end
6333
6334function startDesigner(ID)
6335 setDesignerScreen(ID)
6336 designerSID = ID
6337 designerSmaxX = screens[ID]["sizeX"]
6338 designerSmaxY = screens[ID]["sizeY"]
6339 designerSSelection = ""
6340 designerRefresh = true
6341 undoRedoTable = {}
6342 undoRedoIndex = 0
6343 lastSave = os.clock()
6344 saveTimerID = os.startTimer(180)
6345 setProcessEventFunction(function(name,var1,var2,var3,var4,var5)
6346 if name=="timer" and var1==saveTimerID then
6347 lastSave = os.clock()
6348 saveScreen(designerSID)
6349 saveTimerID = os.startTimer(180)
6350 end
6351 if name=="mouse_up" then
6352 designerSButtonHeld = false
6353 changeProperty(designerSIndicatorID,"BGColor",colorPalette[3])
6354 refresh()
6355 end
6356 if name=="mouse_drag" and designerSButtonHeld then
6357 if var2<=designerSmaxX and var3 <=designerSmaxY then
6358 local currX,currY = getPos(designerSIndicatorID,designerSID)
6359 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,var2,var3)
6360 changePos(designerSIndicatorID,designerSID,var2,var3)
6361 changePos(designerSSelection,designerSID,var2,var3)
6362 refresh()
6363 end
6364 end
6365 if name=="monitor_touch" then
6366 if var2<=designerSmaxX and var3 <=designerSmaxY and getProperty(designerSIndicatorID,"active") then
6367 local currX,currY = getPos(designerSIndicatorID,designerSID)
6368 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,var2,var3)
6369 changePos(designerSIndicatorID,designerSID,var2,var3)
6370 changePos(designerSSelection,designerSID,var2,var3)
6371 refresh()
6372 end
6373 end
6374 if name=="key" then
6375 local x,y = getPos(designerSControlPicID,designerSID)
6376 if var1==200 then
6377 processClickEvent(terminalID,x+2,y)
6378 end
6379 if var1==208 then
6380 processClickEvent(terminalID,x+2,y+2)
6381 end
6382 if var1==203 then
6383 processClickEvent(terminalID,x,y+1)
6384 end
6385 if var1==205 then
6386 processClickEvent(terminalID,x+4,y+1)
6387 end
6388 if var1==31 and CTRLHeld then
6389 lastSave = os.clock()
6390 saveScreen(designerSID)
6391 saveTimerID = os.startTimer(180)
6392 refresh()
6393 end
6394 if var1==44 and CTRLHeld then
6395 processClickEvent(terminalID,getPos(designerSUndoID,designerSID))
6396 end
6397 if var1==21 and CTRLHeld then
6398 processClickEvent(terminalID,getPos(designerSRedoID,designerSID))
6399 end
6400 end
6401 end)
6402
6403 if designerX>designerSmaxX then
6404 addDynamicTextBox(designerSBox1ID,"")
6405 changeProperty(designerSBox1ID,"BGColor",colorPalette[2])
6406 changeProperty(designerSBox1ID,"width",designerX-designerSmaxX)
6407 changeProperty(designerSBox1ID,"height",designerSmaxY)
6408 addElementToScreen(designerSBox1ID,designerSID,designerSmaxX+1,1)
6409 end
6410 if designerY>designerSmaxY then
6411 addDynamicTextBox(designerSBox2ID,"")
6412 changeProperty(designerSBox2ID,"BGColor",colorPalette[2])
6413 changeProperty(designerSBox2ID,"width",designerX)
6414 changeProperty(designerSBox2ID,"height",designerY-designerSmaxY)
6415 addElementToScreen(designerSBox2ID,designerSID,1,designerSmaxY+1)
6416 end
6417
6418 addDynamicTextBox(designerSExitButtonID,"<Save&Exit>")
6419 changeProperty(designerSExitButtonID,"onClickMode","flash")
6420 changeProperty(designerSExitButtonID,"textColor",colorPalette[1])
6421 changeProperty(designerSExitButtonID,"BGColor",colorPalette[2])
6422 changeProperty(designerSExitButtonID,"onActiveFunction",function()
6423 removeElementFromScreen(designerSLastSaveID,designerSID)
6424 removeElementFromScreen(designerSHideUIID,designerSID)
6425 removeElementFromScreen(designerSBox1ID,designerSID)
6426 removeElementFromScreen(designerSBox2ID,designerSID)
6427 removeElementFromScreen(designerSUndoID,designerSID)
6428 removeElementFromScreen(designerSRedoID,designerSID)
6429 removeElementFromScreen(designerSExitButtonID,designerSID)
6430 removeElementFromScreen(designerSAddID,designerSID)
6431 removeElementFromScreen(designerSRemoveID,designerSID)
6432 removeElementFromScreen(designerSSelectionID,designerSID)
6433 removeElementFromScreen(designerSControlPicID,designerSID)
6434 removeElementFromScreen(designerSIndicatorID,designerSID)
6435 removeElementFromScreen(elementsSDDMenu2ID,designerSID)
6436 changeProperty(elementsSDDMenu2ID,"onChangeFunction",nil)
6437 saveScreen(designerSID)
6438 designerSID = nil
6439 designerSSelection = ""
6440 lastSave = nil
6441 setDesignerScreen(screensSID)
6442 setProcessClickEventFunction(nil)
6443 setProcessEventFunction(nil)
6444 designerRefresh = false
6445 fullRefresh()
6446 end)
6447 addElementToScreen(designerSExitButtonID,designerSID,designerX-10,designerY)
6448
6449 addDynamicTextBox(designerSLastSaveID,"Last save: $time min ago.")
6450 changeProperty(designerSLastSaveID,"variables",{["time"]=function () return math.floor((os.clock()-lastSave)/60) end})
6451 changeProperty(designerSLastSaveID,"textColor",colorPalette[1])
6452 changeProperty(designerSLastSaveID,"BGColor",colorPalette[2])
6453 addElementToScreen(designerSLastSaveID,designerSID,designerX-9,1)
6454
6455 addDynamicTextBox(designerSHideUIID,"<Hide UI>")
6456 changeProperty(designerSHideUIID,"onClickMode","flash")
6457 changeProperty(designerSHideUIID,"activeDuration",3)
6458 changeProperty(designerSHideUIID,"textColor",colorPalette[1])
6459 changeProperty(designerSHideUIID,"BGColor",colorPalette[2])
6460 changeProperty(designerSHideUIID,"onActiveFunction",function()
6461 changeProperty(designerSLastSaveID,"visible",false)
6462 changeProperty(designerSIndicatorID,"visible",false)
6463 changeProperty(designerSUndoID,"visible",false)
6464 changeProperty(designerSRedoID,"visible",false)
6465 changeProperty(designerSAddID,"visible",false)
6466 changeProperty(designerSRemoveID,"visible",false)
6467 changeProperty(designerSSelectionID,"visible",false)
6468 changeProperty(designerSExitButtonID,"visible",false)
6469 changeProperty(designerSHideUIID,"visible",false)
6470 changeProperty(designerSControlPicID,"visible",false)
6471 end)
6472 changeProperty(designerSHideUIID,"onInactiveFunction",function()
6473 changeProperty(designerSLastSaveID,"visible",true)
6474 changeProperty(designerSUndoID,"visible",true)
6475 changeProperty(designerSRedoID,"visible",true)
6476 changeProperty(designerSAddID,"visible",true)
6477 changeProperty(designerSExitButtonID,"visible",true)
6478 changeProperty(designerSHideUIID,"visible",true) end)
6479 addElementToScreen(designerSHideUIID,designerSID,designerX-8,3)
6480
6481 addDynamicTextBox(designerSUndoID,"<Undo>")
6482 changeProperty(designerSUndoID,"onClickMode","flash")
6483 changeProperty(designerSUndoID,"textColor",colorPalette[1])
6484 changeProperty(designerSUndoID,"BGColor",colorPalette[2])
6485 changeProperty(designerSUndoID,"activeTextColor",colorPalette[2])
6486 changeProperty(designerSUndoID,"activeBGColor",colorPalette[1])
6487 changeProperty(designerSUndoID,"onActiveFunction",function()
6488 if undoRedoIndex~=0 then
6489 if type(undoRedoTable[undoRedoIndex]["undo"])=="function" then
6490 pcall(undoRedoTable[undoRedoIndex]["undo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
6491 refresh()
6492 end
6493 pcall(getProperty(designerSSelectionID,"onActiveFunction"))
6494 undoRedoIndex = undoRedoIndex - 1
6495 end
6496 end)
6497 screens[designerSID]["sizeX"] = designerX
6498 screens[designerSID]["sizeY"] = designerY
6499 addElementToScreen(designerSUndoID,designerSID,relX(50,designerSID)-6,designerY)
6500 screens[designerSID]["sizeX"] = designerSmaxX
6501 screens[designerSID]["sizeY"] = designerSmaxY
6502
6503 addDynamicTextBox(designerSRedoID,"<Redo>")
6504 changeProperty(designerSRedoID,"onClickMode","flash")
6505 changeProperty(designerSRedoID,"textColor",colorPalette[1])
6506 changeProperty(designerSRedoID,"BGColor",colorPalette[2])
6507 changeProperty(designerSRedoID,"activeTextColor",colorPalette[2])
6508 changeProperty(designerSRedoID,"activeBGColor",colorPalette[1])
6509 changeProperty(designerSRedoID,"onActiveFunction",function()
6510 if undoRedoIndex~=table.getn(undoRedoTable) then
6511 undoRedoIndex = undoRedoIndex + 1
6512 if type(undoRedoTable[undoRedoIndex]["redo"])=="function" then
6513 pcall(undoRedoTable[undoRedoIndex]["redo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
6514 refresh()
6515 end
6516 pcall(getProperty(designerSSelectionID,"onActiveFunction"))
6517 end
6518 end)
6519 screens[designerSID]["sizeX"] = designerX
6520 screens[designerSID]["sizeY"] = designerY
6521 addElementToScreen(designerSRedoID,designerSID,relX(50,designerSID)+1,designerY)
6522 screens[designerSID]["sizeX"] = designerSmaxX
6523 screens[designerSID]["sizeY"] = designerSmaxY
6524
6525 onLoadElementsS()
6526 addDynamicTextBox(designerSAddID,"<Add>")
6527 changeProperty(designerSAddID,"onClickMode","toggle")
6528 changeProperty(designerSAddID,"textColor",colorPalette[1])
6529 changeProperty(designerSAddID,"BGColor",colorPalette[2])
6530 changeProperty(designerSAddID,"activeTextColor",colorPalette[2])
6531 changeProperty(designerSAddID,"activeBGColor",colorPalette[1])
6532 changeProperty(designerSAddID,"onActiveFunction",function()
6533 addElementToScreen(elementsSDDMenu2ID,designerSID,2,2)
6534 changeProperty(elementsSDDMenu2ID,"onChangeFunction",function()
6535 removeElementFromScreen(elementsSDDMenu2ID,designerSID)
6536 addElementToScreen(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],designerSID,1,1)
6537 addToUndoRedoTable(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],removeElementFromScreen,addElementToScreen,designerSID,1,1)
6538 changeProperty(designerSAddID,"active",false)
6539 end)
6540 end)
6541 changeProperty(designerSAddID,"onInactiveFunction",function()
6542 removeElementFromScreen(elementsSDDMenu2ID,designerSID)
6543 end)
6544 addElementToScreen(designerSAddID,designerSID,1,designerY)
6545
6546 addDynamicTextBox(designerSRemoveID,"<Remove>")
6547 changeProperty(designerSRemoveID,"onClickMode","flash")
6548 changeProperty(designerSRemoveID,"textColor",colorPalette[1])
6549 changeProperty(designerSRemoveID,"BGColor",colorPalette[2])
6550 changeProperty(designerSRemoveID,"activeTextColor",colorPalette[2])
6551 changeProperty(designerSRemoveID,"activeBGColor",colorPalette[1])
6552 changeProperty(designerSRemoveID,"visible",false)
6553 changeProperty(designerSRemoveID,"onActiveFunction",function()
6554 local x,y = getPos(designerSSelection,designerSID)
6555 addToUndoRedoTable(designerSSelection,addElementToScreen,removeElementFromScreen,designerSID,x,y)
6556 removeElementFromScreen(designerSSelection,designerSID)
6557 pcall(getProperty(designerSSelectionID,"onActiveFunction"))
6558 end)
6559 addElementToScreen(designerSRemoveID,designerSID,7,designerY)
6560
6561 local b = colorsArrayNumToString[colorPalette[2]]
6562 local t = colorsArrayNumToString[colorPalette[1]]
6563 local a = colorsArrayNumToString[colorPalette[3]]
6564 addPicture(designerSControlPicID,5,3,{""..b..";"..b..";"..t..":"..b..":^;"..b..";"..b..";",""..t..":"..b..":<;"..b..";"..a..":"..b..":o;"..b..";"..t..":"..b..":>;",""..b..";"..b..";"..t..":"..b..":v;"..b..";"..b..";"})
6565 changeProperty(designerSControlPicID,"visible",false)
6566 screens[designerSID]["sizeX"] = designerX
6567 screens[designerSID]["sizeY"] = designerY
6568 addElementToScreen(designerSControlPicID,designerSID,designerX-5,relY(50,designerSID))
6569 screens[designerSID]["sizeX"] = designerSmaxX
6570 screens[designerSID]["sizeY"] = designerSmaxY
6571
6572 addDynamicTextBox(designerSIndicatorID," ")
6573 changeProperty(designerSIndicatorID,"BGColor",colorPalette[3])
6574 addElementToScreen(designerSIndicatorID,designerSID,1,1)
6575 if designerMonitor==terminalID then
6576 changeProperty(designerSIndicatorID,"onClickMode","flash")
6577 changeProperty(designerSIndicatorID,"onActiveFunction",function()
6578 designerSButtonHeld = true
6579 changeProperty(designerSIndicatorID,"BGColor",colorPalette[1])
6580 refresh()
6581 end)
6582 else
6583 changeProperty(designerSIndicatorID,"onClickMode","toggle")
6584 changeProperty(designerSIndicatorID,"activeBGColor",colorPalette[1])
6585 end
6586 changeProperty(designerSIndicatorID,"visible",false)
6587
6588 addDynamicTextBox(designerSSelectionID,"$coords: $ele ($type):$part")
6589 changeProperty(designerSSelectionID,"textColor",colorPalette[1])
6590 changeProperty(designerSSelectionID,"BGColor",colorPalette[2])
6591 changeProperty(designerSSelectionID,"height",1)
6592 changeProperty(designerSSelectionID,"variables",{["ele"]=function() return designerSSelection end,["type"]=function() return getType(designerSSelection) end,["part"]="",["coords"]=function() local x,y = getPos(designerSSelection,designerSID) return x..":"..y end})
6593 changeProperty(designerSSelectionID,"visible",false)
6594 changeProperty(designerSSelectionID,"onClickMode","flash")
6595 changeProperty(designerSSelectionID,"onActiveFunction",function()
6596 designerSSelection = ""
6597 changeProperty(designerSIndicatorID,"visible",false)
6598 changeProperty(designerSControlPicID,"visible",false)
6599 changeProperty(designerSRemoveID,"visible",false)
6600 changeProperty(designerSSelectionID,"visible",false)
6601 end)
6602 addElementToScreen(designerSSelectionID,designerSID,1,designerY-1)
6603
6604 setProcessClickEventFunction(function(type_,ID,part)
6605 if string.len(ID)<32 then
6606 designerSSelection = ID
6607 local x,y = getPos(ID,designerSID)
6608 local b = colorsArrayNumToString[colorPalette[2]]
6609 local t = colorsArrayNumToString[colorPalette[1]]
6610 local a = colorsArrayNumToString[colorPalette[3]]
6611
6612 changePos(designerSIndicatorID,designerSID,x,y)
6613 changeProperty(designerSIndicatorID,"visible",true)
6614 changeProperty(designerSControlPicID,"visible",true)
6615 changeProperty(designerSRemoveID,"visible",true)
6616 changeProperty(designerSSelectionID,"visible",true)
6617 getProperty(designerSSelectionID,"variables")["part"] = part
6618 refresh()
6619 end
6620
6621 if ID==designerSControlPicID then
6622 if part=="3:1" then
6623 local currX,currY = getPos(designerSSelection,designerSID)
6624 local newY = math.max(1,currY-1)
6625 changePos(designerSIndicatorID,designerSID,currX,newY)
6626 changePos(designerSSelection,designerSID,currX,newY)
6627 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,currX,newY)
6628 end
6629 if part=="1:2" then
6630 local currX,currY = getPos(designerSSelection,designerSID)
6631 local newX = math.max(1,currX-1)
6632 changePos(designerSIndicatorID,designerSID,newX,currY)
6633 changePos(designerSSelection,designerSID,newX,currY)
6634 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,newX,currY)
6635 end
6636 if part=="5:2" then
6637 local currX,currY = getPos(designerSSelection,designerSID)
6638 local newX = math.min(designerSmaxX,currX+1)
6639 changePos(designerSIndicatorID,designerSID,newX,currY)
6640 changePos(designerSSelection,designerSID,newX,currY)
6641 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,newX,currY)
6642 end
6643 if part=="3:3" then
6644 local currX,currY = getPos(designerSSelection,designerSID)
6645 local newY = math.min(designerSmaxY,currY+1)
6646 changePos(designerSIndicatorID,designerSID,currX,newY)
6647 changePos(designerSSelection,designerSID,currX,newY)
6648 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,currX,newY)
6649 end
6650 refresh()
6651 end
6652 end)
6653
6654 fullRefresh()
6655end
6656
6657--PROGRAM START
6658if not term.isColor() then
6659 error("EasyGUI is only supported on advanced computers. It's worth spending those gold ingots, trust me.")
6660end
6661term.clear()
6662term.setCursorPos(1,1)
6663
6664if fs.exists(fs.combine(root,"EasyGUI/log.txt")) then
6665 fs.delete(fs.combine(root,"EasyGUI/log.txt"))
6666end
6667logFile = fs.open(fs.combine(root,"EasyGUI/log.txt"),"a")
6668logFile.writeLine("--------------------------------")
6669logFile.writeLine("Log level: "..writingLogLevel)
6670
6671writeToLog("Starting Program. ",2)
6672
6673if shell~=nil then
6674 writeToLog("Loaded as program.",2)
6675 term.clear()
6676 setupStuff()
6677 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
6678 loadMonitors()
6679 else
6680 findMonitors()
6681 saveMonitors()
6682 end
6683 transferDesigner()
6684 if designerMonitor==terminalID then
6685 designerX,designerY = term.getSize()
6686 if designerX<51 then
6687 term.clear()
6688 term.setCursorPos(1,1)
6689 term.setBackgroundColor(colors.black)
6690 error("Turtle and pocket screens are to small to run EasyGUI designer. You can either switch to a computer or run the designer on an attached monitor.")
6691 end
6692 else
6693 monitors[designerMonitor]["peripheral"].setTextScale(tonumber(getProperty(changeMonSScaleDDID,"entries")[getProperty(changeMonSScaleDDID,"selectionID")]))
6694 designerX,designerY = monitors[designerMonitor]["peripheral"].getSize()
6695 end
6696 --main program start
6697 addScreen(mainSID,designerX,designerY,colorPalette[1],colorPalette[2])
6698 setScreenToRenderOnTerminal(nil)
6699 term.setTextColor(colorPalette[1])
6700 term.setBackgroundColor(colorPalette[2])
6701 term.clear()
6702 term.setCursorPos(1,1)
6703 term.write("EasyGUI Designer running on monitor.")
6704 setDesignerScreen(mainSID)
6705 addDynamicTextBox(mainSBorderID,"")
6706 changeProperty(mainSBorderID,"borderThickness",1)
6707 changeProperty(mainSBorderID,"borderColor",colorPalette[3])
6708 changeProperty(mainSBorderID,"width",designerX)
6709 changeProperty(mainSBorderID,"height",designerY)
6710 addElementToScreen(mainSBorderID,mainSID,1,1)
6711
6712 addDynamicTextBox(mainSHeadingID,"EasyGUI Designer Main Menu")
6713 changeProperty(mainSHeadingID,"width",designerX-2)
6714 addElementToScreen(mainSHeadingID,mainSID,2,3)
6715
6716 addDynamicTextBox(mainSButton1ID,"Screens")
6717 changeProperty(mainSButton1ID,"BGColor",colorPalette[3])
6718 changeProperty(mainSButton1ID,"textColor",colorPalette[2])
6719 changeProperty(mainSButton1ID,"borderColor",colorPalette[1])
6720 changeProperty(mainSButton1ID,"width",relX(80,mainSID))
6721 changeProperty(mainSButton1ID,"height",relY(15,mainSID))
6722 changeProperty(mainSButton1ID,"borderThickness",1)
6723 changeProperty(mainSButton1ID,"onClickMode","flash")
6724 changeProperty(mainSButton1ID,"onActiveFunction",function() setDesignerScreen(screensSID)
6725 onLoadScreensS() end)
6726 addElementToScreen(mainSButton1ID,mainSID,relX(10,mainSID),relY(25,mainSID))
6727
6728 addDynamicTextBox(mainSButton2ID,"Elements")
6729 changeProperty(mainSButton2ID,"BGColor",colorPalette[3])
6730 changeProperty(mainSButton2ID,"textColor",colorPalette[2])
6731 changeProperty(mainSButton2ID,"borderColor",colorPalette[1])
6732 changeProperty(mainSButton2ID,"width",relX(80,mainSID))
6733 changeProperty(mainSButton2ID,"height",relY(15,mainSID))
6734 changeProperty(mainSButton2ID,"borderThickness",1)
6735 changeProperty(mainSButton2ID,"onClickMode","flash")
6736 changeProperty(mainSButton2ID,"onActiveFunction",function() setDesignerScreen(elementsSID)
6737 onLoadElementsS() end)
6738 addElementToScreen(mainSButton2ID,mainSID,relX(10,mainSID),relY(50,mainSID))
6739
6740 addDynamicTextBox(mainSButton3ID,"Exit")
6741 changeProperty(mainSButton3ID,"BGColor",colorPalette[3])
6742 changeProperty(mainSButton3ID,"textColor",colorPalette[2])
6743 changeProperty(mainSButton3ID,"borderColor",colorPalette[1])
6744 changeProperty(mainSButton3ID,"width",relX(80,mainSID))
6745 changeProperty(mainSButton3ID,"height",relY(15,mainSID))
6746 changeProperty(mainSButton3ID,"borderThickness",1)
6747 changeProperty(mainSButton3ID,"onClickMode","flash")
6748 changeProperty(mainSButton3ID,"onActiveFunction",function()
6749 os.queueEvent("terminate") end)
6750 addElementToScreen(mainSButton3ID,mainSID,relX(10,mainSID),relY(75,mainSID))
6751
6752 addScreen(screensSID,designerX,designerY,colorPalette[1],colorPalette[2])
6753 addDynamicTextBox(screensSHeadingID,"EasyGUI Designer Screens Menu")
6754 changeProperty(screensSHeadingID,"width",designerX-2)
6755 addElementToScreen(mainSBorderID,screensSID,1,1)
6756 addElementToScreen(screensSHeadingID,screensSID,2,3)
6757
6758 addScreen(newScreenSID,designerX,designerY,colorPalette[1],colorPalette[2])
6759 addElementToScreen(mainSBorderID,newScreenSID,1,1)
6760 addDynamicTextBox(newScreenSHeadingID,"EasyGUI Create new screen")
6761 changeProperty(newScreenSHeadingID,"width",designerX-2)
6762 addElementToScreen(newScreenSHeadingID,newScreenSID,2,3)
6763
6764 addDynamicTextBox(newScreenSTextID,"Please choose the size of the new screen.")
6765 changeProperty(newScreenSTextID,"width",designerX-2)
6766 addElementToScreen(newScreenSTextID,newScreenSID,2,5)
6767
6768 addColorPicker(newScreenSColor1ID,nil)
6769 addColorPicker(newScreenSColor2ID,nil)
6770 changeProperty(newScreenSColor1ID,"visible",false)
6771 changeProperty(newScreenSColor2ID,"visible",false)
6772 addElementToScreen(newScreenSColor1ID,newScreenSID,3,relY(40,newScreenSID))
6773 addElementToScreen(newScreenSColor2ID,newScreenSID,designerX-5,relY(40,newScreenSID))
6774
6775 addDynamicTextBox(newScreenSResultID,"Resulting size: $size <Continue>")
6776 changeProperty(newScreenSResultID,"width",designerX-2)
6777 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "51:19" end})
6778 changeProperty(newScreenSResultID,"onClickMode","flash")
6779 changeProperty(newScreenSResultID,"onActiveFunction",function()
6780 if getProperty(newScreenSColor1ID,"visible") then
6781 if getProperty(newScreenSColor1ID,"selection")~=nil and getProperty(newScreenSColor2ID,"selection")~=nil then
6782 term.setTextColor(colorPalette[1])
6783 term.setBackgroundColor(colorPalette[2])
6784 term.clear()
6785 term.setCursorPos(1,1)
6786 print("Please enter an unique ID for the new screen:")
6787 repeat
6788 local input = read()
6789 if input~="" and input~=nil then
6790 if string.len(input)<32 then
6791 if not IDExists(input) then
6792 ID = input
6793 else
6794 print("ID already taken!")
6795 end
6796 else
6797 print("Must be less than 32 characters!")
6798 end
6799 else
6800 print("Cannot be an empty string.")
6801 end
6802 until ID~=nil
6803
6804 local bool,s = pcall(getProperty(newScreenSResultID,"variables")["size"])
6805 local x = tonumber(string.sub(s,1,string.find(s,":")-1))
6806 local y = tonumber(string.sub(s,string.find(s,":")+1))
6807 addScreen(ID,x,y,getProperty(newScreenSColor1ID,"selection"),getProperty(newScreenSColor2ID,"selection"))
6808 saveScreen(ID)
6809 changeProperty(newScreenSDDM1ID,"visible",true)
6810 changeProperty(newScreenSColor1ID,"visible",false)
6811 changeProperty(newScreenSColor2ID,"visible",false)
6812 changeProperty(newScreenSTextID,"content","Please choose the size of the new screen.")
6813 changeProperty(newScreenSResultID,"content","Resulting size: $size <Continue>")
6814 startDesigner(ID)
6815 end
6816 else
6817 changeProperty(newScreenSDDM1ID,"visible",false)
6818 changeProperty(newScreenSDDM2ID,"visible",false)
6819 changeProperty(newScreenSDDM3ID,"visible",false)
6820 changeProperty(newScreenSTextID,"content","[text] choose default colors [background]")
6821 changeProperty(newScreenSResultID,"content","<Continue>")
6822 changeProperty(newScreenSColor1ID,"visible",true)
6823 changeProperty(newScreenSColor2ID,"visible",true)
6824 refresh()
6825 end
6826 end)
6827 addElementToScreen(newScreenSResultID,newScreenSID,2,designerY-2)
6828
6829 local array = {}
6830 for name,data in pairs(monitors) do
6831 table.insert(array,name)
6832 end
6833 addDropDownMenu(newScreenSDDM2ID,array,1)
6834 changeProperty(newScreenSDDM2ID,"borderThickness",1)
6835 changeProperty(newScreenSDDM2ID,"borderColor",colorPalette[3])
6836 changeProperty(newScreenSDDM2ID,"highlightTextColor",colorPalette[2])
6837 changeProperty(newScreenSDDM2ID,"highlightBGColor",colorPalette[1])
6838 changeProperty(newScreenSDDM2ID,"visible",false)
6839 addElementToScreen(newScreenSDDM2ID,newScreenSID,relX(15,newScreenSID),relY(65,newScreenSID))
6840
6841 addDropDownMenu(newScreenSDDM3ID,{"0.5","1","1.5","2"},1)
6842 changeProperty(newScreenSDDM3ID,"borderThickness",1)
6843 changeProperty(newScreenSDDM3ID,"borderColor",colorPalette[3])
6844 changeProperty(newScreenSDDM3ID,"highlightTextColor",colorPalette[2])
6845 changeProperty(newScreenSDDM3ID,"highlightBGColor",colorPalette[1])
6846 changeProperty(newScreenSDDM3ID,"visible",false)
6847 addElementToScreen(newScreenSDDM3ID,newScreenSID,relX(60,newScreenSID),relY(65,newScreenSID))
6848
6849 addDropDownMenu(newScreenSDDM1ID,{"computer (51:19)","turtle (39:13)","pocket com (26:20)","monitor (variable)","custom"},1)
6850 changeProperty(newScreenSDDM1ID,"borderThickness",1)
6851 changeProperty(newScreenSDDM1ID,"borderColor",colorPalette[3])
6852 changeProperty(newScreenSDDM1ID,"highlightTextColor",colorPalette[2])
6853 changeProperty(newScreenSDDM1ID,"highlightBGColor",colorPalette[1])
6854 changeProperty(newScreenSDDM1ID,"onChangeFunction",function(ID,selec)
6855 if selec==4 then
6856 changeProperty(newScreenSDDM2ID,"visible",true)
6857 changeProperty(newScreenSDDM3ID,"visible",true)
6858 changeProperty(newScreenSResultID,"variables",{["size"]=function() monitors[getProperty(newScreenSDDM2ID,"entries")[getProperty(newScreenSDDM2ID,"selectionID")]]["peripheral"].setTextScale(tonumber(getProperty(newScreenSDDM3ID,"entries")[getProperty(newScreenSDDM3ID,"selectionID")]))
6859 local a,b = monitors[getProperty(newScreenSDDM2ID,"entries")[getProperty(newScreenSDDM2ID,"selectionID")]]["peripheral"].getSize()
6860 return a..":"..b end})
6861 refresh()
6862 else
6863 if selec==1 then
6864 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "51:19" end })
6865 end
6866 if selec==2 then
6867 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "39:13" end })
6868 end
6869 if selec==3 then
6870 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "26:20" end })
6871 end
6872 if selec==5 then
6873 term.setBackgroundColor(colorPalette[2])
6874 term.setTextColor(colorPalette[1])
6875 term.clear()
6876 term.setCursorPos(1,1)
6877 print("Enter size X for new screen:")
6878 local a = read()
6879 print("Enter size Y for new screen:")
6880 local b = read()
6881 changeProperty(newScreenSResultID,"variables",{["size"]=function() return a..":"..b end })
6882 fullRefresh()
6883 end
6884 changeProperty(newScreenSDDM2ID,"visible",false)
6885 changeProperty(newScreenSDDM3ID,"visible",false)
6886 end
6887 end)
6888 addElementToScreen(newScreenSDDM1ID,newScreenSID,relX(15,newScreenSID),relY(35,newScreenSID))
6889
6890 addDynamicTextBox(screensSMsgID,"Please check term!")
6891 changeProperty(screensSMsgID,"width",relX(80,screensSID))
6892 changeProperty(screensSMsgID,"height",relY(15,screensSID))
6893 changeProperty(screensSMsgID,"borderThickness",1)
6894 changeProperty(screensSMsgID,"visible",false)
6895 addElementToScreen(screensSMsgID,screensSID,relX(10,screensSID),relY(25,screensSID))
6896
6897 addDynamicTextBox(screensSButton1ID,"New Screen")
6898 changeProperty(screensSButton1ID,"BGColor",colorPalette[3])
6899 changeProperty(screensSButton1ID,"textColor",colorPalette[2])
6900 changeProperty(screensSButton1ID,"borderColor",colorPalette[1])
6901 changeProperty(screensSButton1ID,"width",relX(80,screensSID))
6902 changeProperty(screensSButton1ID,"height",relY(15,screensSID))
6903 changeProperty(screensSButton1ID,"borderThickness",1)
6904 changeProperty(screensSButton1ID,"onClickMode","flash")
6905 changeProperty(screensSButton1ID,"onActiveFunction",function()
6906 setDesignerScreen(newScreenSID)
6907 fullRefresh()
6908 end)
6909 addElementToScreen(screensSButton1ID,screensSID,relX(10,screensSID),relY(25,screensSID))
6910
6911 addDynamicTextBox(screensSButton2ID,"Edit")
6912 changeProperty(screensSButton2ID,"BGColor",colorPalette[3])
6913 changeProperty(screensSButton2ID,"textColor",colorPalette[2])
6914 changeProperty(screensSButton2ID,"borderColor",colorPalette[1])
6915 changeProperty(screensSButton2ID,"width",relX(40,screensSID)-1)
6916 changeProperty(screensSButton2ID,"height",relY(15,screensSID))
6917 changeProperty(screensSButton2ID,"borderThickness",1)
6918 changeProperty(screensSButton2ID,"onClickMode","flash")
6919 changeProperty(screensSButton2ID,"onActiveFunction",function() startDesigner(getProperty(screensSDDMenuID,"entries")[getProperty(screensSDDMenuID,"selectionID")]) end)
6920 addElementToScreen(screensSButton2ID,screensSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(50,screensSID))
6921
6922 addDynamicTextBox(screensSButton3ID,"Back")
6923 changeProperty(screensSButton3ID,"BGColor",colorPalette[3])
6924 changeProperty(screensSButton3ID,"textColor",colorPalette[2])
6925 changeProperty(screensSButton3ID,"borderColor",colorPalette[1])
6926 changeProperty(screensSButton3ID,"width",relX(80,screensSID))
6927 changeProperty(screensSButton3ID,"height",relY(15,screensSID))
6928 changeProperty(screensSButton3ID,"borderThickness",1)
6929 changeProperty(screensSButton3ID,"onClickMode","flash")
6930 changeProperty(screensSButton3ID,"onActiveFunction",function() setDesignerScreen(mainSID) end)
6931 addElementToScreen(screensSButton3ID,screensSID,relX(10,screensSID),relY(75,screensSID))
6932
6933 addDropDownMenu(screensSDDMenuID,nil,1)
6934 changeProperty(screensSDDMenuID,"borderThickness",1)
6935 changeProperty(screensSDDMenuID,"borderColor",colorPalette[3])
6936 changeProperty(screensSDDMenuID,"highlightTextColor",colorPalette[2])
6937 changeProperty(screensSDDMenuID,"highlightBGColor",colorPalette[1])
6938 changeProperty(screensSDDMenuID,"width",relX(40,screensSID)-1)
6939 addElementToScreen(screensSDDMenuID,screensSID,relX(10,screensSID),relY(50,screensSID))
6940
6941 addScreen(elementsSID,designerX,designerY,colorPalette[1],colorPalette[2])
6942 addDynamicTextBox(elementsSHeadingID,"EasyGUI Designer Elements Menu")
6943 changeProperty(elementsSHeadingID,"width",designerX-2)
6944 addElementToScreen(mainSBorderID,elementsSID,1,1)
6945 addElementToScreen(elementsSHeadingID,elementsSID,2,3)
6946 addElementToScreen(screensSButton3ID,elementsSID,relX(10,screensSID),relY(75,screensSID))
6947
6948 addElementToScreen(screensSMsgID,elementsSID,relX(10,elementsSID),relY(25,elementsSID))
6949
6950 local array = {"dynTextBox","slider","dropDownMenu","navMenu","colorPicker","progressBar","coordsSystem","picture"}
6951
6952 addDynamicTextBox(elementsSButton1ID,"Add")
6953 changeProperty(elementsSButton1ID,"BGColor",colorPalette[3])
6954 changeProperty(elementsSButton1ID,"textColor",colorPalette[2])
6955 changeProperty(elementsSButton1ID,"borderColor",colorPalette[1])
6956 changeProperty(elementsSButton1ID,"width",relX(40,elementsSID)-1)
6957 changeProperty(elementsSButton1ID,"height",relY(15,elementsSID))
6958 changeProperty(elementsSButton1ID,"borderThickness",1)
6959 changeProperty(elementsSButton1ID,"onClickMode","flash")
6960 changeProperty(elementsSButton1ID,"onActiveFunction",function() startEditor(newElement(array[getProperty(elementsSDDMenu1ID,"selectionID")])) end)
6961 addElementToScreen(elementsSButton1ID,elementsSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(25,elementsSID))
6962
6963 addDynamicTextBox(elementsSButton2ID,"Edit")
6964 changeProperty(elementsSButton2ID,"BGColor",colorPalette[3])
6965 changeProperty(elementsSButton2ID,"textColor",colorPalette[2])
6966 changeProperty(elementsSButton2ID,"borderColor",colorPalette[1])
6967 changeProperty(elementsSButton2ID,"width",relX(40,elementsSID)-1)
6968 changeProperty(elementsSButton2ID,"height",relY(15,elementsSID))
6969 changeProperty(elementsSButton2ID,"borderThickness",1)
6970 changeProperty(elementsSButton2ID,"onClickMode","flash")
6971 changeProperty(elementsSButton2ID,"onActiveFunction",function() startEditor(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],getType(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")])) end)
6972 addElementToScreen(elementsSButton2ID,elementsSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(50,elementsSID))
6973
6974 addDropDownMenu(elementsSDDMenu2ID,nil,1)
6975 changeProperty(elementsSDDMenu2ID,"borderThickness",1)
6976 changeProperty(elementsSDDMenu2ID,"borderColor",colorPalette[3])
6977 changeProperty(elementsSDDMenu2ID,"highlightTextColor",colorPalette[2])
6978 changeProperty(elementsSDDMenu2ID,"highlightBGColor",colorPalette[1])
6979 changeProperty(elementsSDDMenu2ID,"width",relX(40,elementsSID)-1)
6980 addElementToScreen(elementsSDDMenu2ID,elementsSID,relX(10,elementsSID),relY(50,elementsSID))
6981
6982 addDropDownMenu(elementsSDDMenu1ID,array,1)
6983 changeProperty(elementsSDDMenu1ID,"borderThickness",1)
6984 changeProperty(elementsSDDMenu1ID,"borderColor",colorPalette[3])
6985 changeProperty(elementsSDDMenu1ID,"highlightTextColor",colorPalette[2])
6986 changeProperty(elementsSDDMenu1ID,"highlightBGColor",colorPalette[1])
6987 changeProperty(elementsSDDMenu1ID,"width",relX(40,elementsSID)-1)
6988 addElementToScreen(elementsSDDMenu1ID,elementsSID,relX(10,elementsSID),relY(25,elementsSID))
6989
6990 run(nil)
6991else
6992 writeToLog("Loaded as API.",2)
6993 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
6994 loadMonitors()
6995 else
6996 print("EasyGUI was loaded as API, but there is no monitor file present. Starting monitor initialization sequence.")
6997 sleep(5)
6998 term.clear()
6999 setupStuff()
7000 findMonitors()
7001 saveMonitors()
7002 end
7003end
7004
7005--END OF EASYGUI API
7006-----------------------------