mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-07-26 10:36:22 +09:00
clear blueprint changed to selection (#435)
* Update surface.lua * Update en.cfg * Update surface.lua * Update en.cfg * Fix description keys for ground items and blueprints * Update roles.lua * Update surface.lua * Update quick_actions.lua * Update en.cfg * Update en.cfg * Update surface.lua * Update zh-CN.cfg * Update zh-TW.cfg * . * . * . * Many fixes and reverts --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
This commit is contained in:
@@ -2,12 +2,17 @@
|
||||
Adds a command that clear item on ground so blueprint can deploy safely
|
||||
]]
|
||||
|
||||
local AABB = require("modules/exp_util/aabb")
|
||||
local Commands = require("modules/exp_commands")
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local move_items = ExpUtil.move_items_to_surface
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local Selection = require("modules/exp_util/selection")
|
||||
local SelectArea = Selection.connect("ExpCommand_ClearBlueprint")
|
||||
local format_player_name = Commands.format_player_name_locale
|
||||
|
||||
--- @class ExpCommand_ClearBlueprint.commands
|
||||
local commands = {}
|
||||
|
||||
--- @param surface LuaSurface
|
||||
--- @return LuaItemStack[]
|
||||
local function get_ground_items(surface)
|
||||
@@ -19,71 +24,73 @@ local function get_ground_items(surface)
|
||||
return items
|
||||
end
|
||||
|
||||
--- Clear all items on the ground, optional to select a single surface
|
||||
Commands.new("clear-ground-items", { "exp-commands_surface.description-items" })
|
||||
--- Clear all items on the ground on a surface
|
||||
commands.clear_ground_items = Commands.new("clear-ground-items", { "exp-commands_surface.description-items" })
|
||||
:optional("surface", { "exp-commands_surface.arg-surface" }, Commands.types.surface)
|
||||
:defaults{
|
||||
surface = function(player) return player.surface end
|
||||
}
|
||||
:register(function(player, surface)
|
||||
--- @cast surface LuaSurface?
|
||||
local player_name = format_player_name(player)
|
||||
if surface then
|
||||
move_items{
|
||||
surface = surface,
|
||||
items = get_ground_items(surface),
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
game.print{ "exp-commands_surface.items-surface", player_name, surface.localised_name }
|
||||
else
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
move_items{
|
||||
surface = surface,
|
||||
items = get_ground_items(surface),
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
end
|
||||
game.print{ "exp-commands_surface.items-all", player_name }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Clear all blueprints, optional to select a single surface
|
||||
Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints" })
|
||||
:optional("surface", { "exp-commands_surface.arg-surface" }, Commands.types.surface)
|
||||
:register(function(player, surface)
|
||||
--- @cast surface LuaSurface?
|
||||
local player_name = format_player_name(player)
|
||||
if surface then
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost" }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
game.print{ "exp-commands_surface.blueprint-surface", player_name, surface.localised_name }
|
||||
else
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost" }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
game.print{ "exp-commands_surface.blueprint-all", player_name }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Clear all blueprints in a radius around you
|
||||
Commands.new("clear-blueprints-radius", { "exp-commands_surface.description-radius" })
|
||||
:argument("radius", { "exp-commands_surface.arg-radius" }, Commands.types.number_range(1, 100))
|
||||
:register(function(player, radius)
|
||||
--- @cast radius number
|
||||
local player_name = format_player_name(player)
|
||||
local entities = player.surface.find_entities_filtered{
|
||||
type = "entity-ghost",
|
||||
position = player.position,
|
||||
radius = radius,
|
||||
--- @cast surface LuaSurface
|
||||
move_items{
|
||||
surface = surface,
|
||||
items = get_ground_items(surface),
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
local player_name = format_player_name(player)
|
||||
game.print{ "exp-commands_surface.items", player_name, surface.localised_name }
|
||||
end)
|
||||
|
||||
--- Clear all blueprints on a surface
|
||||
commands.clear_blueprints_surface = Commands.new("clear-blueprints-surface", { "exp-commands_surface.description-blueprints-surface" })
|
||||
:optional("surface", { "exp-commands_surface.arg-surface" }, Commands.types.surface)
|
||||
:defaults{
|
||||
surface = function(player) return player.surface end
|
||||
}
|
||||
:register(function(player, surface)
|
||||
--- @cast surface LuaSurface
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost" }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
game.print{ "exp-commands_surface.blueprint-radius", player_name, radius, player.surface.localised_name }
|
||||
local player_name = format_player_name(player)
|
||||
game.print{ "exp-commands_surface.blueprints", player_name, surface.localised_name }
|
||||
end)
|
||||
|
||||
--- Clear all blueprint in the area, selected by toggle player selection mode
|
||||
--- @class ExpCommands_ClearBlueprint.commands.clear_blueprint: ExpCommand
|
||||
--- @overload fun(player: LuaPlayer)
|
||||
commands.clear_blueprints = Commands.new("clear-blueprints", { "exp-commands_surface.description-blueprints" })
|
||||
:register(function(player)
|
||||
if SelectArea:stop(player) then
|
||||
return Commands.status.success{ "exp-commands_surface.exit" }
|
||||
end
|
||||
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_surface.enter" }
|
||||
end) --[[ @as any ]]
|
||||
|
||||
--- When an area is selected
|
||||
SelectArea:on_selection(function(event)
|
||||
local player = assert(game.get_player(event.player_index))
|
||||
local area = AABB.expand(event.area)
|
||||
local surface = event.surface
|
||||
local area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y)
|
||||
|
||||
if area_size > 1000 then
|
||||
player.print({ "exp-commands_surface.area-too-large", 1000, area_size }, Commands.print_settings.error)
|
||||
return
|
||||
end
|
||||
|
||||
local entities = surface.find_entities_filtered{ type = "entity-ghost", area = area }
|
||||
for _, entity in ipairs(entities) do
|
||||
entity.destroy()
|
||||
end
|
||||
|
||||
game.print({ "exp-commands_surface.complete", #entities }, Commands.print_settings.default)
|
||||
end)
|
||||
|
||||
return {
|
||||
commands = commands,
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ local addon_artillery = require("modules/exp_scenario/commands/artillery")
|
||||
local addon_trains = require("modules/exp_scenario/commands/trains")
|
||||
local addon_teleport = require("modules/exp_scenario/commands/teleport")
|
||||
local addon_waterfill = require("modules/exp_scenario/commands/waterfill")
|
||||
local addon_surface = require("modules/exp_scenario/commands/surface")
|
||||
local addon_lawnmower = require("modules/exp_scenario/commands/lawnmower")
|
||||
local addon_home = require("modules/exp_scenario/commands/home")
|
||||
local addon_vlayer = require("modules/exp_scenario/commands/vlayer")
|
||||
@@ -21,15 +22,23 @@ local Elements = {}
|
||||
--- @type table<string, { command: ExpCommand, element: ExpElement }>
|
||||
local Actions = {}
|
||||
|
||||
--- @param name string
|
||||
--- @param command ExpCommand | function (this is needed because of the overload on commands)
|
||||
--- @param on_click? ExpElement.EventHandler<EventData.on_gui_click>
|
||||
local function new_quick_action(name, command, on_click)
|
||||
local element = Gui.define("quick_actions/" .. name)
|
||||
local function new_quick_action(command, on_click)
|
||||
local command_name = command.name
|
||||
|
||||
local element = Gui.define("quick_actions/" .. command_name)
|
||||
:draw{
|
||||
type = "button",
|
||||
caption = { "exp-gui_quick-actions.caption-" .. name },
|
||||
tooltip = { "exp-gui_quick-actions.tooltip-" .. name },
|
||||
caption = { "?",
|
||||
{ "exp-gui_quick-actions.caption-" .. command_name },
|
||||
command_name,
|
||||
},
|
||||
tooltip = { "?",
|
||||
{ "exp-gui_quick-actions.tooltip-" .. command_name },
|
||||
command.description,
|
||||
""
|
||||
},
|
||||
}
|
||||
:style{
|
||||
width = 160,
|
||||
@@ -38,26 +47,31 @@ local function new_quick_action(name, command, on_click)
|
||||
command(player)
|
||||
end)
|
||||
|
||||
Elements[name] = element
|
||||
Actions[name] = {
|
||||
Elements[command_name] = element
|
||||
Actions[command_name] = {
|
||||
command = command --[[ @as ExpCommand ]],
|
||||
element = element,
|
||||
}
|
||||
end
|
||||
|
||||
new_quick_action("artillery", addon_artillery.commands.artillery)
|
||||
new_quick_action("trains", addon_trains.commands.set_trains_to_automatic)
|
||||
new_quick_action("spawn", addon_teleport.commands.spawn, function(_def, player, _element, _event)
|
||||
new_quick_action(addon_artillery.commands.artillery)
|
||||
new_quick_action(addon_trains.commands.set_trains_to_automatic)
|
||||
|
||||
new_quick_action(addon_teleport.commands.spawn, function(def, player, element, event)
|
||||
addon_teleport.commands.spawn(player, player)
|
||||
end)
|
||||
new_quick_action("waterfill", addon_waterfill.commands.waterfill)
|
||||
new_quick_action("lawnmower", addon_lawnmower.commands.lawnmower)
|
||||
new_quick_action("home", addon_home.commands.home)
|
||||
new_quick_action("return", addon_home.commands._return)
|
||||
new_quick_action("set-home", addon_home.commands.set_home)
|
||||
new_quick_action("get-home", addon_home.commands.get_home)
|
||||
new_quick_action("vlayer", addon_vlayer.commands.vlayer)
|
||||
new_quick_action("repair", addon_repair.commands.repair)
|
||||
|
||||
new_quick_action(addon_waterfill.commands.waterfill)
|
||||
new_quick_action(addon_lawnmower.commands.lawnmower)
|
||||
new_quick_action(addon_surface.commands.clear_ground_items)
|
||||
new_quick_action(addon_surface.commands.clear_blueprints_surface)
|
||||
new_quick_action(addon_surface.commands.clear_blueprints)
|
||||
new_quick_action(addon_home.commands.home)
|
||||
new_quick_action(addon_home.commands._return)
|
||||
new_quick_action(addon_home.commands.set_home)
|
||||
new_quick_action(addon_home.commands.get_home)
|
||||
new_quick_action(addon_vlayer.commands.vlayer)
|
||||
new_quick_action(addon_repair.commands.repair)
|
||||
|
||||
--- Container added to the left gui flow
|
||||
--- @class ExpGui_QuickActions.elements.container: ExpElement
|
||||
|
||||
@@ -220,14 +220,14 @@ follow-self=You can not follow yourself.
|
||||
[exp-commands_surface]
|
||||
description-items=Clear all items on the ground.
|
||||
description-blueprints=Clear all blueprints.
|
||||
description-radius=Clear all blueprints in an radius around you.
|
||||
description-blueprints-surface=Clear all blueprints on the current surface.
|
||||
arg-surface=Surface to clear on, default all.
|
||||
arg-radius=Radius to clear.
|
||||
items-surface=__1__ cleared all items on the ground of __2__.
|
||||
items-all=__1__ cleared all items on the ground for all surfaces.
|
||||
blueprints-surface=__1__ cleared all blueprints on __2__.
|
||||
blueprints-all=__1__ cleared all blueprints for all surfaces.
|
||||
blueprints-radius=__1__ cleared all blueprints in a __2__ radius around them on __3__.
|
||||
items=__1__ cleared all items on the ground of __2__.
|
||||
blueprints=__1__ cleared all blueprints on __2__.
|
||||
enter=Entered selection mode, select the area.
|
||||
exit=Exited selection mode.
|
||||
area-too-large=Selected area is too large, must be less than __1__, selected __2__.
|
||||
complete=__1__ blueprint ghost were removed.
|
||||
|
||||
[exp-commands_trains]
|
||||
description=Set All Trains to Automatic, does not effect trains with passengers.
|
||||
@@ -347,15 +347,10 @@ caption-net=Net
|
||||
[exp-gui_quick-actions]
|
||||
tooltip-main=Quick Actions
|
||||
caption-artillery=Artillery
|
||||
tooltip-artillery=Select artillery targets
|
||||
caption-research=Auto Research
|
||||
tooltip-research=Toggle auto research queue
|
||||
caption-spawn=Teleport Spawn
|
||||
tooltip-spawn-tooltip=Teleport to spawn
|
||||
caption-trains=Set Auto Train
|
||||
tooltip-trains=Set all trains to automatic
|
||||
caption-waterfill=Waterfill
|
||||
tooltip-waterfill=Change tiles to water
|
||||
|
||||
[exp-gui_readme]
|
||||
main-tooltip=Information
|
||||
|
||||
@@ -215,14 +215,14 @@ follow-self=你不能追蹤自己
|
||||
[exp-commands_surface]
|
||||
description-items=清除地面上的物品
|
||||
description-blueprints=清除藍圖
|
||||
description-radius=清除周邊的藍圖
|
||||
description-blueprints-surface=清除藍圖
|
||||
arg-surface=位面
|
||||
arg-radius=周邊半徑
|
||||
items-surface=__1__ 清除了所有在 __2__ 中掉地上的東西。
|
||||
items-all=__1__ 清除了所有掉地上的東西。
|
||||
blueprints-surface=__1__ 清除了所有在 __2__ 中在地上的藍圖。
|
||||
blueprints-all=__1__ 清除了所有在地上的藍圖。
|
||||
blueprints-radius=__1__ 清除了在 __3__ 上,周邊 __2__ 格的地上的藍圖。
|
||||
items=__1__ 清除了所有在 __2__ 中掉地上的東西。
|
||||
blueprints=__1__ 清除了所有在 __2__ 中在地上的藍圖。
|
||||
enter=現在進入區域選擇
|
||||
exit=已進入區域選擇
|
||||
area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格。
|
||||
complete=__1__ 個地上的藍圖已被清除。
|
||||
|
||||
[exp-commands_trains]
|
||||
description=把火車設置為自動模式
|
||||
|
||||
@@ -215,14 +215,14 @@ follow-self=你不能追蹤自己
|
||||
[exp-commands_surface]
|
||||
description-items=清除地面上的物品
|
||||
description-blueprints=清除藍圖
|
||||
description-radius=清除周邊的藍圖
|
||||
description-blueprints-surface=清除藍圖
|
||||
arg-surface=位面
|
||||
arg-radius=周邊半徑
|
||||
items-surface=__1__ 清除了所有在 __2__ 中掉地上的東西。
|
||||
items-all=__1__ 清除了所有掉地上的東西。
|
||||
blueprints-surface=__1__ 清除了所有在 __2__ 中在地上的藍圖。
|
||||
blueprints-all=__1__ 清除了所有在地上的藍圖。
|
||||
blueprints-radius=__1__ 清除了在 __3__ 上,周邊 __2__ 格的地上的藍圖。
|
||||
items=__1__ 清除了所有在 __2__ 中掉地上的東西。
|
||||
blueprints=__1__ 清除了所有在 __2__ 中在地上的藍圖。
|
||||
enter=現在進入區域選擇
|
||||
exit=已進入區域選擇
|
||||
area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格。
|
||||
complete=__1__ 個地上的藍圖已被清除。
|
||||
|
||||
[exp-commands_trains]
|
||||
description=把火車設置為自動模式
|
||||
|
||||
Reference in New Issue
Block a user