diff --git a/features/retailer.lua b/features/retailer.lua index 5f817faa..7d7d37de 100644 --- a/features/retailer.lua +++ b/features/retailer.lua @@ -29,12 +29,12 @@ Items support the following structure: { 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/' if omitted 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_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 Color = require 'resources.color_presets' local ScoreTracker = require 'utils.score_tracker' +local LocaleBuilder = require 'utils.locale_builder' +local format_number = require 'util'.format_number local format = string.format local size = table.size -local insert = table.insert local pairs = pairs local tonumber = tonumber +local type = type local change_for_global = ScoreTracker.change_for_global local change_for_player = ScoreTracker.change_for_player 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 clamp = math.clamp 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 count_slider_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 = {} @@ -234,10 +241,10 @@ local function redraw_market_items(data) local count = data.count local market_items = data.market_items 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 - grid.add({type = 'label', caption = 'No items available at this time'}) + grid.add({type = 'label', caption = {'retailer.no_items_in_market'}}) return end @@ -268,43 +275,53 @@ local function redraw_market_items(data) local player_bought_max_total = has_player_limit and stack_count == 0 local price = item.price - local tooltip = {'', item.name_label} + local tooltip = LocaleBuilder({'', item.name_label}) local description = item.description local total_price = ceil(price * stack_count) local disabled = item.disabled == true local message if total_price == 0 and player_limit == 0 then - message = 'SOLD!' + message = {'retailer.item_sold_out'} elseif total_price == 0 then - message = 'FREE!' - elseif total_price == 1 then - message = '1 coin' + message = {'retailer.item_is_free'} else - message = total_price .. ' coins' + message = {'', '[img=item.', currency_name, '] ', format_number(total_price, true)} end local missing_coins = total_price - player_coins local is_missing_coins = missing_coins > 0 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 if description then - insert(tooltip, '\n') - insert(tooltip, item.description) + tooltip = tooltip:add(translate_single_newline) + if type(description) == 'table' then + tooltip = tooltip:add(description) + else + tooltip = tooltip:add({'', description}) + end end if disabled then - insert(tooltip, '\n\n') - insert(tooltip, (item.disabled_reason or {'Not available locale string'})) + tooltip = tooltip + :add(translate_double_newline) + :add(item.disabled_reason or {'retailer.generic_item_disabled_message'}) 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 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 local button = grid.add({type = 'flow'}).add({ @@ -336,11 +353,7 @@ local function redraw_market_items(data) end local function do_coin_label(coin_count, label) - if coin_count == 1 then - label.caption = '1 coin available' - else - label.caption = coin_count .. ' coins available' - end + label.caption = {'', coin_count, ' ', currency_item_name, ' ', {'common.available'}} label.style.font = 'default-bold' end @@ -359,7 +372,7 @@ local function draw_market_frame(player, group_name) local grid = scroll_pane.add({type = 'table', column_count = 10}) 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 = { grid = grid, count = 1, @@ -376,7 +389,7 @@ local function draw_market_frame(player, group_name) 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({ type = 'text-box', @@ -528,12 +541,12 @@ Gui.on_click(item_button_name, function (event) local item = data.market_items[button_data.index] if not item then - player.print('This item is no longer available in the market') + player.print({'retailer.item_no_longer_available'}) return end 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 end @@ -541,10 +554,10 @@ Gui.on_click(item_button_name, function (event) local price = item.price 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 - player.print('Insufficient coins') + player.print({'retailer.not_enough_currency', cost - coin_count, currency_item_name, cost}) return end @@ -557,7 +570,7 @@ Gui.on_click(item_button_name, function (event) if item.type == 'item' then local inserted = player.insert({name = name, count = stack_count}) if inserted < stack_count then - player.print('Insufficient inventory space') + player.print({'retailer.no_inventory_space'}) if inserted > 0 then player.remove_item({name = name, count = inserted}) end @@ -566,7 +579,7 @@ Gui.on_click(item_button_name, function (event) end if cost > 0 then - player.remove_item({name = 'coin', count = cost}) + player.remove_item({name = currency_name, count = cost}) end redraw_market_items(data) diff --git a/locale/en/redmew_common.cfg b/locale/en/redmew_common.cfg index b9bf1c20..ee04ac95 100644 --- a/locale/en/redmew_common.cfg +++ b/locale/en/redmew_common.cfg @@ -18,6 +18,8 @@ afk_time=AFK time current_force=Current force current_surface=Current surface player_tag=Player tag +quantity=Quantity +available=Available [ranks] probation=Probation diff --git a/locale/en/redmew_features.cfg b/locale/en/redmew_features.cfg index 77fa1912..f674dcd4 100644 --- a/locale/en/redmew_features.cfg +++ b/locale/en/redmew_features.cfg @@ -109,6 +109,15 @@ teach_chat=To chat with other players, press the __CONTROL__toggle-console__ key [retailer] 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] 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. diff --git a/locale/en/redmew_resources.cfg b/locale/en/redmew_resources.cfg new file mode 100644 index 00000000..1b13e5de --- /dev/null +++ b/locale/en/redmew_resources.cfg @@ -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 diff --git a/resources/market_items.lua b/resources/market_items.lua index 1bc276d0..7507ca04 100644 --- a/resources/market_items.lua +++ b/resources/market_items.lua @@ -1,18 +1,18 @@ return { { name = 'temporary-running-speed-bonus', - name_label = 'Temporary running speed bonus', + name_label = {'market_items.running_speed_bonus_name_label'}, 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', stack_limit = 1, price = 10, }, { name = 'temporary-mining-speed-bonus', - name_label = 'Temporary mining speed bonus', + name_label = {'market_items.mining_speed_bonus_name_label'}, 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', stack_limit = 1, price = 10,