Skip to content

Commit

Permalink
Initial source code upload
Browse files Browse the repository at this point in the history
  • Loading branch information
botder committed Aug 24, 2018
1 parent 9eca496 commit e81f834
Show file tree
Hide file tree
Showing 32 changed files with 3,405 additions and 2 deletions.
Binary file added .github/editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/element-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# mtasa-propertyeditor
(CE)GUI property editor resource for the Multi Theft Auto: San Andreas multiplayer
# Property Editor
(CE)GUI property editor resource for the Multi Theft Auto: San Andreas multiplayer.

**Note:** Don't use this tool on a production server, because for example any button, which is disabled if you shouldn't have access to a certain feature, can be re-enabled by this tool.

## How to use
1. Add the resource to your server
2. Give the developers the ACL permission to use `command.propertyeditor`
3. Refresh the server and start `propertyeditor`
4. Type `/propertyeditor` to show the selection
5. Select a GUI element on your screen with 'right click'
6. Edit the properties of the selected element

## Requirements
- Players require the ACL permission for `command.propertyeditor`

## Screenshots
### Selector
![The selector shows the resource, type and text of the currently cursor-hovered element](.github/selector.png)

### Editor
![This is the main property editor window, where you can edit every supported property](.github/editor.png)

### Element tree
![If you can't select a certain GUI element, then you can always fall back to this little helper window to select the element from a list of all elements](.github/element-tree.png)
Binary file added assets/alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/dot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/saturation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/slider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions client/extension.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function guiButtonSetColor(button, r, g, b, a)
a = a or 255
return guiSetProperty(button, "NormalTextColour", ("%02x%02x%02x%02x"):format(a, r, g, b))
end

function guiComboBoxAutoHeight(comboBox)
-- Add a pseudo item to figure out the amount of items
local itemID = guiComboBoxAddItem(comboBox, "")
guiComboBoxRemoveItem(comboBox, itemID)

local width = guiGetSize(comboBox, false)
return guiSetSize(comboBox, width, itemID * 14 + 40, false)
end

function guiGetResourceName(element)
while true do
element = getElementParent(element)

if not element or element == root then
break
end

if getElementType(element) == "resource" then
return getElementID(element)
end
end

return false
end

function guiGetRelativePosition(element, screenX, screenY)
while element ~= guiRoot do
local x, y = guiGetPosition(element, false)
screenX = screenX - x
screenY = screenY - y
element = getElementParent(element)
end

return screenX, screenY
end

function hasElementAsParent(element, parent)
assert(isElement(element), debug.traceback())
assert(isElement(parent), debug.traceback())

if parent == root then
return true
end

while true do
if element == parent then
return true
end

if element == root then
break
end

element = getElementParent(element)
end

return false
end

function bind(self, func)
return function (...) func(self, ...) end
end
42 changes: 42 additions & 0 deletions client/gui/component.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--
-- Component
--
local factories = {}
local properties = {}

function createComponentFactory(name, factoryFunction)
assert(factories[name] == nil)
assert(type(factoryFunction) == "function")
factories[name] = factoryFunction
end

function setPropertyComponent(name, component, arguments)
assert(properties[name] == nil)
assert(type(component) == "string")

properties[name] = {
name = name,
component = component,
arguments = arguments,
}
end

function createPropertyComponent(name)
local property = properties[name]

if not property then
return false
end

local factory = factories[property.component]

if not factory then
return false
end

if property.arguments then
return factory(name, unpack(property.arguments))
else
return factory(name)
end
end
178 changes: 178 additions & 0 deletions client/gui/components/boolean.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
--
-- Component: Boolean
--
local Component = {}
Component.__index = Component

local function createComponent(propertyName)
local self = setmetatable({}, Component)
self.propertyName = propertyName
self.gui = false
self.visible = true
self.element = false
self.x = -1
self.y = -1
self.parent = false
return self
end
createComponentFactory("Boolean", createComponent)

--
-- Public
--
function Component:setElement(element)
if self.element == element then
return
end

self.element = element

if self.gui then
self:refresh()
end
end

function Component:refresh()
if not self.gui then
return
end

local gui = self.gui
local enabled = guiGetProperty(self.element, self.propertyName) == "True"

if gui.enabled == enabled then
return
end

gui.enabled = enabled
guiSetText(gui.toggle_btn, enabled and "On" or "Off")

if enabled then
guiButtonSetColor(gui.toggle_btn, 100, 255, 100)
else
guiButtonSetColor(gui.toggle_btn, 255, 100, 100)
end
end

function Component:render(x, y, width, parent)
if not self.gui then
-- Create GUI for the first time
self:_createGUI(x, y, width, parent)
return
end

if self.parent and self.parent ~= parent then
-- Parent has changed, delete everything
self:_destroyGUI()
self:_createGUI(x, y, width, parent)
return
end

if self.x ~= x or self.y ~= y then
-- Component must be moved
self:_moveGUI(x, y, width)
return
end
end

function Component:getHeight()
return self.gui and 30 or 0
end

function Component:show()
if not self.visible then
self.visible = true
self:_updateGUIVisibility()
end
end

function Component:hide()
if self.visible then
self.visible = false
self:_updateGUIVisibility()
end
end

function Component:isVisible()
return self.visible
end

--
-- Private
--
function Component:_createGUI(x, y, width, parent)
if self.gui then
return
end

local gui = {}
local half_width = width / 2

gui.label = guiCreateLabel(x, y + 2, half_width, 20, self.propertyName, false, parent)
guiSetFont(gui.label, "clear-normal")

gui.enabled = guiGetProperty(self.element, self.propertyName) == "True"
gui.toggle_btn = guiCreateButton(x + half_width, y, 25, 22, gui.enabled and "On" or "Off", false, parent)
guiSetFont(gui.toggle_btn, "default-small")

if gui.enabled then
guiButtonSetColor(gui.toggle_btn, 100, 255, 100)
else
guiButtonSetColor(gui.toggle_btn, 255, 100, 100)
end

addEventHandler("onClientGUIClick", gui.toggle_btn,
function ()
gui.enabled = not gui.enabled

if gui.enabled then
guiButtonSetColor(gui.toggle_btn, 100, 255, 100)
guiSetText(gui.toggle_btn, "On")
guiSetProperty(self.element, self.propertyName, "True")
else
guiButtonSetColor(gui.toggle_btn, 255, 100, 100)
guiSetText(gui.toggle_btn, "Off")
guiSetProperty(self.element, self.propertyName, "False")
end
end,
false)

self.x = x
self.y = y
self.parent = parent
self.gui = gui
end

function Component:_destroyGUI()
if not self.gui then
return
end

local gui = self.gui
destroyElement(gui.label)
destroyElement(gui.toggle_btn)
end

function Component:_moveGUI(x, y, width)
if not self.gui then
return
end

local gui = self.gui
local half_width = width / 2
guiSetPosition(gui.label, x, y + 2, false)
guiSetPosition(gui.toggle_btn, x + half_width, y, false)

self.x = x
self.y = y
end

function Component:_updateGUIVisibility()
if not self.gui then
return
end

local gui = self.gui
guiSetVisible(gui.label, self.visible)
guiSetVisible(gui.toggle_btn, self.visible)
end
Loading

0 comments on commit e81f834

Please sign in to comment.