mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
Merge branch 'tag-group-refactor' of https://github.com/grilledham/RedMew
This commit is contained in:
commit
6a1b5dd3d3
@ -1,4 +1,4 @@
|
||||
_DEBUG = false
|
||||
_DEBUG = true
|
||||
|
||||
global.scenario = {}
|
||||
global.spys = {"valansch", "air20"}
|
||||
|
@ -19,7 +19,7 @@ require 'bot'
|
||||
require 'info'
|
||||
require 'player_list'
|
||||
require 'poll'
|
||||
require 'band'
|
||||
require 'tag_group'
|
||||
require 'tasklist'
|
||||
require 'blueprint_helper'
|
||||
require 'paint'
|
||||
@ -137,7 +137,6 @@ end
|
||||
|
||||
Event.add(defines.events.on_player_created, player_joined)
|
||||
Event.add(defines.events.on_console_chat, hodor)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
@ -154,6 +153,6 @@ Event.add(
|
||||
|
||||
local gui = player.gui
|
||||
gui.top.style = 'slot_table_spacing_horizontal_flow'
|
||||
gui.left.style = 'slot_table_spacing_vertical_flow'
|
||||
gui.left.style = 'slot_table_spacing_vertical_flow'
|
||||
end
|
||||
)
|
||||
|
@ -1,201 +0,0 @@
|
||||
-- A part of band.lua
|
||||
-- Feel free to edit.
|
||||
|
||||
return {
|
||||
['Trooper'] = {
|
||||
paths = {'item/tank'},
|
||||
tooltips = {
|
||||
'Incoming!!!',
|
||||
"If the facts don't fit the theory, change the facts.",
|
||||
'I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.',
|
||||
"There's a fine line between genius and insanity. I have erased this line."
|
||||
},
|
||||
verbs = {
|
||||
'strengthened'
|
||||
}
|
||||
},
|
||||
['Mining'] = {
|
||||
paths = {
|
||||
'item/iron-axe',
|
||||
'item/steel-axe',
|
||||
'item/iron-ore',
|
||||
'item/copper-ore'
|
||||
},
|
||||
tooltips = {
|
||||
'Mine or not to mine',
|
||||
'The nation behaves well if it treats the natural resources as assets which\n it must turn over to the next generation increased, and not impaired, in value.'
|
||||
},
|
||||
verbs = {
|
||||
'enriched'
|
||||
-- "smelted"
|
||||
}
|
||||
},
|
||||
['Smelting'] = {
|
||||
paths = {
|
||||
'item/stone-furnace',
|
||||
'item/steel-furnace'
|
||||
},
|
||||
tooltips = {
|
||||
'Mirrors are ice which do not melt: what melts are those who admire themselves in them.',
|
||||
"It's as certain that as long as fossil fuels are the cheapest energy, we will just keep burning them."
|
||||
},
|
||||
verbs = {
|
||||
'fused'
|
||||
}
|
||||
},
|
||||
['Production'] = {
|
||||
paths = {
|
||||
'item/assembling-machine-1',
|
||||
'item/assembling-machine-2',
|
||||
'item/assembling-machine-3'
|
||||
},
|
||||
tooltips = {
|
||||
"When every physical and mental resources is focused, one's power to solve a problem multiplies tremendously.",
|
||||
'The production of too many useful things results in too many useless people. ',
|
||||
'Everything must be made as simple as possible. But not simpler.'
|
||||
},
|
||||
verbs = {
|
||||
'enhanced'
|
||||
}
|
||||
},
|
||||
['Science'] = {
|
||||
paths = {
|
||||
'item/science-pack-1',
|
||||
'item/science-pack-2',
|
||||
'item/science-pack-3',
|
||||
'item/military-science-pack',
|
||||
'item/production-science-pack',
|
||||
'item/high-tech-science-pack',
|
||||
'item/space-science-pack'
|
||||
},
|
||||
tooltips = {
|
||||
'Science without religion is lame, religion without science is blind',
|
||||
'If we knew what it was we were doing, it would not be called research, would it?',
|
||||
'Somewhere, something incredible is waiting to be known.',
|
||||
"I'm sure the universe is full of intelligent life. It's just been too intelligent to come here."
|
||||
},
|
||||
verbs = {
|
||||
'advanced'
|
||||
}
|
||||
},
|
||||
['Wizard'] = {
|
||||
paths = {
|
||||
'item/arithmetic-combinator',
|
||||
'item/green-wire',
|
||||
'item/red-wire',
|
||||
'item/decider-combinator'
|
||||
},
|
||||
tooltips = {
|
||||
"Without mathematics, there's nothing you can do. Everything around you is mathematics. Everything around you is numbers.",
|
||||
'Pure mathematics is, in its way, the poetry of logical ideas.',
|
||||
'God used beautiful mathematics in creating the world.',
|
||||
'The numbers may be said to rule the whole world of quantity, and the four rules of arithmetic may be regarded as the complete equipment of the mathematician.',
|
||||
'But if the technological Singularity can happen, it will.'
|
||||
--"One day it will have a mind of it´s own!."
|
||||
},
|
||||
verbs = {
|
||||
'combinated',
|
||||
'equaled'
|
||||
}
|
||||
},
|
||||
['Trains'] = {
|
||||
paths = {
|
||||
'item/locomotive',
|
||||
'entity/curved-rail',
|
||||
'item/cargo-wagon',
|
||||
'item/fluid-wagon',
|
||||
'item/rail-signal',
|
||||
'item/rail'
|
||||
},
|
||||
tooltips = {
|
||||
'Ch, ch, choooo!',
|
||||
'The only way of catching a train I have ever discovered is to miss the train before. ',
|
||||
"If a trainstation is where the train stops, what's a workstation...?"
|
||||
},
|
||||
verbs = {
|
||||
'expanded',
|
||||
'derailed'
|
||||
}
|
||||
},
|
||||
['Oil'] = {
|
||||
paths = {
|
||||
'item/pumpjack',
|
||||
'item/storage-tank',
|
||||
'item/oil-refinery',
|
||||
'item/chemical-plant',
|
||||
'fluid/crude-oil'
|
||||
},
|
||||
tooltips = {
|
||||
"We're running out of oil!",
|
||||
'Black gold',
|
||||
"Naturally occurring, yellow-to-black liquid found in geological formations beneath the Earth's surface, which is commonly refined into various types of fuels.",
|
||||
'Components of petroleum are separated using a technique called fractional distillation.',
|
||||
'The petroleum industry generally classifies crude oil by the geographic location it is produced in (e.g. West Texas Intermediate, Brent, or Oman), its API gravity (an oil industry measure of density), and its sulfur content.'
|
||||
},
|
||||
verbs = {
|
||||
'lubricated',
|
||||
'sulfured'
|
||||
}
|
||||
},
|
||||
['Powah!'] = {
|
||||
paths = {'item/steam-engine', 'item/nuclear-reactor', 'item/solar-panel'},
|
||||
tooltips = {
|
||||
'I ve Got The power!',
|
||||
'Power Overwhelming!!!111',
|
||||
'Its Over 9000!!!',
|
||||
'If you want to find the secrets of the universe, think in terms of energy, frequency and vibration.'
|
||||
},
|
||||
verbs = {
|
||||
'amplified',
|
||||
'teslaed',
|
||||
'electrified'
|
||||
}
|
||||
},
|
||||
['Spaceman'] = {
|
||||
paths = {'item/rocket-silo', 'item/rocket-fuel'},
|
||||
tooltips = {
|
||||
"That's one small step for a man, one giant leap for mankind.",
|
||||
"The sky is the limit only for those who aren't afraid to fly!",
|
||||
'Apocalyptic explosions, dead reactors, terrorists, mass murder, death-slugs, and now a blindness plague. This is a terrible planet. We should not have come here.',
|
||||
'A still more glorious dawn awaits. Not a sunrise, but a galaxy rise. A morning filled with 400 billion suns. The rising of the milky way',
|
||||
'The Universe is under no obligation to make sense to you.'
|
||||
},
|
||||
verbs = {
|
||||
'warped'
|
||||
}
|
||||
},
|
||||
['Cat'] = {
|
||||
paths = {'item/raw-fish'},
|
||||
tooltips = {
|
||||
'=^.^=',
|
||||
'Meow',
|
||||
"In a cat's eye, all things belong to cats.",
|
||||
"Cats don't like change without their consent.",
|
||||
'Heard melodies are sweet, but those unheard, are sweeter'
|
||||
},
|
||||
verbs = {
|
||||
'mewed',
|
||||
'purred',
|
||||
'miaowed'
|
||||
}
|
||||
},
|
||||
['Dog'] = {
|
||||
paths = {
|
||||
'entity/small-biter',
|
||||
'entity/medium-biter',
|
||||
'entity/big-biter',
|
||||
'entity/behemoth-biter'
|
||||
},
|
||||
tooltips = {
|
||||
'Not a cat',
|
||||
'Friend',
|
||||
"It's not the size of the dog in the fight, it's the size of the fight in the dog.",
|
||||
'When what you want is a relationship, and not a person, get a dog',
|
||||
'A dog has one aim in life... to bestow his heart.'
|
||||
},
|
||||
verbs = {
|
||||
'woofed',
|
||||
'howled'
|
||||
}
|
||||
}
|
||||
}
|
53
resources/tag_groups.lua
Normal file
53
resources/tag_groups.lua
Normal file
@ -0,0 +1,53 @@
|
||||
-- A part of band.lua
|
||||
-- Feel free to edit.
|
||||
|
||||
return {
|
||||
['Trooper'] = {
|
||||
path = 'item/tank',
|
||||
verb = 'strengthened'
|
||||
},
|
||||
['Mining'] = {
|
||||
path = 'item/electric-mining-drill',
|
||||
verb = 'enriched'
|
||||
},
|
||||
['Smelting'] = {
|
||||
path = 'item/stone-furnace',
|
||||
verb = 'fused'
|
||||
},
|
||||
['Production'] = {
|
||||
path = 'item/assembling-machine-2',
|
||||
verb = 'enhanced'
|
||||
},
|
||||
['Science'] = {
|
||||
path = 'item/science-pack-3',
|
||||
verb = 'advanced'
|
||||
},
|
||||
['Wizard'] = {
|
||||
path = 'item/green-wire',
|
||||
verb = 'combinated'
|
||||
},
|
||||
['Trains'] = {
|
||||
path = 'item/locomotive',
|
||||
verb = 'derailed'
|
||||
},
|
||||
['Oil'] = {
|
||||
path = 'fluid/crude-oil',
|
||||
verb = 'lubricated'
|
||||
},
|
||||
['Powah!'] = {
|
||||
path = 'item/steam-engine',
|
||||
verb = 'electrified'
|
||||
},
|
||||
['Spaceman'] = {
|
||||
path = 'item/rocket-silo',
|
||||
verb = 'warped'
|
||||
},
|
||||
['Cat'] = {
|
||||
path = 'item/raw-fish',
|
||||
verb = 'mewed'
|
||||
},
|
||||
['Dog'] = {
|
||||
path = 'entity/medium-biter',
|
||||
verb = 'woofed'
|
||||
}
|
||||
}
|
@ -1,29 +1,39 @@
|
||||
local Event = require 'utils.event'
|
||||
local Gui = require 'utils.gui'
|
||||
local Token = require 'utils.global_token'
|
||||
local Global = require 'utils.global'
|
||||
local UserGroups = require 'user_groups'
|
||||
|
||||
local band_roles = require 'resources.band_roles'
|
||||
local band_roles_token = Token.register_global(band_roles)
|
||||
local deafult_verb = 'expanded'
|
||||
|
||||
local tag_groups = require 'resources.tag_groups'
|
||||
local player_tags = {}
|
||||
local player_tags_token = Token.register_global(player_tags)
|
||||
local no_notify_players = {}
|
||||
|
||||
Event.on_load(
|
||||
function()
|
||||
band_roles = Token.get_global(band_roles_token)
|
||||
player_tags = Token.get_global(player_tags_token)
|
||||
Global.register(
|
||||
{tag_groups = tag_groups, player_tags = player_tags, no_notify_players = no_notify_players},
|
||||
function(data)
|
||||
tag_groups = data.tag_groups
|
||||
player_tags = data.player_tags
|
||||
no_notify_players = data.no_notify_players
|
||||
end
|
||||
)
|
||||
|
||||
local function change_player_tag(player, band_name)
|
||||
local function notify_players(message)
|
||||
for _, p in ipairs(game.connected_players) do
|
||||
if p.valid and not no_notify_players[p.index] then
|
||||
p.print(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function change_player_tag(player, tag_name, silent)
|
||||
local old_tag = player.tag
|
||||
if band_name == '' and old_tag == '' then
|
||||
if tag_name == '' and old_tag == '' then
|
||||
return false
|
||||
end
|
||||
|
||||
local tag_name = '[' .. band_name .. ']'
|
||||
if old_tag == tag_name then
|
||||
local tag = '[' .. tag_name .. ']'
|
||||
if old_tag == tag then
|
||||
return false
|
||||
end
|
||||
|
||||
@ -34,36 +44,34 @@ local function change_player_tag(player, band_name)
|
||||
end
|
||||
end
|
||||
|
||||
if band_name == '' then
|
||||
if tag_name == '' then
|
||||
player.tag = ''
|
||||
if not silent then
|
||||
notify_players(player.name .. ' has left the ' .. old_tag .. ' squad')
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local band = band_roles[band_name]
|
||||
if not band then
|
||||
local tag_data = tag_groups[tag_name]
|
||||
if not tag_data then
|
||||
return false
|
||||
end
|
||||
|
||||
local players = player_tags[tag_name]
|
||||
local players = player_tags[tag]
|
||||
if not players then
|
||||
players = {}
|
||||
player_tags[tag_name] = players
|
||||
player_tags[tag] = players
|
||||
end
|
||||
|
||||
players[player.index] = true
|
||||
|
||||
player.tag = tag_name
|
||||
player.tag = tag
|
||||
|
||||
local verbs = band.verbs
|
||||
local verb
|
||||
if verbs then
|
||||
verb = verbs[math.random(#verbs)]
|
||||
else
|
||||
verb = 'expanded'
|
||||
local verb = tag_data.verb or deafult_verb
|
||||
|
||||
if not silent then
|
||||
notify_players(tag .. ' squad has `' .. verb .. '` with ' .. player.name)
|
||||
end
|
||||
|
||||
game.print(tag_name .. ' squad has `' .. verb .. '` with ' .. player.name)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -94,19 +102,20 @@ end
|
||||
|
||||
local main_button_name = Gui.uid_name()
|
||||
local main_frame_name = Gui.uid_name()
|
||||
local band_button_name = Gui.uid_name()
|
||||
local band_label_name = Gui.uid_name()
|
||||
local main_frame_content_name = Gui.uid_name()
|
||||
local tag_button_name = Gui.uid_name()
|
||||
local tag_label_name = Gui.uid_name()
|
||||
local clear_button_name = Gui.uid_name()
|
||||
local create_tag_button_name = Gui.uid_name()
|
||||
local delete_tag_button_name = Gui.uid_name()
|
||||
local edit_tag_button_name = Gui.uid_name()
|
||||
local notify_checkbox_name = Gui.uid_name()
|
||||
|
||||
local create_tag_frame_name = Gui.uid_name()
|
||||
local create_tag_choose_icon_name = Gui.uid_name()
|
||||
local create_tag_icon_type_name = Gui.uid_name()
|
||||
local close_create_tag_name = Gui.uid_name()
|
||||
local confirm_create_tag_name = Gui.uid_name()
|
||||
|
||||
local main_frame_content_name = Gui.uid_name()
|
||||
local delete_tag_name = Gui.uid_name()
|
||||
local close_create_tag_name = Gui.uid_name()
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
@ -123,40 +132,48 @@ end
|
||||
|
||||
local function draw_main_frame_content(parent)
|
||||
local player = parent.gui.player
|
||||
local grid = parent.add {type = 'table', column_count = 1}
|
||||
grid.style.vertical_spacing = 0
|
||||
|
||||
for band_name, band_data in pairs(band_roles) do
|
||||
local tag_name = '[' .. band_name .. ']'
|
||||
local players = player_tags[tag_name]
|
||||
for tag_name, tag_data in pairs(tag_groups) do
|
||||
local tag = '[' .. tag_name .. ']'
|
||||
local players = player_tags[tag]
|
||||
|
||||
local size = get_size(players)
|
||||
local path = band_data.paths[math.random(#band_data.paths)]
|
||||
local tooltip = band_data.tooltips[math.random(#band_data.tooltips)]
|
||||
local path = tag_data.path
|
||||
|
||||
local row = parent.add {type = 'flow', direction = 'horizontal'}
|
||||
row.style.top_padding = 0
|
||||
row.style.bottom_padding = 0
|
||||
local row = grid.add {type = 'table', column_count = 4}
|
||||
row.style.horizontal_spacing = 0
|
||||
|
||||
if player.admin then
|
||||
local delete_button =
|
||||
row.add {type = 'sprite-button', name = delete_tag_button_name, sprite = 'utility/remove'}
|
||||
delete_button.tooltip = 'Delete tag group'
|
||||
delete_button.style.top_padding = 0
|
||||
delete_button.style.bottom_padding = 0
|
||||
delete_button.style.maximal_height = 32
|
||||
Gui.set_data(delete_button, band_name)
|
||||
if player.admin or UserGroups.is_regular(player.name) then
|
||||
local edit_button =
|
||||
row.add {
|
||||
type = 'sprite-button',
|
||||
name = edit_tag_button_name,
|
||||
sprite = 'utility/rename_icon_normal',
|
||||
tooltip = 'Edit tag group'
|
||||
}
|
||||
edit_button.style.top_padding = 0
|
||||
edit_button.style.bottom_padding = 0
|
||||
edit_button.style.maximal_height = 32
|
||||
Gui.set_data(edit_button, tag_name)
|
||||
end
|
||||
|
||||
local button = row.add {type = 'sprite-button', name = band_button_name, sprite = path}
|
||||
button.tooltip = tooltip
|
||||
button.style.top_padding = 0
|
||||
button.style.bottom_padding = 0
|
||||
button.style.maximal_height = 32
|
||||
Gui.set_data(button, band_name)
|
||||
local tag_button =
|
||||
row.add {
|
||||
type = 'sprite-button',
|
||||
name = tag_button_name,
|
||||
sprite = path,
|
||||
tooltip = tag_name
|
||||
}
|
||||
|
||||
local role_label = row.add {type = 'label', name = band_label_name, caption = band_name .. size}
|
||||
role_label.style.top_padding = 4
|
||||
role_label.style.minimal_width = 120
|
||||
Gui.set_data(role_label, {band_name = band_name, path = path})
|
||||
tag_button.style.maximal_height = 32
|
||||
Gui.set_data(tag_button, tag_name)
|
||||
|
||||
local tag_label = row.add {type = 'label', name = tag_label_name, caption = tag_name .. size}
|
||||
tag_label.style.left_padding = 4
|
||||
tag_label.style.minimal_width = 120
|
||||
Gui.set_data(tag_label, {tag_name = tag_name, path = path})
|
||||
|
||||
local list = row.add {type = 'flow', direction = 'horizontal'}
|
||||
|
||||
@ -197,17 +214,34 @@ local function draw_main_frame(player)
|
||||
|
||||
draw_main_frame_content(scroll_pane)
|
||||
|
||||
local flow = main_frame.add {type = 'flow'}
|
||||
flow.add {type = 'button', name = main_button_name, caption = 'Close'}
|
||||
flow.add {type = 'button', name = clear_button_name, caption = 'Clear Tag'}
|
||||
main_frame.add {
|
||||
type = 'checkbox',
|
||||
name = notify_checkbox_name,
|
||||
caption = 'Notify me when tag groups change.',
|
||||
state = not no_notify_players[player.index],
|
||||
tooltip = 'Receive a message when a player enters or leaves a tag group or when a tag group is created, edited or deleted.'
|
||||
}
|
||||
|
||||
local bottom_flow = main_frame.add {type = 'flow', direction = 'horizontal'}
|
||||
|
||||
local left_flow = bottom_flow.add {type = 'flow', direction = 'horizontal'}
|
||||
left_flow.style.align = 'left'
|
||||
left_flow.style.horizontally_stretchable = true
|
||||
|
||||
left_flow.add {type = 'button', name = main_button_name, caption = 'Close'}
|
||||
|
||||
local right_flow = bottom_flow.add {type = 'flow', direction = 'horizontal'}
|
||||
right_flow.style.align = 'right'
|
||||
|
||||
right_flow.add {type = 'button', name = clear_button_name, caption = 'Clear Tag'}
|
||||
|
||||
if player.admin or UserGroups.is_regular(player.name) then
|
||||
flow.add {type = 'button', name = create_tag_button_name, caption = 'Create Tag'}
|
||||
right_flow.add {type = 'button', name = create_tag_button_name, caption = 'Create Tag'}
|
||||
end
|
||||
end
|
||||
|
||||
local function redraw_main_frame()
|
||||
for _, p in ipairs(game.connected_players) do
|
||||
for _, p in pairs(game.players) do
|
||||
local main_frame = p.gui.left[main_frame_name]
|
||||
if main_frame and main_frame.valid then
|
||||
local content = main_frame[main_frame_content_name]
|
||||
@ -215,7 +249,9 @@ local function redraw_main_frame()
|
||||
Gui.remove_data_recursivly(content)
|
||||
content.clear()
|
||||
|
||||
draw_main_frame_content(content)
|
||||
if p.connected then
|
||||
draw_main_frame_content(content)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -223,7 +259,7 @@ end
|
||||
local function redraw_main_button(player, path)
|
||||
local main_button = player.gui.top[main_button_name]
|
||||
|
||||
if path == '' then
|
||||
if path == '' or path == nil then
|
||||
main_button.sprite = 'utility/pump_cannot_connect_icon'
|
||||
main_button.caption = 'tag'
|
||||
else
|
||||
@ -253,20 +289,54 @@ local choices = {
|
||||
'recipe'
|
||||
}
|
||||
|
||||
local function draw_create_tag_frame(event)
|
||||
local center = event.player.gui.center
|
||||
local function draw_create_tag_frame(event, tag_data)
|
||||
local name
|
||||
local verb
|
||||
local path
|
||||
local spirte_type
|
||||
local frame_caption
|
||||
local confirm_caption
|
||||
if tag_data then
|
||||
name = tag_data.name
|
||||
verb = tag_data.verb
|
||||
path = tag_data.path
|
||||
|
||||
if center[create_tag_frame_name] then
|
||||
return
|
||||
if path and path ~= '' then
|
||||
spirte_type, path = path:match('([^/]+)/([^/]+)')
|
||||
if spirte_type == 'virtual-signal' then
|
||||
spirte_type = 'signal'
|
||||
path = {type = 'virtual', name = path}
|
||||
end
|
||||
else
|
||||
spirte_type = choices[1]
|
||||
path = nil
|
||||
end
|
||||
|
||||
frame_caption = 'Edit Tag'
|
||||
confirm_caption = 'Edit'
|
||||
else
|
||||
name = ''
|
||||
verb = 'expanded'
|
||||
spirte_type = choices[1]
|
||||
frame_caption = 'Create A New Tag'
|
||||
confirm_caption = 'Create'
|
||||
end
|
||||
|
||||
local frame =
|
||||
center.add {type = 'frame', name = create_tag_frame_name, caption = 'Create A New Tag', direction = 'vertical'}
|
||||
local player = event.player
|
||||
local center = player.gui.center
|
||||
|
||||
local frame = center[create_tag_frame_name]
|
||||
if frame then
|
||||
Gui.remove_data_recursivly(frame)
|
||||
frame.destroy()
|
||||
end
|
||||
|
||||
frame = center.add {type = 'frame', name = create_tag_frame_name, caption = frame_caption, direction = 'vertical'}
|
||||
|
||||
local main_table = frame.add {type = 'table', column_count = 2}
|
||||
|
||||
main_table.add {type = 'label', caption = 'Name'}
|
||||
local name_field = main_table.add {type = 'textfield'}
|
||||
local name_field = main_table.add {type = 'textfield', text = name}
|
||||
Gui.set_data(name_field, frame)
|
||||
|
||||
main_table.add {type = 'label', caption = 'Icon'}
|
||||
@ -274,16 +344,16 @@ local function draw_create_tag_frame(event)
|
||||
local selection_flow = icons_flow.add {type = 'flow'}
|
||||
|
||||
local focus
|
||||
for i, value in ipairs(choices) do
|
||||
for _, value in ipairs(choices) do
|
||||
local radio =
|
||||
selection_flow.add({type = 'flow'}).add {
|
||||
type = 'radiobutton',
|
||||
name = create_tag_icon_type_name,
|
||||
caption = value,
|
||||
state = i == 1
|
||||
state = value == spirte_type
|
||||
}
|
||||
|
||||
if i == 1 then
|
||||
if value == spirte_type then
|
||||
focus = radio
|
||||
end
|
||||
|
||||
@ -294,71 +364,93 @@ local function draw_create_tag_frame(event)
|
||||
icons_flow.add {
|
||||
type = 'choose-elem-button',
|
||||
name = create_tag_choose_icon_name,
|
||||
elem_type = choices[1]
|
||||
elem_type = spirte_type
|
||||
}
|
||||
|
||||
if path then
|
||||
choose.elem_value = path
|
||||
end
|
||||
|
||||
Gui.set_data(choose, frame)
|
||||
|
||||
main_table.add {type = 'label', caption = 'Verb'}
|
||||
local verb_field = main_table.add {type = 'textfield', text = 'expanded'}
|
||||
local verb_field = main_table.add {type = 'textfield', text = verb}
|
||||
Gui.set_data(verb_field, frame)
|
||||
|
||||
local flow = frame.add {type = 'flow', direction = 'horizontal'}
|
||||
local bottom_flow = frame.add {type = 'flow', direction = 'horizontal'}
|
||||
|
||||
local close_button = flow.add {type = 'button', name = close_create_tag_name, caption = 'Close'}
|
||||
local left_flow = bottom_flow.add {type = 'flow', direction = 'horizontal'}
|
||||
left_flow.style.align = 'left'
|
||||
left_flow.style.horizontally_stretchable = true
|
||||
|
||||
local close_button = left_flow.add {type = 'button', name = close_create_tag_name, caption = 'Close'}
|
||||
Gui.set_data(close_button, frame)
|
||||
|
||||
local confirm_button = flow.add {type = 'button', name = confirm_create_tag_name, caption = 'Confirm'}
|
||||
local right_flow = bottom_flow.add {type = 'flow', direction = 'horizontal'}
|
||||
right_flow.style.align = 'right'
|
||||
|
||||
if tag_data then
|
||||
local delete_button = right_flow.add {type = 'button', name = delete_tag_name, caption = 'Delete'}
|
||||
Gui.set_data(delete_button, frame)
|
||||
end
|
||||
|
||||
local confirm_button = right_flow.add {type = 'button', name = confirm_create_tag_name, caption = confirm_caption}
|
||||
Gui.set_data(confirm_button, frame)
|
||||
|
||||
Gui.set_data(
|
||||
frame,
|
||||
{
|
||||
focus = focus,
|
||||
choose = choose,
|
||||
icons_flow = icons_flow,
|
||||
name = name_field,
|
||||
verb = verb_field
|
||||
}
|
||||
)
|
||||
local data = {
|
||||
focus = focus,
|
||||
choose = choose,
|
||||
icons_flow = icons_flow,
|
||||
name = name_field,
|
||||
verb = verb_field,
|
||||
tag_data = tag_data
|
||||
}
|
||||
Gui.set_data(frame, data)
|
||||
|
||||
event.player.opened = frame
|
||||
player.opened = frame
|
||||
end
|
||||
|
||||
Gui.on_click(main_button_name, toggle)
|
||||
|
||||
Gui.on_click(
|
||||
band_button_name,
|
||||
function(event)
|
||||
local tag = Gui.get_data(event.element)
|
||||
local path = event.element.sprite
|
||||
|
||||
if change_player_tag(event.player, tag) then
|
||||
redraw_main_frame()
|
||||
redraw_main_button(event.player, path)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
band_label_name,
|
||||
function(event)
|
||||
local data = Gui.get_data(event.element)
|
||||
local tag = data.band_name
|
||||
local path = data.path
|
||||
|
||||
if change_player_tag(event.player, tag) then
|
||||
redraw_main_frame()
|
||||
redraw_main_button(event.player, path)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
delete_tag_button_name,
|
||||
tag_button_name,
|
||||
function(event)
|
||||
local tag_name = Gui.get_data(event.element)
|
||||
local path = event.element.sprite
|
||||
|
||||
if not band_roles[tag_name] then
|
||||
if change_player_tag(event.player, tag_name) then
|
||||
redraw_main_frame()
|
||||
redraw_main_button(event.player, path)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
tag_label_name,
|
||||
function(event)
|
||||
local data = Gui.get_data(event.element)
|
||||
local tag_name = data.tag_name
|
||||
local path = data.path
|
||||
|
||||
if change_player_tag(event.player, tag_name) then
|
||||
redraw_main_frame()
|
||||
redraw_main_button(event.player, path)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
delete_tag_name,
|
||||
function(event)
|
||||
local frame = Gui.get_data(event.element)
|
||||
local data = Gui.get_data(frame)
|
||||
local tag_data = data.tag_data
|
||||
local tag_name = tag_data.name
|
||||
|
||||
Gui.remove_data_recursivly(frame)
|
||||
frame.destroy()
|
||||
|
||||
if not tag_groups[tag_name] then
|
||||
event.player.print("Sorry, Tag name '" .. tag_name .. "' not found.")
|
||||
return
|
||||
end
|
||||
@ -366,7 +458,7 @@ Gui.on_click(
|
||||
local tag = '[' .. tag_name .. ']'
|
||||
|
||||
for _, player in pairs(game.players) do
|
||||
if player.tag == tag then
|
||||
if player.valid and player.tag == tag then
|
||||
change_player_tag(player, '')
|
||||
|
||||
if player.connected then
|
||||
@ -375,11 +467,45 @@ Gui.on_click(
|
||||
end
|
||||
end
|
||||
|
||||
band_roles[tag_name] = nil
|
||||
tag_groups[tag_name] = nil
|
||||
|
||||
redraw_main_frame()
|
||||
|
||||
game.print(event.player.name .. ' has deleted the ' .. tag_name .. ' tag group')
|
||||
notify_players(event.player.name .. ' has deleted the ' .. tag_name .. ' tag group')
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
edit_tag_button_name,
|
||||
function(event)
|
||||
local tag_name = Gui.get_data(event.element)
|
||||
|
||||
local tag_data = tag_groups[tag_name]
|
||||
if not tag_data then
|
||||
event.player.print("Sorry, Tag name '" .. tag_name .. "' not found.")
|
||||
return
|
||||
end
|
||||
|
||||
tag_data.name = tag_name
|
||||
|
||||
draw_create_tag_frame(event, tag_data)
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_click(
|
||||
notify_checkbox_name,
|
||||
function(event)
|
||||
local player_index = event.player_index
|
||||
local checkbox = event.element
|
||||
|
||||
local new_state
|
||||
if checkbox.state then
|
||||
new_state = nil
|
||||
else
|
||||
new_state = true
|
||||
end
|
||||
|
||||
no_notify_players[player_index] = new_state
|
||||
end
|
||||
)
|
||||
|
||||
@ -427,16 +553,17 @@ Gui.on_click(
|
||||
local player = event.player
|
||||
local frame = Gui.get_data(event.element)
|
||||
local data = Gui.get_data(frame)
|
||||
local old_tag_data = data.tag_data
|
||||
|
||||
local name = data.name.text
|
||||
local tag_name = data.name.text
|
||||
|
||||
if name == '' then
|
||||
if tag_name == '' then
|
||||
player.print('Sorry, the tag needs a name')
|
||||
return
|
||||
end
|
||||
|
||||
if band_roles[name] then
|
||||
player.print('Sorry, tag ' .. data.name .. ' is already in use.')
|
||||
if not old_tag_data and tag_groups[tag_name] then
|
||||
player.print('Sorry, tag ' .. tag_name .. ' is already in use.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -445,37 +572,65 @@ Gui.on_click(
|
||||
|
||||
local path
|
||||
if not sprite or sprite == '' then
|
||||
path = 'utility/pump_cannot_connect_icon'
|
||||
path = nil
|
||||
elseif type == 'signal' then
|
||||
path = 'virtual-signal/' .. data.choose.elem_value.name
|
||||
else
|
||||
path = type .. '/' .. data.choose.elem_value
|
||||
end
|
||||
|
||||
if not frame.gui.is_valid_sprite_path(path) then
|
||||
if path and not frame.gui.is_valid_sprite_path(path) then
|
||||
player.print('Sorry, ' .. path .. ' is not a valid sprite')
|
||||
return
|
||||
end
|
||||
|
||||
local verb = data.verb.text
|
||||
if verb == '' then
|
||||
verb = 'expanded'
|
||||
verb = deafult_verb
|
||||
end
|
||||
|
||||
local band_role = {
|
||||
paths = {path},
|
||||
verbs = {verb},
|
||||
tooltips = {name}
|
||||
}
|
||||
|
||||
band_roles[name] = band_role
|
||||
|
||||
redraw_main_frame()
|
||||
|
||||
Gui.remove_data_recursivly(frame)
|
||||
frame.destroy()
|
||||
|
||||
game.print(player.name .. ' has made a new tag group called ' .. name)
|
||||
local tag_data = {
|
||||
path = path,
|
||||
verb = verb
|
||||
}
|
||||
tag_groups[tag_name] = tag_data
|
||||
|
||||
local message
|
||||
if old_tag_data then
|
||||
local old_name = old_tag_data.name
|
||||
if old_name == tag_name and old_tag_data.path == path and old_tag_data.verb == verb then
|
||||
return
|
||||
end
|
||||
|
||||
if old_name ~= tag_name then
|
||||
message = player.name .. ' has edited the ' .. tag_name .. ' (formerly ' .. old_name .. ') tag group'
|
||||
|
||||
local old_tag = '[' .. old_name .. ']'
|
||||
|
||||
for _, p in pairs(game.players) do
|
||||
if p.valid and p.tag == old_tag then
|
||||
change_player_tag(p, tag_name, true)
|
||||
|
||||
if p.connected then
|
||||
redraw_main_button(player, '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tag_groups[old_name] = nil
|
||||
else
|
||||
message = player.name .. ' has edited the ' .. tag_name .. ' tag group'
|
||||
end
|
||||
else
|
||||
message = player.name .. ' has made a new tag group called ' .. tag_name
|
||||
end
|
||||
|
||||
redraw_main_frame()
|
||||
|
||||
notify_players(message)
|
||||
end
|
||||
)
|
||||
|
||||
@ -530,7 +685,7 @@ local function tag_command(cmd)
|
||||
end
|
||||
|
||||
local tag_name = string.sub(cmd.parameter, params[1]:len() + 2)
|
||||
local tag = band_roles[tag_name]
|
||||
local tag = tag_groups[tag_name]
|
||||
|
||||
if tag == nil then
|
||||
player_print("Tag '" .. tag_name .. "' does not exist. Create the tag first by clicking Tag -> Create Tag.")
|
||||
@ -544,4 +699,4 @@ local function tag_command(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
commands.add_command('tag', '<player> <tag> Sets a players tag. (Admins only)', tag_command)
|
||||
commands.add_command('tag', "<player> <tag> Sets a player's tag. (Admins only)", tag_command)
|
24
utils/global.lua
Normal file
24
utils/global.lua
Normal file
@ -0,0 +1,24 @@
|
||||
local Event = require 'utils.event'
|
||||
local Token = require 'utils.global_token'
|
||||
|
||||
Global = {}
|
||||
|
||||
local data = {}
|
||||
|
||||
function Global.register(tbl, callback)
|
||||
local token = Token.register_global(tbl)
|
||||
table.insert(data, {tbl = tbl, callback = callback, token = token})
|
||||
end
|
||||
|
||||
Event.on_load(
|
||||
function()
|
||||
for _, d in ipairs(data) do
|
||||
local tbl = Token.get_global(d.token)
|
||||
d.callback(tbl)
|
||||
end
|
||||
|
||||
data = nil
|
||||
end
|
||||
)
|
||||
|
||||
return Global
|
Loading…
x
Reference in New Issue
Block a user