1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Added functional GUI for stone sent

This commit is contained in:
Lynn 2018-10-11 22:17:25 +02:00
parent 440327b882
commit 029a2b38fd
4 changed files with 118 additions and 70 deletions

View File

@ -171,26 +171,24 @@ local Config = {
stone_to_surface_amount = 50,
currency_item = 'stone',
-- price in currency_item
-- item_name to give
unlockables = {
{stone = 50, type = 'buff', prototype = {name = 'mining_speed', value = 10}},
{stone = 50, type = 'buff', prototype = {name = 'inventory_slot', value = 3}},
{stone = 50, type = 'market', prototype = {price = 50, item_name = 'raw-fish'}},
{stone = 50, type = 'market', prototype = {price = 175, item_name = 'steel-axe'}},
{stone = 50, type = 'market', prototype = {price = 50, name = 'raw-fish'}},
{stone = 50, type = 'market', prototype = {price = 175, name = 'steel-axe'}},
{stone = 250, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 250, type = 'buff', prototype = {name = 'inventory_slot', value = 2}},
{stone = 250, type = 'market', prototype = {price = 50, item_name = 'small-electric-pole'}},
{stone = 250, type = 'market', prototype = {price = 50, item_name = 'small-lamp'}},
{stone = 250, type = 'market', prototype = {price = 25, item_name = 'stone-brick'}},
{stone = 250, type = 'market', prototype = {price = 125, item_name = 'stone-wall'}},
{stone = 250, type = 'market', prototype = {price = 50, name = 'small-electric-pole'}},
{stone = 250, type = 'market', prototype = {price = 50, name = 'small-lamp'}},
{stone = 250, type = 'market', prototype = {price = 25, name = 'stone-brick'}},
{stone = 250, type = 'market', prototype = {price = 125, name = 'stone-wall'}},
{stone = 450, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 450, type = 'buff', prototype = {name = 'inventory_slot', value = 2}},
{stone = 450, type = 'market', prototype = {price = 1000, item_name = 'submachine-gun'}},
{stone = 450, type = 'market', prototype = {price = 100, item_name = 'firearm-magazine'}},
{stone = 450, type = 'market', prototype = {price = 500, item_name = 'light-armor'}},
{stone = 450, type = 'market', prototype = {price = 1000, name = 'submachine-gun'}},
{stone = 450, type = 'market', prototype = {price = 100, name = 'firearm-magazine'}},
{stone = 450, type = 'market', prototype = {price = 500, name = 'light-armor'}},
{stone = 750, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 750, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
@ -209,8 +207,8 @@ local Config = {
{stone = 10000, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 10000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 10000, type = 'market', prototype = {price = 175, item_name = 'piercing-rounds-magazine'}},
{stone = 10000, type = 'market', prototype = {price = 750, item_name = 'heavy-armor'}},
{stone = 10000, type = 'market', prototype = {price = 175, name = 'piercing-rounds-magazine'}},
{stone = 10000, type = 'market', prototype = {price = 750, name = 'heavy-armor'}},
{stone = 15000, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 15000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
@ -219,7 +217,7 @@ local Config = {
{stone = 35000, type = 'buff', prototype = {name = 'mining_speed', value = 5}},
{stone = 35000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
{stone = 35000, type = 'market', prototype = {price = 1500, item_name = 'modular-armor'}},
{stone = 35000, type = 'market', prototype = {price = 1500, name = 'modular-armor'}},
{stone = 50000, type = 'buff', prototype = {name = 'inventory_slot', value = 1}},
},

View File

@ -46,15 +46,6 @@ local on_market_timeout_finished = Token.register(function(params)
Template.market(params.surface, params.position, params.player_force, params.currency_item, {})
end)
local function on_init()
Task.set_timeout_in_ticks(50, on_market_timeout_finished, {
surface = game.surfaces.nauvis,
position = config.market_spawn_position,
player_force = game.forces.player,
currency_item = config.currency_item,
})
end
local function update_mining_speed(force)
-- remove the current buff
local old_modifier = force.manual_mining_speed_modifier - mining_efficiency.active_modifier
@ -93,7 +84,7 @@ local function update_market_contents(market)
if (is_in_range and unlockable.type == 'market') then
market.add_market_item({
price = {{config.currency_item, unlockable.prototype.price}},
offer = {type = 'give-item', item = unlockable.prototype.item_name, count = 1}
offer = {type = 'give-item', item = unlockable.prototype.name, count = 1}
})
elseif (is_in_range and unlockable.type == 'buff' and unlockable.prototype.name == 'mining_speed') then
should_update_mining_speed = true
@ -153,6 +144,97 @@ local function on_placed_entity(event)
update_market_contents(event.entity)
end
function MarketExchange.get_extra_map_info(config)
return 'Market Exchange, trade your stone or send it to the surface'
end
local function redraw_title(data)
data.frame.caption = stone_tracker.stone_sent_to_surface .. ' stone sent to the surface'
end
local function redraw_list(data)
local market_scroll_pane = data.market_scroll_pane
Gui.clear(market_scroll_pane)
for _, unlockable in pairs(config.unlockables) do
local is_unlocked = unlockable.stone <= stone_tracker.stone_sent_to_surface
local message
-- only add the item to the market if it's between the old and new stone range
if (unlockable.type == 'market') then
message = 'Market item: ' .. unlockable.prototype.name
elseif (unlockable.type == 'buff' and unlockable.prototype.name == 'mining_speed') then
message = 'Manual mining speed: +' .. unlockable.prototype.value .. '%'
elseif (unlockable.type == 'buff' and unlockable.prototype.name == 'inventory_slot') then
message = 'Inventory slot: +' .. unlockable.prototype.value
else
Debug.print('failed getting a message for: ' .. serpent.line(unlockable))
end
message = unlockable.stone .. ' stone: ' .. message
local label = market_scroll_pane.add({type = 'label', caption = message})
if (is_unlocked) then
label.style.font_color = {r = 1, g = 1, b = 1}
else
label.style.font_color = {r = 0.5, g = 0.5, b = 0.5}
end
end
end
local function toggle(event)
local player = event.player
local center = player.gui.center
local frame = center['Diggy.MarketExchange.Frame']
if (frame) then
Gui.destroy(frame)
return
end
frame = center.add({name = 'Diggy.MarketExchange.Frame', type = 'frame', direction = 'vertical'})
local market_scroll_pane = frame.add({type = 'scroll-pane'})
market_scroll_pane.style.maximal_height = 400
frame.add({ type = 'button', name = 'Diggy.MarketExchange.Button', caption = 'Close'})
local data = {
frame = frame,
market_scroll_pane = market_scroll_pane,
}
redraw_title(data)
redraw_list(data)
Gui.set_data(frame, data)
player.opened = frame
end
local function on_player_created(event)
game.players[event.player_index].gui.top.add({
name = 'Diggy.MarketExchange.Button',
type = 'sprite-button',
sprite = 'item/stone',
})
end
Gui.on_click('Diggy.MarketExchange.Button', toggle)
Gui.on_custom_close('Diggy.MarketExchange.Frame', function (event)
event.element.destroy()
end)
function MarketExchange.on_init()
Task.set_timeout_in_ticks(50, on_market_timeout_finished, {
surface = game.surfaces.nauvis,
position = config.market_spawn_position,
player_force = game.forces.player,
currency_item = config.currency_item,
})
update_mining_speed(game.forces.player)
end
--[[--
Registers all event handlers.
]]
@ -167,44 +249,7 @@ function MarketExchange.register(cfg)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(Template.events.on_placed_entity, on_placed_entity)
end
function MarketExchange.get_extra_map_info(config)
return 'Market Exchange, trade your stone or send it to the surface'
end
function MarketExchange.on_init()
if ('function' ~= type(on_init)) then
error('Expected local on_init in MarketExchange to have a function assigned.')
end
on_init()
update_mining_speed(game.forces.player)
end
local function toggle(event)
local player = event.player
local center = player.gui.center
local main_frame = center['Diggy.MarketExchange.Frame']
if (main_frame) then
Gui.destroy(main_frame)
return
end
main_frame = center.add({name = 'Diggy.MarketExchange.Frame', type = 'frame', direction = 'vertical'})
end
--[[--
@param config LuaGuiElement
]]
function MarketExchange.top_menu_button_prototype(config)
return {
name = 'Diggy.MarketExchange.Button',
type = 'sprite-button',
sprite = 'item/stone',
toggle = toggle,
}
Event.add(defines.events.on_player_created, on_player_created)
end
return MarketExchange

View File

@ -87,20 +87,24 @@ function SimpleRoomGenerator.register(config)
return
end
local noise = get_noise(event.surface, position.x, position.y)
local surface = event.surface
local noise = get_noise(surface, position.x, position.y)
for _, noise_range in pairs(config.room_noise_ranges) do
if (noise >= noise_range.min and noise <= noise_range.max) then
handle_noise(noise_range.name, event.surface, position)
handle_noise(noise_range.name, surface, position)
end
end
end)
if (config.enable_noise_grid) then
Event.add(defines.events.on_chunk_generated, function (event)
for x = event.area.left_top.x, event.area.left_top.x + 31 do
for y = event.area.left_top.y, event.area.left_top.y + 31 do
Debug.print_grid_value(get_noise(event.surface, x, y), event.surface, {x = x, y = y})
local surface = event.surface
local area = event.area
for x = area.left_top.x, area.left_top.x + 31 do
for y = area.left_top.y, area.left_top.y + 31 do
Debug.print_grid_value(get_noise(surface, x, y), surface, {x = x, y = y})
end
end
end)

View File

@ -24,14 +24,15 @@ function StartingZone.register(config)
local function on_chunk_generated(event)
local start_point_area = {{-1, -1}, {0, 0}}
local surface = event.surface
-- hack to figure out whether the important chunks are generated via Diggy.Feature.RefreshMap.
if (4 ~= event.surface.count_tiles_filtered({start_point_area, name = 'lab-dark-1'})) then
if (4 ~= surface.count_tiles_filtered({start_point_area, name = 'lab-dark-1'})) then
return
end
-- ensure a clean starting point
for _, entity in pairs(event.surface.find_entities_filtered({area = start_point_area, type = 'resource'})) do
for _, entity in pairs(surface.find_entities_filtered({area = start_point_area, type = 'resource'})) do
entity.destroy()
end
@ -55,7 +56,7 @@ function StartingZone.register(config)
-- hack to avoid starting area from collapsing
if (distance > floor(starting_zone_size / 10)) then
DiggyCaveCollapse.stress_map_blur_add(event.surface, {x = x, y = y}, -0.3)
DiggyCaveCollapse.stress_map_blur_add(surface, {x = x, y = y}, -0.3)
end
end
end