1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-02-01 13:08:05 +02:00

Merge pull request #948 from linaori/retailer-translations

Added retailer translations
This commit is contained in:
Lynn 2019-06-10 19:12:04 +02:00 committed by GitHub
commit 76977dd9f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 36 deletions

View File

@ -29,12 +29,12 @@
Items support the following structure: Items support the following structure:
{ {
name: the (raw) item inserted in inventory, does nothing when type is not item name: the (raw) item inserted in inventory, does nothing when type is not item
name_label: the name shown in the GUI. If omitted and a prototype exists for 'name', it will use that LocalisedString name_label: the name shown in the GUI. If omitted and a prototype exists for 'name', it will use that LocalisedString, can be a LocalisedString
sprite: a custom sprite, will use 'item/<name>' if omitted sprite: a custom sprite, will use 'item/<name>' if omitted
price: the price of an item, supports floats (0.95 for example) price: the price of an item, supports floats (0.95 for example)
description: an additional description displayed in the tooltip description: an additional description displayed in the tooltip, can be a LocalisedString
disabled: whether or not the item should be disabled by default disabled: whether or not the item should be disabled by default
disabled_reason: the reason the item is disabled disabled_reason: the reason the item is disabled, can be a LocalisedString
} }
]] ]]
@ -47,14 +47,18 @@ local Schedule = require 'utils.task'
local math = require 'utils.math' local math = require 'utils.math'
local Color = require 'resources.color_presets' local Color = require 'resources.color_presets'
local ScoreTracker = require 'utils.score_tracker' local ScoreTracker = require 'utils.score_tracker'
local LocaleBuilder = require 'utils.locale_builder'
local format_number = require 'util'.format_number
local format = string.format local format = string.format
local size = table.size local size = table.size
local insert = table.insert
local pairs = pairs local pairs = pairs
local tonumber = tonumber local tonumber = tonumber
local type = type
local change_for_global = ScoreTracker.change_for_global local change_for_global = ScoreTracker.change_for_global
local change_for_player = ScoreTracker.change_for_player local change_for_player = ScoreTracker.change_for_player
local coins_spent_name = 'coins-spent' local coins_spent_name = 'coins-spent'
local currency_name = 'coin'
local currency_item_name = {'item-name.coin'}
local set_timeout_in_ticks = Schedule.set_timeout_in_ticks local set_timeout_in_ticks = Schedule.set_timeout_in_ticks
local clamp = math.clamp local clamp = math.clamp
local floor = math.floor local floor = math.floor
@ -65,6 +69,9 @@ local market_frame_close_button_name = Gui.uid_name()
local item_button_name = Gui.uid_name() local item_button_name = Gui.uid_name()
local count_slider_name = Gui.uid_name() local count_slider_name = Gui.uid_name()
local count_text_name = Gui.uid_name() local count_text_name = Gui.uid_name()
local price_format = '%.2f'
local translate_single_newline = {'', '\n'}
local translate_double_newline = {'', '\n\n'}
local Retailer = {} local Retailer = {}
@ -234,10 +241,10 @@ local function redraw_market_items(data)
local count = data.count local count = data.count
local market_items = data.market_items local market_items = data.market_items
local player_index = data.player_index local player_index = data.player_index
local player_coins = game.get_player(player_index).get_item_count('coin') local player_coins = game.get_player(player_index).get_item_count(currency_name)
if size(market_items) == 0 then if size(market_items) == 0 then
grid.add({type = 'label', caption = 'No items available at this time'}) grid.add({type = 'label', caption = {'retailer.no_items_in_market'}})
return return
end end
@ -268,43 +275,53 @@ local function redraw_market_items(data)
local player_bought_max_total = has_player_limit and stack_count == 0 local player_bought_max_total = has_player_limit and stack_count == 0
local price = item.price local price = item.price
local tooltip = {'', item.name_label} local tooltip = LocaleBuilder({'', item.name_label})
local description = item.description local description = item.description
local total_price = ceil(price * stack_count) local total_price = ceil(price * stack_count)
local disabled = item.disabled == true local disabled = item.disabled == true
local message local message
if total_price == 0 and player_limit == 0 then if total_price == 0 and player_limit == 0 then
message = 'SOLD!' message = {'retailer.item_sold_out'}
elseif total_price == 0 then elseif total_price == 0 then
message = 'FREE!' message = {'retailer.item_is_free'}
elseif total_price == 1 then
message = '1 coin'
else else
message = total_price .. ' coins' message = {'', '[img=item.', currency_name, '] ', format_number(total_price, true)}
end end
local missing_coins = total_price - player_coins local missing_coins = total_price - player_coins
local is_missing_coins = missing_coins > 0 local is_missing_coins = missing_coins > 0
if price ~= 0 then if price ~= 0 then
insert(tooltip, format('\nprice: %.2f', price)) tooltip = tooltip
:add(translate_single_newline)
:add({'', currency_item_name, ': ', format(price_format, price)})
end end
if description then if description then
insert(tooltip, '\n') tooltip = tooltip:add(translate_single_newline)
insert(tooltip, item.description) if type(description) == 'table' then
tooltip = tooltip:add(description)
else
tooltip = tooltip:add({'', description})
end
end end
if disabled then if disabled then
insert(tooltip, '\n\n') tooltip = tooltip
insert(tooltip, (item.disabled_reason or {'Not available locale string'})) :add(translate_double_newline)
:add(item.disabled_reason or {'retailer.generic_item_disabled_message'})
elseif is_missing_coins then elseif is_missing_coins then
insert(tooltip, '\n\n' .. format('Missing %s coins to buy %s', missing_coins, stack_count)) tooltip = tooltip
:add(translate_double_newline)
:add({'retailer.not_enough_currency', missing_coins, currency_item_name, stack_count})
end end
if has_player_limit then if has_player_limit then
insert(tooltip, '\n\n' .. format('You have bought this item %s out of %s times', item.player_limit - player_limit, item.player_limit)) local item_player_limit = item.player_limit
tooltip = tooltip
:add(translate_double_newline)
:add({'retailer.item_with_player_limit_description', item_player_limit - player_limit, item_player_limit})
end end
local button = grid.add({type = 'flow'}).add({ local button = grid.add({type = 'flow'}).add({
@ -336,11 +353,7 @@ local function redraw_market_items(data)
end end
local function do_coin_label(coin_count, label) local function do_coin_label(coin_count, label)
if coin_count == 1 then label.caption = {'', coin_count, ' ', currency_item_name, ' ', {'common.available'}}
label.caption = '1 coin available'
else
label.caption = coin_count .. ' coins available'
end
label.style.font = 'default-bold' label.style.font = 'default-bold'
end end
@ -359,7 +372,7 @@ local function draw_market_frame(player, group_name)
local grid = scroll_pane.add({type = 'table', column_count = 10}) local grid = scroll_pane.add({type = 'table', column_count = 10})
local market_items = Retailer.get_items(group_name) local market_items = Retailer.get_items(group_name)
local player_coins = player.get_item_count('coin') local player_coins = player.get_item_count(currency_name)
local data = { local data = {
grid = grid, grid = grid,
count = 1, count = 1,
@ -376,7 +389,7 @@ local function draw_market_frame(player, group_name)
local bottom_grid = frame.add({type = 'table', column_count = 2}) local bottom_grid = frame.add({type = 'table', column_count = 2})
bottom_grid.add({type = 'label', caption = 'Quantity: '}).style.font = 'default-bold' bottom_grid.add({type = 'label', caption = {'', {'common.quantity'}, ': '}}).style.font = 'default-bold'
local count_text = bottom_grid.add({ local count_text = bottom_grid.add({
type = 'text-box', type = 'text-box',
@ -528,12 +541,12 @@ Gui.on_click(item_button_name, function (event)
local item = data.market_items[button_data.index] local item = data.market_items[button_data.index]
if not item then if not item then
player.print('This item is no longer available in the market') player.print({'retailer.item_no_longer_available'})
return return
end end
if item.disabled then if item.disabled then
player.print({'', item.name_label, ' is disabled. ', item.disabled_reason or ''}) player.print({'retailer.item_disabled_reason', item.name_label, {item.disabled_reason or ''}})
return return
end end
@ -541,10 +554,10 @@ Gui.on_click(item_button_name, function (event)
local price = item.price local price = item.price
local cost = ceil(price * stack_count) local cost = ceil(price * stack_count)
local coin_count = player.get_item_count('coin') local coin_count = player.get_item_count(currency_name)
if cost > coin_count then if cost > coin_count then
player.print('Insufficient coins') player.print({'retailer.not_enough_currency', cost - coin_count, currency_item_name, cost})
return return
end end
@ -557,7 +570,7 @@ Gui.on_click(item_button_name, function (event)
if item.type == 'item' then if item.type == 'item' then
local inserted = player.insert({name = name, count = stack_count}) local inserted = player.insert({name = name, count = stack_count})
if inserted < stack_count then if inserted < stack_count then
player.print('Insufficient inventory space') player.print({'retailer.no_inventory_space'})
if inserted > 0 then if inserted > 0 then
player.remove_item({name = name, count = inserted}) player.remove_item({name = name, count = inserted})
end end
@ -566,7 +579,7 @@ Gui.on_click(item_button_name, function (event)
end end
if cost > 0 then if cost > 0 then
player.remove_item({name = 'coin', count = cost}) player.remove_item({name = currency_name, count = cost})
end end
redraw_market_items(data) redraw_market_items(data)

View File

@ -18,6 +18,8 @@ afk_time=AFK time
current_force=Current force current_force=Current force
current_surface=Current surface current_surface=Current surface
player_tag=Player tag player_tag=Player tag
quantity=Quantity
available=Available
[ranks] [ranks]
probation=Probation probation=Probation

View File

@ -109,6 +109,15 @@ teach_chat=To chat with other players, press the __CONTROL__toggle-console__ key
[retailer] [retailer]
market_name=Market market_name=Market
no_items_in_market=No items available at this time
item_sold_out=SOLD OUT!
item_is_free=FREE!
generic_item_disabled_message=Item is disabled
not_enough_currency=Missing __1__ __2__ to buy __3__
item_with_player_limit_description=You have bought this item __1__ out of __plural_for_parameter_2_{1=1 time|rest=__2__ times}__
item_no_longer_available=This item is no longer available in the market
item_disabled_reason=__1__ is disabled. __2__
no_inventory_space=Insufficient inventory space
[biter_attacks] [biter_attacks]
first_rocket_launch_attack=The ground rumbles as the first rocket is launched.. But there's more.. The rocket is out of sight but the ground continues to tremble. An attack is coming, bigger than any previous. first_rocket_launch_attack=The ground rumbles as the first rocket is launched.. But there's more.. The rocket is out of sight but the ground continues to tremble. An attack is coming, bigger than any previous.

View File

@ -0,0 +1,5 @@
[market_items]
running_speed_bonus_name_label=Temporary running speed bonus
running_speed_bonus_description=Increases running speed by one level for a short period
mining_speed_bonus_name_label=Temporary mining speed bonus
mining_speed_bonus_description=Increases manual mining speed by one level for a short period

View File

@ -1,18 +1,18 @@
return { return {
{ {
name = 'temporary-running-speed-bonus', name = 'temporary-running-speed-bonus',
name_label = 'Temporary running speed bonus', name_label = {'market_items.running_speed_bonus_name_label'},
type = 'temporary-buff', type = 'temporary-buff',
description = 'Increases running speed by one level for a short period', description = {'market_items.running_speed_bonus_description'},
sprite = 'technology/exoskeleton-equipment', sprite = 'technology/exoskeleton-equipment',
stack_limit = 1, stack_limit = 1,
price = 10, price = 10,
}, },
{ {
name = 'temporary-mining-speed-bonus', name = 'temporary-mining-speed-bonus',
name_label = 'Temporary mining speed bonus', name_label = {'market_items.mining_speed_bonus_name_label'},
type = 'temporary-buff', type = 'temporary-buff',
description = 'Increases manual mining speed by one level for a short period', description = {'market_items.mining_speed_bonus_description'},
sprite = 'technology/mining-productivity-1', sprite = 'technology/mining-productivity-1',
stack_limit = 1, stack_limit = 1,
price = 10, price = 10,