Divergent/mods/UI Rework/gamedata/scripts/z_utils_xml.script

205 lines
5.9 KiB
Plaintext
Raw Normal View History

local clr_icon_1 = GetARGB(255, 255, 255, 255)
local clr_icon_2 = GetARGB(100, 255, 255, 255)
local ico_size, rw, rh, _le = 0.7,1,1,50
local ico_width
function utils_xml.set_icon(sec, hidden, XML_temp, XML_box, XML_box_small)
-- Edited by Sota
-- ico_width = ico_width or (is_widescreen() and 0.8 or 1)
ico_width = ico_width or utils_xml.screen_ratio()
if not (XML_temp and XML_box) then
callstack()
printe("!ERROR utils_xml.set_icon | XML_box or XML_temp doesn't exist")
return
end
if not (sec and ini_sys:section_exist(sec)) then
XML_box:Show(false)
callstack()
printe("!ERROR utils_xml.set_icon | section [%s] doesn't exist in system ini", sec)
return
end
-- Icon
local ico = utils_xml.get_item_axis(sec)
XML_box:InitTexture( utils_xml.get_icons_texture(sec) )
XML_box:SetTextureRect(Frect():set(ico.x1, ico.y1, ico.x2, ico.y2))
XML_box:SetTextureColor( hidden and clr_icon_2 or clr_icon_1 )
XML_box:SetStretchTexture(true)
XML_box:Show(true)
local pos = XML_temp:GetWndPos()
local _w = XML_temp:GetWidth()
local _h = XML_temp:GetHeight()
local ratio = ico.w/ico.h
local h, w
ico.w = ico.w * ico_size * ico_width
ico.h = ico.h * ico_size
for i=1,2 do
local w_t, h_t = 0, 0
local resize = false
if (ico.w > _w) then -- if icon width is bigger than frame width
-- Edited by Sota
-- w_t = ico.w - _w
w_t = (ico.w - _w) / ico_width -- remove width scaling for correct comparison with height
resize = true
end
if (ico.h > _h) then -- if icon height is bigger than frame height
h_t = ico.h - _h
resize = true
end
if resize then -- resize is required
if (w_t >= h_t) then -- if icon width is the big number (or square), use it as a base for resizing
w = _w
-- Edited by Sota
-- h = w / ratio
h = w / ratio / ico_width -- remove width scaling (no need for height)
elseif (w_t < h_t) then -- if icon width is the big number, use it as a base for resizing
h = _h
-- Edited by Sota
-- w = h * ratio
w = h * ratio * ico_width -- add width scaling because we get width from height
end
else -- no resize
w = ico.w
h = ico.h
end
end
local offset_x = (_w - w)/2
local offset_y = (_h - h)/2
XML_box:SetWndSize(vector2():set(w , h))
XML_box:SetWndPos(vector2():set(pos.x + offset_x , pos.y + offset_y))
local ico_layer = ini_sys:r_string_ex(sec,"1icon_layer")
if XML_box_small and ico_layer then
local ico_layer_x = ini_sys:r_float_ex(sec,"1icon_layer_x")
local ico_layer_y = ini_sys:r_float_ex(sec,"1icon_layer_y")
local ico_layer_scale = ini_sys:r_float_ex(sec,"1icon_layer_scale")
if (ico_layer_x == 0) and (ico_layer_y == 0) and (ico_layer_scale == 1) then
utils_xml.set_icon(ico_layer, hidden, XML_temp, XML_box_small)
end
end
end
local upgr_chk = {
["weapon"] = {
{ x = 1724 , y = 802 , w = 167 , h = 159 }
},
["outfit"] = {
{ x = 716 , y = 824 , w = 198 , h = 129 },
{ x = 814 , y = 579 , w = 159 , h = 137 },
{ x = 90 , y = 818 , w = 185 , h = 140 }
},
}
function utils_xml.set_upgr_icon(obj, sec, XML_box, XML_temp)
-- Edited by Sota
-- ico_width = ico_width or (utils_xml.is_widescreen() and 0.8 or 1)
ico_width = ico_width or utils_xml.screen_ratio()
local upgr_x = ini_sys:r_float_ex(sec,"upgr_icon_x")
local upgr_y = ini_sys:r_float_ex(sec,"upgr_icon_y")
local upgr_w = ini_sys:r_float_ex(sec,"upgr_icon_width")
local upgr_h = ini_sys:r_float_ex(sec,"upgr_icon_height")
if not (upgr_x and upgr_y and upgr_w and upgr_h) then
utils_xml.set_icon(sec, nil, XML_temp, XML_box)
return
end
-- Get upgrade dds
local upgr_path = ini_sys:r_string_ex(sec,"upgr_icon_path")
upgr_path = upgr_path or IsWeapon(obj) and "ui\\ui_actor_weapons" or "ui\\ui_actor_armor"
-- Decide if it should use normal icon instead
local use_ico = false
local t = {}
if IsWeapon(obj) then
for i=1,#upgr_chk["weapon"] do
t = upgr_chk["weapon"][i]
if (t.x == upgr_x) and (t.y == upgr_y) and (t.w == upgr_w) and (t.h == upgr_h) then
use_ico = true
break
end
end
elseif IsOutfit(obj) then
for i=1,#upgr_chk["outfit"] do
t = upgr_chk["outfit"][i]
if (t.x == upgr_x) and (t.y == upgr_y) and (t.w == upgr_w) and (t.h == upgr_h) then
use_ico = true
break
end
end
end
if use_ico then
utils_xml.set_icon(sec, nil, XML_temp, XML_box)
return
end
local ico = {}
ico.x1 = upgr_x
ico.y1 = upgr_y
ico.x2 = upgr_x + upgr_w
ico.y2 = upgr_y + upgr_h
ico.w = upgr_w
ico.h = upgr_h
XML_box:InitTexture(upgr_path)
XML_box:SetTextureRect(Frect():set(ico.x1, ico.y1, ico.x2, ico.y2))
XML_box:SetStretchTexture(true)
XML_box:Show(true)
local pos = XML_temp:GetWndPos()
local _w = XML_temp:GetWidth()
local _h = XML_temp:GetHeight()
local ratio = ico.w/ico.h
local h, w
ico.w = ico.w * ico_size * ico_width
ico.h = ico.h * ico_size
for i=1,2 do
local w_t, h_t = 0, 0
local resize = false
if (ico.w > _w) then -- if icon width is bigger than frame width
-- Edited by Sota
-- w_t = ico.w - _w
w_t = (ico.w - _w) / ico_width -- remove width scaling for correct comparison with height
resize = true
end
if (ico.h > _h) then -- if icon height is bigger than frame height
h_t = ico.h - _h
resize = true
end
if resize then -- resize is required
if (w_t >= h_t) then -- if icon width is the big number (or square), use it as a base for resizing
w = _w
-- Edited by Sota
-- h = w / ratio
h = w / ratio / ico_width -- remove width scaling (no need for height)
elseif (w_t < h_t) then -- if icon width is the big number, use it as a base for resizing
h = _h
-- Edited by Sota
-- w = h * ratio
w = h * ratio * ico_width -- add width scaling because we get width from height
end
else -- no resize
w = ico.w
h = ico.h
end
end
local offset_x = (_w - w)/2
local offset_y = (_h - h)/2
XML_box:SetWndSize(vector2():set(w , h))
XML_box:SetWndPos(vector2():set(pos.x + offset_x , pos.y + offset_y))
end