├── Elements list.md ├── Exemples ├── AllElements.lua ├── JobChoiceUI.lua ├── JobListUI.lua ├── QuestChoiceUI.lua └── TeamChoiceUI.lua ├── README.md ├── UI API ├── icon.png ├── media │ └── lua │ │ └── client │ │ ├── Exemples │ │ ├── AllElements.lua │ │ ├── JobChoiceUI.lua │ │ ├── JobListUI.lua │ │ ├── QuestChoiceUI.lua │ │ └── TeamChoiceUI.lua │ │ └── ISUI │ │ ├── GlobalFunctions.lua │ │ ├── ISSimpleButton.lua │ │ ├── ISSimpleComboBox.lua │ │ ├── ISSimpleEmpty.lua │ │ ├── ISSimpleEntry.lua │ │ ├── ISSimpleImage.lua │ │ ├── ISSimpleImageButton.lua │ │ ├── ISSimpleProgressBar.lua │ │ ├── ISSimpleRichText.lua │ │ ├── ISSimpleScrollingListBox.lua │ │ ├── ISSimpleText.lua │ │ ├── ISSimpleTickBox.lua │ │ └── ISSimpleUI.lua ├── mod.info └── preview.png ├── UI functions.md ├── Vanilla functions.md ├── Variables.md └── images ├── Hello x4.jpg ├── HelloWorld.jpg ├── Shema.drawio ├── Shema.drawio.png ├── exemple1.gif ├── jobBoard.gif ├── jobChoice.gif ├── preview perso.png ├── quest.jpg ├── schema2d (1).png └── team.jpg /Elements list.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | - [Common functions](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#common-functions) 3 | - [Empty](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#empty-space) 4 | - [Text](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#text) 5 | - [Rich Text](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#rich-text) 6 | - [Progress bar](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#progress-bar) 7 | - [Button](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#button) 8 | - [Tick box](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#tick-box) 9 | - [Entry](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#entry) 10 | - [Combo box](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#combo-box) 11 | - [Scrolling list](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#scrolling-list) 12 | - [Image](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#image) 13 | - [Image button](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md#image-button) 14 | 15 | All original class can be found in `media/lua/client/ISUI` 16 | 17 | ------------------------- 18 | 19 | # Note about name 20 | You will see that when you add an element, there is a variable name. 21 | This variable is useful to have access to the element from the UI object. For example if you add text with `UI:addText("text1", "My text")`, you could access the text1 element with `UI["text1"]` or `UI.text1`. 22 | 23 | If you never neeed to acces the element, you can add an empty name (`""`) or a nil. Like that the element is put in the `noNameElements` table. 24 | 25 | **Otherwise you have to be a little careful when choosing a name !** 26 | Because you can rewrite a variable already used by the UI. The best example being if you make a title and use "title" as the variable name. You are going to rewrite the "title" variable which already exists. It will create errors. 27 | If this happens, the console will output an error "UI API - ERROR: element name '" .. name .. "' is already a variable name. Change it !" 28 | To avoid this problem **I strongly recommend using a number in each variable name.** So "title" becomes "title1", even if there is only one. 29 | 30 | ------------------------- 31 | 32 | ## Common functions 33 | ### Before saveLayout() 34 | Need to be call before saveLayout() 35 | ```lua 36 | -- To force the width of an element. Can make an error if width total is higher that with of window 37 | -- For image and image buton, need to be call before nextLine() otherwise the image will not have the correct height to keep the ratio 38 | UI["text1"]:setWidthPercent(pctW) 39 | UI["text1"]:setWidthPixel(pxlW) 40 | ``` 41 | 42 | ### After saveLayout() 43 | Can be call everywhere 44 | ```lua 45 | -- Add or remove a border to the element 46 | UI["text1"]:setBorder(bool) 47 | 48 | -- To show it or hide it, disable button, list, ect. 49 | UI["text1"]:setVisible(bool); 50 | ``` 51 | 52 | ## Empty space 53 | Derived from `ISUIElement` 54 | ```lua 55 | -- @name: Variable name of the element, if nb > 1, name gonna be name1, name2, name3, ect 56 | -- @nb: Number of empty space to make (Optional, 1 by default) 57 | -- @pctW: Width of element in percent of screen [0-1] (Optional) 58 | -- @pxlW: Width of element in pixel (Optional) 59 | UI:addEmpty(name, nb, pctW, pxlW) 60 | 61 | -- Change background color 62 | UI["empty1"]:setColor(a, r, g, b) -- Next update 63 | ``` 64 | 65 | ## Text 66 | Derived from `ISUIElement` 67 | ```lua 68 | -- @name: variable name of the element 69 | -- @text: Text to display 70 | -- @font: Font to use (see Variables/Fonts sections) (Optional, Small by default) 71 | -- @position: Position of text in the box (Optional, Left by default) 72 | UI:addText(name, text, font, position) 73 | 74 | -- Exemple: 75 | UI:addText("text1", "My Title", "Title", "Center") 76 | UI:addText(_, "My text") 77 | 78 | -- Change the text: 79 | UI["text1"]:setText("My New Title") 80 | -- Change the color: 81 | UI["text1"]:setColor(a, r, g, b) 82 | -- Change position: 83 | UI["text1"]:setPosition("Right") 84 | ``` 85 | [All fonts and position](https://github.com/MrBounty/PZ-UI_API/blob/main/Variables.md) 86 | 87 | ## Rich Text 88 | Derived from `ISUIElement` with a `RichTextLayout` element 89 | ```lua 90 | -- @name: variable name of the element 91 | -- @text: Text to display 92 | UI:addRichText(name, text) 93 | 94 | -- Exemple: 95 | UI:addRichText("rich1", text) 96 | 97 | -- Change the text: 98 | UI["rich1"]:setText("", "My new text") 99 | -- Change the background color: 100 | UI["rich1"]:setColor(a, r, g, b) 101 | ``` 102 | [Text formating](https://github.com/MrBounty/PZ-UI_API/blob/main/Variables.md) 103 | 104 | ## Progress bar 105 | Derived from `ISUIElement` 106 | ```lua 107 | -- @name: variable name of the element 108 | -- @value: value to display 109 | -- @min: min of the value 110 | -- @max: max of the value 111 | UI:addProgressBar(name, value, min, max) 112 | 113 | -- Exemple: 114 | UI:addProgressBar("pbar1", 20, 0, 50) 115 | 116 | -- Change the value 117 | UI["pbar1"]:setValue(v) 118 | -- Change min max 119 | UI["pbar1"]:setMinMax(min, max) 120 | -- Change margin of the bar 121 | UI["pbar1"]:setMarginPercent(pctW, pctH) 122 | UI["pbar1"]:setMarginPixel(pxlW, pxlH) 123 | -- Change the color (white by default) 124 | UI["pbar1"]:setColor(a, r, g, b) 125 | ``` 126 | 127 | ## Button 128 | Derived from `ISButton` 129 | ```lua 130 | -- @name: variable name of the element 131 | -- @text: Text to display in the button 132 | -- @func: Function to call when press. 133 | UI:addButton(name, text, func) 134 | 135 | -- Exemple: 136 | UI:addButton("button1", "", close) 137 | local close(button, args) 138 | --Code 139 | end 140 | 141 | -- Change the text: 142 | UI["button1"]:setText("My new text") 143 | -- Change the function: 144 | UI["button1"]:setOnClick(func) 145 | -- Add an argument to the args table to use in the function 146 | UI["button1"]:addArg("index", 1); 147 | ``` 148 | 149 | ## Tick box 150 | Derived from `ISUIElement` with a `ISTickBox` element 151 | ```lua 152 | -- @name: variable name of the element 153 | -- @position: variable name of the element (Optional, Centre by default) 154 | UI:addTickBox(name, position) 155 | 156 | -- Exemple: 157 | UI:addTickBox("tick1", "Left") 158 | 159 | -- Get the value: 160 | UI["tick1"]:getValue() 161 | ``` 162 | 163 | ## Entry 164 | Derived from `ISTextEntryBox` 165 | ```lua 166 | -- @name: variable name of the element 167 | -- @default: Default text/value 168 | -- @isNumber: true if use for a number 169 | UI:addEntry(name, default, isNumber) 170 | 171 | -- Exemples: 172 | UI:addEntry("entry1", "", false) 173 | UI:addEntry("entry2", 100, true) 174 | 175 | -- To get the value: 176 | UI["entry1"]:getValue() 177 | -- Add a func when enter is press, function take 3 arg: the element, the text and the arg table 178 | UI["entry1"]:setEnterFunc(func) 179 | -- Add arg for the func when enter is press 180 | UI["entry1"]:addArg(name, value) 181 | ``` 182 | 183 | ------------------------- 184 | 185 | # Note about combo box and scrolling list 186 | items table can use number as key from 1 to x with a step of 1 (list of string), in that case value and text to display is the same. 187 | Or string as key, in that case the text display is the key and the value get with getValue is the variable of the key. 188 | ```lua 189 | -- Both work: 190 | local items = {"item 1", "item 2", "item 3"} 191 | 192 | local items = {} 193 | items["text1"] = "item1" 194 | items["text2"] = "item2" 195 | items["text3"] = "item3" 196 | ``` 197 | ------------------------- 198 | 199 | ## Combo box 200 | Derived from `ISComboBox` 201 | ```lua 202 | -- @name: variable name of the element 203 | -- @items: List of items to add in the list 204 | UI:addComboBox(name, items) 205 | 206 | -- Exemple: 207 | UI:addComboBox("combo1", {"item 1", "item 2", "item 3"}) 208 | 209 | -- Get selected value: 210 | text = UI["combo1"]:getValue() 211 | -- Change items: 212 | UI["combo1"]:setItems({"item 4", "item 5", "item 6"}) 213 | ``` 214 | 215 | ## Scrolling list 216 | Derived from `ISScrollingListBox` 217 | ```lua 218 | -- @name: variable name of the element 219 | -- @items: List of items to add in the list 220 | UI:addScrollList(name, items) 221 | 222 | -- Exemple: 223 | UI:addScrollList("scroll1", {"item 1", "item 2", "item 3"}) 224 | 225 | -- Get selected value or false if not selected: 226 | text, item = UI["scroll1"]:getValue() 227 | -- Change items: 228 | UI["scroll1"]:setItems({"item 4", "item 5", "item 6"}) 229 | ``` 230 | 231 | ## Image 232 | Derived from `ISImage` 233 | ```lua 234 | -- @name: variable name of the element 235 | -- @path: path of the image file 236 | UI:addImage(name, path) 237 | 238 | -- Exemple: 239 | UI:addImage("image1", "media/ui/myImage.png") 240 | 241 | -- Change image 242 | UI["image1"]:setPath(path) 243 | -- Change color 244 | UI["image1"]:setColor(r, g, b) 245 | ``` 246 | 247 | ## Image button 248 | Derived from `ISButton` 249 | ```lua 250 | -- @name: variable name of the element 251 | -- @path: path of the image file 252 | -- @func: function to call when press 253 | UI:addImageButton(name, path, func) 254 | 255 | -- Exemple: 256 | UI:addImageButton("ibutton1", "media/ui/myImage.png", toDo) 257 | 258 | -- Change image 259 | UI["ibutton1"]:setPath(path) 260 | -- Change function 261 | UI["ibutton1"]:setOnClick(func) 262 | -- Add an argument to the args table to use in the function 263 | UI["ibutton1"]:addArg("index", 1); 264 | -- Change color 265 | UI["ibutton1"]:setColor(a, r, g, b) 266 | ``` 267 | -------------------------------------------------------------------------------- /Exemples/AllElements.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | 3 | local text1 = "

Rich Text Add a small desc
- xx - xx - xx - xx" 4 | 5 | local items1 = {"item1", "item2", "item3", "item4", "item5", "item5", "item6", "item7", "item8", "item9", "item10", "item11", "item12"} 6 | 7 | local items2 = {} 8 | items2["name1"] = "item1" 9 | items2["name2"] = "item2" 10 | items2["name3"] = "item3" 11 | items2["name4"] = "item4" 12 | items2["name5"] = "item5" 13 | items2["name6"] = "item6" 14 | items2["name7"] = "item7" 15 | items2["name8"] = "item8" 16 | items2["name9"] = "item9" 17 | items2["name10"] = "item10" 18 | items2["name11"] = "item11" 19 | items2["name12"] = "item12" 20 | items2["name13"] = "item13" 21 | 22 | -- Create the UI with all element exept image and image button 23 | function onCreateUI() 24 | UI = NewUI(); 25 | UI:setTitle("All elements UI test") 26 | UI:setColumnWidthPixel(1, 100); 27 | 28 | UI:addText("", "Empty:", _, "Center"); 29 | UI:addEmpty(); 30 | UI:nextLine(); 31 | 32 | UI:addText("", "Rich text:", _, "Center"); 33 | UI:addRichText("", text1); 34 | UI:nextLine(); 35 | 36 | UI:addText("", "Progress bar:", _, "Center"); 37 | UI:addProgressBar("pb1", 0, 0, 100); 38 | UI:nextLine(); 39 | 40 | UI:addText("", "Button:", _, "Center"); 41 | UI:addButton("", "", _); 42 | UI:nextLine(); 43 | 44 | UI:addText("", "Tick box:", _, "Center"); 45 | UI:addTickBox("t1"); 46 | UI:nextLine(); 47 | 48 | UI:addText("", "Entry:", _, "Center"); 49 | UI:addEntry("e1", ""); 50 | UI:nextLine(); 51 | 52 | UI:addText("", "Combo:", _, "Center"); 53 | UI:addComboBox("c1", items1); 54 | UI:nextLine(); 55 | 56 | UI:addText("", "ScrollList:", _, "Center"); 57 | UI:addScrollList("s1", items2); 58 | 59 | UI:setBorderToAllElements(true); -- Add border 60 | UI:saveLayout(); -- Save and create the UI 61 | end 62 | 63 | local function everyTenMinutes() 64 | print("Tick box: ", UI["t1"]:getValue()); 65 | print("Entry: ", UI["e1"]:getValue()); 66 | print("Combo: ", UI["c1"]:getValue()); 67 | print("ScrollList: ", UI["s1"]:getValue()); 68 | end 69 | 70 | function everyMinute() 71 | if not UI then return false end 72 | UI["pb1"]:setValue(i); 73 | if i > 100 then i = 0 end 74 | i = i + 5; 75 | end 76 | 77 | Events.OnCreateUI.Add(onCreateUI) 78 | Events.EveryTenMinutes.Add(everyTenMinutes) 79 | Events.EveryOneMinute.Add(everyMinute) 80 | -------------------------------------------------------------------------------- /Exemples/JobChoiceUI.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | local jobSelect = ""; 3 | 4 | -- Text for the rich text element 5 | local text1 = "

Your a policeman ! You are here to protect people ! You can: - Do that - And that - And a lot more" 6 | local text2 = "

Your an engineer ! You are here to create thing ! You can: - Do that - And that - And a lot more" 7 | local text3 = "

Your a doctor ! You are here to help people ! You can: - Do that - And that - And a lot more" 8 | local text4 = "

Your nothing ! You are here to die ! You can: - Do that - And that - And a lot more" 9 | local texts = {text1, text2, text3, text4} 10 | 11 | local jobs = {"Policeman", "Engineer", "Doctor", "Nothing"} 12 | 13 | -- Functions for buttons 14 | local function press(button, args) 15 | UI["rtext"]:setText(texts[args.index]) 16 | jobSelect = jobs[args.index] 17 | getPlayer():Say("I selected " .. jobSelect); 18 | end 19 | 20 | local function ok() 21 | getPlayer():Say("I'm a " .. jobSelect .. " now !"); 22 | UI:close(); 23 | end 24 | 25 | 26 | -- Create the UI 27 | function onCreateUI() 28 | UI = NewUI(); 29 | 30 | -- Add window title 31 | UI:addText("title1", "Choose you job !", "Title", "Center"); 32 | UI["title1"]:setBorder(true); 33 | UI:nextLine(); 34 | 35 | -- Add job description 36 | UI:addRichText("rtext", text1); 37 | UI:nextLine(); 38 | 39 | -- Add buttons 40 | UI:addButton("button1", jobs[1], press); 41 | UI["button1"]:addArg("index", 1); 42 | 43 | UI:addButton("button2", jobs[2], press); 44 | UI["button2"]:addArg("index", 2); 45 | 46 | UI:addButton("button3", jobs[3], press); 47 | UI["button3"]:addArg("index", 3); 48 | 49 | UI:addButton("button4", jobs[4], press); 50 | UI["button4"]:addArg("index", 4); 51 | 52 | UI:addButton("", "Button", ok); 53 | UI:nextLine(); 54 | 55 | -- Save window 56 | UI:saveLayout(); 57 | end 58 | 59 | Events.OnCreateUI.Add(onCreateUI) 60 | -------------------------------------------------------------------------------- /Exemples/JobListUI.lua: -------------------------------------------------------------------------------- 1 | local listUI, descUI 2 | local text1 = "

The longest night
In this mission, you gonna need to survivre all night.
Reward: - M14 - 20 ammo
Failure Conditions: -Death" 3 | local text2 = "

I need medical supply !
Please someone come to xx to help me ! I need a doctor or I'm gonna die.
Reward: - Everything I have" 4 | local text3 = "

Help me clean my neighborhood
I need someone to help me fight a group of zombie near xx, there is around xx of them and I don't want to do it alone.
Reward: - 100$" 5 | local text4 = "

Looking for seed
I'm looking for seed, every type of seed. I can pay or exchange. Contact me on my public frequencies xx.x." 6 | local items = {}; 7 | items["EVENT - The longest night"] = text1; 8 | items["URGENT - Medical delivery"] = text2; 9 | items["Help me clean my neighborhood"] = text3; 10 | items["Looking for seed"] = text4; 11 | items["item5"] = ""; 12 | items["item6"] = ""; 13 | items["item7"] = ""; 14 | items["item8"] = ""; 15 | items["item9"] = ""; 16 | items["item10"] = ""; 17 | items["item11"] = ""; 18 | 19 | local function choose(button, args) 20 | getPlayer():Say("I accepted this mission !"); 21 | listUI:close(); 22 | end 23 | 24 | local function openJobDesc(_, item) 25 | descUI:open(); 26 | descUI:setPositionPixel(listUI:getX() + listUI:getWidth(), listUI:getY()); 27 | descUI["rtext"]:setText(item); 28 | end 29 | 30 | function onCreateUI() 31 | -- List UI 32 | listUI = NewUI(); -- Create UI 33 | listUI:setTitle("Job board"); 34 | listUI:setMarginPixel(10, 10); 35 | listUI:setWidthPercent(0.15); 36 | 37 | listUI:addScrollList("list", items); -- Create list 38 | listUI["list"]:setOnMouseDownFunction(_, openJobDesc) 39 | 40 | listUI:saveLayout(); -- Create window 41 | 42 | -- Description UI 43 | descUI = NewUI(); 44 | descUI:setTitle("Job desc"); 45 | descUI:isSubUIOf(listUI); 46 | descUI:setWidthPercent(0.1); 47 | 48 | descUI:addEmpty(_, _, _, 10); -- Margin only for rich text 49 | descUI:addRichText("rtext", ""); 50 | descUI:setLineHeightPercent(0.2); 51 | descUI:addEmpty(_, _, _, 10); -- Margin only for rich text 52 | descUI:nextLine(); 53 | 54 | descUI:addButton("b1", "Accept ?", choose); 55 | 56 | descUI:saveLayout(); 57 | descUI:close(); 58 | end 59 | 60 | --Events.OnCreateUI.Add(onCreateUI) -------------------------------------------------------------------------------- /Exemples/QuestChoiceUI.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | local text1 = "

The longest night
In this mission, you gonna need to survivre all night.
Reward: - M14 - 20 ammo
Failure Conditions: -Death" 3 | 4 | local function choose(button, args) 5 | getPlayer():Say(args.choice); 6 | UI:close(); 7 | end 8 | 9 | function onCreateUI() 10 | UI = NewUI(); 11 | 12 | UI:addRichText("rtext", text1); 13 | UI:setLineHeightPercent(0.2); 14 | UI:nextLine(); 15 | 16 | UI:addText("t1", "Accept ?", _, "Center"); 17 | UI["t1"]:addBorder(); 18 | UI:addButton("b1", "Yes", choose); 19 | UI["b1"]:addArg("choice", "yes"); 20 | UI:addButton("b2", "No", choose); 21 | UI["b2"]:addArg("choice", "no"); 22 | 23 | UI:saveLayout(); 24 | end 25 | 26 | --Events.OnCreateUI.Add(onCreateUI) -------------------------------------------------------------------------------- /Exemples/TeamChoiceUI.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | 3 | local text1 = "Players: - MrBounty - Dane - xx - xx - xx - xx - xx - xx - xx - xx - xx" 4 | local text2 = "Players: - xx - xx - xx - xx - xx - xx - xx - xx - xx" 5 | 6 | local function choose(button, args) 7 | getPlayer():Say("I'm in the " .. args.team .. " team now !"); 8 | UI:close(); 9 | end 10 | 11 | function onCreateUI() 12 | UI = NewUI(); 13 | UI:addText("", "Choose your team", "Large", "Center"); 14 | UI:nextLine(); 15 | 16 | UI:addRichText("", text1); 17 | UI:addRichText("", text2); 18 | UI:setLineHeightPercent(0.2); 19 | UI:nextLine(); 20 | 21 | UI:addText("t1", "11/12", _, "Center"); 22 | UI:addText("t2", "9/12", _, "Center"); 23 | UI["t1"]:setColor(1, 0, 0, 1); 24 | UI["t2"]:setColor(1, 1, 0, 0); 25 | UI:nextLine(); 26 | 27 | UI:addButton("b1", "Blue", choose); 28 | UI:addButton("b2", "Red", choose); 29 | UI["b1"]:addArg("team", "blue"); 30 | UI["b2"]:addArg("team", "red"); 31 | 32 | UI:addBorderToAllElements(); 33 | UI:setWidthPercent(0.15); 34 | UI:saveLayout(); 35 | end 36 | 37 | --Events.OnCreateUI.Add(onCreateUI) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PZ-Simple UI library 2 | Want to make a simple menu for your mod to : 3 | - Ask the player to choose between two things? 4 | - Ask the player a nickname, age, height, weight, etc ? 5 | - Display a map ? 6 | - Display player-related information from your mod such as amount of money, time on server, etc ? 7 | - Warn players the start of an event ? 8 | - Make a job board systeme ? 9 | - And more ? 10 | 11 | [This mod is for you !](https://steamcommunity.com/sharedfiles/filedetails/?id=2760035814) 12 | 13 | My mod is only an overlay of what the base game does to simplify placement, initializations and get the most useful functions of UIs. 14 | This means that all elements are vanilla elements. So for example, buttons has access to all functions of `ISButton` and `ISUIElement`. 15 | The windows itself is a derivate of `ISCollapsableWindow`. 16 | It means you can add whatever you want to my UI like for the vanilla game if you want something specific. Here is a [guide](https://github.com/MrBounty/PZ-Mod---Doc/blob/main/Make%20an%20custom%20UI.md) to understanding the basics of how the game does UIs. You can also copy an `ISSimpleElement.lua` to make a custom one. 17 | Found all vanilla files in `media/lua/client/ISUI` of the game folder. 18 | Note, an UI is the whole (window + elements) and the window is just the window object, without the elements. 19 | 20 | # Make my first window 21 | A window created with my mod is composed of lines. On each line, there are elements. Elements are anything that can be in a UI like text or a button. 22 | 23 | Step by step: 24 | 1. Create a new UI with the `NewUI()` function. Here you have a window without elements. 25 | 2. Add elements to the line. You can add as many elements as you want per line, the mod will take care of sizing them. 26 | 3. Jump to the next line. When you added your elements, you jump to the next line with the function `ui:nextLine()`. 27 | 4. Repet 2. 28 | 5. Once all line create, you just call `ui:saveLayout()` to finish creating the ui. 29 | 30 | All useable function of UI [here](https://github.com/MrBounty/PZ-UI_API/blob/main/UI%20functions.md). 31 | All elements [here](https://github.com/MrBounty/PZ-UI_API/blob/main/Elements%20list.md). 32 | List of usefull vanilla function [here](https://github.com/MrBounty/PZ-UI_API/blob/main/Vanilla%20functions.md). 33 | 34 | 35 | As in the following diagram: 36 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/preview%20perso.png) 37 | 38 | I highly recommend doing the UIs in event `OnCreateUI` but you can do it anywhere. 39 | 40 | # Understand coordinates 41 | - Menus are in 2d. 42 | - Dimensions of 2d object are its **position in x and y** as well as its **size in width and height**. 43 | - x and y are coordinates of the left top corner. 44 | - Positions and sizes are in percentage of screen or in pixel. 45 | 46 | Percent is to simplify and allow compatibility between different screen sizes. For example a width of 0.2 will take 20% of the screen. 47 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/schema2d%20(1).png) 48 | 49 | You can also try to make your UI from scratch, I made a [guide](https://github.com/MrBounty/PZ-Mod---Doc/blob/main/Make%20an%20custom%20UI.md) to understand the base. 50 | 51 | # Examples 52 | ## Hello world 53 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/HelloWorld.jpg) 54 | ```lua 55 | local function onCreateUI() 56 | local UI = NewUI(); 57 | UI:addText("", "Hello world", "Small", "Center") 58 | UI:saveLayout() 59 | end 60 | 61 | Events.OnCreateUI.Add(onCreateUI) 62 | ``` 63 | 64 | ## Quest 65 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/quest.jpg) 66 |
67 | See code 68 | 69 | ```lua 70 | local UI 71 | local text1 = "

The longest night
In this mission, you gonna need to survivre all night.
Reward: - M14 - 20 ammo
Failure Conditions: -Death" 72 | 73 | local function choose(button, args) 74 | getPlayer():Say(args.choice); 75 | UI:close(); 76 | end 77 | 78 | local function onCreateUI() 79 | UI = NewUI(); 80 | 81 | UI:addRichText("rtext", text1); 82 | UI:setLineHeightPercent(0.2); 83 | UI:nextLine(); 84 | 85 | UI:addText("t1", "Accept ?", _, "Center"); 86 | UI["t1"]:setBorder(true); 87 | 88 | UI:addButton("b1", "Yes", choose); 89 | UI:addButton("b2", "No", choose); 90 | 91 | UI["b1"]:addArg("choice", "yes"); 92 | UI["b2"]:addArg("choice", "no"); 93 | 94 | UI:saveLayout(); 95 | end 96 | 97 | Events.OnCreateUI.Add(onCreateUI) 98 | ``` 99 |

100 | 101 | ## Choose your team 102 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/team.jpg) 103 |
104 | See code 105 | 106 | ```lua 107 | local UI 108 | 109 | local text1 = "Players: - MrBounty - Dane - xx - xx - xx - xx - xx - xx - xx - xx - xx" 110 | local text2 = "Players: - xx - xx - xx - xx - xx - xx - xx - xx - xx" 111 | 112 | local function choose(button, args) 113 | getPlayer():Say("I'm in the " .. args.team .. " team now !"); 114 | UI:close(); 115 | end 116 | 117 | local function onCreateUI() 118 | UI = NewUI(); 119 | UI:addText("", "Choose your team", "Large", "Center"); 120 | UI:nextLine(); 121 | 122 | UI:addRichText("", text1); 123 | UI:addRichText("", text2); 124 | UI:setLineHeightPercent(0.2); 125 | UI:nextLine(); 126 | 127 | UI:addText("t1", "11/12", _, "Center"); 128 | UI:addText("t2", "9/12", _, "Center"); 129 | UI["t1"]:setColor(1, 0, 0, 1); 130 | UI["t2"]:setColor(1, 1, 0, 0); 131 | UI:nextLine(); 132 | 133 | UI:addButton("b1", "Blue", choose); 134 | UI:addButton("b2", "Red", choose); 135 | UI["b1"]:addArg("team", "blue"); 136 | UI["b2"]:addArg("team", "red"); 137 | 138 | UI:setBorderToAllElements(true); 139 | UI:setWidthPercent(0.15); 140 | UI:saveLayout(); 141 | end 142 | 143 | Events.OnCreateUI.Add(onCreateUI) 144 | ``` 145 |
146 | 147 | ## Choose a job 148 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/jobChoice.gif) 149 |
150 | See code 151 | 152 | ```lua 153 | local UI 154 | local jobSelect = ""; 155 | 156 | -- Text for the rich text element 157 | local text1 = "

Your a policeman ! You are here to protect people ! You can: - Do that - And that - And a lot more" 158 | local text2 = "

Your an engineer ! You are here to create thing ! You can: - Do that - And that - And a lot more" 159 | local text3 = "

Your a doctor ! You are here to help people ! You can: - Do that - And that - And a lot more" 160 | local text4 = "

Your nothing ! You are here to die ! You can: - Do that - And that - And a lot more" 161 | local texts = {text1, text2, text3, text4} 162 | 163 | local jobs = {"Policeman", "Engineer", "Doctor", "Nothing"} 164 | 165 | -- Functions for buttons 166 | local function press(button, args) 167 | UI["rtext"]:setText(texts[args.index]) 168 | jobSelect = jobs[args.index] 169 | getPlayer():Say("I selected " .. jobSelect); 170 | end 171 | 172 | local function ok() 173 | getPlayer():Say("I'm a " .. jobSelect .. " now !"); 174 | UI:close(); 175 | end 176 | 177 | -- Create the UI 178 | local function onCreateUI() 179 | UI = NewUI(0.15); 180 | 181 | -- Add window title 182 | UI:addText("title1", "Choose you job !", "Title", "Center"); 183 | UI["title1"]:setBorder(true); 184 | UI:nextLine(); 185 | 186 | -- Add job description 187 | UI:addRichText("rtext", text1); 188 | UI:nextLine(); 189 | 190 | -- Add buttons 191 | UI:addButton("button1", jobs[1], press); 192 | UI:addButton("button2", jobs[2], press); 193 | UI:addButton("button3", jobs[3], press); 194 | UI:addButton("button4", jobs[4], press); 195 | 196 | UI["button1"]:addArg("index", 1); 197 | UI["button2"]:addArg("index", 2); 198 | UI["button3"]:addArg("index", 3); 199 | UI["button4"]:addArg("index", 4); 200 | 201 | UI:addButton("", "Button", ok); 202 | UI:nextLine(); 203 | 204 | -- Save window 205 | UI:saveLayout(); 206 | end 207 | 208 | Events.OnCreateUI.Add(onCreateUI) 209 | ``` 210 |

211 | 212 | ## Job list 213 | Example with 2 UI 214 | ![alt text](https://github.com/MrBounty/PZ-UI_API/blob/main/images/jobBoard.gif) 215 |
216 | See code 217 | 218 | ```lua 219 | local listUI, descUI 220 | local text1 = "

The longest night
In this mission, you gonna need to survivre all night.
Reward: - M14 - 20 ammo
Failure Conditions: -Death" 221 | local text2 = "

I need medical supply !
Please someone come to xx to help me ! I need a doctor or I'm gonna die.
Reward: - Everything I have" 222 | local text3 = "

Help me clean my neighborhood
I need someone to help me fight a group of zombie near xx, there is around xx of them and I don't want to do it alone.
Reward: - 100$" 223 | local text4 = "

Looking for seed
I'm looking for seed, every type of seed. I can pay or exchange. Contact me on my public frequencies xx.x." 224 | local items = {}; 225 | items["EVENT - The longest night"] = text1; 226 | items["URGENT - Medical delivery"] = text2; 227 | items["Help me clean my neighborhood"] = text3; 228 | items["Looking for seed"] = text4; 229 | items["item5"] = ""; 230 | items["item6"] = ""; 231 | items["item7"] = ""; 232 | items["item8"] = ""; 233 | items["item9"] = ""; 234 | items["item10"] = ""; 235 | items["item11"] = ""; 236 | 237 | local function choose(button, args) 238 | getPlayer():Say("I accepted this mission !"); 239 | listUI:close(); 240 | end 241 | 242 | local function openJobDesc(_, item) 243 | descUI:open(); 244 | descUI:setPositionPixel(listUI:getX() + listUI:getWidth(), listUI:getY()); 245 | descUI["rtext"]:setText(item); 246 | end 247 | 248 | local function onCreateUI() 249 | -- List UI 250 | listUI = NewUI(); -- Create UI 251 | listUI:setTitle("Job board"); 252 | listUI:setWidthPercent(0.15); 253 | 254 | listUI:addScrollList("list", items); -- Create list 255 | listUI["list"]:setOnMouseDownFunction(_, openJobDesc) 256 | 257 | listUI:saveLayout(); -- Create window 258 | 259 | -- Description UI 260 | descUI = NewUI(); 261 | descUI:setTitle("Job desc"); 262 | descUI:isSubUIOf(listUI); 263 | descUI:setWidthPercent(0.1); 264 | 265 | descUI:addEmpty(_, _, _, 10); -- Margin only for rich text 266 | descUI:addRichText("rtext", ""); 267 | descUI:setLineHeightPercent(0.2); 268 | descUI:addEmpty(_, _, _, 10); -- Margin only for rich text 269 | descUI:nextLine(); 270 | 271 | descUI:addButton("b1", "Accept ?", choose); 272 | 273 | descUI:saveLayout(); 274 | descUI:close(); 275 | end 276 | 277 | Events.OnCreateUI.Add(onCreateUI) 278 | ``` 279 |

280 | -------------------------------------------------------------------------------- /UI API/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/UI API/icon.png -------------------------------------------------------------------------------- /UI API/media/lua/client/Exemples/AllElements.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | 3 | local text1 = "

Rich Text Add a small desc
- xx - xx - xx - xx" 4 | 5 | local items1 = {"item1", "item2", "item3", "item4", "item5", "item5", "item6", "item7", "item8", "item9", "item10", "item11", "item12"} 6 | 7 | local items2 = {} 8 | items2["name1"] = "item1" 9 | items2["name2"] = "item2" 10 | items2["name3"] = "item3" 11 | items2["name4"] = "item4" 12 | items2["name5"] = "item5" 13 | items2["name6"] = "item6" 14 | items2["name7"] = "item7" 15 | items2["name8"] = "item8" 16 | items2["name9"] = "item9" 17 | items2["name10"] = "item10" 18 | items2["name11"] = "item11" 19 | items2["name12"] = "item12" 20 | items2["name13"] = "item13" 21 | 22 | -- Create the UI with all element exept image and image button 23 | function onCreateUI() 24 | UI = NewUI(); 25 | 26 | UI:addText("", "Empty:", _, "Center"); 27 | UI:addEmpty() 28 | UI:nextLine(); 29 | 30 | UI:addText("", "Rich text:", _, "Center"); 31 | UI:addRichText("", text1); 32 | --UI:setLineHeightPixel(UI:getDefaultLineHeightPixel()) 33 | UI:nextLine(); 34 | 35 | UI:addText("", "Progress bar:", _, "Center"); 36 | UI:addProgressBar("pb1", 0, 0, 100); 37 | UI:nextLine(); 38 | 39 | UI:addText("", "Button:", _, "Center"); 40 | UI:addButton("", "", _) 41 | UI:nextLine(); 42 | 43 | UI:addText("", "Tick box:", _, "Center"); 44 | UI:addTickBox("t1") 45 | UI:nextLine(); 46 | 47 | UI:addText("", "Entry:", _, "Center"); 48 | UI:addEntry("e1", "") 49 | UI:nextLine(); 50 | 51 | UI:addText("", "Combo:", _, "Center"); 52 | UI:addComboBox("c1", items1) 53 | UI:nextLine(); 54 | 55 | UI:addText("", "ScrollList:", _, "Center"); 56 | UI:addScrollList("s1", items2) 57 | 58 | UI:setBorderToAllElements(true); -- Add border 59 | UI:saveLayout(); -- Save and create the UI 60 | end 61 | 62 | local function everyTenMinutes() 63 | print("Tick box: ", UI["t1"]:getValue()); 64 | print("Entry: ", UI["e1"]:getValue()); 65 | print("Combo: ", UI["c1"]:getValue()); 66 | print("ScrollList: ", UI["s1"]:getValue()); 67 | end 68 | 69 | function everyMinute() 70 | if not UI then return false end 71 | UI["pb1"]:setValue(i); 72 | if i > 100 then i = 0 end 73 | i = i + 5; 74 | end 75 | 76 | Events.OnCreateUI.Add(onCreateUI) 77 | Events.EveryTenMinutes.Add(everyTenMinutes) 78 | Events.EveryOneMinute.Add(everyMinute) -------------------------------------------------------------------------------- /UI API/media/lua/client/Exemples/JobChoiceUI.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | local jobSelect = ""; 3 | 4 | -- Text for the rich text element 5 | local text1 = "

Your a policeman ! You are here to protect people ! You can: - Do that - And that - And a lot more" 6 | local text2 = "

Your an engineer ! You are here to create thing ! You can: - Do that - And that - And a lot more" 7 | local text3 = "

Your a doctor ! You are here to help people ! You can: - Do that - And that - And a lot more" 8 | local text4 = "

Your nothing ! You are here to die ! You can: - Do that - And that - And a lot more" 9 | local texts = {text1, text2, text3, text4} 10 | 11 | local jobs = {"Policeman", "Engineer", "Doctor", "Nothing"} 12 | 13 | -- Functions for buttons 14 | local function press(button, args) 15 | UI["rtext"]:setText(texts[args.index]) 16 | jobSelect = jobs[args.index] 17 | getPlayer():Say("I selected " .. jobSelect); 18 | end 19 | 20 | local function ok() 21 | getPlayer():Say("I'm a " .. jobSelect .. " now !"); 22 | UI:close(); 23 | end 24 | 25 | 26 | -- Create the UI 27 | function onCreateUI() 28 | UI = NewUI(); 29 | 30 | -- Add window title 31 | UI:addText("title1", "Choose you job !", "Title", "Center"); 32 | UI["title1"]:setBorder(true); 33 | UI:nextLine(); 34 | 35 | -- Add job description 36 | UI:addRichText("rtext", text1); 37 | UI:nextLine(); 38 | 39 | -- Add buttons 40 | UI:addButton("button1", jobs[1], press); 41 | UI["button1"]:addArg("index", 1); 42 | 43 | UI:addButton("button2", jobs[2], press); 44 | UI["button2"]:addArg("index", 2); 45 | 46 | UI:addButton("button3", jobs[3], press); 47 | UI["button3"]:addArg("index", 3); 48 | 49 | UI:addButton("button4", jobs[4], press); 50 | UI["button4"]:addArg("index", 4); 51 | 52 | UI:addButton("", "Button", ok); 53 | UI:nextLine(); 54 | 55 | -- Save window 56 | UI:saveLayout(); 57 | end 58 | 59 | Events.OnCreateUI.Add(onCreateUI) 60 | -------------------------------------------------------------------------------- /UI API/media/lua/client/Exemples/JobListUI.lua: -------------------------------------------------------------------------------- 1 | local listUI, descUI 2 | local text1 = "

The longest night
In this mission, you gonna need to survivre all night.
Reward: - M14 - 20 ammo
Failure Conditions: -Death" 3 | local text2 = "

I need medical supply !
Please someone come to xx to help me ! I need a doctor or I'm gonna die.
Reward: - Everything I have" 4 | local text3 = "

Help me clean my neighborhood
I need someone to help me fight a group of zombie near xx, there is around xx of them and I don't want to do it alone.
Reward: - 100$" 5 | local text4 = "

Looking for seed
I'm looking for seed, every type of seed. I can pay or exchange. Contact me on my public frequencies xx.x." 6 | local items = {}; 7 | items["EVENT - The longest night"] = text1; 8 | items["URGENT - Medical delivery"] = text2; 9 | items["Help me clean my neighborhood"] = text3; 10 | items["Looking for seed"] = text4; 11 | items["item5"] = ""; 12 | items["item6"] = ""; 13 | items["item7"] = ""; 14 | items["item8"] = ""; 15 | items["item9"] = ""; 16 | items["item10"] = ""; 17 | items["item11"] = ""; 18 | 19 | local function choose(button, args) 20 | getPlayer():Say("I accepted this mission !"); 21 | listUI:close(); 22 | end 23 | 24 | local function openJobDesc(_, item) 25 | descUI:open(); 26 | descUI:setPositionPixel(listUI:getX() + listUI:getWidth(), listUI:getY()); 27 | descUI["rtext"]:setText(item); 28 | end 29 | 30 | function onCreateUI() 31 | -- List UI 32 | listUI = NewUI(); -- Create UI 33 | listUI:setTitle("Job board"); 34 | listUI:setMarginPixel(10, 10); 35 | listUI:setWidthPercent(0.15); 36 | 37 | listUI:addScrollList("list", items); -- Create list 38 | listUI["list"]:setOnMouseDownFunction(_, openJobDesc) 39 | 40 | listUI:saveLayout(); -- Create window 41 | 42 | -- Description UI 43 | descUI = NewUI(); 44 | descUI:setTitle("Job desc"); 45 | descUI:isSubUIOf(listUI); 46 | descUI:setWidthPercent(0.1); 47 | 48 | descUI:addEmpty(_, _, _, 10); -- Margin only for rich text 49 | descUI:addRichText("rtext", ""); 50 | descUI:setLineHeightPercent(0.2); 51 | descUI:addEmpty(_, _, _, 10); -- Margin only for rich text 52 | descUI:nextLine(); 53 | 54 | descUI:addButton("b1", "Accept ?", choose); 55 | 56 | descUI:saveLayout(); 57 | descUI:close(); 58 | end 59 | 60 | --Events.OnCreateUI.Add(onCreateUI) -------------------------------------------------------------------------------- /UI API/media/lua/client/Exemples/QuestChoiceUI.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | local text1 = "

The longest night
In this mission, you gonna need to survivre all night.
Reward: - M14 - 20 ammo
Failure Conditions: -Death" 3 | 4 | local function choose(button, args) 5 | getPlayer():Say(args.choice); 6 | UI:close(); 7 | end 8 | 9 | function onCreateUI() 10 | UI = NewUI(); 11 | 12 | UI:addRichText("rtext", text1); 13 | UI:setLineHeightPercent(0.2); 14 | UI:nextLine(); 15 | 16 | UI:addText("t1", "Accept ?", _, "Center"); 17 | UI["t1"]:addBorder(); 18 | UI:addButton("b1", "Yes", choose); 19 | UI["b1"]:addArg("choice", "yes"); 20 | UI:addButton("b2", "No", choose); 21 | UI["b2"]:addArg("choice", "no"); 22 | 23 | UI:saveLayout(); 24 | end 25 | 26 | --Events.OnCreateUI.Add(onCreateUI) -------------------------------------------------------------------------------- /UI API/media/lua/client/Exemples/TeamChoiceUI.lua: -------------------------------------------------------------------------------- 1 | local UI 2 | 3 | local text1 = "Players: - MrBounty - Dane - xx - xx - xx - xx - xx - xx - xx - xx - xx" 4 | local text2 = "Players: - xx - xx - xx - xx - xx - xx - xx - xx - xx" 5 | 6 | local function choose(button, args) 7 | getPlayer():Say("I'm in the " .. args.team .. " team now !"); 8 | UI:close(); 9 | end 10 | 11 | function onCreateUI() 12 | UI = NewUI(); 13 | UI:addText("", "Choose your team", "Large", "Center"); 14 | UI:nextLine(); 15 | 16 | UI:addRichText("", text1); 17 | UI:addRichText("", text2); 18 | UI:setLineHeightPercent(0.2); 19 | UI:nextLine(); 20 | 21 | UI:addText("t1", "11/12", _, "Center"); 22 | UI:addText("t2", "9/12", _, "Center"); 23 | UI["t1"]:setColor(1, 0, 0, 1); 24 | UI["t2"]:setColor(1, 1, 0, 0); 25 | UI:nextLine(); 26 | 27 | UI:addButton("b1", "Blue", choose); 28 | UI:addButton("b2", "Red", choose); 29 | UI["b1"]:addArg("team", "blue"); 30 | UI["b2"]:addArg("team", "red"); 31 | 32 | UI:addBorderToAllElements(); 33 | UI:setWidthPercent(0.15); 34 | UI:saveLayout(); 35 | end 36 | 37 | --Events.OnCreateUI.Add(onCreateUI) -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/GlobalFunctions.lua: -------------------------------------------------------------------------------- 1 | local allUI = {}; 2 | 3 | function NewUI() 4 | local ui = ISSimpleUI:new(0.4, 0.4, 0.2) 5 | ui:initialise(); 6 | ui:instantiate(); 7 | table.insert(allUI, ui); 8 | return ui 9 | end 10 | 11 | function cutTextToLong(text, width, font, zoom) 12 | if not zoom then zoom = 1 end 13 | while getTextManager():MeasureStringX(font, text) * zoom > width do 14 | text = string.sub(text, 1, #text-1); 15 | if text == "" then break end 16 | end 17 | return text, getTextManager():MeasureStringX(font, text) * zoom; 18 | end 19 | 20 | function onCustomUIKeyPressed(key) 21 | for i, ui in ipairs(allUI) do 22 | if ui.key and key == ui.key then 23 | ui:toggle(); 24 | end 25 | end 26 | end 27 | 28 | Events.OnCustomUIKeyPressed.Add(onCustomUIKeyPressed) -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleButton.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISButton" 2 | 3 | ISSimpleButton = ISButton:derive("ISSimpleButton"); 4 | 5 | function ISSimpleButton:setText(text) 6 | self:setTitle(text); 7 | end 8 | 9 | function ISSimpleButton:onMouseUp(x, y) 10 | if not self:getIsVisible() then 11 | return; 12 | end 13 | local process = false; 14 | if self.pressed == true then 15 | process = true; 16 | end 17 | self.pressed = false; 18 | if self.onclick == nil then 19 | return; 20 | end 21 | if self.enable and (process or self.allowMouseUpProcessing) then 22 | getSoundManager():playUISound(self.sounds.activate) 23 | self.onclick(self, self.args); 24 | end 25 | end 26 | 27 | function ISSimpleButton:setPositionAndSize() 28 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 29 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 30 | self.pxlH = self.parentUI.elemH[self.line]; 31 | 32 | self:setX(self.pxlX); 33 | self:setY(self.pxlY); 34 | self:setWidth(self.pxlW); 35 | self:setHeight(self.pxlH); 36 | self:setOnClick(self.func); 37 | end 38 | 39 | function ISSimpleButton:render() 40 | ISButton.render(self) 41 | if self.border then 42 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 43 | end 44 | end 45 | 46 | function ISSimpleButton:new(parentUI, title, func) 47 | local o = {}; 48 | o = ISButton:new(0, 0, 1, 1, title); 49 | setmetatable(o, self); 50 | self.__index = self; 51 | 52 | o.parentUI = parentUI; 53 | o.line = line; 54 | o.column = column; 55 | 56 | -- Parent and position 57 | o.parentUI = parentUI; 58 | o.line = parentUI.lineAct; 59 | o.column = parentUI.columnAct; 60 | o.pxlY = parentUI.yAct; 61 | 62 | o.func = func; 63 | o.args = {}; 64 | 65 | return o; 66 | end 67 | 68 | -- Commun function 69 | 70 | function ISSimpleButton:setBorder(v) 71 | self.border = v; 72 | end 73 | 74 | function ISSimpleButton:addArg(name, value) 75 | self.args[name] = value; 76 | end 77 | 78 | function ISSimpleButton:setWidthPercent(w) 79 | self.isWidthForce = true; 80 | self.pxlW = w * getCore():getScreenWidth(); 81 | end 82 | 83 | function ISSimpleButton:setWidthPixel(w) 84 | self.isWidthForce = true; 85 | self.pxlW = w; 86 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleComboBox.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISComboBox" 2 | 3 | ISSimpleComboBox = ISComboBox:derive("ISSimpleComboBox"); 4 | 5 | function ISSimpleComboBox:setPositionAndSize() 6 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 7 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 8 | self.pxlH = self.parentUI.elemH[self.line]; 9 | 10 | self:setX(self.pxlX); 11 | self:setY(self.pxlY); 12 | self:setWidth(self.pxlW); 13 | self:setHeight(self.pxlH); 14 | self.baseHeight = self.pxlH; 15 | 16 | if self.simpleItems[1] ~= nil then 17 | for name, item in ipairs(self.simpleItems) do 18 | self:addOption(item); 19 | end 20 | else 21 | for name, item in pairs(self.simpleItems) do 22 | self:addOptionWithData(name, item); 23 | end 24 | end 25 | end 26 | 27 | function ISSimpleComboBox:render() 28 | ISComboBox.render(self) 29 | if self.border then 30 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 31 | end 32 | end 33 | 34 | function ISSimpleComboBox:new(parentUI, simpleItems) 35 | local o = {}; 36 | o = ISComboBox:new(0, 0, 1, 1); 37 | setmetatable(o, self); 38 | self.__index = self; 39 | 40 | o.parentUI = parentUI; 41 | o.line = line; 42 | o.column = column; 43 | 44 | -- Parent and position 45 | o.parentUI = parentUI; 46 | o.line = parentUI.lineAct; 47 | o.column = parentUI.columnAct; 48 | o.pxlY = parentUI.yAct; 49 | o.simpleItems = simpleItems; 50 | 51 | return o; 52 | end 53 | 54 | -- Commun function 55 | 56 | function ISSimpleComboBox:setBorder(v) 57 | self.border = v; 58 | end 59 | 60 | -- Simple element function 61 | function ISSimpleComboBox:getValue() 62 | return self:getSelectedText(); 63 | end 64 | 65 | function ISSimpleComboBox:setitems(v) 66 | self:clear(); 67 | self.simpleItems = v; 68 | for index, value in ipairs(self.simpleItems) do 69 | self:addItem(value); 70 | end 71 | end 72 | 73 | function ISSimpleComboBox:setWidthPercent(w) 74 | self.isWidthForce = true; 75 | self.pxlW = w * getCore():getScreenWidth(); 76 | end 77 | 78 | function ISSimpleComboBox:setWidthPixel(w) 79 | self.isWidthForce = true; 80 | self.pxlW = w; 81 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleEmpty.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISUIElement" 2 | 3 | ISSimpleEmpty = ISUIElement:derive("ISSimpleEmpty"); 4 | 5 | function ISSimpleEmpty:render() 6 | self:drawRect(0, 0, self.width, self.height, self.backgroundColor.a, self.backgroundColor.r, self.backgroundColor.g, self.backgroundColor.b); 7 | 8 | if self.border then 9 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 10 | end 11 | end 12 | 13 | function ISSimpleEmpty:setPositionAndSize() 14 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 15 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 16 | self.pxlH = self.parentUI.elemH[self.line]; 17 | 18 | self:setX(self.pxlX); 19 | self:setY(self.pxlY); 20 | self:setWidth(self.pxlW); 21 | self:setHeight(self.pxlH); 22 | end 23 | 24 | function ISSimpleEmpty:new(parentUI) 25 | local o = {}; 26 | o = ISUIElement:new(0, 0, 1, 1); 27 | setmetatable(o, self); 28 | self.__index = self; 29 | 30 | -- Parent and position 31 | o.parentUI = parentUI; 32 | o.line = parentUI.lineAct; 33 | o.column = parentUI.columnAct; 34 | o.pxlY = parentUI.yAct; 35 | o.isEmptyElement = true; 36 | 37 | o.backgroundColor = {r=0, g=0, b=0, a=1}; 38 | 39 | return o; 40 | end 41 | 42 | -- Commun function 43 | function ISSimpleEmpty:setBorder(v) 44 | self.border = v; 45 | end 46 | 47 | function ISSimpleEmpty:setWidthPercent(w) 48 | self.isWidthForce = true; 49 | self.pxlW = w * getCore():getScreenWidth(); 50 | end 51 | 52 | function ISSimpleEmpty:setWidthPixel(w) 53 | self.isWidthForce = true; 54 | self.pxlW = w; 55 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleEntry.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISTextEntryBox" 2 | 3 | ISSimpleEntry = ISTextEntryBox:derive("ISSimpleEntry"); 4 | 5 | function ISSimpleEntry:setText(text) 6 | self:setTitle(text); 7 | end 8 | 9 | function ISSimpleEntry:setPositionAndSize() 10 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 11 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 12 | self.pxlH = self.parentUI.elemH[self.line]; 13 | 14 | self:setX(self.pxlX); 15 | self:setY(self.pxlY); 16 | self:setWidth(self.pxlW); 17 | self:setHeight(self.pxlH); 18 | end 19 | 20 | function ISSimpleEntry:render() 21 | ISTextEntryBox.render(self) 22 | if self.border then 23 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 24 | end 25 | end 26 | 27 | function ISSimpleEntry:new(parentUI, text, isNumber) 28 | local o = {}; 29 | o = ISTextEntryBox:new(text, 0, 0, 1, 1); 30 | setmetatable(o, self); 31 | self.__index = self; 32 | 33 | o.parentUI = parentUI; 34 | o.line = line; 35 | o.column = column; 36 | 37 | -- Parent and position 38 | o.parentUI = parentUI; 39 | o.line = parentUI.lineAct; 40 | o.column = parentUI.columnAct; 41 | o.pxlY = parentUI.yAct; 42 | o.textOriginal = text; 43 | o.isNumber = isNumber; 44 | 45 | return o; 46 | end 47 | 48 | -- Commun function 49 | 50 | function ISSimpleEntry:setBorder(v) 51 | self.border = v; 52 | end 53 | 54 | -- Simple element function 55 | function ISSimpleEntry:getValue() 56 | if self.isNumber then 57 | return tonumber(self:getInternalText()); 58 | else 59 | return self:getInternalText(); 60 | end 61 | end 62 | 63 | function ISSimpleEntry:setValue(v) 64 | if self.isNumber then 65 | self:setText(tostring(v)); 66 | else 67 | self:setText(v); 68 | end 69 | end 70 | 71 | function ISSimpleEntry:setWidthPercent(w) 72 | self.isWidthForce = true; 73 | self.pxlW = w * getCore():getScreenWidth(); 74 | end 75 | 76 | function ISSimpleEntry:setWidthPixel(w) 77 | self.isWidthForce = true; 78 | self.pxlW = w; 79 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleImage.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISImage" 2 | 3 | ISSimpleImage = ISImage:derive("ISSimpleImage"); 4 | 5 | function ISSimpleImage:setPositionAndSize() 6 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 7 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 8 | self.pxlH = self.parentUI.elemH[self.line]; 9 | 10 | self:setX(self.pxlX); 11 | self:setY(self.pxlY); 12 | self:setWidth(self.pxlW); 13 | self:setHeight(self.pxlH); 14 | self.scaledWidth = self.pxlW; 15 | self.scaledHeight = self.pxlH; 16 | end 17 | 18 | function ISSimpleImage:render() 19 | if self.border then 20 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 21 | end 22 | end 23 | 24 | function ISSimpleImage:new(parentUI, path) 25 | local o = {}; 26 | if not getTexture(path) then 27 | print("UI API - ERROR : Texture at the path ".. path .." not found for image. Changed to default texture.") 28 | path = "ui/emotes/no.png"; 29 | end 30 | o = ISImage:new(0, 0, 1, 1, getTexture(path)); 31 | setmetatable(o, self); 32 | self.__index = self; 33 | 34 | -- Parent and position 35 | o.parentUI = parentUI; 36 | o.line = parentUI.lineAct; 37 | o.column = parentUI.columnAct; 38 | o.pxlY = parentUI.yAct; 39 | o.textOriginal = text; 40 | o.path = path; 41 | o.isImage = true; 42 | 43 | o.origW = o.texture:getWidthOrig(); 44 | o.origH = o.texture:getWidthOrig(); 45 | o.ratio = o.origH / o.origW; 46 | o.border = false; 47 | 48 | return o; 49 | end 50 | 51 | -- Commun function 52 | 53 | function ISSimpleImage:setBorder(v) 54 | self.border = v; 55 | end 56 | 57 | function ISSimpleImage:setWidthPercent(w) 58 | self.isWidthForce = true; 59 | self.pxlW = w * getCore():getScreenWidth(); 60 | end 61 | 62 | function ISSimpleImage:setWidthPixel(w) 63 | self.isWidthForce = true; 64 | self.pxlW = w; 65 | end 66 | 67 | function ISSimpleImage:setPath(path) 68 | self.path = path; 69 | if not getTexture(path) then 70 | print("UI API - ERROR : Texture at the path ".. path .." not found for image. Changed to default texture.") 71 | self.path = "ui/emotes/no.png"; 72 | end 73 | self.texture = getTexture(path); 74 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleImageButton.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISButton" 2 | 3 | ISSimpleImageButton = ISButton:derive("ISSimpleImageButton"); 4 | 5 | function ISSimpleImageButton:setText(text) 6 | self:setTitle(text); 7 | end 8 | 9 | function ISSimpleImageButton:onMouseUp(x, y) 10 | if not self:getIsVisible() then 11 | return; 12 | end 13 | local process = false; 14 | if self.pressed == true then 15 | process = true; 16 | end 17 | self.pressed = false; 18 | if self.onclick == nil then 19 | return; 20 | end 21 | if self.enable and (process or self.allowMouseUpProcessing) then 22 | getSoundManager():playUISound(self.sounds.activate) 23 | self.onclick(self, self.args); 24 | end 25 | end 26 | 27 | function ISSimpleImageButton:setPositionAndSize() 28 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 29 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 30 | self.pxlH = self.parentUI.elemH[self.line]; 31 | 32 | self:setX(self.pxlX); 33 | self:setY(self.pxlY); 34 | self:setWidth(self.pxlW); 35 | self:setHeight(self.pxlH); 36 | self:setOnClick(self.func); 37 | self:setImage(self.texture); 38 | self:forceImageSize(self.pxlW, self.pxlH); 39 | end 40 | 41 | function ISSimpleImageButton:render() 42 | ISButton.render(self) 43 | if self.border then 44 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 45 | end 46 | end 47 | 48 | function ISSimpleImageButton:new(parentUI, path, func) 49 | local o = {}; 50 | o = ISButton:new(0, 0, 1, 1, ""); 51 | setmetatable(o, self); 52 | self.__index = self; 53 | 54 | o.parentUI = parentUI; 55 | o.line = line; 56 | o.column = column; 57 | if not getTexture(path) then 58 | print("UI API - ERROR : Texture at the path "..path.." not found for image button. Changed to default texture.") 59 | path = "ui/emotes/no.png"; 60 | end 61 | o.texture = getTexture(path); 62 | 63 | -- Parent and position 64 | o.parentUI = parentUI; 65 | o.line = parentUI.lineAct; 66 | o.column = parentUI.columnAct; 67 | o.pxlY = parentUI.yAct; 68 | o.path = path; 69 | o.isImage = true; 70 | 71 | o.origW = o.texture:getWidthOrig(); 72 | o.origH = o.texture:getWidthOrig(); 73 | o.ratio = o.origH / o.origW; 74 | o.border = false; 75 | 76 | o.func = func; 77 | o.args = {}; 78 | 79 | return o; 80 | end 81 | 82 | -- Commun function 83 | 84 | function ISSimpleImageButton:setBorder(v) 85 | self.border = v; 86 | end 87 | 88 | function ISSimpleImage:setPath(path) 89 | self.path = path; 90 | if not getTexture(path) then 91 | print("UI API - ERROR : Texture at the path ".. path .." not found for image. Changed to default texture.") 92 | self.path = "ui/emotes/no.png"; 93 | end 94 | self.texture = getTexture(path); 95 | self:setImage(self.texture); 96 | end 97 | 98 | function ISSimpleImageButton:addArg(name, value) 99 | self.args[name] = value; 100 | end 101 | 102 | function ISSimpleImageButton:setWidthPercent(w) 103 | self.isWidthForce = true; 104 | self.pxlW = w * getCore():getScreenWidth(); 105 | end 106 | 107 | function ISSimpleImageButton:setWidthPixel(w) 108 | self.isWidthForce = true; 109 | self.pxlW = w; 110 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleProgressBar.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISUIElement" 2 | 3 | ISSimpleProgressBar = ISUIElement:derive("ISSimpleProgressBar"); 4 | 5 | function ISSimpleProgressBar:render() 6 | if self.value < self.min then self.value = self.min 7 | elseif self.value > self.max then self.value = self.max 8 | end 9 | 10 | local pct = (self.value - self.min) / (self.max - self.min); 11 | self:drawRect(self.barMarginW, self.barMarginH, (self.pxlW-self.barMarginW*2) * pct, self.pxlH - self.barMarginH*2, self.a, self.r, self.g, self.b); 12 | 13 | if self.border then 14 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 15 | end 16 | end 17 | 18 | function ISSimpleProgressBar:setPositionAndSize() 19 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 20 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 21 | self.pxlH = self.parentUI.elemH[self.line]; 22 | 23 | self:setX(self.pxlX); 24 | self:setY(self.pxlY); 25 | self:setWidth(self.pxlW); 26 | self:setHeight(self.pxlH); 27 | end 28 | 29 | function ISSimpleProgressBar:new(parentUI, value, min, max) 30 | local o = {}; 31 | o = ISUIElement:new(0, 0, 1, 1); 32 | setmetatable(o, self); 33 | self.__index = self; 34 | 35 | -- Parent and position 36 | o.parentUI = parentUI; 37 | o.line = parentUI.lineAct; 38 | o.column = parentUI.columnAct; 39 | o.pxlY = parentUI.yAct; 40 | 41 | -- Color 42 | o.a = 1; 43 | o.r = 1; 44 | o.g = 1; 45 | o.b = 1; 46 | o.backgroundColor = {r=0, g=0, b=0, a=1}; 47 | 48 | o.anchorLeft = true; 49 | o.anchorRight = false; 50 | o.anchorTop = true; 51 | o.anchorBottom = false; 52 | 53 | -- For this element 54 | o.value = value; 55 | o.min = min; 56 | o.max = max; 57 | o.barMarginW = 0; 58 | o.barMarginH = 0; 59 | 60 | return o; 61 | end 62 | 63 | -- Commun function 64 | function ISSimpleProgressBar:setBorder(v) 65 | self.border = v; 66 | end 67 | 68 | function ISSimpleProgressBar:setWidthPercent(w) 69 | self.isWidthForce = true; 70 | self.pxlW = w * getCore():getScreenWidth(); 71 | end 72 | 73 | function ISSimpleProgressBar:setWidthPixel(w) 74 | self.isWidthForce = true; 75 | self.pxlW = w; 76 | end 77 | 78 | -- For element 79 | 80 | function ISSimpleProgressBar:setColor(a, r, g, b) 81 | self.a = a; 82 | self.r = r; 83 | self.g = g; 84 | self.b = b; 85 | end 86 | 87 | function ISSimpleProgressBar:setValue(v) 88 | self.value = v; 89 | end 90 | 91 | function ISSimpleProgressBar:setMinMax(min, max) 92 | self.min = min; 93 | self.max = max; 94 | end 95 | 96 | function ISSimpleProgressBar:setMarginPercent(pctW, pctH) 97 | self.barMarginW = pctW * getCore():getScreenWidth(); 98 | self.barMarginH = pctH * getCore():getScreenHeight(); 99 | end 100 | 101 | function ISSimpleProgressBar:setMarginPixel(pxlW, pxlH) 102 | self.barMarginW = pxlW; 103 | self.barMarginH = pxlH; 104 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleRichText.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISUIElement" 2 | 3 | ISSimpleRichText = ISUIElement:derive("ISSimpleRichText"); 4 | 5 | function ISSimpleRichText:setPositionAndSize() 6 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 7 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 8 | self.pxlH = self.parentUI.elemH[self.line]; 9 | 10 | self.richText:setWidth(self.pxlW); 11 | self.richText:setText(self.text); 12 | self.richText:initialise(); 13 | self.richText:paginate(); 14 | 15 | self:setX(self.pxlX); 16 | self:setY(self.pxlY); 17 | self:setWidth(self.pxlW); 18 | self:setHeight(self.pxlH); 19 | end 20 | 21 | function ISSimpleRichText:initialise() 22 | ISUIElement.initialise(self); 23 | self.richText = ISRichTextLayout:new(self.width); 24 | self.richText.marginLeft = 0; 25 | self.richText.marginTop = 0; 26 | self.richText.marginRight = 0; 27 | self.richText.marginBottom = 0; 28 | end 29 | 30 | function ISSimpleRichText:prerender() 31 | self.richText:render(0, self:getYScroll(), self); 32 | if self.border then 33 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 34 | end 35 | end 36 | 37 | function ISSimpleRichText:onMouseWheel(del) 38 | self:setYScroll(self:getYScroll() - (del*18)); 39 | return true; 40 | end 41 | 42 | function ISSimpleRichText:new(parentUI, text) 43 | local o = {}; 44 | o = ISUIElement:new(0, 0, 1, 1); 45 | setmetatable(o, self); 46 | self.__index = self; 47 | o.parentUI = parentUI; 48 | o.line = line; 49 | o.column = column; 50 | -- Parent and position 51 | o.parentUI = parentUI; 52 | o.line = parentUI.lineAct; 53 | o.column = parentUI.columnAct; 54 | o.pxlY = parentUI.yAct; 55 | o.text = text; 56 | return o; 57 | end 58 | 59 | -- Commun function 60 | function ISSimpleRichText:setBorder(v) 61 | self.border = v; 62 | end 63 | 64 | function ISSimpleRichText:setText(text) 65 | self.richText:setText(text); 66 | self.richText:paginate(); 67 | end 68 | 69 | function ISSimpleRichText:setWidthPercent(w) 70 | self.isWidthForce = true; 71 | self.pxlW = w * getCore():getScreenWidth(); 72 | end 73 | 74 | function ISSimpleRichText:setWidthPixel(w) 75 | self.isWidthForce = true; 76 | self.pxlW = w; 77 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleScrollingListBox.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISScrollingListBox" 2 | 3 | ISSimpleScrollingListBox = ISScrollingListBox:derive("ISSimpleScrollingListBox"); 4 | 5 | function ISSimpleScrollingListBox:setPositionAndSize() 6 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 7 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 8 | self.pxlH = self.parentUI.elemH[self.line]; 9 | 10 | self:setX(self.pxlX); 11 | self:setY(self.pxlY); 12 | self:setWidth(self.pxlW); 13 | self:setHeight(self.pxlH); 14 | self:setFont(UIFont.Small, 2); 15 | 16 | if self.simpleItems[1] ~= nil then 17 | for name, item in ipairs(self.simpleItems) do 18 | self:addItem(item, item); 19 | end 20 | else 21 | for name, item in pairs(self.simpleItems) do 22 | self:addItem(name, item); 23 | end 24 | end 25 | end 26 | 27 | function ISSimpleScrollingListBox:render() 28 | ISScrollingListBox.render(self) 29 | if self.border then 30 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 31 | end 32 | end 33 | 34 | function ISSimpleScrollingListBox:doDrawItem(y, item, alt) 35 | if not item.height then item.height = self.itemheight end -- compatibililty 36 | if y < -self:getYScroll() then return y + item.height; end -- Not draw if out of box 37 | if y > self:getHeight()-self:getYScroll() then return y + item.height; end -- Not draw if out of box 38 | 39 | if self.selected == item.index then 40 | self:drawRect(0, (y), self:getWidth(), item.height-1, 0.3, 0.7, 0.35, 0.15); 41 | end 42 | self:drawRectBorder(0, (y), self:getWidth(), item.height, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b); 43 | local itemPadY = self.itemPadY or (item.height - self.fontHgt) / 2 44 | self:drawText(item.text, 15, (y)+itemPadY, 0.9, 0.9, 0.9, 0.9, self.font); 45 | y = y + item.height; 46 | return y; 47 | 48 | end 49 | 50 | function ISSimpleScrollingListBox:new(parentUI, simpleItems) 51 | local o = {}; 52 | o = ISScrollingListBox:new(0, 0, 1, 1); 53 | setmetatable(o, self); 54 | self.__index = self; 55 | 56 | o.parentUI = parentUI; 57 | o.line = line; 58 | o.column = column; 59 | o.border = false; 60 | 61 | -- Parent and position 62 | o.parentUI = parentUI; 63 | o.line = parentUI.lineAct; 64 | o.column = parentUI.columnAct; 65 | o.pxlY = parentUI.yAct; 66 | o.simpleItems = simpleItems; 67 | 68 | return o; 69 | end 70 | 71 | -- Commun function 72 | 73 | function ISSimpleScrollingListBox:setBorder(v) 74 | self.border = v; 75 | end 76 | 77 | -- Simple element function 78 | function ISSimpleScrollingListBox:getValue() 79 | return self.items[self.selected].text, self.items[self.selected].item; 80 | end 81 | 82 | function ISSimpleScrollingListBox:setitems(v) 83 | self:clear(); 84 | self.simpleItems = v; 85 | for index, value in ipairs(self.simpleItems) do 86 | self:addItem(value); 87 | end 88 | end 89 | 90 | function ISSimpleScrollingListBox:setWidthPercent(w) 91 | self.isWidthForce = true; 92 | self.pxlW = w * getCore():getScreenWidth(); 93 | end 94 | 95 | function ISSimpleScrollingListBox:setWidthPixel(w) 96 | self.isWidthForce = true; 97 | self.pxlW = w; 98 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleText.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISUIElement" 2 | 3 | ISSimpleText = ISUIElement:derive("ISSimpleText"); 4 | 5 | function ISSimpleText:render() 6 | self:drawRect(0, 0, self.width, self.height, self.backgroundColor.a, self.backgroundColor.r, self.backgroundColor.g, self.backgroundColor.b); 7 | local y = (self.pxlH - self.textH)/2; 8 | 9 | if self.position == "Left" then 10 | self:drawText(self.textToDisplay, 0, y, self.r, self.g, self.b, self.a, self.font); 11 | elseif self.position == "Right" then 12 | self:drawTextRight(self.textToDisplay, self:getWidth()-self.textW, y, self.r, self.g, self.b, self.a, self.font); 13 | elseif self.position == "Center" then 14 | self:drawTextCentre(self.textToDisplay, self:getWidth()/2, y, self.r, self.g, self.b, self.a, self.font); 15 | else 16 | self:drawText(self.textToDisplay, 0, y, self.r, self.g, self.b, self.a, self.font); 17 | end 18 | 19 | if self.border then 20 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 21 | end 22 | end 23 | 24 | function ISSimpleText:setPositionAndSize() 25 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 26 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 27 | self.pxlH = self.parentUI.elemH[self.line]; 28 | self.textH = getTextManager():getFontHeight(self.font); 29 | 30 | self:setX(self.pxlX); 31 | self:setY(self.pxlY); 32 | self:setWidth(self.pxlW); 33 | self:setHeight(self.pxlH); 34 | 35 | self.textToDisplay, self.textW = cutTextToLong(self.textOriginal, self:getWidth(), self.font); 36 | end 37 | 38 | function ISSimpleText:new(parentUI, text, font, position) 39 | local o = {}; 40 | o = ISUIElement:new(0, 0, 1, 1); 41 | setmetatable(o, self); 42 | self.__index = self; 43 | 44 | -- Parent and position 45 | o.parentUI = parentUI; 46 | o.line = parentUI.lineAct; 47 | o.column = parentUI.columnAct; 48 | o.pxlY = parentUI.yAct; 49 | 50 | -- Color 51 | o.a = 1; 52 | o.r = 1; 53 | o.g = 1; 54 | o.b = 1; 55 | o.backgroundColor = {r=0, g=0, b=0, a=1}; 56 | 57 | o.anchorLeft = true; 58 | o.anchorRight = false; 59 | o.anchorTop = true; 60 | o.anchorBottom = false; 61 | 62 | -- For this element 63 | if text then 64 | o.textOriginal = text; 65 | else 66 | o.textOriginal = ""; 67 | end 68 | 69 | if font then 70 | o.font = UIFont[font]; 71 | else 72 | o.font = UIFont.Small; 73 | end 74 | 75 | if position then 76 | o.position = position; 77 | else 78 | o.position = "Left"; 79 | end 80 | 81 | return o; 82 | end 83 | 84 | -- Commun function 85 | function ISSimpleText:setBorder(v) 86 | self.border = v; 87 | end 88 | 89 | function ISSimpleText:setWidthPercent(w) 90 | self.isWidthForce = true; 91 | self.pxlW = w * getCore():getScreenWidth(); 92 | end 93 | 94 | function ISSimpleText:setWidthPixel(w) 95 | self.isWidthForce = true; 96 | self.pxlW = w; 97 | end 98 | 99 | -- For element 100 | function ISSimpleText:setText(txt) 101 | self.textOriginal = txt; 102 | self.textToDisplay, self.textW = cutTextToLong(self.textOriginal, self:getWidth(), self.font); 103 | end 104 | 105 | function ISSimpleText:setPosition(position) 106 | self.position = position 107 | end 108 | 109 | function ISSimpleText:setColor(a, r, g, b) 110 | self.a = a; 111 | self.r = r; 112 | self.g = g; 113 | self.b = b; 114 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleTickBox.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISUIElement" 2 | 3 | ISSimpleTickBox = ISUIElement:derive("ISSimpleTickBox"); 4 | 5 | -- Vanilla element function 6 | function ISSimpleTickBox:setPositionAndSize() 7 | self.pxlW = self.parentUI.elemW[self.line][self.column]; 8 | self.pxlX = self.parentUI.elemX[self.line][self.column]; 9 | self.pxlH = self.parentUI.elemH[self.line]; 10 | 11 | self:setX(self.pxlX); 12 | self:setY(self.pxlY); 13 | self:setWidth(self.pxlW); 14 | self:setHeight(self.pxlH); 15 | local x, y 16 | 17 | if self.pxlW > self.pxlH then 18 | self.tickSize = self.pxlH; 19 | x = (self.pxlW - self.tickSize)/2; 20 | y = 0; 21 | else 22 | self.tickSize = self.pxlW; 23 | x = 0; 24 | y = (self.pxlH - self.tickSize)/2; 25 | end 26 | 27 | self.tickBox:setX(x); 28 | self.tickBox:setY(y); 29 | self.tickBox:setWidth(self.tickSize); 30 | self.tickBox:setHeight(self.tickSize); 31 | self.tickBox.borderColor = {r=1, g=1, b=1, a=1}; 32 | self.tickBox:bringToTop(); 33 | end 34 | 35 | function ISSimpleTickBox:createChildren() 36 | self.tickBox = ISTickBox:new(0, 0, 1, 1); 37 | self.tickBox:initialise(); 38 | self.tickBox:instantiate(); 39 | self.tickBox:addOption(""); 40 | self:addChild(self.tickBox); 41 | end 42 | 43 | function ISSimpleTickBox:onMouseWheel(del) 44 | self:setYScroll(self:getYScroll() - (del*18)); 45 | return true; 46 | end 47 | 48 | function ISSimpleTickBox:render() 49 | ISUIElement.render(self) 50 | if self.border then 51 | self:drawRectBorder(0, 0, self:getWidth(), self:getHeight(), 0.5, 1, 1, 1); 52 | end 53 | end 54 | 55 | -- New 56 | function ISSimpleTickBox:new(parentUI) 57 | local o = {}; 58 | o = ISUIElement:new(0, 0, 1, 1); 59 | setmetatable(o, self); 60 | self.__index = self; 61 | o.parentUI = parentUI; 62 | o.line = line; 63 | o.column = column; 64 | -- Parent and position 65 | o.parentUI = parentUI; 66 | o.line = parentUI.lineAct; 67 | o.column = parentUI.columnAct; 68 | o.pxlY = parentUI.yAct; 69 | return o; 70 | end 71 | 72 | -- Commun function 73 | function ISSimpleTickBox:setBorder(v) 74 | self.border = v; 75 | end 76 | 77 | -- Simple element function 78 | function ISSimpleTickBox:getValue() 79 | return self.tickBox.selected[1]; 80 | end 81 | 82 | function ISSimpleTickBox:setValue(v) 83 | self.tickBox.selected[1] = v; 84 | end 85 | 86 | function ISSimpleTickBox:setWidthPercent(w) 87 | self.isWidthForce = true; 88 | self.pxlW = w * getCore():getScreenWidth(); 89 | end 90 | 91 | function ISSimpleTickBox:setWidthPixel(w) 92 | self.isWidthForce = true; 93 | self.pxlW = w; 94 | end -------------------------------------------------------------------------------- /UI API/media/lua/client/ISUI/ISSimpleUI.lua: -------------------------------------------------------------------------------- 1 | require "ISUI/ISCollapsableWindow" 2 | 3 | ISSimpleUI = ISCollapsableWindow:derive("ISSimpleUI"); 4 | 5 | function ISSimpleUI:initialise() 6 | ISCollapsableWindow.initialise(self); 7 | end 8 | 9 | function ISSimpleUI:render() 10 | ISCollapsableWindow.render(self); 11 | 12 | if self.isSubUI and not self.parentUI.isUIVisible then 13 | self:close(); 14 | end 15 | end 16 | 17 | function ISSimpleUI:addLineToMatrices(isLastLine) 18 | local i = self.lineAct; 19 | local nbElemWidthForce = 0; 20 | local widthLeft = self.pxlW; 21 | self.elemW[i] = {}; 22 | self.elemX[i] = {}; 23 | local nbElement = self.lineColumnCount[i]; -- Number of element in the line 24 | local w = math.floor(self.pxlW / nbElement); -- Size of element 25 | 26 | for j=1,self.lineColumnCount[i] do -- Check if an element got this width force 27 | if self.matriceLayout[i][j].isWidthForce then 28 | nbElemWidthForce = nbElemWidthForce + 1; 29 | widthLeft = widthLeft - self.matriceLayout[i][j].pxlW; 30 | end 31 | end 32 | 33 | for j=1,self.lineColumnCount[i] do -- For every column in line 34 | if nbElemWidthForce ~= 0 or self.forceColumnWidht ~= {} then 35 | if widthLeft < 1 then 36 | print("UI API - ERROR : At line ".. i .." of the UI " .. self:getTitle() .. ". Width set to element wider that the window width."); 37 | end 38 | local nbElementLeft = nbElement - nbElemWidthForce; 39 | local w = math.floor(widthLeft / nbElementLeft); -- Size of element 40 | local elem = self.matriceLayout[i][j]; 41 | 42 | -- Set size of element 43 | if elem.isWidthForce then -- Id the element get this width force 44 | self.elemW[i][j] = elem.pxlW; 45 | elseif self.forceColumnWidht[j] ~= nil then -- If width of the column is set 46 | self.elemW[i][j] = self.forceColumnWidht[j]; 47 | else 48 | self.elemW[i][j] = w; 49 | end 50 | 51 | -- Set x position of element 52 | if j == 1 then 53 | self.elemX[i][j] = 0; 54 | else 55 | self.elemX[i][j] = self.elemX[i][j-1] + self.elemW[i][j-1]; -- set position 56 | end 57 | else 58 | self.elemW[i][j] = w; -- set size 59 | self.elemX[i][j] = w * (j-1); -- set position 60 | end 61 | end 62 | if self.lineColumnCount[i] > 0 then 63 | self.elemW[i][self.lineColumnCount[i]] = self.pxlW - self.elemX[i][self.lineColumnCount[i]]; -- Set size to last element to the border in case pixel is lost with math.floor 64 | elseif not isLastLine then 65 | print("UI API - ERROR : LINE " .. i .." WITHOUT ELEMENT") 66 | end 67 | end 68 | 69 | 70 | function ISSimpleUI:setElementsPositionAndSize() 71 | for index, value in ipairs(self.noNameElements) do 72 | value:setPositionAndSize() 73 | end 74 | for index, value in pairs(self.namedElements) do 75 | value:setPositionAndSize() 76 | end 77 | end 78 | 79 | function ISSimpleUI:setBorderToAllElements(v) 80 | for index, value in ipairs(self.noNameElements) do 81 | value:setBorder(v) 82 | end 83 | for index, value in pairs(self.namedElements) do 84 | value:setBorder(v) 85 | end 86 | end 87 | 88 | function ISSimpleUI:new(pctX, pctY, pctW) 89 | local x = getCore():getScreenWidth() * pctX; 90 | local y = getCore():getScreenHeight() * pctY; 91 | local w = getCore():getScreenWidth() * pctW; 92 | local o = {}; 93 | o = ISCollapsableWindow:new(x, y, w, 1); 94 | setmetatable(o, self); 95 | self.__index = self; 96 | 97 | o:setHeight(o:titleBarHeight()); 98 | 99 | -- Position 100 | o.pctX = pctX; 101 | o.pctY = pctY; 102 | o.pxlX = o.pctX * getCore():getScreenWidth(); 103 | o.pxlY = o.pctY * getCore():getScreenHeight(); 104 | 105 | --Size 106 | o.pctW = pctW; 107 | o.pxlW = o.pctW * getCore():getScreenWidth(); 108 | 109 | -- My stuff 110 | o.noNameElements = {}; -- List of elements with no name 111 | o.namedElements = {}; -- List of elements with name 112 | o.lineAct = 1; -- Actual line of the UI 113 | o.elemY = {}; -- y position for each line 114 | o.elemH = {}; -- height for each line 115 | o.elemW = {}; 116 | o.elemX = {}; 117 | o.lineColumnCount = {}; -- Number of columns in a line 118 | o.columnAct = 0; -- Actual columns of the UI 119 | o.yAct = o:titleBarHeight(); -- Actual position 120 | o.forceColumnWidht = {}; 121 | o.deltaY = 0; 122 | o.lineHaveImages = false; 123 | o.isUIVisible = true; 124 | o.useMargin = false; 125 | o.defaultLineHeight = getTextManager():getFontHeight(UIFont.Small) + 4; 126 | o.matriceLayout = {} -- Matrice of the layout, like that matriceLayout[line][column] 127 | table.insert(o.elemY, o.yAct); 128 | table.insert(o.lineColumnCount, 0); 129 | 130 | -- ISCollapsableWindow stuff 131 | o.resizable = false; 132 | o.drawFrame = true; 133 | return o; 134 | end 135 | 136 | 137 | -- Toggle 138 | 139 | function ISSimpleUI:open() 140 | if not self.isUIVisible then 141 | self:setVisible(true); 142 | self.isUIVisible = true; 143 | end 144 | end 145 | 146 | function ISSimpleUI:close() 147 | if self.isUIVisible then 148 | self:setVisible(false); 149 | self.isUIVisible = false; 150 | end 151 | end 152 | 153 | function ISSimpleUI:toggle() 154 | if self.isUIVisible then 155 | self:setVisible(false); 156 | self.isUIVisible = false; 157 | else 158 | self:setVisible(true); 159 | self.isUIVisible = true; 160 | end 161 | end 162 | 163 | 164 | -- Line and column 165 | 166 | function ISSimpleUI:nextLine(isNextLine) 167 | if not isNextLine and self.useMargin and self.marginW ~= 0 then 168 | self:addEmpty(_, _, _, self.marginW); 169 | end 170 | 171 | self:addLineToMatrices(); 172 | 173 | self.columnAct = 0; 174 | if self.lineHaveImages then 175 | self.lineHaveImages = false; 176 | for index, value in ipairs(self.matriceLayout[self.lineAct]) do 177 | if value.isImage then 178 | if self.deltaY < self.elemW[value.line][value.column] * value.ratio then self.deltaY = self.elemW[value.line][value.column] * value.ratio 179 | else self.elemW[value.line][value.column] = self.deltaY / value.ratio; 180 | end 181 | end 182 | end 183 | for index, value in ipairs(self.matriceLayout[self.lineAct]) do 184 | if value.isImage then 185 | if self.deltaY < self.elemW[value.line][value.column] * value.ratio then self.deltaY = self.elemW[value.line][value.column] * value.ratio 186 | else self.elemW[value.line][value.column] = self.deltaY / value.ratio; 187 | end 188 | end 189 | end 190 | end 191 | 192 | self.lineAct = self.lineAct + 1; 193 | self.yAct = self.yAct + self.deltaY; 194 | table.insert(self.elemH, self.deltaY); 195 | self.deltaY = 0; 196 | table.insert(self.elemY, self.yAct); 197 | table.insert(self.lineColumnCount, 0); 198 | 199 | if not isNextLine and self.useMargin and self.marginW ~= 0 then 200 | self:addEmpty(_, _, _, self.marginW); 201 | end 202 | end 203 | 204 | function ISSimpleUI:initAndAddToTable(newE, name) 205 | newE:initialise(); 206 | newE:instantiate(); 207 | self:addChild(newE); 208 | 209 | if name and self[name] ~= nil then 210 | print("UI API - ERROR : element name '" .. name .. "' is already a variable name. Change it !") 211 | end 212 | 213 | if name == "" or not name then 214 | table.insert(self.noNameElements, newE); 215 | else 216 | self.namedElements[name] = newE; 217 | self[name] = newE; 218 | end 219 | 220 | if not self.matriceLayout[self.lineAct] then self.matriceLayout[self.lineAct] = {} end 221 | self.matriceLayout[self.lineAct][self.columnAct] = newE; 222 | end 223 | 224 | function ISSimpleUI:setLineHeightPercent(pctH) 225 | self.deltaY = pctH * getCore():getScreenHeight(); 226 | end 227 | 228 | function ISSimpleUI:setLineHeightPixel(pxlH) 229 | self.deltaY = pxlH; 230 | end 231 | 232 | function ISSimpleUI:setColumnWidthPercent(column, pctW) 233 | self.forceColumnWidht[column] = pctW * getCore():getScreenWidth(); 234 | end 235 | 236 | function ISSimpleUI:setColumnWidthPixel(column, pxlW) 237 | self.forceColumnWidht[column] = pxlW; 238 | end 239 | 240 | function ISSimpleUI:nextColumn() 241 | -- Not use by user 242 | -- Add a column 243 | self.lineColumnCount[self.lineAct] = self.lineColumnCount[self.lineAct] + 1; 244 | self.columnAct = self.columnAct + 1; 245 | end 246 | 247 | function ISSimpleUI:saveLayout() 248 | self:nextLine(); 249 | if self.useMargin and self.marginH ~= 0 then 250 | self:addEmpty(); 251 | self:setLineHeightPixel(self.marginH); 252 | self:nextLine(true); 253 | end 254 | self:setHeight(self.yAct); 255 | self:setElementsPositionAndSize(); 256 | 257 | -- Remove collapse button 258 | self.collapseButton:setVisible(false); 259 | self.pinButton:setVisible(false); 260 | 261 | self:addToUIManager(); 262 | self:setInCenterOfScreen(); 263 | end 264 | 265 | function ISSimpleUI:isSubUIOf(parent) 266 | self.isSubUI = true; 267 | self.parentUI = parent; 268 | end 269 | 270 | function ISSimpleUI:setMarginPercent(pctW, pctH) 271 | self.useMargin = true; 272 | self.marginW = pctW * getCore():getScreenWidth(); 273 | self.marginH = pctH * getCore():getScreenHeight(); 274 | if self.marginH ~= 0 then 275 | self:addEmpty(); 276 | self:setLineHeightPixel(self.marginH); 277 | self:nextLine(); 278 | end 279 | 280 | if pctW == 0 and pctH == 0 then self.useMargin = false; end 281 | end 282 | 283 | function ISSimpleUI:setMarginPixel(pxlW, pxlH) 284 | self.useMargin = true; 285 | self.marginW = pxlW; 286 | self.marginH = pxlH; 287 | if self.marginH ~= 0 then 288 | self:addEmpty(); 289 | self:setLineHeightPixel(self.marginH); 290 | self:nextLine(); 291 | end 292 | 293 | if pxlH == 0 and pxlW == 0 then self.useMargin = false; end 294 | end 295 | 296 | 297 | -- Elements 298 | 299 | function ISSimpleUI:addEmpty(name, nb, pctW, pxlW) 300 | if not nb then nb = 1 end 301 | for i=1,nb do 302 | self:nextColumn(); 303 | local newE = ISSimpleEmpty:new(self); 304 | if name and name ~= "" then 305 | self:initAndAddToTable(newE, name .. i); 306 | else 307 | self:initAndAddToTable(newE, ""); 308 | end 309 | 310 | if pctW then 311 | newE:setWidthPercent(pctW); 312 | elseif pxlW then 313 | newE:setWidthPixel(pxlW); 314 | end 315 | end 316 | 317 | -- Add to yAct 318 | local deltaY = self.defaultLineHeight; 319 | if self.deltaY < deltaY then self.deltaY = deltaY end 320 | end 321 | 322 | function ISSimpleUI:addText(name, txt, font, position) 323 | self:nextColumn(); 324 | 325 | -- Create element 326 | local newE = ISSimpleText:new(self, txt, font, position); 327 | self:initAndAddToTable(newE, name); 328 | 329 | -- Add to yAct 330 | local deltaY = getTextManager():getFontHeight(newE.font); 331 | if self.deltaY < deltaY then self.deltaY = deltaY end 332 | end 333 | 334 | function ISSimpleUI:addProgressBar(name, value, min, max) 335 | self:nextColumn(); 336 | 337 | -- Create element 338 | local newE = ISSimpleProgressBar:new(self, value, min, max); 339 | self:initAndAddToTable(newE, name); 340 | 341 | -- Add to yAct 342 | local deltaY = getTextManager():getFontHeight(newE.font); 343 | if self.deltaY < deltaY then self.deltaY = deltaY end 344 | end 345 | 346 | function ISSimpleUI:addRichText(name, text) 347 | self:nextColumn(); 348 | 349 | -- Create element 350 | local newE = ISSimpleRichText:new(self, text); 351 | self:initAndAddToTable(newE, name); 352 | 353 | -- Add to yAct 354 | local deltaY = self.defaultLineHeight * 8; 355 | if self.deltaY < deltaY then self.deltaY = deltaY end 356 | end 357 | 358 | function ISSimpleUI:addButton(name, text, func) 359 | self:nextColumn(); 360 | 361 | -- Create element 362 | local newE = ISSimpleButton:new(self, text, func); 363 | self:initAndAddToTable(newE, name); 364 | 365 | -- Add to yAct 366 | local deltaY = self.defaultLineHeight; 367 | if self.deltaY < deltaY then self.deltaY = deltaY end 368 | end 369 | 370 | function ISSimpleUI:addTickBox(name) 371 | self:nextColumn(); 372 | 373 | -- Create element 374 | local newE = ISSimpleTickBox:new(self); 375 | self:initAndAddToTable(newE, name); 376 | 377 | -- Add to yAct 378 | local deltaY = self.defaultLineHeight; 379 | if self.deltaY < deltaY then self.deltaY = deltaY end 380 | end 381 | 382 | function ISSimpleUI:addEntry(name, text, isNumber) 383 | self:nextColumn(); 384 | 385 | -- Create element 386 | local newE = ISSimpleEntry:new(self, text, isNumber); 387 | self:initAndAddToTable(newE, name); 388 | 389 | -- Add to yAct 390 | local deltaY = self.defaultLineHeight; 391 | if self.deltaY < deltaY then self.deltaY = deltaY end 392 | end 393 | 394 | function ISSimpleUI:addComboBox(name, items) 395 | self:nextColumn(); 396 | 397 | -- Create element 398 | local newE = ISSimpleComboBox:new(self, items); 399 | self:initAndAddToTable(newE, name); 400 | 401 | -- Add to yAct 402 | local deltaY = self.defaultLineHeight * 1.5; 403 | if self.deltaY < deltaY then self.deltaY = deltaY end 404 | end 405 | 406 | function ISSimpleUI:addScrollList(name, items) 407 | self:nextColumn(); 408 | 409 | -- Create element 410 | local newE = ISSimpleScrollingListBox:new(self, items); 411 | newE.isScrollList = true; 412 | self:initAndAddToTable(newE, name); 413 | 414 | -- Add to yAct 415 | local deltaY = self.defaultLineHeight * 8; 416 | if self.deltaY < deltaY then self.deltaY = deltaY end 417 | end 418 | 419 | function ISSimpleUI:addImage(name, path) 420 | self:nextColumn(); 421 | self.lineHaveImages = true; 422 | 423 | -- Create element 424 | local newE = ISSimpleImage:new(self, path); 425 | self:initAndAddToTable(newE, name); 426 | 427 | -- Add to yAct 428 | local deltaY = self.defaultLineHeight; 429 | if self.deltaY < deltaY then self.deltaY = deltaY end 430 | end 431 | 432 | function ISSimpleUI:addImageButton(name, path, func) 433 | self:nextColumn(); 434 | self.lineHaveImages = true; 435 | 436 | -- Create element 437 | local newE = ISSimpleImageButton:new(self, path, func); 438 | self:initAndAddToTable(newE, name); 439 | 440 | -- Add to yAct 441 | local deltaY = self.defaultLineHeight; 442 | if self.deltaY < deltaY then self.deltaY = deltaY end 443 | end 444 | 445 | 446 | -- Position and size 447 | 448 | function ISSimpleUI:setPositionPercent(pctX, pctY) 449 | self.pctX = pctX; 450 | self.pctY = pctY; 451 | self.pxlX = pctX * getCore():getScreenWidth(); 452 | self.pxlY = pctY * getCore():getScreenHeight(); 453 | self:setX(self.pxlX); 454 | self:setY(self.pxlY); 455 | end 456 | 457 | function ISSimpleUI:setPositionPixel(pxlX, pxlY) 458 | self.pxlX = pxlX; 459 | self.pxlY = pxlY; 460 | self.pctX = pxlX / getCore():getScreenWidth(); 461 | self.pctY = pxlY / getCore():getScreenHeight(); 462 | self:setX(self.pxlX); 463 | self:setY(self.pxlY); 464 | end 465 | 466 | function ISSimpleUI:setXPercent(pctX) 467 | self.pctX = pctX; 468 | self.pxlX = pctX * getCore():getScreenWidth(); 469 | self:setX(self.pxlX); 470 | end 471 | 472 | function ISSimpleUI:setXPixel(pxlX) 473 | self.pxlX = pxlX; 474 | self.pctX = pxlX / getCore():getScreenWidth(); 475 | self:setX(self.pxlX); 476 | end 477 | 478 | function ISSimpleUI:setYPercent(pctY) 479 | self.pctY = pctY; 480 | self.pxlY = pctY * getCore():getScreenHeight(); 481 | self:setX(self.pxlY); 482 | end 483 | 484 | function ISSimpleUI:setYPixel(pxlY) 485 | self.pxlY = pxlY; 486 | self.pctY = pxlY / getCore():getScreenHeight(); 487 | self:setX(self.pxlY); 488 | end 489 | 490 | function ISSimpleUI:setWidthPercent(pctW) 491 | self.pctW = pctW; 492 | self.pxlW = pctW * getCore():getScreenWidth(); 493 | self:setWidth(self.pxlW); 494 | end 495 | 496 | function ISSimpleUI:setWidthPixel(pxlW) 497 | self.pctW = pxlW / getCore():getScreenWidth(); 498 | self.pxlW = pxlW; 499 | self:setWidth(self.pxlW); 500 | end 501 | 502 | function ISSimpleUI:setInCenterOfScreen() 503 | self.pxlX = (getCore():getScreenWidth() - self:getWidth()) / 2 ; 504 | self.pxlY = (getCore():getScreenHeight() - self:getHeight()) / 2; 505 | self.pctX = self.pxlX / getCore():getScreenWidth(); 506 | self.pctY = self.pxlY / getCore():getScreenHeight(); 507 | self:setX(self.pxlX); 508 | self:setY(self.pxlY); 509 | end 510 | 511 | function ISSimpleUI:setDefaultLineHeightPercent(pctH) 512 | self.defaultLineHeight = pctH * getCore():getScreenHeight(); 513 | end 514 | 515 | function ISSimpleUI:setDefaultLineHeightPixel(pxlH) 516 | self.defaultLineHeight = pxlH; 517 | end 518 | 519 | function ISSimpleUI:getDefaultLineHeightPercent() 520 | return self.defaultLineHeight / getCore():getScreenHeight(); 521 | end 522 | 523 | function ISSimpleUI:getDefaultLineHeightPixel() 524 | return self.defaultLineHeight; 525 | end 526 | 527 | 528 | -- Key 529 | 530 | function ISSimpleUI:setKey(k) 531 | self.key = k; 532 | end 533 | 534 | 535 | -- For collapse if click 536 | 537 | function ISSimpleUI:setCollapse(v) 538 | if v then 539 | self.canCollapse = v; 540 | if self.pin then 541 | self.collapseButton:setVisible(true); 542 | self.pinButton:setVisible(false); 543 | else 544 | self.collapseButton:setVisible(false); 545 | self.pinButton:setVisible(true); 546 | end 547 | else 548 | self.collapseButton:setVisible(false); 549 | self.pinButton:setVisible(false); 550 | self.canCollapse = v; 551 | end 552 | end 553 | 554 | function ISSimpleUI:onMouseDownOutside(x, y) -- Add don't collapse if in subUI 555 | if((self:getMouseX() < 0 or self:getMouseY() < 0 or self:getMouseX() > self:getWidth() or self:getMouseY() > self:getHeight()) and not self.pin and self.canCollapse) then 556 | self.isCollapsed = true; 557 | self.wasCollapsed = true; 558 | self:setMaxDrawHeight(self:titleBarHeight()); 559 | self.lastHeight = self:getHeight(); 560 | if self.collapseBottom then 561 | self:setHeightAndParentHeight(self:titleBarHeight()); 562 | self:setY(self:getY() + self.heightAbs - self:titleBarHeight()) 563 | end 564 | end 565 | end -------------------------------------------------------------------------------- /UI API/mod.info: -------------------------------------------------------------------------------- 1 | name=UI API 2 | poster=preview.png 3 | icon=icon.png 4 | id=UIAPI 5 | description=Mod to make simple UI to other mod. By MrBounty. -------------------------------------------------------------------------------- /UI API/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/UI API/preview.png -------------------------------------------------------------------------------- /UI functions.md: -------------------------------------------------------------------------------- 1 | # UI functions 2 | ## Toggle 3 | ```lua 4 | UI:open() -- Display the UI 5 | UI:close() -- Hide the UI 6 | UI:toggle() -- Toggle the UI 7 | ``` 8 | 9 | ## Position 10 | ```lua 11 | UI:setPositionPercent(x, y) -- Position of the top left corner of the window in % of the screen [0-1] 12 | UI:setPositionPixel(x, y) -- Position of the top left corner of the window in pixel 13 | 14 | UI:setXPercent(x) -- Position of x of the top left corner of the window in % of the screen [0-1] 15 | UI:setXPixel(x) -- Position of x of the top left corner of the window in pixel 16 | 17 | UI:setYPercent(y) -- Position of y of the top left corner of the window in % of the screen [0-1] 18 | UI:setYPixel(y) -- Position of y of the top left corner of the window in pixel 19 | 20 | UI:setInCenterOfScreen() -- Set in center of the screen 21 | ``` 22 | 23 | ## Call before creating elements 24 | ```lua 25 | UI:setColumnWidthPercent(column, pctW) -- Set the default width of elements for a column. column is an int 26 | UI:setColumnWidthPixel(column, pxlW) 27 | -- Note: This function can be used after element creation and before saveLayout() if there is no image or button image as elements. 28 | 29 | -- Set default height of elements that follow this function (can be call at the beginning or in the middle of an UI) 30 | UI:setDefaultLineHeightPercent(h) 31 | UI:setDefaultLineHeightPixel(h) 32 | 33 | UI:setWidthPercent(pctW) -- Set width of window in % of the screen [0-1] 34 | UI:setWidthPixel(pxlW) -- Set width of window in pixel 35 | ``` 36 | 37 | ## Call before nextLine() 38 | ```lua 39 | UI:setLineHeightPercent(pctH) -- Force height of actual line in % of the screen [0-1] 40 | UI:setLineHeightPixel(pxlH) -- Force height of actual line in pixel 41 | ``` 42 | 43 | ## Other 44 | ```lua 45 | UI:isSubUIOf(UI2) -- If the UI is a sub UI. Like that if the parent is close, the sub UI is close too. And you can acces the parentUI with the variable 46 | 47 | UI:nextLine() -- To jump to an other line 48 | 49 | UI:getIsVisible() -- To know if the player see the UI 50 | 51 | UI:setBorderToAllElements(bool) -- Add/remove border to all elements of the ui 52 | UI:setTitle(string) -- Add a title to the top bar of the UI 53 | UI:setKey(key) -- Key to toggle the UI 54 | UI:setCollapse(boolean) -- If the window can collapse when click outside of it, default false 55 | 56 | UI:getDefaultLineHeightPercent() -- Can be usefull for rich text and list like that UI:setLineHeightPixel(UI:getDefaultLineHeightPixel()) 57 | UI:getDefaultLineHeightPixel() 58 | ``` 59 | Find all key value [here](https://theindiestone.com/forums/index.php?/topic/9799-key-code-reference/) 60 | -------------------------------------------------------------------------------- /Vanilla functions.md: -------------------------------------------------------------------------------- 1 | I will try to put a list of usefull function from the vanilla game. 2 | 3 | # For elements and windows 4 | ```lua 5 | -- Get position 6 | ui:getX() 7 | ui:getY() 8 | ui:getRight() -- ui:getX() + ui:getWidth() 9 | ui:getBottom() -- ui:getY() + ui:getHeight() 10 | 11 | -- Get size 12 | ui:getWidth() 13 | ui:getHeight() 14 | 15 | ui:setDrawFrame(false) -- remove the title bar 16 | ui:bringToTop() -- put the ui in front of all the others 17 | ``` 18 | 19 | # Other 20 | ```lua 21 | -- Find size of text 22 | getTextManager():getFontHeight(UIFont.Small) -- get height of a font 23 | getTextManager():MeasureStringX(UIFont.Small, "My text") -- get width in pixel of a text for a font 24 | 25 | -- Screen size 26 | getCore():getScreenWidth() 27 | getCore():getScreenHeight() 28 | 29 | -- Mouse position 30 | getMouseX() 31 | getMouseY() 32 | 33 | -- Key 34 | isShiftKeyDown() -- True if the shift key is down 35 | isCtrlKeyDown() -- True if the ctrl key is down 36 | 37 | getPlayerInfoPanel(0) -- The main vanilla panel (health, protection...) 38 | ``` 39 | 40 | # Font size 41 | ```lua 42 | -------------------------------------------------------------------------------- /Variables.md: -------------------------------------------------------------------------------- 1 | ## Fonts 2 | - Small 3 | - Medium 4 | - Large 5 | - Title 6 | 7 | ## Positions 8 | - Left 9 | - Right 10 | - Center 11 | 12 | ## Text formatting 13 | For the rich text element, you can use that to make complexe text. 14 | If you put that in you text, the text that follow it will change. 15 | Check example in `media/lua/shared/Translate` 16 | - `, ,
`: Position. 17 | - `, , `: Change font 18 | - `,
`: New line (br = 2x line) 19 | - `

,

, `: To make title (change position size and color) 20 | - `, , , `: Change color 21 | - ``: Add an image to the text. 22 | - ``: Add an image to the text at custom position. 23 | - ``: Set x position 24 | - ``: No idea 25 | -------------------------------------------------------------------------------- /images/Hello x4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/Hello x4.jpg -------------------------------------------------------------------------------- /images/HelloWorld.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/HelloWorld.jpg -------------------------------------------------------------------------------- /images/Shema.drawio: -------------------------------------------------------------------------------- 1 | 7VvbcqM4EP0aVyUPTgGyETzGSfZSld2aquzUzjzKINtMBGKFHOP5+hVIYG4OduIAntgPCXTrxumjpjnYI3Dnx78zFK7+oi4mI0Nz4xG4HxmGoWlT8S+xbKUFaqY0LJnnSpO+Mzx5P7Eyasq69lwclRpySgn3wrLRoUGAHV6yIcboptxsQUl51hAtcc3w5CBSt/7ruXwlrZYBd/Y/sLdcZTPrpi09PsoaqyuJVsilm4IJPIzAHaOUyyM/vsMkAS/DRfb7bY83XxjDAT+kA/j68IN8sR/583K2vhvH/B7ejtUoL4is1QWrxfJthgCj68DFySDaCMw2K4/jpxA5iXcjYi5sK+4TcaaLQzUcZhzHe9ep51cvaIOpjznbiiaqw0ThpQijm+p8s4NfzzBdFaDPbEhFfJmPvANFHChcjsDIaMdIjCIIidvxQVEoWbrw4gTT2cIj5I4SytKBAE4/wh5xRp9xwQNMYAM392Rk1E4D+rQd9E4xBwdgHri3yQYXZwENcBnnMmmPBxnHHv+meifH39W4yfF9XHDcb7OTQFz3t6xZcvK96Nl1Ss+2pdBht5aEKoETV07XzMHtNOWILTFva1cnQiHS04ZIZzaGCeLeS3m5TeFXM3yhnriQnGf5zlVEM0CFQfIyVa9iNqsOBCuMtSoDSRxqA6VszC/77QSdDISg+vEE1S4E3U9Q07ixDcsGglCWDiZTq8IyeKNBXTOhpeuWOZ1Yb2MvrAxjlGeBlUUYnVJ72k5tUcuEyeGC4FhxfFagu0NQFHnOa4w/lFe9JSqrkqi0NyYqUM141YE+OJpmezS7rvDA4Eo8eEA2P/cSDwytxrMGcgs9oxoPHngLhX2mzsmparxJzzWePRCCnlGNdxYEBZUiz6yw7DQ1HqgWeeVZ+q3xMnmtwO1/cMzfVxqUb1sfVSxYfRcLepM4YRIx7SxkuISf+d86kfdmcxqPI++nFyxH4Fa0mFPmYjYWZnGS4qT5IuBeMOY0lE20sOabU86pX3dTAfCC0M1YhiRxB5T5iOQtQuS6+eS62dBXutCa09xFvACPM0TTjjeTae5Vl8CQ660j6S+OuxHu8Zxh9Ny4IEemu8TDlvMrMXbiMkRANEOzd8c6vM77LGjAExSxWk0KQYawOFqq/++NRDrPAvke2co2ci3ZXxP5YdoQgElC+kUSIBrQmmd/Hx8H5Jj2Dg0iKp6pjuhCvDlmIknSoHV5iTdKN/Un42KVO1//TP2SQAKRBLr0UbbEoJCMHb3Y+UiWVWcVcMjUK+cVKUlOLb1XAu7oOnPOWWmtgej3KJC5amhQGC/dC69b96Z9vae0X33+zlN8Me1PGtK++WFpv0nyu6T9YaX913bt8wk3LaFOmkGatqzoKnZnmpM7XZPsuGdFnae1v/EmQaE5qV2fUyoa6/rgctFFo00Do9k3duEDYVl4eLNm269kmyHxuaM7OZUCb/aswGfRG5IEbw5OgjcOeeV/7hq8OTQN3hjKe+wzEuEzpra/yAZ95k94Khke9izDGwcUOxcd/iw5anaixJtDVuKN+gv6gSrxtZqhdyXeaHpvf5FkjpJkulLVPwmq+5BLYB7lAth9sSFwbFd37Rbt5aA4lRRssaXkrIdLZK0K0FsEvNOJ4d2C+ar0LhY6Wwu6BqcQ6JvCdKa6ffWpvX+tzKh/z+hMbrC5UFHAzuz0/nrAN2D6hw1qA4Mte9D63PodhGVx1moO0rHFvN2zmgeaxNlLdfS+6uiCXDd1ZWMl+J5aM0Iv+BFt6Zq3lDhNZdyvVfnADisfcbr74ajMbLuf34KH/wE= -------------------------------------------------------------------------------- /images/Shema.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/Shema.drawio.png -------------------------------------------------------------------------------- /images/exemple1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/exemple1.gif -------------------------------------------------------------------------------- /images/jobBoard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/jobBoard.gif -------------------------------------------------------------------------------- /images/jobChoice.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/jobChoice.gif -------------------------------------------------------------------------------- /images/preview perso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/preview perso.png -------------------------------------------------------------------------------- /images/quest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/quest.jpg -------------------------------------------------------------------------------- /images/schema2d (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/schema2d (1).png -------------------------------------------------------------------------------- /images/team.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrBounty/PZ-UI_API/e1222ca0cf1ae8b25dfb33b8a4d33e66d3325eeb/images/team.jpg --------------------------------------------------------------------------------