1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Merge pull request #271 from iltar/character-item-modifier-text

Added scrolling text popups and UX for market chests
This commit is contained in:
Lynn 2018-11-08 18:57:02 +01:00 committed by GitHub
commit 36758c2fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 9 deletions

View File

@ -10,6 +10,7 @@ local Debug = require 'map_gen.Diggy.Debug'
local Task = require 'utils.Task'
local Token = require 'utils.global_token'
local Global = require 'utils.global'
local Game = require 'utils.game'
local insert = table.insert
local random = math.random
local floor = math.floor
@ -308,18 +309,19 @@ function DiggyCaveCollapse.register(cfg)
Event.add(defines.events.on_marked_for_deconstruction, function (event)
if (nil ~= support_beam_entities[event.entity.name]) then
event.entity.cancel_deconstruction(game.players[event.player_index].force)
event.entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force)
end
end)
Event.add(defines.events.on_pre_player_mined_item, function(event)
if (nil ~= deconstruction_alert_message_shown[event.player_index]) then
local player_index = event.player_index
if (nil ~= deconstruction_alert_message_shown[player_index]) then
return
end
if (nil ~= support_beam_entities[event.entity.name]) then
require 'popup'.player(
game.players[event.player_index],[[
Game.get_player_by_index(player_index),[[
Mining entities such as walls, stone paths, concrete
and rocks, can cause a cave-in, be careful miner!
@ -328,7 +330,7 @@ prevent a cave-in. Use stone paths and concrete
to reinforce it further.
]]
)
deconstruction_alert_message_shown[event.player_index] = true
deconstruction_alert_message_shown[player_index] = true
end
end)

View File

@ -10,6 +10,7 @@ local Gui = require 'utils.gui'
local Debug = require 'map_gen.Diggy.Debug'
local Template = require 'map_gen.Diggy.Template'
local Global = require 'utils.global'
local Game = require 'utils.game'
local insert = table.insert
local max = math.max
@ -412,7 +413,10 @@ local function on_market_item_purchased(event)
return
end
send_stone_to_surface(config.stone_to_surface_amount * event.count)
local sum = config.stone_to_surface_amount * event.count
Game.print_player_floating_text(event.player_index, '-' .. sum .. ' stone', {r = 0.6, g = 0.55, b = 0.42})
send_stone_to_surface(sum)
update_market_contents(event.market)
end
@ -471,7 +475,7 @@ local function toggle(event)
end
local function on_player_created(event)
game.players[event.player_index].gui.top.add({
Game.get_player_by_index(event.player_index).gui.top.add({
name = 'Diggy.MarketExchange.Button',
type = 'sprite-button',
sprite = 'item/stone',
@ -533,10 +537,13 @@ function MarketExchange.register(cfg)
end
local area = {{x_min, y_min}, {x_max + 1, y_max + 1}}
local message_x = (x_max + x_min) * 0.5
local message_y = (y_max + y_min) * 0.5
Event.on_nth_tick(config.void_chest_frequency, function ()
local send_to_surface = 0
local find_entities_filtered = game.surfaces.nauvis.find_entities_filtered
local surface = game.surfaces.nauvis
local find_entities_filtered = surface.find_entities_filtered
local chests = find_entities_filtered({area = area, type = {'container', 'logistic-container'}})
local to_fetch = stone_collecting.active_modifier
@ -556,6 +563,16 @@ function MarketExchange.register(cfg)
end
if (send_to_surface == 0) then
if (0 == to_fetch) then
return
end
local message = 'Missing chests below market'
if (#chests > 0) then
message = 'No stone in chests found'
end
Game.print_floating_text(surface, {x = message_x, y = message_y}, message, { r = 220, g = 100, b = 50})
return
end
@ -566,6 +583,10 @@ function MarketExchange.register(cfg)
return
end
local message = send_to_surface .. ' stone sent to the surface'
Game.print_floating_text(surface, {x = message_x, y = message_y}, message, { r = 0.6, g = 0.55, b = 0.42})
send_stone_to_surface(send_to_surface)
update_market_contents(markets[1])
end)

View File

@ -5,6 +5,7 @@
-- dependencies
local Event = require 'utils.event'
local Debug = require 'map_gen.Diggy.Debug'
local Game = require 'utils.game'
-- this
local SetupPlayer = {}
@ -13,13 +14,12 @@ global.SetupPlayer = {
first_player_spawned = false,
}
--[[--
Registers all event handlers.
]]
function SetupPlayer.register(config)
Event.add(defines.events.on_player_created, function (event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
local position = {0, 0}
local surface = player.surface

View File

@ -1,4 +1,5 @@
local Global = require 'utils.global'
local random = math.random
local Game = {}
@ -39,4 +40,43 @@ function Game.get_player_by_index(index)
end
end
--[[
@param Position String to display at
@param text String to display
@param color table in {r = 0~1, g = 0~1, b = 0~1}, defaults to white.
@param surface LuaSurface
@return the created entity
]]
function Game.print_floating_text(surface, position, text, color)
color = color or {r = 1, g = 1, b = 1}
return surface.create_entity {
name = 'tutorial-flying-text',
color = color,
text = text,
position = position,
}
end
--[[
Creates a floating text entity at the player location with the specified color in {r, g, b} format.
Example: "+10 iron" or "-10 coins"
@param text String to display
@param color table in {r = 0~1, g = 0~1, b = 0~1}, defaults to white.
@return the created entity
]]
function Game.print_player_floating_text(player_index, text, color)
local player = Game.get_player_by_index(player_index)
if not player or not player.valid then
return
end
local position = player.position
return Game.print_floating_text(player.surface, {x = position.x, y = position.y - 1.5}, text, color)
end
return Game