Files
factorio-scenario-ExpCluster/docs/core/Gui.html
Cooldude2606 6c39335b80 Cleaner docs
2019-08-25 01:12:18 +01:00

1896 lines
70 KiB
HTML

<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gui core</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../spectre.min.css" type="text/css" />
<link rel="stylesheet" href="../spectre-icons.min.css" type="text/css" />
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div class="container grid-1280">
<div class="columns">
<!-- sidebar start -->
<div id="sidebar" class="column col-3 col-sm-12">
<div class="sidebar-custom">
<div class="project-infobox">
<!-- project title -->
<a href="../index.html"><h1>ExpGaming Scenario</h1></a>
<!-- project description -->
<p class="project-desc">Explosive Gaming's server scenario for 0.17</p>
<!-- project full description -->
</div>
<!-- sidebar navigation -->
<!-- list of items in a module -->
<ul class="nav nav-module-contents">
<li class="nav-item">
<h2>Sections</h2>
<ul class="nav">
<li class="nav-item"><a href="#Concept_Base"><span class="fragment-hashtag">#</span> Concept Base </a></li>
<li class="nav-item"><a href="#Concept_Instances"><span class="fragment-hashtag">#</span> Concept Instances </a></li>
<li class="nav-item"><a href="#Concept_Data"><span class="fragment-hashtag">#</span> Concept Data </a></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Core</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Commands.html"><span class="module-name-item">Commands</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Common-Library.html"><span class="module-name-item">Common-Library</span></a></div></li>
<li class="nav-item active"><div class="nav-item-block-active block"><a href="../core/Gui.html"><span class="module-name-item">Gui</span></a><i class="icon icon-arrow-left icon-arrow-left-custom"></i></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Permissions-Groups.html"><span class="module-name-item">Permissions-Groups</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Roles.html"><span class="module-name-item">Roles</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Store.html"><span class="module-name-item">Store</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Sudo.html"><span class="module-name-item">Sudo</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Addons</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Advanced-Start.html"><span class="module-name-item">Advanced-Start</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Chat-Popups.html"><span class="module-name-item">Chat-Popups</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Chat-Reply.html"><span class="module-name-item">Chat-Reply</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Compilatron.html"><span class="module-name-item">Compilatron</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Damage-Popups.html"><span class="module-name-item">Damage-Popups</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Death-Logger.html"><span class="module-name-item">Death-Logger</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Discord-Alerts.html"><span class="module-name-item">Discord-Alerts</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Pollution-Grading.html"><span class="module-name-item">Pollution-Grading</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Player-Colours.html"><span class="module-name-item">Player-Colours</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Scorched-Earth.html"><span class="module-name-item">Scorched-Earth</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Spawn-Area.html"><span class="module-name-item">Spawn-Area</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Commands</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Admin-Chat.html"><span class="module-name-item">Admin-Chat</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Bonus.html"><span class="module-name-item">Bonus</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Cheat-Mode.html"><span class="module-name-item">Cheat-Mode</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Clear-Inventory.html"><span class="module-name-item">Clear-Inventory</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Debug.html"><span class="module-name-item">Debug</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Find.html"><span class="module-name-item">Find</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Help.html"><span class="module-name-item">Help</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Home.html"><span class="module-name-item">Home</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Interface.html"><span class="module-name-item">Interface</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Jail.html"><span class="module-name-item">Jail</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Kill.html"><span class="module-name-item">Kill</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Me.html"><span class="module-name-item">Me</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Rainbow.html"><span class="module-name-item">Rainbow</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Repair.html"><span class="module-name-item">Repair</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Reports.html"><span class="module-name-item">Reports</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Roles.html"><span class="module-name-item">Roles</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Spawn.html"><span class="module-name-item">Spawn</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Tag.html"><span class="module-name-item">Tag</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Teleport.html"><span class="module-name-item">Teleport</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Warnings.html"><span class="module-name-item">Warnings</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Control</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Jail.html"><span class="module-name-item">Jail</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Production.html"><span class="module-name-item">Production</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Reports.html"><span class="module-name-item">Reports</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Rockets.html"><span class="module-name-item">Rockets</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Tasks.html"><span class="module-name-item">Tasks</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Warnings.html"><span class="module-name-item">Warnings</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Warps.html"><span class="module-name-item">Warps</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Guis</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Player-List.html"><span class="module-name-item">Player-List</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Rocket-Info.html"><span class="module-name-item">Rocket-Info</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Science-Info.html"><span class="module-name-item">Science-Info</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Task-List.html"><span class="module-name-item">Task-List</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Warps-List.html"><span class="module-name-item">Warps-List</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Configs</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/File-Loader.html"><span class="module-name-item">File-Loader</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Player-List.html"><span class="module-name-item">Player-List</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Advanced-Start.html"><span class="module-name-item">Advanced-Start</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Bonuses.html"><span class="module-name-item">Bonuses</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Chat-Reply.html"><span class="module-name-item">Chat-Reply</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Compilatron.html"><span class="module-name-item">Compilatron</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Death-Logger.html"><span class="module-name-item">Death-Logger</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Discord-Alerts.html"><span class="module-name-item">Discord-Alerts</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Auth-Admin.html"><span class="module-name-item">Commands-Auth-Admin</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Auth-Roles.html"><span class="module-name-item">Commands-Auth-Roles</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Auth-Runtime-Disable.html"><span class="module-name-item">Commands-Auth-Runtime-Disable</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Parse.html"><span class="module-name-item">Commands-Parse</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Parse-Roles.html"><span class="module-name-item">Commands-Parse-Roles</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Permission-Groups.html"><span class="module-name-item">Permission-Groups</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Pollution-Grading.html"><span class="module-name-item">Pollution-Grading</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Popup-Messages.html"><span class="module-name-item">Popup-Messages</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Preset-Player-Colours.html"><span class="module-name-item">Preset-Player-Colours</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Repair.html"><span class="module-name-item">Repair</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Rockets.html"><span class="module-name-item">Rockets</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Roles.html"><span class="module-name-item">Roles</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Science.html"><span class="module-name-item">Science</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Scorched-Earth.html"><span class="module-name-item">Scorched-Earth</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Spawn-Area.html"><span class="module-name-item">Spawn-Area</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Tasks.html"><span class="module-name-item">Tasks</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Warnings.html"><span class="module-name-item">Warnings</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Warps.html"><span class="module-name-item">Warps</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Modules</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/control.html"><span class="module-name-item">control</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.alien_evolution_progress.html"><span class="module-name-item">utils.alien_evolution_progress</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.core.html"><span class="module-name-item">utils.core</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.debug.html"><span class="module-name-item">utils.debug</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.dump_env.html"><span class="module-name-item">utils.dump_env</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.event.html"><span class="module-name-item">utils.event</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.event_core.html"><span class="module-name-item">utils.event_core</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.math.html"><span class="module-name-item">utils.math</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.recipe_locker.html"><span class="module-name-item">utils.recipe_locker</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.state_machine.html"><span class="module-name-item">utils.state_machine</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.table.html"><span class="module-name-item">utils.table</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.task.html"><span class="module-name-item">utils.task</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.timestamp.html"><span class="module-name-item">utils.timestamp</span></a></div></li>
</ul>
</li>
</ul>
<ul class="nav nav-modules">
<li class="nav-item">
<h2>Topics</h2>
<ul class="nav">
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../topics/readme.md.html"><span class="module-name-item">readme.md</span></a></div></li>
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../topics/license.html"><span class="module-name-item">license</span></a></div></li>
</ul>
</li>
</ul>
</div>
<div class="up-to-top">
<!-- list of items in a module -->
<ul class="nav nav-module-contents">
<li class="nav-item">
<h4>Jump to Section</h4>
<ul class="nav">
<li class="nav-item"><a href="#Concept_Base"><span class="fragment-hashtag">#</span> Concept Base </a></li>
<li class="nav-item"><a href="#Concept_Instances"><span class="fragment-hashtag">#</span> Concept Instances </a></li>
<li class="nav-item"><a href="#Concept_Data"><span class="fragment-hashtag">#</span> Concept Data </a></li>
</ul>
</li>
</ul>
<a href="#">Top <i class="icon icon-upward"></i></a>
</div>
</div>
<!-- sidebar end -->
<!-- content body start -->
<div class="column col-9 col-sm-12">
<!-- module list on the main page start -->
<!-- module list on the main page end -->
<!-- module contents -->
<!-- module content header start -->
<h2><span class="body-module-name"><strong><em>Gui</em></strong></span> core</h2>
<p>Core Module - Gui</p>
<p></p>
<!-- module info start -->
<!-- module info end -->
<!-- module usage start -->
<h3>Usage</h3>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Making the base button concept
</span><span class="keyword">local</span> button =
Gui.new_concept(<span class="string">'Button'</span>)
:new_event(<span class="string">'on_click'</span>,defines.events.on_gui_click)
:new_property(<span class="string">'tooltip'</span>)
:new_property(<span class="string">'caption'</span>,<span class="keyword">nil</span>,<span class="keyword">function</span>(properties,value)
properties.caption = value
properties.sprite = <span class="keyword">nil</span>
properties.<span class="global">type</span> = <span class="string">'button'</span>
<span class="keyword">end</span>)
:new_property(<span class="string">'sprite'</span>,<span class="keyword">nil</span>,<span class="keyword">function</span>(properties,value)
properties.image = value
properties.caption = <span class="keyword">nil</span>
properties.<span class="global">type</span> = <span class="string">'sprite-button'</span>
<span class="keyword">end</span>)</code></pre>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Makeing a alternative button based on the first
</span><span class="keyword">local</span> custom_button =
button:clone(<span class="string">'CustomButton'</span>)
:new_event(<span class="string">'on_admin_clicked'</span>,defines.events.on_gui_click,<span class="keyword">function</span>(event)
<span class="keyword">return</span> event.player.admin <span class="comment">-- only raise custom event when an admin clicks the button
</span><span class="keyword">end</span>)
:set_caption(<span class="string">'Custom Button'</span>)
:set_tooltip(<span class="string">'Only admins can press this button'</span>)
:on_click(<span class="keyword">function</span>(event)
<span class="keyword">if</span> <span class="keyword">not</span> event.player.admin <span class="keyword">then</span>
event.player.<span class="global">print</span>(<span class="string">'You must be admin to use this button'</span>)
<span class="keyword">end</span>
<span class="keyword">end</span>)
:on_admin_clicked(<span class="keyword">function</span>(event)
<span class="comment">-- Yes i know this can just be an if else but its an example
</span> game.<span class="global">print</span>(event.player.name..<span class="string">' pressed my admin button'</span>)
<span class="keyword">end</span>)</code></pre>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Drawing a concept
</span>custom_button:draw(game.player.gui.left)</code></pre>
<!-- module usage end -->
<!-- module content header end -->
<!-- module section list start -->
<table class="section-content-list">
<thead>
<h3><a href="#Concept_Base">Concept Base </a></h3>
<span></span>
</thead>
<tbody>
<tr>
<td class="name"><a href="#Prototype:clone">Prototype:clone(concept_name)</a></td>
<td class="summary">Used to copy all the settings from one concept to another and removing links to the orginal</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:new_event">Prototype:new_event(event_name[, factorio_event][, event_condition])</a></td>
<td class="summary">Adds a new event trigger to the concept which can be linked to a factorio event</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:on_custom_event">Prototype:on_custom_event(handler)</a></td>
<td class="summary">Adds a custom event handler, replace with the name of the event</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:raise_event">Prototype:raise_event(event_name[, event={}][, from_factorio=false])</a></td>
<td class="summary">Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:new_property">Prototype:new_property(property_name, default[, setter_callback])</a></td>
<td class="summary">Adds a new property to the concept, such as caption, tooltip, or some custom property you want to control</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:set_custom_property">Prototype:set_custom_property(value)</a></td>
<td class="summary">Sets a new value for a property, triggers setter method if provided, replace with property name</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:define_draw">Prototype:define_draw(draw_callback)</a></td>
<td class="summary">Used to define how the concept is turned into an ingame element or "instance" as we may refer to them</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:draw">Prototype:draw(parent_element)</a></td>
<td class="summary">Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used</td>
</tr>
</tbody>
</table>
<table class="section-content-list">
<thead>
<h3><a href="#Concept_Instances">Concept Instances </a></h3>
<span></span>
</thead>
<tbody>
<tr>
<td class="name"><a href="#Prototype:define_instance_store">Prototype:define_instance_store([category_callback])</a></td>
<td class="summary">Adds an instance store to the concept; when a new instance is made it is stored so you can access it later</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.get_instances">Prototype.get_instances([category])</a></td>
<td class="summary">Gets all insatnces in a category, category may be nil to return all</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.add_instance">Prototype.add_instance(element[, category])</a></td>
<td class="summary">Adds an instance to this concept, used automatically during concept:draw</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.update_instances">Prototype.update_instances([category], update_callback)</a></td>
<td class="summary">Applies an update function to all instances, simialr use to what table.forEach would be</td>
</tr>
</tbody>
</table>
<table class="section-content-list">
<thead>
<h3><a href="#Concept_Data">Concept Data </a></h3>
<span></span>
</thead>
<tbody>
<tr>
<td class="name"><a href="#Prototype:define_data_store">Prototype:define_data_store([category_callback])</a></td>
<td class="summary">Adds a data store to this concept which allows you to store synced/percistent data between instances</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.get_data">Prototype.get_data([category])</a></td>
<td class="summary">Gets the data that is stored for this category</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.set_data">Prototype.set_data([category], value)</a></td>
<td class="summary">Sets the data that is stored for this category</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.clear_data">Prototype.clear_data([category])</a></td>
<td class="summary">Clears the data that is stored for this category</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.update_data">Prototype.update_data([category], update_callback)</a></td>
<td class="summary">Updates the data that is stored for this category</td>
</tr>
<tr>
<td class="name"><a href="#Prototype:define_combined_store">Prototype:define_combined_store([category_callback], get_callback, set_callback)</a></td>
<td class="summary">Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them all</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.set_instance_from_store">Prototype.set_instance_from_store(the)</a></td>
<td class="summary">Will set the state of an instance based on the value in the store</td>
</tr>
<tr>
<td class="name"><a href="#Prototype.set_store_from_instance">Prototype.set_store_from_instance(the)</a></td>
<td class="summary">Will set the value in the store and update the other instances based on the instance given</td>
</tr>
</tbody>
</table>
<!-- module section list end -->
<br />
<!-- section start -->
<h3><span id="Concept_Base" class="section-title"><a href="#Concept_Base">Concept Base </a></span></h3>
<dl class="section-body-container">
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:clone" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:clone">Prototype:clone(concept_name)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Used to copy all the settings from one concept to another and removing links to the orginal</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>concept_name</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
the name of the new concept; must be unique
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">the base for building a custom gui</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Clones the base Button concept to make a alternative button
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'Button'</span>):clone(<span class="string">'CustomButton'</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:new_event" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:new_event">Prototype:new_event(event_name[, factorio_event][, event_condition])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Adds a new event trigger to the concept which can be linked to a factorio event</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>event_name</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
the name of the event to add, must be unique, recomented to start with "on_"
</li>
<li class="section-subitem-li">
<strong><em>factorio_event</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/defines.html#defines.events">defines.events</a></span>)
when given will fire the custom event when the factorio event is raised
(<em>optional</em>)
</li>
<li class="section-subitem-li">
<strong><em>event_condition</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
used to filter when a factorio event triggers the custom event; if the event contains a reference to an element then names are automatically filtered
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adds an on_admin_clicked event to fire when ever an admin clicks the button
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'Button'</span>):clone(<span class="string">'CustomButton'</span>)
:new_event(<span class="string">'on_admin_clicked'</span>,defines.events.on_gui_click,<span class="keyword">function</span>(event)
<span class="keyword">return</span> event.player.admin <span class="comment">-- only raise custom event when an admin clicks the button
</span><span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:on_custom_event" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:on_custom_event">Prototype:on_custom_event(handler)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Adds a custom event handler, replace with the name of the event</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>handler</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
the function which will recive the event
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- When an admin clicks the button a message is printed
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
:on_admin_clicked(<span class="keyword">function</span>(event)
game.<span class="global">print</span>(event.player.name..<span class="string">' pressed my admin button'</span>)
<span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:raise_event" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:raise_event">Prototype:raise_event(event_name[, event={}][, from_factorio=false])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Raises a custom event, folowing keys included automaticlly: concept, event name, game tick, player from player_index, element if valid</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>event_name</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
the name of the event that you want to raise
</li>
<li class="section-subitem-li">
<strong><em>event</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
table containg data you want to send with the event, some keys already included
(<em>default</em>: {})
</li>
<li class="section-subitem-li">
<strong><em>from_factorio</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#boolean">boolean</a></span>)
internal use, if the raise came from the factorio event handler
(<em>default</em>: false)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Raising the custom event on_admin_clicked
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
<span class="comment">-- Note that this is an example and would not work due it expecting a valid element for event.element
</span><span class="comment">-- this will however work fine if you can provide all expected keys, or its not linked to any factorio event
</span>custom_button:raise_event(<span class="string">'on_admin_clicked'</span>,{
player_index = game.player.index
})</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:new_property" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:new_property">Prototype:new_property(property_name, default[, setter_callback])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Adds a new property to the concept, such as caption, tooltip, or some custom property you want to control</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>property_name</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
the name of the new property, must be unique
</li>
<li class="section-subitem-li">
<strong><em>default</em></strong>
<strong> : </strong>
(<span class="types"><span class="type">any</span></span>)
the default value for this property, although not strictly required is is strongly recomented
</li>
<li class="section-subitem-li">
<strong><em>setter_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
this function is called when set is called, if not provided then key in concept.properties is updated to new value
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding caption, sprite, and tooltip to the base button concept
</span><span class="keyword">local</span> button =
Gui.get_concept(<span class="string">'Button'</span>)
:new_property(<span class="string">'tooltip'</span>)
:new_property(<span class="string">'caption'</span>,<span class="keyword">nil</span>,<span class="keyword">function</span>(properties,value)
properties.caption = value
properties.sprite = <span class="keyword">nil</span>
properties.<span class="global">type</span> = <span class="string">'button'</span>
<span class="keyword">end</span>)
:new_property(<span class="string">'sprite'</span>,<span class="keyword">nil</span>,<span class="keyword">function</span>(properties,value)
properties.image = value
properties.caption = <span class="keyword">nil</span>
properties.<span class="global">type</span> = <span class="string">'sprite-button'</span>
<span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:set_custom_property" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:set_custom_property">Prototype:set_custom_property(value)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Sets a new value for a property, triggers setter method if provided, replace with property name</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>value</em></strong>
<strong> : </strong>
(<span class="types"><span class="type">any</span></span>)
the value that you want to set for this property
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Setting the caption on the base button concept after a cloning
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'Button'</span>)
:set_caption(<span class="string">'Default Button'</span>)</code></pre>
<pre class="code" data-lang="Lua"><code><span class="comment">-- In our examples CustomButton is cloned from Button, this means the caption property already exists
</span><span class="comment">-- note that what ever values that properties have at the time of cloning are also copied
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
:set_caption(<span class="string">'Custom Button'</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:define_draw" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:define_draw">Prototype:define_draw(draw_callback)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Used to define how the concept is turned into an ingame element or "instance" as we may refer to them</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>draw_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
the function that will be called to draw/update the instance; this function must return the instance or the new acting instance
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding the draw define for the base button concept, we then return the element
</span><span class="keyword">local</span> button =
Gui.get_concept(<span class="string">'Button'</span>)
:define_draw(<span class="keyword">function</span>(properties,parent,element)
<span class="comment">-- Note that element might be nil if this is the first draw function
</span> <span class="comment">-- for this example we assume button was cloned from Prototype and so has no other draw functions defined
</span> <span class="comment">-- although not shown here you also can recive any extra arguments here from the call to draw
</span> <span class="keyword">if</span> properties.<span class="global">type</span> == <span class="string">'button'</span> <span class="keyword">then</span>
element = parent.draw{
<span class="global">type</span> = properties.<span class="global">type</span>,
name = properties.name,
caption = properties.caption,
tooltip = properties.tooltip
}
<span class="keyword">else</span>
element = parent.draw{
<span class="global">type</span> = properties.<span class="global">type</span>,
name = properties.name,
sprite = properties.sprite,
tooltip = properties.tooltip
}
<span class="keyword">end</span>
<span class="comment">-- We must return the element or what we want to be seen as the instance
</span> <span class="comment">-- this is so other draw functions have access to it, say if our custom button defined a draw function to change the font color to red
</span> <span class="keyword">return</span> element
<span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:draw" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:draw">Prototype:draw(parent_element)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>parent_element</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the element that the concept will use as a base
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
<span class="return-text">the element that was created and then passed though and returned by the draw functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Drawing the custom button concept
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
<span class="comment">-- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define
</span>custom_button:draw(game.player.gui.left)</code></pre>
<!-- usage end -->
</dd>
</dl>
<h3><span id="Concept_Instances" class="section-title"><a href="#Concept_Instances">Concept Instances </a></span></h3>
<dl class="section-body-container">
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:define_instance_store" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:define_instance_store">Prototype:define_instance_store([category_callback])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Adds an instance store to the concept; when a new instance is made it is stored so you can access it later</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
when given will act as a way to turn an element into a string to act as a key; keys returned can over lap
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Allowing storing instances of the custom button; stored by the players index
</span><span class="comment">-- Note even thou this is a copy of Button; if Button had an instance store it would not be cloned over
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
:define_instance_store(<span class="keyword">function</span>(element)
<span class="keyword">return</span> element.player_index <span class="comment">-- The instances are stored based on player id
</span><span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.get_instances" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.get_instances">Prototype.get_instances([category])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Gets all insatnces in a category, category may be nil to return all</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a> or <a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the category to get, can only be nil if categories are not used
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
<span class="return-text">a table which contains all the instances</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Getting all the instances of the player with index 1
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
custom_button.get_instances(<span class="number">1</span>) -- player index <span class="number">1</span></code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.add_instance" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.add_instance">Prototype.add_instance(element[, category])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Adds an instance to this concept, used automatically during concept:draw</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>element</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the element that will be added as an instance
</li>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
the category to add this element under, if nil the category callback is used to assign one
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding an element as a instance for this concept, mostly for internal use
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
custom_button.add_instance(element) -- normally <span class="keyword">not</span> needed due to use <span class="keyword">in</span> concept:draw</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.update_instances" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.update_instances">Prototype.update_instances([category], update_callback)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Applies an update function to all instances, simialr use to what table.forEach would be</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a> or <a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the category to get, can only be nil if categories are not used
(<em>optional</em>)
</li>
<li class="section-subitem-li">
<strong><em>update_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
the function which is called on each instance, recives other args passed to update_instances
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Changing the font color of all instances for player 1
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
custom_button.update_instances(<span class="number">1</span>,<span class="keyword">function</span>(element)
element.style.font_color = {r=<span class="number">1</span>,g=<span class="number">0</span>,b=<span class="number">0</span>}
<span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
</dl>
<h3><span id="Concept_Data" class="section-title"><a href="#Concept_Data">Concept Data </a></span></h3>
<dl class="section-body-container">
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:define_data_store" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:define_data_store">Prototype:define_data_store([category_callback])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Adds a data store to this concept which allows you to store synced/percistent data between instances</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
when given will act as a way to turn an element into a string to act as a key; keys returned can over lap
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a way to store data for this concept; each player has their own store
</span><span class="comment">-- Note even thou this is a copy of Button; if Button had an data store it would not be cloned over
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
:define_data_store(<span class="keyword">function</span>(element)
<span class="keyword">return</span> element.player_index <span class="comment">-- The data is stored based on player id
</span><span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.get_data" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.get_data">Prototype.get_data([category])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Gets the data that is stored for this category</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a> or <a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the category to get, can only be nil if categories are not used
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">any</span></span>)
<span class="return-text">the data that you had stored in this location</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Getting the stored data for player 1
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
custom_button.get_data(<span class="number">1</span>) -- player index <span class="number">1</span></code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.set_data" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.set_data">Prototype.set_data([category], value)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Sets the data that is stored for this category</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a> or <a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the category to set, can only be nil if categories are not used
(<em>optional</em>)
</li>
<li class="section-subitem-li">
<strong><em>value</em></strong>
<strong> : </strong>
(<span class="types"><span class="type">any</span></span>)
the data that you want to stored in this location
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Setting the data for player 1 to a table with two keys
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
<span class="comment">-- A table is used to show correct way to use a table with self.update_data
</span><span class="comment">-- but a table is not required and can be any data, however upvalues may cause desyncs
</span>custom_button.set_data(<span class="number">1</span>,{
clicks = <span class="number">0</span>,
required_clicks = <span class="number">100</span>
}) -- player index <span class="number">1</span></code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.clear_data" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.clear_data">Prototype.clear_data([category])</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Clears the data that is stored for this category</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a> or <a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the category to clear, can only be nil if categories are not used
(<em>optional</em>)
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Clearing the data for player 1
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
custom_button.clear_data(<span class="number">1</span>) -- player index <span class="number">1</span></code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.update_data" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.update_data">Prototype.update_data([category], update_callback)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Updates the data that is stored for this category</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a> or <a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
the category to clear, can only be nil if categories are not used
(<em>optional</em>)
</li>
<li class="section-subitem-li">
<strong><em>update_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
the function which is called to update the data
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Updating the clicks key in the concept data for player 1
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
custom_button.update_data(<span class="number">1</span>,<span class="keyword">function</span>(tbl)
tbl.clicks = tbl.clicks + <span class="number">1</span> <span class="comment">-- here we are incrementing the clicks by 1
</span><span class="keyword">end</span>) <span class="comment">-- player index 1
</span></code></pre>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Updating a value when a table is not used, alterative to get set
</span><span class="comment">-- so for this example assume that we did custom_button.set_data(1,0)
</span>custom_button.update_data(<span class="number">1</span>,<span class="keyword">function</span>(value)
<span class="keyword">return</span> value + <span class="number">1</span> <span class="comment">-- here we are incrementing the value by 1, we may only be tracking clicks
</span><span class="keyword">end</span>) -- player index <span class="number">1</span></code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype:define_combined_store" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype:define_combined_store">Prototype:define_combined_store([category_callback], get_callback, set_callback)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Used to add a both instance and data stores which are linked together, new instances are synced to current value, changing one instances changes them all</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>category_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
when given will act as a way to turn an element into a string to act as a key; keys returned can over lap
(<em>optional</em>)
</li>
<li class="section-subitem-li">
<strong><em>get_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
the function which is called when you set the store from an instance
</li>
<li class="section-subitem-li">
<strong><em>set_callback</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
the function which is called when you update an instance using the value in the store
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<strong>Returns:</strong>
<ul>
<li>
(<span class="types"><span class="type">GuiConcept</span></span>)
<span class="return-text">to allow chaing of functions</span>
</li>
</ul>
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a way to sync captions bettween all instances, more useful for things that arnt buttons
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
:define_combined_store(
<span class="keyword">function</span>(element)
<span class="keyword">return</span> element.player_index <span class="comment">-- The data is stored based on player id
</span><span class="keyword">end</span>,
<span class="keyword">function</span>(element)
<span class="keyword">return</span> element.caption <span class="comment">-- We want to store the caption
</span><span class="keyword">end</span>,
<span class="keyword">function</span>(element,value)
element.caption = value <span class="comment">-- This is the inverse of above
</span><span class="keyword">end</span>)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.set_instance_from_store" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.set_instance_from_store">Prototype.set_instance_from_store(the)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Will set the state of an instance based on the value in the store</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>the</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
element that you want to have update
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Setting the caption of this element to be the same as the stored value
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
<span class="comment">-- Used internally when first draw and automatically when the store updates
</span>custom_button.set_instance_from_store(element)</code></pre>
<!-- usage end -->
</dd>
<dt>
<div class="divider divider-custom"></div>
<div class="block section-item-header">
<a href="#Prototype.set_store_from_instance" class="fragment-hashtag">#</a>
<span class="section-item-title" id="Prototype.set_store_from_instance">Prototype.set_store_from_instance(the)</span>
</div>
</dt>
<dd>
<div class="section-item-body">
<p class="section-item-summary">Will set the value in the store and update the other instances based on the instance given</p>
<p class="section-item-description"></p>
<!-- parameters start -->
<strong>Parameters:</strong>
<ul>
<li class="section-subitem-li">
<strong><em>the</em></strong>
<strong> : </strong>
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/LuaGuiElement.html">LuaGuiElement</a></span>)
element that you want to use to update the store
</li>
</ul>
<!-- parameters end -->
<!-- returns start -->
<!-- returns end -->
<!-- see also start -->
<!-- see also end -->
<!-- usage start -->
<strong>Usage:</strong>
<pre class="code" data-lang="Lua"><code><span class="comment">-- Setting the stored value to be the same as the caption for this element
</span><span class="keyword">local</span> custom_button =
Gui.get_concept(<span class="string">'CustomButton'</span>)
<span class="comment">-- You may want to use this with gui events
</span>custom_button.set_store_from_instance(element)</code></pre>
<!-- usage end -->
</dd>
</dl>
<!-- section end -->
</div>
</div>
</div>
<div class="footer container grid-1280">
<div class="divider divider-custom"></div>
<div class="footer-columns columns">
<div class="sidebar-footer column col-3 col-sm-12">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc </a></i>
</div>
<div class="content-footer column col-9 col-sm-12">
<i>Last updated 2019-08-25 01:11:55 UTC</i>
</div>
</div>
</div>
</body>
</html>