Changeset - 6a1418ea15ae
[Not reviewed]
adaptivity
0 5 3
Silverwing - 2 years ago 2022-08-06 10:00:51

Technical improvements
8 files changed with 130 insertions and 62 deletions:
0 comments (0 inline, 0 general) First comment
decor.lua
Show inline comments
 
@@ -1018,34 +1018,33 @@ function decor:load()
 
end
 
std.mod_cmd(
 
	function(cmd)
 
		if cmd[1] ~= '@decor_click' then
 
			return
 
		end
 
		local nam = cmd[2]
 
		local e = decor.objects[nam]
 
		local t = e[2]
 
		local press, x, y, btn = cmd[3], cmd[4], cmd[5], cmd[6]
 
		local r, v
 
		local a
 
		if type(decor[t].click) == 'function' then
 
			a = decor[t]:click(e, press, x, y, btn)
 
		else
 
			a = { }
 
		end
 
		table.insert(a, 1, nam)
 
		table.insert(a, 2, press)
 
		table.insert(a, 3, x - e.xc)
 
		table.insert(a, 4, y - e.yc)
 
		table.insert(a, 5, btn)
 
	    if cmd[1] == '@decor_click' then
 
		    local nam = cmd[2]
 
		    local e = decor.objects[nam]
 
		    local t = e[2]
 
		    local press, x, y, btn = cmd[3], cmd[4], cmd[5], cmd[6]
 
		    local r, v
 
		    local a
 
		    if type(decor[t].click) == 'function' then
 
			    a = decor[t]:click(e, press, x, y, btn)
 
		    else
 
			    a = { }
 
		    end
 
		    table.insert(a, 1, nam)
 
		    table.insert(a, 2, press)
 
		    table.insert(a, 3, x - e.xc)
 
		    table.insert(a, 4, y - e.yc)
 
		    table.insert(a, 5, btn)
 

	
 
		local r, v = std.call(std.here(), 'ondecor', std.unpack(a))
 
		if not r and not v then
 
			r, v = std.call(std.game, 'ondecor', std.unpack(a))
 
		end
 
		if not r and not v then
 
			return nil, false
 
		end
 
		return r, v
 
		    local r, v = std.call(std.here(), 'ondecor', std.unpack(a))
 
		    if not r and not v then
 
			    r, v = std.call(std.game, 'ondecor', std.unpack(a))
 
		    end
 
		    if not r and not v then
 
			    return nil, false
 
		    end
 
		    return r, v
 
	    end;
 
end)
 
std.mod_start(
 
	function(load)
 
@@ -1068,7 +1067,7 @@ std.mod_step(
 
			end
 
			return
 
		end
 
		if not iface:raw_mode() then -- debugger?
 
		if not iface:raw_mode() then -- debugger
 
			decor:cache_clear()
 
			decor:process()
 
			decor:render()
images/characters/solarscale.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/main_theme/settings.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/tower_theme/settings.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
main3.lua
Show inline comments
 
@@ -18,6 +18,10 @@ game.use = function(s)
 
end;
 
game.inv = 'Это предмет. Он существует. ';
 

	
 
instead.notitle = function()
 
    return here().notitle;
 
end;
 

	
 
require "fmt"
 
require "noinv"
 
require 'snd'
 
@@ -108,7 +112,8 @@ declare {
 
        'wind_gust_3';
 
    },
 
    menu_sprites = {
 
    }
 
    },
 
    in_game = false
 
}
 

	
 
include "tutorial"
 
@@ -205,8 +210,19 @@ function stop_menu()
 
    D {'title'};
 
end;
 

	
 
game.ondecor = function(s, name, press, x, y, btn)
 
    if press then
 
        if name == 'settings_open' then
 
            in_game = true;
 
            walk('intro_settings');
 
            return true;
 
        end;
 
    end;
 
    return false;
 
end;
 

	
 
game.afterwalk = function()
 
    print(from().nam, '->', here().nam);
 
    dprint(from().nam, '->', here().nam);
 

	
 
    if from().themeDispose then
 
        from():themeDispose();
 
@@ -217,6 +233,7 @@ game.afterwalk = function()
 
    end;
 
    
 
    if here().theme ~= nil and here().theme ~= current_theme then
 
        dprint('Switch theme', current_theme, '->', here().theme);
 
        set_theme(std.call(here(), 'theme'));
 
    end;
 
end;
 
@@ -346,12 +363,16 @@ end;
 

	
 
