Commit b6c9f7ef2c58733ecbdba4b0069f27dfd3b402f1

Authored by DarkGod
1 parent 75fc94e1

language selector! woot!

... ... @@ -71,8 +71,8 @@ end
71 71 -- @string orname
72 72 -- @return font object
73 73 -- @return size
74   -function _M:resolveFont(name, orname)
75   - local font = packages[cur_id]
  74 +function _M:resolveFont(name, orname, package_id)
  75 + local font = packages[package_id or cur_id]
76 76 local size = cur_size
77 77 if not font[name] then name = orname end
78 78 if not font[name] then name = "default" end
... ... @@ -86,16 +86,16 @@ end
86 86 -- @string orname
87 87 -- @return font
88 88 -- @return size
89   -function _M:getFont(name, orname)
90   - local font, size = self:resolveFont(name, orname)
  89 +function _M:getFont(name, orname, package_id)
  90 + local font, size = self:resolveFont(name, orname, package_id)
91 91 return font.font, math.ceil(font[size] * config.settings.font_scale / 100)
92 92 end
93 93
94 94 --- Get by name.
95 95 -- @string name
96 96 -- @param[type=?boolean] force make a font bold no matter what
97   -function _M:get(name, force)
98   - local font, size = self:resolveFont(name)
  97 +function _M:get(name, force, package_id)
  98 + local font, size = self:resolveFont(name, nil, package_id)
99 99 local f = core.display.newFont(font.font, math.ceil(font[size] * config.settings.font_scale / 100), font.bold or force)
100 100 if font.bold then f:setStyle("bold") end
101 101 return f
... ...
... ... @@ -50,6 +50,12 @@ end
50 50 function _M:generateList(actions)
51 51 local default_actions = {
52 52 resume = { _t"Resume", function() game:unregisterDialog(self) end },
  53 + language = { _t"Language", function()
  54 + game:unregisterDialog(self)
  55 + package.loaded["engine.dialogs.LanguageSelect"] = nil
  56 + local menu = require("engine.dialogs.LanguageSelect").new()
  57 + game:registerDialog(menu)
  58 + end },
53 59 keybinds = { _t"Key Bindings", function()
54 60 game:unregisterDialog(self)
55 61 local menu = require("engine.dialogs.KeyBinder").new(game.normal_key, nil, game.gestures)
... ...
  1 +-- TE4 - T-Engine 4
  2 +-- Copyright (C) 2009 - 2019 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +require "engine.class"
  21 +local Dialog = require "engine.ui.Dialog"
  22 +local FontPackage = require "engine.FontPackage"
  23 +local VariableList = require "engine.ui.VariableList"
  24 +local Textzone = require "engine.ui.Textzone"
  25 +local Separator = require "engine.ui.Separator"
  26 +
  27 +--- Language selection
  28 +-- @classmod engine.dialogs.LanguageSelect
  29 +module(..., package.seeall, class.inherit(Dialog))
  30 +
  31 +function _M:init()
  32 + Dialog.init(self, _t"Language Selection", 400, 500)
  33 +
  34 + self:generateList()
  35 +
  36 + self.c_list = VariableList.new{width=self.iw, max_height=self.ih, list=self.list, fct=function(item) self:select(item) end}
  37 +
  38 + self:loadUI{
  39 + {left=0, top=0, ui=self.c_list},
  40 + }
  41 + self:setFocus(self.c_list)
  42 + self:setupUI(false, true)
  43 +
  44 + self.key:addBinds{
  45 + EXIT = function() game:unregisterDialog(self) end,
  46 + }
  47 +end
  48 +
  49 +function _M:select(item)
  50 + if not item then return end
  51 +
  52 + game:saveSettings("locale", ("locale = %q\n"):format(item.locale))
  53 + config.settings.locale = item.locale
  54 +
  55 + game:saveGame()
  56 + util.showMainMenu(false, nil, nil, game.__mod_info.short_name, game.save_name, false)
  57 +end
  58 +
  59 +function _M:generateList()
  60 + local list = {
  61 + {name = "English (English)", locale="en_US"},
  62 + {name = "简体中文 (Simplified Chinese)", locale="zh_hans", font=FontPackage:get("default", nil, "chinese")},
  63 + }
  64 +
  65 + self:triggerHook{"I18N:listLanguages", list=list}
  66 +
  67 + self.list = list
  68 +end
... ...
... ... @@ -50,7 +50,7 @@ function _M:generate()
50 50 self.max = #self.list
51 51
52 52 local fw, fh = self.w, self.font_h
53   - self.fw, self.fh = fw, fh
  53 + self.fw = fw, fh
54 54
55 55 self.frame = self:makeFrame(nil, fw, fh)
56 56 self.frame_sel = self:makeFrame("ui/selector-sel", fw, fh)
... ... @@ -65,12 +65,18 @@ function _M:generate()
65 65 local color = item.color or {255,255,255}
66 66 local width = fw - self.frame_sel.b4.w - self.frame_sel.b6.w
67 67
68   - local text = self.font:draw(item[self.display_prop], width, color[1], color[2], color[3])
  68 + local font, fh = self.font, fh
  69 + if item.font then
  70 + font = item.font
  71 + fh = font:lineSkip()
  72 + end
  73 +
  74 + local text = font:draw(item[self.display_prop], width, color[1], color[2], color[3])
69 75 ifh = fh * #text + self.frame_sel.b8.w / 3 * 2
70 76
71 77 local texs = {}
72 78 for z, tex in ipairs(text) do
73   - texs[z] = {t=tex._tex, tw=tex._tex_w, th = tex._tex_h, w=tex.w, h=tex.h, y = (z - 1) * self.font_h + self.frame_sel.b8.w / 3}
  79 + texs[z] = {t=tex._tex, tw=tex._tex_w, th = tex._tex_h, w=tex.w, h=tex.h, y = (z - 1) * fh + self.frame_sel.b8.w / 3}
74 80 end
75 81 item.start_h = sh
76 82 item.fh = ifh
... ...
... ... @@ -64,6 +64,7 @@ function _M:init()
64 64 end
65 65 game:registerDialog(d)
66 66 end},
  67 + "language",
67 68 "video",
68 69 "sound",
69 70 "steam",
... ...
... ... @@ -2361,6 +2361,7 @@ do return end
2361 2361 { _t"Inventory", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_INVENTORY") end },
2362 2362 { _t"Character Sheet", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_CHARACTER_SHEET") end },
2363 2363 "keybinds",
  2364 + "language",
2364 2365 {_t"Game Options", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.GameOptions").new()) end},
2365 2366 "video",
2366 2367 "sound",
... ...