mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
render text when hover over market
This commit is contained in:
parent
c9cc32a1c0
commit
41f2fc8c50
@ -586,6 +586,12 @@ function Retailer.add_market(group_name, market_entity)
|
||||
set_market_group_name(market_entity.position, group_name)
|
||||
end
|
||||
|
||||
---Returns the group name of the market, nil if not registered.
|
||||
---@param market_entity LuaEntity
|
||||
function Retailer.get_market_group_name(market_entity)
|
||||
return get_market_group_name(market_entity.position)
|
||||
end
|
||||
|
||||
---Sets an item for all the group_name markets.
|
||||
---@param group_name string
|
||||
---@param prototype table with item name and price
|
||||
|
@ -17,6 +17,7 @@ local concat = table.concat
|
||||
local floor = math.floor
|
||||
local format = string.format
|
||||
local tostring = tostring
|
||||
local draw_text = rendering.draw_text
|
||||
|
||||
local b = require 'map_gen.shared.builders'
|
||||
|
||||
@ -1750,6 +1751,51 @@ local function coin_mined(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function market_selected(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local selected = player.selected
|
||||
|
||||
if not selected or not selected.valid or selected.name ~= 'market' then
|
||||
return
|
||||
end
|
||||
|
||||
local group = Retailer.get_market_group_name(selected)
|
||||
local prototype = Retailer.get_items(group)['upgrade']
|
||||
|
||||
if prototype.disabled then
|
||||
return
|
||||
end
|
||||
|
||||
local args = {
|
||||
text = nil,
|
||||
target = selected,
|
||||
target_offset = nil,
|
||||
alignment = 'center',
|
||||
surface = selected.surface,
|
||||
color = {1, 1, 1},
|
||||
players = {player},
|
||||
scale = 1.5,
|
||||
scale_with_zoom = true,
|
||||
time_to_live = 180
|
||||
}
|
||||
|
||||
args.text = prototype.name_label
|
||||
args.target_offset = {0, -5}
|
||||
draw_text(args)
|
||||
|
||||
args.text = 'Price: ' .. prototype.price
|
||||
args.target_offset = {0, -4}
|
||||
draw_text(args)
|
||||
|
||||
args.text = prototype.description
|
||||
args.target_offset = {0, -3}
|
||||
draw_text(args)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_tick, tick)
|
||||
Event.add(defines.events.on_entity_died, turret_died)
|
||||
|
||||
@ -1763,4 +1809,6 @@ Event.add(defines.events.on_player_mined_item, coin_mined)
|
||||
|
||||
Event.add(Retailer.events.on_market_purchase, do_outpost_upgrade)
|
||||
|
||||
Event.add(defines.events.on_selected_entity_changed, market_selected)
|
||||
|
||||
return Public
|
||||
|
Loading…
Reference in New Issue
Block a user