room {
 
    nam = 'main';
 
    notitle = true;
 
    nosave = true;
 
    noautosave = true;
 
    noinv = true;
 
    nofading = true;
 
    disp = '';
 
    theme = 'menu';
 
    onenter = function(s)
 
        in_game = false;
 
    end;
 
    themeInit = function(s)
 
        init_menu(false, {'start', 'load', 'about', 'settings', 'quit'});
 
    end;
 
@@ -364,7 +385,7 @@ room {
 
        timer:stop();
 
    end;
 
    ondecor = function(s, name, press, x, y, btn)
 
        if not press then
 
        if press then
 
            if name == 'start' then
 
                walk('intro_start');
 
                return true;
 
@@ -391,6 +412,7 @@ room {
 

	
 
room {
 
    nam = 'intro_start';
 
    notitle = true;
 
    nosave = true;
 
    noautosave = true;
 
    noinv = true;
 
@@ -408,12 +430,14 @@ room {
 
        timer:stop();
 
    end;
 
    ondecor = function(s, name, press, x, y, btn)
 
        if not press then
 
        if press then
 
            if name == 'start' then
 
                walk('above_forest');
 
                in_game = true;
 
                return true;
 
            elseif name == 'tutorial' then
 
                walk('tutorial_start');
 
                in_game = true;
 
                return true;
 
            elseif name == 'back' then
 
                walk('main');
 
@@ -427,6 +451,7 @@ room {
 

	
 
room {
 
    nam = 'intro_info';
 
    notitle = true;
 
    nosave = true;
 
    noautosave = true;
 
    noinv = true;
 
@@ -444,15 +469,13 @@ room {
 
        timer:stop();
 
    end;
 
    ondecor = function(s, name, press, x, y, btn)
 
        if not press then
 
            if name == 'start' then
 
                walk('intro_start');
 
                return true;
 
            elseif name == 'back' then
 
                walk('main');
 
                return true;
 
            elseif name == 'settings' then
 
                walk('intro_settings');
 
        if press then
 
            if name == 'back' then
 
                if in_game then
 
                    walk('menu');
 
                else
 
                    walk('main');
 
                end;
 
                return true;
 
            end;
 
        end;
 
@@ -477,6 +500,7 @@ end;
 

	
 
room {
 
    nam = 'intro_settings';
 
    notitle = true;
 
    nosave = true;
 
    noautosave = true;
 
    noinv = true;
 
@@ -494,15 +518,13 @@ room {
 
        timer:stop();
 
    end;
 
    ondecor = function(s, name, press, x, y, btn)
 
        if not press then
 
            if name == 'start' then
 
                walk('intro_start');
 
                return true;
 
            elseif name == 'back' then
 
                walk('main');
 
                return true;
 
            elseif name == 'about' then
 
                walk('intro_info');
 
        if press then
 
            if name == 'back' then
 
                if in_game then
 
                    walk(from());
 
                else
 
                    walk('main');
 
                end;
 
                return true;
 
            end;
 
        end;
 
@@ -1007,6 +1029,7 @@ function set_theme(t)
 
    -- 640x480 is the base size
 
    -- For lesser sizes -- enable downscaling
 
    -- Integer upscaling if effective resolution is no less than 640x480
 
    D {'settings_open'};
 

	
 
    local width = tonumber(theme.get('scr.w'));
 
    local height = tonumber(theme.get('scr.h'));
 
@@ -1030,7 +1053,7 @@ function set_theme(t)
 
            prefs.graphic_scale = false;
 
        end;
 
    end;
 
    print(font_scale);
 
    
 
    if font_scale > 200 * scale then
 
        font_scale = scale;
 
        prefs.font_scale = font_scale * 100
 
@@ -1081,9 +1104,9 @@ function set_theme(t)
 
        if height < 520 * scale then
 
            diretheme.set_text_area({
 
                rect = {
 
                    ty = -110 + vpadding,
 
                    ty = -95 + vpadding,
 
                    wmax = 538 - hpadding * 2,
 
                    hmax = 342 - vpadding * 2,
 
                    hmax = 322 - vpadding * 2,
 
                    ay = 0
 
                },
 
                text = {
 
@@ -1102,9 +1125,9 @@ function set_theme(t)
 
        else
 
            diretheme.set_text_area({
 
                rect = {
 
                    ty = -35 + vpadding,
 
                    ty = -10 + vpadding,
 
                    wmax = 538 - hpadding * 2,
 
                    hmax = 342 - vpadding * 2,
 
                    hmax = 322 - vpadding * 2,
 
                    ay = 0
 
                },
 
                text = {
 
@@ -1302,6 +1325,16 @@ function set_theme(t)
 
            height = interval,
 
            scaleui = 3
 
        }, true);
 
        D {
 
            'settings_open', 
 
            'img', 
 
            get_sprite('images/main_theme/settings.png'),
 
            x=width - 32 * scale, 
 
            y=height - 32 * scale, 
 
            frames=1, 
 
            click=true,
 
            z=-1
 
        };
 
    elseif t == 'tower' then
 
        theme.reset('snd.click');
 
        diretheme.set_background('#181E37', 255, 'images/tower_theme/background.png', {mode=2, scale=true});
 
@@ -1452,6 +1485,17 @@ function set_theme(t)
 
            height = interval,
 
            scaleui = 3
 
        });
 
        
 
        D {
 
            'settings_open', 
 
            'img', 
 
            get_sprite('images/tower_theme/settings.png'),
 
            x=width - 32 * scale, 
 
            y=height - 32 * scale, 
 
            frames=1, 
 
            click=true,
 
            z=-1
 
        };
 
    elseif t == 'terminal' then
 
        theme.set('snd.click', '');
 
        diretheme.set_background('#181E37', 255, 'images/tower_theme/background.png', {mode=2});
 
@@ -1602,9 +1646,9 @@ function set_theme(t)
 
end;
 

	
 
function start(load)
 
    dprint('start', load);
 
    local w, h = diretheme.get_screen();
 
    local name = theme.name();
 
    
 
    if here() ~= _'theme_warning' and here() ~= _'resolution_warning' then
 
        if name ~= '.' then
 
            walkin('theme_warning');
 
@@ -1678,7 +1722,8 @@ function start(load)
 
    end;
 
end;
 

	
 
function init()    
 
function init() 
 
    print('init');
 
    if not prefs.graphic_scale then
 
        prefs.graphic_scale = false;
 
    end;
terminal.lua
Show inline comments
 
@@ -152,14 +152,14 @@ local release_handled_keys = Set {
 
    'left shift'
 
}
 

	
 
function keys:filter(press, key)
 
--[[function keys:filter(press, key)
 
    if handled_keys[key] then
 
        return press; -- ловим все нажатия
 
    end;
 
    if release_handled_keys[key] then
 
        return true;
 
    end;
 
end
 
end]]
 

	
 
local mapping_decor_key = {
 
    btn_backquote = '`';
 
@@ -315,6 +315,15 @@ room {
 
    mx = false;
 
    my = false;
 
    
 
    keysfilter = function(s, press, key)
 
        if handled_keys[key] then
 
            return press; -- ловим все нажатия
 
        end;
 
        if release_handled_keys[key] then
 
            return true;
 
        end;
 
    end;
 
    
 
    query_formatter = function(s, path, entry)
 
        if s.status == 'command' then
 
            return s.path .. '>' .. s.entry .. '_';
theme.ini
Show inline comments
 
@@ -58,3 +58,4 @@ menu.button.y = 573
 
scr.gfx.cursor.normal = images/cursor.png
 
scr.gfx.cursor.use = images/cursor_active.png
 
scr.gfx.icon = icon.ico
 

	
utils.lua
Show inline comments
 
declare {
 
    keysfilter = false;
 
}
 

	
 
function keys:filter(press, key)
 
    local rval;
 
    if here().keysfilter then
 
        rval = here():keysfilter(press, key);
 
    end;
 
    if keysfilter then
 
        return keysfilter(press, key);
 
    end;
 
end
 

	
 
--[[
 
	Walk from links
 
]]
 
@@ -70,7 +84,7 @@ end
 

	
 
local __ds = false;
 

	
 
std.mod_step(function(state)
 
--[[std.mod_step(function(state)
 
	if (player_moved()) and std.cmd[1] ~= 'load' then
 
		if here().nofading then
 
			__ds = true;
 
@@ -85,7 +99,7 @@ std.mod_cmd(function(cmd)
 
		sprite.direct(false);
 
		return std.nop();
 
	end;
 
end, -1);
 
end, -1);]]
 

	
 

	
 
function has_object (tab, val)
 
@@ -173,4 +187,4 @@ function robj(t)
 
		table.insert(t.way, pathout {'Назад'});
 
	end;
 
	return room(t);
 
end;
 
\ No newline at end of file
 
end;
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now