mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-16 10:19:27 +02:00
4258568c90
* Add creep spread mechanic * Added bot ore islands, use bool flag to turn on. * Added a noise based chest spawning system for artefacts * Added coin loot from biters and mining * Track artefacts launched into space * Add Creepy map preset * Update donators.lua * Add scenario info for crashsite (#291) * Split colors resources from colors code & catchup on donators (#288) * Split colors resources from colors code * Switch back to colors * Added jail button Moved parts of the jail command to report.lua Made jailing possible from a users report. closes #215 * Added sound for new reports Admins now get a sound when a new report is created. Useful for admins that doesn't have Factorio as active window. Currently set the sound_path as utility/tutorial_notice * Split chat triggers from control * Move cheat tracking outside of control.lua * Remove player-specific code * Split donator/on_join messages out of control * Move features into features folder * Indentation fix I aimed to fix the troublesome indentation. * Added a single indent * Make sure biter modifiers are accessible for mods * Consistency change regarding table access * Added NightTime.lua Split the time assignment into a new file NightTime.lua allowing for it to be disabled. (Restore normal day/night cycle) Also added a popup when a player places a solar panel informing that they are purely cosmetic Removed the recipe for portable solar panels because they are useless, but the technology is needed. * Fixed debug print grid value to show non-rounded value * added support for hidden tiles * Add newline to eof * Fixed no newline, indentation and scope of research * crash_site outposts set hidden tile to 'grass-1' * Log items spawned by crafting in cheat mode * Newline to eof * Put responses into table * Use trigger as table key * Change name of lattice to diagonal lattice (#297) * Add Diagonal Ribbon to map presets (#294) * Reorganize control (#312) * Check for config before disabling fish market (#311) * Force diggy biters to spawn, even if there's no space (#308) * Fixed some small things from feedback and issues (#313) * Update fractal_balls.lua * Add ALo's message and color (#314) * Add join message for ALo * Add ALo's color * Typo in donators.lua * fixed tile corruption issus closes #310 (#317) * Update player_list.lua * Update diagonal_ribbon.lua (#322) * Regulars: remove duplicates and sort alphabetically (#320)
227 lines
5.9 KiB
Lua
227 lines
5.9 KiB
Lua
local Event = require 'utils.event'
|
|
local Gui = require 'utils.gui'
|
|
local Game = require 'utils.game'
|
|
|
|
local brush_tool = 'refined-hazard-concrete'
|
|
|
|
local valid_filters = {
|
|
'dirt-1',
|
|
'dirt-2',
|
|
'dirt-3',
|
|
'dirt-4',
|
|
'dirt-5',
|
|
'dirt-6',
|
|
'dirt-7',
|
|
'dry-dirt',
|
|
'grass-1',
|
|
'grass-2',
|
|
'grass-3',
|
|
'grass-4',
|
|
'lab-dark-1',
|
|
'lab-dark-2',
|
|
'lab-white',
|
|
'red-desert-0',
|
|
'red-desert-1',
|
|
'red-desert-2',
|
|
'red-desert-3',
|
|
'sand-1',
|
|
'sand-2',
|
|
'sand-3',
|
|
'tutorial-grid'
|
|
}
|
|
|
|
local main_button_name = Gui.uid_name()
|
|
local main_frame_name = Gui.uid_name()
|
|
|
|
local filter_button_name = Gui.uid_name()
|
|
local filter_clear_name = Gui.uid_name()
|
|
local filter_element_name = Gui.uid_name()
|
|
local filters_table_name = Gui.uid_name()
|
|
local filter_table_close_button_name = Gui.uid_name()
|
|
|
|
global.paint_brushes_by_player = {}
|
|
local function player_build_tile(event)
|
|
if not global.scenario.config.paint.enable then
|
|
return
|
|
end
|
|
if event.item.name ~= brush_tool then
|
|
return
|
|
end
|
|
|
|
local replace_tile = global.paint_brushes_by_player[event.player_index]
|
|
if not replace_tile then
|
|
return
|
|
end
|
|
|
|
local player = Game.get_player_by_index(event.player_index)
|
|
if not player.gui.left[main_frame_name] then
|
|
return
|
|
end
|
|
|
|
local tiles = event.tiles
|
|
local count = 0
|
|
for _, tile_data in ipairs(tiles) do
|
|
tile_data.name = replace_tile
|
|
if tile_data.old_tile.name == replace_tile then
|
|
count = count + 1
|
|
end
|
|
end
|
|
|
|
game.surfaces[event.surface_index].set_tiles(tiles)
|
|
|
|
if count > 0 then
|
|
player.insert {name = brush_tool, count = count}
|
|
end
|
|
end
|
|
|
|
local function player_joined(event)
|
|
if not global.scenario.config.paint.enable then
|
|
return
|
|
end
|
|
local player = Game.get_player_by_index(event.player_index)
|
|
if not player or not player.valid then
|
|
return
|
|
end
|
|
|
|
if player.gui.top[main_button_name] ~= nil then
|
|
return
|
|
end
|
|
|
|
player.gui.top.add {name = main_button_name, type = 'sprite-button', sprite = 'utility/spray_icon'}
|
|
end
|
|
|
|
local function draw_filters_table(event)
|
|
local center = event.player.gui.center
|
|
|
|
if center[filters_table_name] then
|
|
return
|
|
end
|
|
|
|
local frame = center.add {type = 'frame', name = filters_table_name, direction = 'vertical', caption = 'Palette'}
|
|
|
|
local t = frame.add {type = 'table', column_count = 10}
|
|
t.style.horizontal_spacing = 0
|
|
t.style.vertical_spacing = 0
|
|
|
|
for _, v in ipairs(valid_filters) do
|
|
local flow = t.add {type = 'flow'}
|
|
local b = flow.add {type = 'sprite-button', name = filter_element_name, sprite = 'tile/' .. v, tooltip = v}
|
|
Gui.set_data(b, frame)
|
|
b.style = 'slot_button'
|
|
end
|
|
|
|
local flow = frame.add {type = 'flow'}
|
|
|
|
local close = flow.add {type = 'button', name = filter_table_close_button_name, caption = 'Close'}
|
|
Gui.set_data(close, frame)
|
|
|
|
event.player.opened = frame
|
|
|
|
Gui.set_data(frame, event.element)
|
|
end
|
|
|
|
local function toggle(event)
|
|
local left = event.player.gui.left
|
|
local main_frame = left[main_frame_name]
|
|
|
|
if main_frame and main_frame.valid then
|
|
Gui.remove_data_recursivly(main_frame)
|
|
main_frame.destroy()
|
|
else
|
|
main_frame =
|
|
left.add {
|
|
type = 'frame',
|
|
name = main_frame_name,
|
|
direction = 'vertical',
|
|
caption = 'Paint Brush'
|
|
}
|
|
main_frame.add {
|
|
type = 'label',
|
|
caption = 'Choose a replacement tile for Refined hazard concrete'
|
|
}
|
|
|
|
local tooltip = global.paint_brushes_by_player[event.player_index] or ''
|
|
|
|
local brush =
|
|
main_frame.add({type = 'flow'}).add {
|
|
type = 'sprite-button',
|
|
name = filter_button_name,
|
|
tooltip = tooltip,
|
|
sprite = tooltip ~= '' and 'tile/' .. tooltip or nil
|
|
}
|
|
brush.style = 'slot_button'
|
|
|
|
local buttons_flow = main_frame.add {type = 'flow', direction = 'horizontal'}
|
|
|
|
buttons_flow.add {type = 'button', name = main_button_name, caption = 'Close'}
|
|
|
|
local clear_bursh = buttons_flow.add {type = 'button', name = filter_clear_name, caption = 'Clear Brush'}
|
|
Gui.set_data(clear_bursh, brush)
|
|
end
|
|
end
|
|
|
|
Gui.on_click(main_button_name, toggle)
|
|
|
|
Gui.on_click(
|
|
filter_button_name,
|
|
function(event)
|
|
if event.button == defines.mouse_button_type.right then
|
|
global.paint_brushes_by_player[event.player_index] = nil
|
|
local element = event.element
|
|
element.sprite = 'utility/pump_cannot_connect_icon'
|
|
element.tooltip = ''
|
|
else
|
|
draw_filters_table(event)
|
|
end
|
|
end
|
|
)
|
|
|
|
Gui.on_click(
|
|
filter_clear_name,
|
|
function(event)
|
|
local brush = Gui.get_data(event.element)
|
|
|
|
brush.sprite = 'utility/pump_cannot_connect_icon'
|
|
brush.tooltip = ''
|
|
|
|
global.paint_brushes_by_player[event.player_index] = nil
|
|
end
|
|
)
|
|
|
|
Gui.on_click(
|
|
filter_element_name,
|
|
function(event)
|
|
local element = event.element
|
|
local frame = Gui.get_data(element)
|
|
local filter_button = Gui.get_data(frame)
|
|
|
|
global.paint_brushes_by_player[event.player_index] = element.tooltip
|
|
filter_button.sprite = element.sprite
|
|
filter_button.tooltip = element.tooltip
|
|
|
|
Gui.remove_data_recursivly(frame)
|
|
frame.destroy()
|
|
end
|
|
)
|
|
|
|
Gui.on_click(
|
|
filter_table_close_button_name,
|
|
function(event)
|
|
local frame = Gui.get_data(event.element)
|
|
Gui.remove_data_recursivly(frame)
|
|
frame.destroy()
|
|
end
|
|
)
|
|
|
|
Gui.on_custom_close(
|
|
filters_table_name,
|
|
function(event)
|
|
local element = event.element
|
|
Gui.remove_data_recursivly(element)
|
|
element.destroy()
|
|
end
|
|
)
|
|
|
|
Event.add(defines.events.on_player_joined_game, player_joined)
|
|
Event.add(defines.events.on_player_built_tile, player_build_tile)
|