mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 04:06:39 +09:00
Button docs
This commit is contained in:
58
expcore/gui/concepts/button.lua
Normal file
58
expcore/gui/concepts/button.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
--[[-- Core Module - Gui
|
||||
@module Gui
|
||||
@alias Gui
|
||||
]]
|
||||
|
||||
local Gui = require 'expcore.gui.core'
|
||||
|
||||
--[[-- The basic button element
|
||||
@element button
|
||||
@param on_click fired when the player clicks the button
|
||||
@param on_left_click fired when the player clicks with the left mouse button
|
||||
@param on_left_click fired when the player clicks with the right mouse button
|
||||
@tparam ?string|Concepts.LocalisedString caption the message that is shown on the button
|
||||
@tparam ?string|Concepts.LocalisedString tooltip the tooltip that shows when a player hovers over the button
|
||||
@tparam SpritePath sprite upto three sprites in the order: default, hovered, clicked
|
||||
]]
|
||||
Gui.new_concept('button')
|
||||
:new_event('on_click',defines.events.on_gui_click)
|
||||
:new_event('on_left_click',defines.events.on_gui_click,function(event)
|
||||
return event.mouse_button == defines.mouse_button_type.left
|
||||
end)
|
||||
:new_event('on_right_click',defines.events.on_gui_click,function(event)
|
||||
return event.mouse_button == defines.mouse_button_type.right
|
||||
end)
|
||||
:new_property('tooltip')
|
||||
:new_property('caption',nil,function(properties,value)
|
||||
properties.caption = value
|
||||
properties.type = 'button'
|
||||
end)
|
||||
:new_property('sprite',nil,function(properties,value,hovered_sprite,clicked_sprite)
|
||||
properties.sprite = value
|
||||
properties.hovered_sprite = hovered_sprite
|
||||
properties.clicked_sprite = clicked_sprite
|
||||
properties.type = 'sprite-button'
|
||||
end)
|
||||
:define_draw(function(properties,parent,element)
|
||||
if properties.type == 'button' then
|
||||
element = parent.add{
|
||||
name = properties.name,
|
||||
type = properties.type,
|
||||
caption = properties.caption,
|
||||
tooltip = properties.tooltip
|
||||
}
|
||||
|
||||
else
|
||||
element = parent.add{
|
||||
name = properties.name,
|
||||
type = properties.type,
|
||||
sprite = properties.sprite,
|
||||
hovered_sprite = properties.hovered_sprite,
|
||||
clicked_sprite = properties.clicked_sprite,
|
||||
tooltip = properties.tooltip
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
return element
|
||||
end)
|
||||
Reference in New Issue
Block a user