diff --git a/main3.lua b/main3.lua --- a/main3.lua +++ b/main3.lua @@ -16,7 +16,6 @@ require "lib/dire/theme" require "lib/locale" require "lib/fading" require "lib/smoke" -include "translation" declare({ closed_beta_participants = 'arbtttrn6, De@th K!d, Fehatt, Lesha Pak, Łukasz Sawicki, Niko Flang, Oleg Bosh, Terracon, Андрей Лобанов'; @@ -27,15 +26,15 @@ fmt.filter = function(r) local utf8 = (std.ref 'game'.codepage == 'UTF-8' or std.ref 'game'.codepage == 'utf-8') if utf8 then - r = r:gsub('"([^"]*)"', translate_now(common_locale, 'quotes')); + r = r:gsub('"([^"]*)"', translate_now("common_locale", 'quotes')); end; return r; end; -game.act = translate(main_locale, 'empty_act'); +game.act = translate('main_locale', 'empty_act'); game.use = function(s) - return translate_now(main_locale, random_phrase({ + return translate_now('main_locale', random_phrase({ 'empty_use_1', 'empty_use_2', 'empty_use_3', @@ -43,7 +42,7 @@ game.use = function(s) 'empty_use_5' })); end; -game.inv = translate(main_locale, 'empty_inv'); +game.inv = translate("main_locale", 'empty_inv'); instead.notitle = function() return here().notitle; @@ -170,7 +169,11 @@ function get_sprite(path, transparent) local s = diretheme.get_scale(); if not menu_sprites[path] then - menu_sprites[path] = pixels.new(path):scale(s, s):sprite(); + if s ~= 1 then + menu_sprites[path] = pixels.new(path):scale(s, s):sprite(); + else + menu_sprites[path] = sprite.new(path); + end; if transparent then menu_sprites[path]:colorkey(transparent); end; @@ -179,6 +182,28 @@ function get_sprite(path, transparent) return menu_sprites[path]; end; +function get_button(button_name) + local path = 'images/title/' .. button_name .. '.' .. get_language() .. '.png'; + if menu_sprites[path] then + return menu_sprites[path]; + end; + + local sprite = nil; + + --Check if file exists(only used here, so not moved to function) + local f = io.open(path, 'r'); + if f then + f:close(); + sprite = get_sprite(path, 'fuchsia') + end; + + if not sprite then + local path = 'images/title/' .. button_name .. '.' .. get_default_language() .. '.png'; + sprite = get_sprite(path, 'fuchsia'); + end; + return sprite +end; + function stop_menu() D {'bgframe'}; D {'background'}; @@ -272,7 +297,7 @@ function init_menu(with_text, buttons) D { buttons[1], 'img', - get_sprite('images/title/' .. buttons[1] .. '.' .. get_language() .. '.png', 'fuchsia'), + get_button(buttons[1]), x=ox + 398 * scale, y=oy + (btop + button_dy) * scale, click=true, @@ -283,7 +308,7 @@ function init_menu(with_text, buttons) D { buttons[1], 'img', - get_sprite('images/title/' .. buttons[1] .. '.' .. get_language() .. '.png', 'fuchsia'), + get_button(buttons[1]), x=ox + (157 + button_dx) * scale, y=oy + (btop + button_dy) * scale, click=true, @@ -293,8 +318,8 @@ function init_menu(with_text, buttons) D { buttons[2], 'img', - get_sprite('images/title/' .. buttons[2] .. '.' .. get_language() .. '.png', 'fuchsia'), - x=ox + 398 * scale, + get_button(buttons[2]), + x=ox + 398 * scale, y=oy + (btop + button_dy) * scale, click=true, background=true, @@ -303,7 +328,7 @@ function init_menu(with_text, buttons) D { buttons[3], 'img', - get_sprite('images/title/' .. buttons[3] .. '.' .. get_language() .. '.png', 'fuchsia'), + get_button(buttons[3]), x=ox + (639 - button_dx) * scale, y=oy + (btop + button_dy) * scale, click=true, @@ -317,7 +342,7 @@ function init_menu(with_text, buttons) D { buttons[4], 'img', - get_sprite('images/title/' .. buttons[4] .. '.' .. get_language() .. '.png', 'fuchsia'), + get_button(buttons[4]), x=ox + (278 + button_dx / 2) * scale, y=oy + (btop + button_dy) * scale, click=true, @@ -328,7 +353,7 @@ function init_menu(with_text, buttons) D { buttons[5], 'img', - get_sprite('images/title/' .. buttons[5] .. '.' .. get_language() .. '.png', 'fuchsia'), + get_button(buttons[5]), x=ox + (519 - button_dx / 2) * scale, y=oy + (btop + button_dy) * scale, click=true, @@ -483,7 +508,7 @@ room { end; return false; end; - decor = translate(menu_locale, 'intro'); + decor = translate("menu_locale", 'intro'); } room { @@ -519,14 +544,14 @@ room { return false; end; decor = function(s) - return translate_now(menu_locale, 'credits_author') .. ': Khaelenmore Thaal^' .. - translate_now(menu_locale, 'credits_art') .. ': Sabra Naikomy^' .. - translate_now(menu_locale, 'credits_music') .. ': Khaelenmore Thaal^' .. - translate_now(menu_locale, 'credits_engine') .. ': INSTEAD ' .. translate_now(menu_locale, 'credits_engine_author') .. ' {$link https://github.com/instead-hub/instead/}^' .. - translate_now(menu_locale, 'credits_sounds') .. ': {$link https://freesound.org/} CC-0^' .. - translate_now(menu_locale, 'credits_fonts') .. ': VileR {$link https://int10h.org/oldschool-pc-fonts/} CC-BY-SA 4.0^^' .. - translate_now(menu_locale, 'credits_closed_beta') .. ': ' .. closed_beta_participants .. '^^'.. - translate_now(menu_locale, 'credits_thanks'); + return translate_now("menu_locale", 'credits_author') .. ': Khaelenmore Thaal^' .. + translate_now("menu_locale", 'credits_art') .. ': Sabra Naikomy^' .. + translate_now("menu_locale", 'credits_music') .. ': Khaelenmore Thaal^' .. + translate_now("menu_locale", 'credits_engine') .. ': INSTEAD ' .. translate_now("menu_locale", 'credits_engine_author') .. ' {$link https://github.com/instead-hub/instead/}^' .. + translate_now("menu_locale", 'credits_sounds') .. ': {$link https://freesound.org/} CC-0^' .. + translate_now("menu_locale", 'credits_fonts') .. ': VileR {$link https://int10h.org/oldschool-pc-fonts/} CC-BY-SA 4.0^^' .. + translate_now("menu_locale", 'credits_closed_beta') .. ': ' .. closed_beta_participants .. '^^'.. + translate_now("menu_locale", 'credits_thanks'); end; } @@ -573,7 +598,7 @@ room { obj { nam = '#system_settings'; dsc = function(s) - return fmt.c(fmt.b('{[' .. translate_now(menu_locale, 'system_settings') .. ']}^^')); + return fmt.c(fmt.b('{[' .. translate_now("menu_locale", 'system_settings') .. ']}^^')); end; act = function(s) instead.menu('settings'); @@ -582,30 +607,25 @@ room { obj { nam = '#language'; dsc = function(s) - local l = translate_now(menu_locale, 'auto_option'); + local l = translate_now("menu_locale", 'auto_option'); - pn(fmt.c(fmt.b(translate_now(menu_locale, 'language')))); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'language')))); - local t = ''; + local t; if get_language_saved() == '' then - t = t .. l .. ' | '; + t = l; else - t = t .. '{#l_auto|'.. l .. '} | '; + t = '{#l_auto|'.. l .. '}'; end; - - if get_language_saved() == 'ru' then - t = t .. 'Русский | '; - else - t = t .. '{#l_ru|Русский} | '; - end; - - if get_language_saved() == 'en' then - t = t .. 'English'; - else - t = t .. '{#l_en|English}'; - end; + for i, language in ipairs(get_language_list()) do + if get_language_saved() == language[1] then + t = t .. ' | ' .. language[2]; + else + t = t .. ' | ' .. '{@set_language ' .. language[1] .. '|' .. language[2] .. '}'; + end; + end; pn(fmt.c(t) .. '^') end; @@ -617,27 +637,13 @@ room { walk(here()); end; }; - obj { - nam = '#l_en'; - act = function(s) - set_language('en'); - walk(here()); - end; - }; - obj { - nam = '#l_ru'; - act = function(s) - set_language('ru'); - walk(here()); - end; - }; }; obj { nam = '#graphics_scale'; dsc = function(s) local graphic_scale = get_graphic_scale(); - pn(fmt.c(fmt.b(translate_now(menu_locale, 'graphic_scale')) .. ' {[' .. translate_now(menu_locale, 'auto_option') .. ']}')) + pn(fmt.c(fmt.b(translate_now("menu_locale", 'graphic_scale')) .. ' {[' .. translate_now("menu_locale", 'auto_option') .. ']}')) local t = ''; @@ -647,7 +653,7 @@ room { t = t .. '<< '; end; - local l = translate_now(menu_locale, 'auto_option') .. ' (' .. tostring(graphic_scale * 100) .. '%)'; + local l = translate_now("menu_locale", 'auto_option') .. ' (' .. tostring(graphic_scale * 100) .. '%)'; if prefs.graphic_scale then @@ -724,7 +730,7 @@ room { dsc = function(s) local cursor_scale = get_cursor_scale(); - pn(fmt.c(fmt.b(translate_now(menu_locale, 'cursor_scale')) .. ' {[' .. translate_now(menu_locale, 'auto_option') .. ']}')) + pn(fmt.c(fmt.b(translate_now("menu_locale", 'cursor_scale')) .. ' {[' .. translate_now("menu_locale", 'auto_option') .. ']}')) local t = ''; @@ -734,7 +740,7 @@ room { t = t .. '<< '; end; - local l = translate_now(menu_locale, 'auto_option') .. ' (' .. tostring(cursor_scale * 100) .. '%)'; + local l = translate_now("menu_locale", 'auto_option') .. ' (' .. tostring(cursor_scale * 100) .. '%)'; if prefs.cursor_scale then l = tostring(cursor_scale * 100) .. '%'; @@ -811,7 +817,7 @@ room { local graphic_scale = get_graphic_scale(); local font_scale = get_font_scale(); - pn(fmt.c(fmt.b(translate_now(menu_locale, 'font_scale')) .. ' {[' .. translate_now(menu_locale, 'auto_option') .. ']}')); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'font_scale')) .. ' {[' .. translate_now("menu_locale", 'auto_option') .. ']}')); local t = ''; @@ -824,7 +830,7 @@ room { if prefs.font_scale then t = t .. tostring(font_scale) .. '%'; else - t = t .. translate_now(menu_locale, 'auto_option') .. ' (' .. tostring(font_scale) .. '%)'; + t = t .. translate_now("menu_locale", 'auto_option') .. ' (' .. tostring(font_scale) .. '%)'; end; @@ -871,7 +877,7 @@ room { local graphic_scale = get_graphic_scale(); local font_scale = get_inventory_font_scale(); - pn(fmt.c(fmt.b(translate_now(menu_locale, 'inventory_scale')) .. ' {[' .. translate_now(menu_locale, 'auto_option') .. ']}')); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'inventory_scale')) .. ' {[' .. translate_now("menu_locale", 'auto_option') .. ']}')); local t = ''; @@ -884,7 +890,7 @@ room { if prefs.inventory_scale then t = t .. tostring(font_scale) .. '%'; else - t = t .. translate_now(menu_locale, 'auto_option') .. ' (' .. tostring(font_scale) .. '%)'; + t = t .. translate_now("menu_locale", 'auto_option') .. ' (' .. tostring(font_scale) .. '%)'; end; @@ -928,7 +934,7 @@ room { obj { nam = '#text_width'; dsc = function(s) - pn(fmt.c(fmt.b(translate_now(menu_locale, 'text_width')))); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'text_width')))); local t = ''; if prefs.text_width > 40 then t = t .. '{#fw_less|<<} '; @@ -986,21 +992,21 @@ room { obj { nam = '#text_alignment'; dsc = function(s) - pn(fmt.c(fmt.b(translate_now(menu_locale, 'text_alignment')))); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'text_alignment')))); local t = ''; if prefs.text_alignment == 1 then - t = t .. translate_now(menu_locale, 'text_alignment_justify') .. ' | '; + t = t .. translate_now("menu_locale", 'text_alignment_justify') .. ' | '; else - t = t .. '{#align_just|' .. translate_now(menu_locale, 'text_alignment_justify') .. '} | '; + t = t .. '{#align_just|' .. translate_now("menu_locale", 'text_alignment_justify') .. '} | '; end; if prefs.text_alignment == 2 then - t = t .. translate_now(menu_locale, 'text_alignment_left'); + t = t .. translate_now("menu_locale", 'text_alignment_left'); else - t = t .. '{#align_left|' .. translate_now(menu_locale, 'text_alignment_left') .. '}'; + t = t .. '{#align_left|' .. translate_now("menu_locale", 'text_alignment_left') .. '}'; end; pn(fmt.c(t) .. '^'); end; @@ -1029,21 +1035,21 @@ room { obj { nam = '#padding'; dsc = function(s) - pn(fmt.c(fmt.b(translate_now(menu_locale, 'padding')))); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'padding')))); local t = ''; if prefs.text_padding == 1 then - t = t .. translate_now(menu_locale, 'normal') .. ' | '; + t = t .. translate_now("menu_locale", 'normal') .. ' | '; else - t = t .. '{#pad_norm|' .. translate_now(menu_locale, 'normal') .. '} | '; + t = t .. '{#pad_norm|' .. translate_now("menu_locale", 'normal') .. '} | '; end; if prefs.text_padding == 2 then - t = t .. translate_now(menu_locale, 'extended'); + t = t .. translate_now("menu_locale", 'extended'); else - t = t .. '{#pad_large|' .. translate_now(menu_locale, 'extended') .. '}'; + t = t .. '{#pad_large|' .. translate_now("menu_locale", 'extended') .. '}'; end; pn(fmt.c(t) .. '^'); end; @@ -1072,21 +1078,21 @@ room { obj { nam = '#interval'; dsc = function(s) - pn(fmt.c(fmt.b(translate_now(menu_locale, 'interval')))); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'interval')))); local t = ''; if prefs.text_interval == 1 then - t = t .. translate_now(menu_locale, 'normal') .. ' | '; + t = t .. translate_now("menu_locale", 'normal') .. ' | '; else - t = t .. '{#int_norm|' .. translate_now(menu_locale, 'normal') .. '} | '; + t = t .. '{#int_norm|' .. translate_now("menu_locale", 'normal') .. '} | '; end; if prefs.text_interval == 2 then - t = t .. translate_now(menu_locale, 'extended'); + t = t .. translate_now("menu_locale", 'extended'); else - t = t .. '{#int_large|' .. translate_now(menu_locale, 'extended') .. '}'; + t = t .. '{#int_large|' .. translate_now("menu_locale", 'extended') .. '}'; end; pn(fmt.c(t) .. '^'); end; @@ -1115,13 +1121,13 @@ room { obj { nam = '#textinput'; dsc = function(s) - pn(fmt.c(fmt.b(translate_now(menu_locale, 'use_text_input')))); + pn(fmt.c(fmt.b(translate_now("menu_locale", 'use_text_input')))); local t = ''; if prefs.text_input then - t = '{#ti_disable|' .. translate_now(menu_locale, 'disable') .. '} | ' .. translate_now(menu_locale, 'enable'); + t = '{#ti_disable|' .. translate_now("menu_locale", 'disable') .. '} | ' .. translate_now("menu_locale", 'enable'); else - t = translate_now(menu_locale, 'disable') .. ' | {#ti_enable|' .. translate_now(menu_locale, 'enable') .. '}'; + t = translate_now("menu_locale", 'disable') .. ' | {#ti_enable|' .. translate_now("menu_locale", 'enable') .. '}'; end; pn(fmt.c(t) .. '^'); @@ -1153,13 +1159,13 @@ room { theme = 'black'; noinv = true; nam = 'resolution_warning'; - title = translate(menu_locale, 'warning'); - decor = translate(menu_locale, 'resolution_warning'); + title = translate("menu_locale", 'warning'); + decor = translate("menu_locale", 'resolution_warning'); onenter = stop_menu; }: with { obj { nam = '#sysset'; - dsc = function(s) return '{' .. translate_now(menu_locale, 'system_settings') .. '}'; end; + dsc = function(s) return '{' .. translate_now("menu_locale", 'system_settings') .. '}'; end; act = function(s) instead.menu(); end; @@ -1173,13 +1179,13 @@ room { theme = 'black'; noinv = true; nam = 'theme_warning'; - title = translate(menu_locale, 'warning'); - decor = translate(menu_locale, 'theme_warning'); + title = translate("menu_locale", 'warning'); + decor = translate("menu_locale", 'theme_warning'); onenter = stop_menu; }: with { obj { nam = '#sysset'; - dsc = function(s) return '{' .. translate_now(menu_locale, 'system_settings') .. '}'; end; + dsc = function(s) return '{' .. translate_now("menu_locale", 'system_settings') .. '}'; end; act = function(s) instead.menu(); end;