Темы с автоподбором

This commit is contained in:
Alexander Yakovlev 2020-12-23 12:55:21 +07:00
parent bd3d9bb3c7
commit 69b1b6102e
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
8 changed files with 26 additions and 24 deletions

View file

@ -1,20 +1,17 @@
local msg = dprint or print
local function autodetect_theme()
if not instead.screen_size then
return
end
local f = io.open(instead.savepath().."/config.ini", "r")
if f then
msg("Найден конфиг темы.");
f:close()
return
end
f = io.open(instead.gamepath().."/themes/default/theme.ini", "r")
if not f then
return
end
f:close()
local themes = {}
local vertical = false
for d in std.readdir(instead.gamepath().."/themes") do
if d ~= '.' and d ~= '..' then
local p = instead.gamepath().."/themes/" .. d
@ -34,8 +31,13 @@ local function autodetect_theme()
h = tonumber(h)
local r = w / h
if r < 1 then r = 1 / r end
table.insert(themes, { nam = d, w = w, h = h, mobile = w < h, ratio = r })
vertical = vertical or (w < h)
table.insert(themes, {
nam = d,
w = w,
h = h,
vertical = w < h,
ratio = r
})
end
f:close()
end
@ -46,20 +48,18 @@ local function autodetect_theme()
return
end
local w, h = instead.screen_size()
local r = w / h
local mobile = w < h or PLATFORM == "ANDROID" or PLATFORM == "IOS" or PLATFORM == "S60" or PLATFORM == "WINRT" or PLATFORM == "WINCE"
if w < h then
r = 1 / r
end
local ratio = w / h
local mobile = PLATFORM == "ANDROID" or PLATFORM == "IOS" or PLATFORM == "S60" or PLATFORM == "WINRT" or PLATFORM == "WINCE"
local vertical = w < h
local d = 1000
local t = false
for _, v in ipairs(themes) do
local dd = math.abs(v.ratio - r)
local dd = math.abs(v.ratio - ratio)
if dd < d then
if mobile and (not vertical or v.mobile) then
if mobile and (not vertical or v.vertical) then
d = dd
t = v
elseif not mobile and not v.mobile then
elseif not mobile and not v.vertical then
d = dd
t = v
end

View file

@ -1,6 +1,7 @@
;$Name:Parser
include = arctic
scr.w = 1024
scr.h = 576
scr.w = 1920
scr.h = 1080
scr.gfx.bg = ;bg.png
scr.col.bg = white
win.x = 20
@ -11,6 +12,7 @@ inv.x = 505
inv.y = 10
inv.col.link = #666666
inv.col.fg = #222222
;inv.w = 127
;inv.h = 440
menu.button.x = 1000
@ -28,10 +30,10 @@ scr.gfx.w = 144
scr.gfx.h = 448
scr.gfx.mode = embedded
win.fnt.name = theme/{LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
win.fnt.name = ../common/{LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
win.fnt.size = 18
inv.fnt.name = theme/{LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
inv.fnt.name = ../common/{LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
inv.fnt.size = 18
menu.gfx.button = theme/menu.png
menu.gfx.button = ../common/menu.png

View file

@ -30,10 +30,10 @@ scr.gfx.w = 144
scr.gfx.h = 448
scr.gfx.mode = embedded
win.fnt.name = {LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
win.fnt.name = ../common/{LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
win.fnt.size = 18
inv.fnt.name = {LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
inv.fnt.name = ../common/{LiberationSerif-Regular,LiberationSerif-Bold,LiberationSerif-Italic,LiberationSerif-BoldItalic}.ttf
inv.fnt.size = 18
menu.gfx.button = menu.png
menu.gfx.button = ../common/menu.png