Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 46 additions & 20 deletions features/retailer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ local function redraw_market_items(data)
number = stack_count,
tooltip = tooltip,
})
button.style = 'slot_button'
button.style = 'slot_button_in_shallow_frame'

Gui.set_data(button, {index = i, data = data, stack_count = stack_count})

Expand All @@ -353,21 +353,40 @@ local function redraw_market_items(data)
end

local function do_coin_label(coin_count, label)
label.caption = {'', coin_count, ' ', currency_item_name, ' ', {'common.available'}}
label.style.font = 'default-bold'
label.caption = { '', coin_count, ' ', currency_item_name, ' ', { 'common.available' } }
end

local function draw_market_frame(player, group_name)
local frame = player.gui.center.add({
type = 'frame',
name = market_frame_name,
caption = Retailer.get_market_group_label(group_name),
direction = 'vertical',
style = 'non_draggable_frame'
})

local scroll_pane = frame.add({type = 'scroll-pane'})
local scroll_style = scroll_pane.style
scroll_style.maximal_height = 600
do -- Header
local header = frame.add { type = 'flow', direction = 'horizontal' }
Gui.set_style(header, { horizontal_spacing = 8, vertical_align = 'center', bottom_padding = 4 })

header.add { type = 'label', caption = Retailer.get_market_group_label(group_name), style = 'frame_title' }
Gui.add_pusher(header)

local button = header.add {
type = 'sprite-button',
name = market_frame_close_button_name,
sprite = 'utility/close',
clicked_sprite = 'utility/close_black',
style = 'close_button',
tooltip = {'gui.close-instruction'}
}
Gui.set_data(button, frame)
end

local inner = frame.add { type = 'frame', style = 'entity_frame', direction = 'vertical' }
Gui.set_style(inner, { padding = 0 })

local scroll_pane = inner.add{ type = 'scroll-pane' }
Gui.set_style(scroll_pane, { maximal_height = 600, padding = 8, top_padding = 12 })

local grid = scroll_pane.add({type = 'table', column_count = 10})

Expand All @@ -381,34 +400,41 @@ local function draw_market_frame(player, group_name)
player_index = player.index,
}

local coin_label = frame.add({type = 'label'})
local footer = inner.add { type = 'frame', style = 'subheader_frame' }.add { type = 'flow', direction = 'horizontal' }
Gui.set_style(footer, { vertical_align = 'center', padding = 4, horizontal_spacing = 8 })

local coin_label = footer.add { type = 'label', style = 'bold_label' }
do_coin_label(player_coins, coin_label)
data.coin_label = coin_label
Gui.add_pusher(footer)

redraw_market_items(data)

local bottom_grid = frame.add({type = 'table', column_count = 2})
footer.add{ type = 'label', caption = { '', {'common.quantity'}, ': ' }, style = 'caption_label' }

bottom_grid.add({type = 'label', caption = {'', {'common.quantity'}, ': '}}).style.font = 'default-bold'

local count_text = bottom_grid.add({
type = 'text-box',
local count_text = footer.add {
type = 'textfield',
name = count_text_name,
text = '1',
})
numeric = true,
allow_decimal = false,
allow_negative = false,
}
Gui.set_style(count_text, { width = 45 })

local count_slider = frame.add({
local count_slider = footer.add {
type = 'slider',
name = count_slider_name,
minimum_value = 1,
maximum_value = 7,
value = 1,
})

frame.add({name = market_frame_close_button_name, type = 'button', caption = 'Close'})
style = 'notched_slider',
}
Gui.set_style(count_slider, { width = 115 })

count_slider.style.width = 115
count_text.style.width = 45
Gui.add_pusher(footer)
local padding = footer.add { type = 'empty-widget' }
Gui.set_style(padding, { width = 100 })

data.slider = count_slider
data.text = count_text
Expand Down
28 changes: 21 additions & 7 deletions map_gen/maps/crash_site/outpost_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,13 @@ local function to_shape(blocks, part_size, on_init)
top_left = {nil, nil},
bottom_right = {nil, nil},
level = 1,
maximum_level = nil,
upgrade_rate = nil,
upgrade_base_cost = nil,
upgrade_cost_base = nil,
artillery_area = nil,
artillery_turrets = nil,
last_fire_tick = nil
last_fire_tick = nil,
}
end

Expand Down Expand Up @@ -988,9 +989,13 @@ local function update_market_upgrade_description(outpost_data)

prototype.description = tooltip_str
prototype.disabled = false

prototype.mapview_description = mapview_str

if outpost_data.maximum_level and (outpost_data.level >= outpost_data.maximum_level) then
prototype.disabled = true
prototype.disabled_reason = 'Max level reached.'
end

Retailer.set_item(outpost_id, prototype)
end

Expand Down Expand Up @@ -1736,6 +1741,13 @@ Public.market_set_items_callback =
outpost_data.upgrade_rate = callback_data.upgrade_rate
outpost_data.upgrade_base_cost = upgrade_base_cost
outpost_data.upgrade_cost_base = callback_data.upgrade_cost_base
if callback_data.maximum_level_count then
outpost_data.maximum_level = callback_data.maximum_level
end
if callback_data.maximum_level_formula then
local formula = Token.get(callback_data.maximum_level_formula)
outpost_data.maximum_level = formula(callback_data)
end

Retailer.add_market(market_id, entity)
Retailer.set_market_group_label(market_id, callback_data.market_name)
Expand Down Expand Up @@ -1946,8 +1958,10 @@ local function market_selected(event)

local args = {
text = nil,
target = selected,
target_offset = nil,
target = {
entity = selected,
offset = nil,
},
alignment = 'center',
surface = selected.surface,
color = {1, 1, 1},
Expand All @@ -1958,15 +1972,15 @@ local function market_selected(event)
}

args.text = prototype.name_label
args.target_offset = {0, -6.5}
args.target.offset = {0, -6.5}
draw_text(args)

args.text = 'Price: ' .. prototype.price
args.target_offset = {0, -5}
args.target.offset = {0, -5}
draw_text(args)

args.text = prototype.mapview_description
args.target_offset = {0, -3.5}
args.target.offset = {0, -3.5}
draw_text(args)
end

Expand Down
7 changes: 6 additions & 1 deletion map_gen/maps/crash_site/scenario.lua
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,19 @@ local function init(config)

map = b.apply_entity(map, ore_grid)

local spawn_maximum_level_formula = Token.register(function()
return game.is_multiplayer() and 6 or nil
end)

local market = {
callback = spawn_callback,
data = {
market_name = 'Spawn',
upgrade_rate = 0.5,
upgrade_base_cost = 500,
upgrade_cost_base = 2,
maximum_level_count = nil,
maximum_level_formula = spawn_maximum_level_formula,
Comment thread
grilledham marked this conversation as resolved.
{
price = 0,
stack_limit = 1,
Expand Down Expand Up @@ -862,7 +868,6 @@ local function init(config)
name_label = {'command_description.crash_site_barrage_radius_name_label', 1},
sprite = 'virtual-signal/signal-B',
description = {'command_description.crash_site_barrage_radius', 1, 0, 25}

},
{
price = 1000,
Expand Down