rework QuickLinkOpener
This commit is contained in:
parent
b7ecc1e6b5
commit
40ce9dcb81
@ -1,26 +1,80 @@
|
|||||||
bool menu_visibility = false;
|
[Setting name="Number of links saved in cache"]
|
||||||
string quickURL;
|
uint S_NbOfLinksInCache = 5;
|
||||||
|
|
||||||
void Main() {}
|
const string C_LinksCache = "LinksCache.txt";
|
||||||
|
|
||||||
void Render() {
|
string G_QuickURL = "";
|
||||||
if (!menu_visibility) {
|
bool G_PressEnter = false;
|
||||||
return;
|
bool G_WasEditing = false;
|
||||||
}
|
|
||||||
UI::Begin("\\$cf9" + Icons::ExternalLinkAlt + "\\$z Quick Link Opener###Quick Link Opener", menu_visibility, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse);
|
|
||||||
quickURL = UI::InputText("", quickURL);
|
|
||||||
UI::SameLine();
|
|
||||||
if (UI::Button(Icons::ExternalLinkAlt + " Go !###QuickURL")) {
|
|
||||||
string parsedURL = Regex::Replace(quickURL,'uplay:\\/\\/launch\\/5595\\/0\\/','maniaplanet://');
|
|
||||||
CTrackMania@ app = cast<CTrackMania>(GetApp());
|
|
||||||
app.ManiaPlanetScriptAPI.OpenLink(parsedURL, CGameManiaPlanetScriptAPI::ELinkType::ManialinkBrowser);
|
|
||||||
menu_visibility = false;
|
|
||||||
}
|
|
||||||
UI::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderMenu() {
|
array<string> G_LinksCache;
|
||||||
if(UI::MenuItem("\\$cf9" + Icons::ExternalLinkAlt + "\\$z Quick Link Opener", "", menu_visibility)) {
|
|
||||||
menu_visibility = !menu_visibility;
|
void Main() {
|
||||||
|
trace("Loading links cache");
|
||||||
|
string filepath = IO::FromStorageFolder(C_LinksCache);
|
||||||
|
IO::File file(filepath);
|
||||||
|
|
||||||
|
file.Open(IO::FileMode::Read);
|
||||||
|
while(!file.EOF()) {
|
||||||
|
G_LinksCache.InsertLast(file.ReadLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderMenuMain() {
|
||||||
|
if (!G_PressEnter && UI::BeginMenu("\\$cf9" + Icons::ExternalLinkAlt + "\\$z Quick Link Opener##QuickLinkOpenerMenu")) {
|
||||||
|
G_QuickURL = UI::InputText("###quickURL", G_QuickURL, G_PressEnter, UI::InputTextFlags::EnterReturnsTrue + UI::InputTextFlags::CallbackAlways, UI::InputTextCallback(ITCB));
|
||||||
|
|
||||||
|
if (G_LinksCache.Length > 0) {
|
||||||
|
UI::Separator();
|
||||||
|
|
||||||
|
for(uint i = 0; i < G_LinksCache.Length; i++ ) {
|
||||||
|
if (UI::MenuItem(G_LinksCache[i] + "###" + i)) {
|
||||||
|
LoadLink(G_LinksCache[i], false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UI::EndMenu();
|
||||||
|
} else if (G_PressEnter || G_WasEditing) {
|
||||||
|
G_PressEnter = false;
|
||||||
|
G_WasEditing = false;
|
||||||
|
LoadLink(G_QuickURL, true);
|
||||||
|
G_QuickURL = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITCB(UI::InputTextCallbackData@ d) {
|
||||||
|
G_WasEditing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadLink(string _Url, bool _NewUrl) {
|
||||||
|
if (_Url == "") return;
|
||||||
|
|
||||||
|
string parsedURL = "";
|
||||||
|
if (_NewUrl) {
|
||||||
|
parsedURL = Regex::Replace(_Url,'uplay:\\/\\/launch\\/5595\\/0\\/','maniaplanet://');
|
||||||
|
|
||||||
|
G_LinksCache.InsertAt(0, parsedURL);
|
||||||
|
|
||||||
|
// Clear cache if too long
|
||||||
|
if (G_LinksCache.Length > S_NbOfLinksInCache) {
|
||||||
|
G_LinksCache.RemoveRange(S_NbOfLinksInCache, G_LinksCache.Length - S_NbOfLinksInCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute text for the cache file
|
||||||
|
string content;
|
||||||
|
for(uint i = 0; i < G_LinksCache.Length; i++ ) {
|
||||||
|
content = content + G_LinksCache[i] + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
trace("Writing links cache");
|
||||||
|
string filepath = IO::FromStorageFolder(C_LinksCache);
|
||||||
|
IO::File file(filepath, IO::FileMode::Write);
|
||||||
|
file.Write(content);
|
||||||
|
} else {
|
||||||
|
parsedURL = _Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTrackMania@ app = cast<CTrackMania>(GetApp());
|
||||||
|
app.ManiaPlanetScriptAPI.OpenLink(parsedURL, CGameManiaPlanetScriptAPI::ELinkType::ManialinkBrowser);
|
||||||
|
}
|
||||||
|
@ -4,11 +4,6 @@ author = "Beu"
|
|||||||
category = "Utilities"
|
category = "Utilities"
|
||||||
|
|
||||||
siteid = 101
|
siteid = 101
|
||||||
version = "1.1"
|
version = "2.0"
|
||||||
|
|
||||||
perms = "paid"
|
|
||||||
|
|
||||||
blocks = [ "Plugin_QuickLinkOpener" ]
|
blocks = [ "Plugin_QuickLinkOpener" ]
|
||||||
|
|
||||||
[script]
|
|
||||||
imports = [ "Icons.as" ]
|
|
Loading…
Reference in New Issue
Block a user