Skip to content
Snippets Groups Projects
Commit b6c9f7ef authored by DarkGod's avatar DarkGod
Browse files

language selector! woot!

parent 75fc94e1
No related branches found
No related tags found
No related merge requests found
......@@ -71,8 +71,8 @@ end
-- @string orname
-- @return font object
-- @return size
function _M:resolveFont(name, orname)
local font = packages[cur_id]
function _M:resolveFont(name, orname, package_id)
local font = packages[package_id or cur_id]
local size = cur_size
if not font[name] then name = orname end
if not font[name] then name = "default" end
......@@ -86,16 +86,16 @@ end
-- @string orname
-- @return font
-- @return size
function _M:getFont(name, orname)
local font, size = self:resolveFont(name, orname)
function _M:getFont(name, orname, package_id)
local font, size = self:resolveFont(name, orname, package_id)
return font.font, math.ceil(font[size] * config.settings.font_scale / 100)
end
--- Get by name.
-- @string name
-- @param[type=?boolean] force make a font bold no matter what
function _M:get(name, force)
local font, size = self:resolveFont(name)
function _M:get(name, force, package_id)
local font, size = self:resolveFont(name, nil, package_id)
local f = core.display.newFont(font.font, math.ceil(font[size] * config.settings.font_scale / 100), font.bold or force)
if font.bold then f:setStyle("bold") end
return f
......
......@@ -50,6 +50,12 @@ end
function _M:generateList(actions)
local default_actions = {
resume = { _t"Resume", function() game:unregisterDialog(self) end },
language = { _t"Language", function()
game:unregisterDialog(self)
package.loaded["engine.dialogs.LanguageSelect"] = nil
local menu = require("engine.dialogs.LanguageSelect").new()
game:registerDialog(menu)
end },
keybinds = { _t"Key Bindings", function()
game:unregisterDialog(self)
local menu = require("engine.dialogs.KeyBinder").new(game.normal_key, nil, game.gestures)
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009 - 2019 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Dialog = require "engine.ui.Dialog"
local FontPackage = require "engine.FontPackage"
local VariableList = require "engine.ui.VariableList"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
--- Language selection
-- @classmod engine.dialogs.LanguageSelect
module(..., package.seeall, class.inherit(Dialog))
function _M:init()
Dialog.init(self, _t"Language Selection", 400, 500)
self:generateList()
self.c_list = VariableList.new{width=self.iw, max_height=self.ih, list=self.list, fct=function(item) self:select(item) end}
self:loadUI{
{left=0, top=0, ui=self.c_list},
}
self:setFocus(self.c_list)
self:setupUI(false, true)
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:select(item)
if not item then return end
game:saveSettings("locale", ("locale = %q\n"):format(item.locale))
config.settings.locale = item.locale
game:saveGame()
util.showMainMenu(false, nil, nil, game.__mod_info.short_name, game.save_name, false)
end
function _M:generateList()
local list = {
{name = "English (English)", locale="en_US"},
{name = "简体中文 (Simplified Chinese)", locale="zh_hans", font=FontPackage:get("default", nil, "chinese")},
}
self:triggerHook{"I18N:listLanguages", list=list}
self.list = list
end
......@@ -50,7 +50,7 @@ function _M:generate()
self.max = #self.list
local fw, fh = self.w, self.font_h
self.fw, self.fh = fw, fh
self.fw = fw, fh
self.frame = self:makeFrame(nil, fw, fh)
self.frame_sel = self:makeFrame("ui/selector-sel", fw, fh)
......@@ -65,12 +65,18 @@ function _M:generate()
local color = item.color or {255,255,255}
local width = fw - self.frame_sel.b4.w - self.frame_sel.b6.w
local text = self.font:draw(item[self.display_prop], width, color[1], color[2], color[3])
local font, fh = self.font, fh
if item.font then
font = item.font
fh = font:lineSkip()
end
local text = font:draw(item[self.display_prop], width, color[1], color[2], color[3])
ifh = fh * #text + self.frame_sel.b8.w / 3 * 2
local texs = {}
for z, tex in ipairs(text) do
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}
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}
end
item.start_h = sh
item.fh = ifh
......
......@@ -64,6 +64,7 @@ function _M:init()
end
game:registerDialog(d)
end},
"language",
"video",
"sound",
"steam",
......
......@@ -2361,6 +2361,7 @@ do return end
{ _t"Inventory", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_INVENTORY") end },
{ _t"Character Sheet", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_CHARACTER_SHEET") end },
"keybinds",
"language",
{_t"Game Options", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.GameOptions").new()) end},
"video",
"sound",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment