Add open link button to marketing popup
This commit is contained in:
parent
d3f77f62c9
commit
66ee0c0c50
@ -12,42 +12,22 @@ LUI.onmenuopen("main_campaign", function(menu)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function makelink(element, link)
|
LUI.common_menus.MarketingPopup.OnPopupAction = function(a1, a2)
|
||||||
element:setHandleMouseMove(true)
|
local data = a1.popupData
|
||||||
element:setHandleMouseButton(true)
|
if (type(data.link) == "string") then
|
||||||
element:registerAnimationState("focused", {
|
game:openlink(data.link)
|
||||||
color = {
|
|
||||||
r = 1,
|
|
||||||
g = 1,
|
|
||||||
b = 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
local entered = false
|
|
||||||
element:registerEventHandler("mouseenter", function()
|
|
||||||
if (not entered) then
|
|
||||||
Engine.PlaySound(CoD.SFX.MouseOver)
|
|
||||||
entered = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
element:animateToState("focused")
|
|
||||||
end)
|
|
||||||
|
|
||||||
element:registerEventHandler("mouseleave", function()
|
|
||||||
entered = false
|
|
||||||
element:animateToState("default")
|
|
||||||
end)
|
|
||||||
|
|
||||||
element:registerEventHandler("leftmousedown", function()
|
|
||||||
Engine.PlaySound(CoD.SFX.MouseClick)
|
|
||||||
game:openlink(link)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local marketingbase = LUI.MarketingPopup.Base
|
local marketingbase = LUI.MarketingPopup.Base
|
||||||
LUI.MarketingPopup.Base = function(a1, data, a3)
|
LUI.MarketingPopup.Base = function(a1, data, a3)
|
||||||
local element = marketingbase(a1, data, a3)
|
local haslink = data.popupAction ~= nil and game:islink(data.popupAction)
|
||||||
|
if (haslink) then
|
||||||
|
data.link = data.popupAction
|
||||||
|
data.popupAction = "depot"
|
||||||
|
end
|
||||||
|
|
||||||
|
local element = marketingbase(a1, data, a3)
|
||||||
local blur = element:getFirstDescendentById("generic_popup_screen_overlay_blur"):getNextSibling()
|
local blur = element:getFirstDescendentById("generic_popup_screen_overlay_blur"):getNextSibling()
|
||||||
local parent = blur:getFirstChild():getNextSibling():getNextSibling():getNextSibling()
|
local parent = blur:getFirstChild():getNextSibling():getNextSibling():getNextSibling()
|
||||||
local image = parent:getFirstChild()
|
local image = parent:getFirstChild()
|
||||||
@ -57,6 +37,11 @@ LUI.MarketingPopup.Base = function(a1, data, a3)
|
|||||||
local imagecontainer = LUI.UIStencilText.new(state)
|
local imagecontainer = LUI.UIStencilText.new(state)
|
||||||
local material = RegisterMaterial(data.image)
|
local material = RegisterMaterial(data.image)
|
||||||
|
|
||||||
|
local helpertext = element:getFirstDescendentById("helper_text_text")
|
||||||
|
if (haslink and helpertext) then
|
||||||
|
helpertext:setText(Engine.Localize("@MENU_OPEN_LINK"))
|
||||||
|
end
|
||||||
|
|
||||||
local ratio = Engine.GetMaterialAspectRatio(material)
|
local ratio = Engine.GetMaterialAspectRatio(material)
|
||||||
local width = 525
|
local width = 525
|
||||||
local height = width / ratio
|
local height = width / ratio
|
||||||
|
@ -116,5 +116,8 @@
|
|||||||
"LUA_MENU_SP_LOCATION_OILRIG": "LUA_MENU_SP_LOCATION_OILRIG",
|
"LUA_MENU_SP_LOCATION_OILRIG": "LUA_MENU_SP_LOCATION_OILRIG",
|
||||||
"LUA_MENU_SP_LOCATION_ROADKILL": "LUA_MENU_SP_LOCATION_ROADKILL",
|
"LUA_MENU_SP_LOCATION_ROADKILL": "LUA_MENU_SP_LOCATION_ROADKILL",
|
||||||
"LUA_MENU_SP_LOCATION_TRAINER": "LUA_MENU_SP_LOCATION_TRAINER",
|
"LUA_MENU_SP_LOCATION_TRAINER": "LUA_MENU_SP_LOCATION_TRAINER",
|
||||||
"LUA_MENU_SP_LOCATION_MUSEUM": "LUA_MENU_SP_LOCATION_MUSEUM"
|
"LUA_MENU_SP_LOCATION_MUSEUM": "LUA_MENU_SP_LOCATION_MUSEUM",
|
||||||
|
|
||||||
|
"DEPOT_GO_TO_THE_DEPOT": "DEPOT_GO_TO_THE_DEPOT",
|
||||||
|
"MENU_OPEN_LINK": "Open link"
|
||||||
}
|
}
|
@ -16,6 +16,8 @@ namespace motd
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
utils::concurrency::container<links_map_t> links;
|
||||||
|
|
||||||
utils::concurrency::container<nlohmann::json, std::recursive_mutex> marketing;
|
utils::concurrency::container<nlohmann::json, std::recursive_mutex> marketing;
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> image_cache;
|
std::unordered_map<std::string, std::string> image_cache;
|
||||||
@ -91,9 +93,7 @@ namespace motd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void download_images()
|
void download_images(nlohmann::json& data)
|
||||||
{
|
|
||||||
marketing.access([&](nlohmann::json& data)
|
|
||||||
{
|
{
|
||||||
if (!data.is_object())
|
if (!data.is_object())
|
||||||
{
|
{
|
||||||
@ -102,11 +102,54 @@ namespace motd
|
|||||||
|
|
||||||
download_motd_image(data);
|
download_motd_image(data);
|
||||||
download_featured_tabs_images(data);
|
download_featured_tabs_images(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_links(links_map_t& map)
|
||||||
|
{
|
||||||
|
map =
|
||||||
|
{
|
||||||
|
{"github", "https://github.com/fedddddd/h2-mod"},
|
||||||
|
{"donate", "https://www.paypal.com/donate/?hosted_button_id=LM5BA9UABEV4Q"},
|
||||||
|
{"credits_1", "https://github.com/momo5502"},
|
||||||
|
{"credits_2", "https://github.com/VladWinner"},
|
||||||
|
{"credits_3", "https://github.com/diamante0018"},
|
||||||
|
{"credits_4", "https://github.com/JariKCoding"},
|
||||||
|
{"credits_5", "https://github.com/netadr"},
|
||||||
|
{"credits_6", "https://github.com/Joelrau"},
|
||||||
|
{"credits_7", "https://github.com/xensik"},
|
||||||
|
{"credits_8", "https://github.com/ZoneTool/zonetool"},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_links(nlohmann::json& data)
|
||||||
|
{
|
||||||
|
links.access([&](links_map_t& map)
|
||||||
|
{
|
||||||
|
init_links(map);
|
||||||
|
if (!data.is_object() || !data["links"].is_object())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& [link, url] : data["links"].items())
|
||||||
|
{
|
||||||
|
if (!url.is_string())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
map.insert(std::make_pair(link, url.get<std::string>()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(bool load_images = true)
|
void init(bool load_images = true)
|
||||||
{
|
{
|
||||||
|
links.access([](links_map_t& map)
|
||||||
|
{
|
||||||
|
init_links(map);
|
||||||
|
});
|
||||||
|
|
||||||
marketing.access([&](nlohmann::json& data)
|
marketing.access([&](nlohmann::json& data)
|
||||||
{
|
{
|
||||||
image_cache.clear();
|
image_cache.clear();
|
||||||
@ -119,9 +162,11 @@ namespace motd
|
|||||||
{
|
{
|
||||||
const auto& value = marketing_data.value();
|
const auto& value = marketing_data.value();
|
||||||
data = nlohmann::json::parse(value);
|
data = nlohmann::json::parse(value);
|
||||||
|
|
||||||
|
add_links(data);
|
||||||
if (load_images)
|
if (load_images)
|
||||||
{
|
{
|
||||||
download_images();
|
download_images(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
@ -133,6 +178,14 @@ namespace motd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
links_map_t get_links()
|
||||||
|
{
|
||||||
|
return links.access<links_map_t>([&](links_map_t& map)
|
||||||
|
{
|
||||||
|
return map;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
int get_num_featured_tabs()
|
int get_num_featured_tabs()
|
||||||
{
|
{
|
||||||
return marketing.access<nlohmann::json>([&](nlohmann::json& data)
|
return marketing.access<nlohmann::json>([&](nlohmann::json& data)
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace motd
|
namespace motd
|
||||||
{
|
{
|
||||||
|
using links_map_t = std::unordered_map<std::string, std::string>;
|
||||||
|
links_map_t get_links();
|
||||||
|
|
||||||
int get_num_featured_tabs();
|
int get_num_featured_tabs();
|
||||||
nlohmann::json get_motd();
|
nlohmann::json get_motd();
|
||||||
nlohmann::json get_featured_tab(const int index);
|
nlohmann::json get_featured_tab(const int index);
|
||||||
|
@ -334,20 +334,7 @@ namespace ui_scripting
|
|||||||
|
|
||||||
game_type["openlink"] = [](const game&, const std::string& name)
|
game_type["openlink"] = [](const game&, const std::string& name)
|
||||||
{
|
{
|
||||||
static std::unordered_map<std::string, std::string> links =
|
const auto links = motd::get_links();
|
||||||
{
|
|
||||||
{"github", "https://github.com/fedddddd/h2-mod"},
|
|
||||||
{"donate", "https://www.paypal.com/donate/?hosted_button_id=LM5BA9UABEV4Q"},
|
|
||||||
{"credits_1", "https://github.com/momo5502"},
|
|
||||||
{"credits_2", "https://github.com/VladWinner"},
|
|
||||||
{"credits_3", "https://github.com/diamante0018"},
|
|
||||||
{"credits_4", "https://github.com/JariKCoding"},
|
|
||||||
{"credits_5", "https://github.com/netadr"},
|
|
||||||
{"credits_6", "https://github.com/Joelrau"},
|
|
||||||
{"credits_7", "https://github.com/xensik"},
|
|
||||||
{"credits_8", "https://github.com/ZoneTool/zonetool"},
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto link = links.find(name);
|
const auto link = links.find(name);
|
||||||
if (link == links.end())
|
if (link == links.end())
|
||||||
{
|
{
|
||||||
@ -357,6 +344,31 @@ namespace ui_scripting
|
|||||||
ShellExecuteA(nullptr, "open", link->second.data(), nullptr, nullptr, SW_SHOWNORMAL);
|
ShellExecuteA(nullptr, "open", link->second.data(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
game_type["getlinkurl"] = [](const game&, const std::string& name)
|
||||||
|
-> script_value
|
||||||
|
{
|
||||||
|
const auto links = motd::get_links();
|
||||||
|
const auto link = links.find(name);
|
||||||
|
if (link == links.end())
|
||||||
|
{
|
||||||
|
return script_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
return link->second;
|
||||||
|
};
|
||||||
|
|
||||||
|
game_type["islink"] = [](const game&, const std::string& name)
|
||||||
|
{
|
||||||
|
const auto links = motd::get_links();
|
||||||
|
const auto link = links.find(name);
|
||||||
|
if (link == links.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
lua["string"]["escapelocalization"] = [](const std::string& str)
|
lua["string"]["escapelocalization"] = [](const std::string& str)
|
||||||
{
|
{
|
||||||
return "\x1F"s.append(str);
|
return "\x1F"s.append(str);
|
||||||
|
Loading…
Reference in New Issue
Block a user