/// <summary> /// Example: DisplayHi calls DisplayHi(); /// </summary> public static void ExecuteFunction(string funcName) { if (string.IsNullOrWhiteSpace(funcName)) { RAGE.Chat.Output("[ExecuteFunction(string fn)]: fn null or empty or whitespace"); return; } MainBrowser.ExecuteJs($"{funcName}();"); }
private void UpdateProgressBar(object[] args) { //ProvideError(args); Guid id; if (!Guid.TryParse(args[0].ToString(), out id)) { return; } int currentValue; if (!int.TryParse(args[1].ToString(), out currentValue)) { return; } bool showCurrentValue = false; bool.TryParse(args[2].ToString(), out showCurrentValue); string currentValueText = ""; if (showCurrentValue) { currentValueText = currentValue + "%"; } BrowserWindow.ExecuteJs($"document.getElementById(\"{id}\").setAttribute(\"style\", \"width:{currentValue}%\"); document.getElementById(\"{id}\").innerHTML=\"{currentValueText}\""); }
public void OnSetChatState(object[] args) { if (args[0] == null) { return; } var state = (bool)args[0]; ChatBrowser.ExecuteJs(state ? "setEnabled(true);" : "setEnabled(false);"); }
private void ShowErrorAlert(object[] args) { switch ((int)args[0]) { case 1: browserLogin.ExecuteJs("ShowError()"); break; case 2: browserLogin.ExecuteJs("ShowError2()"); break; case 3: browserLogin.ExecuteJs("ShowError3()"); break; case 4: browserLogin.ExecuteJs("ShowError4()"); break; } }
public static void ExecuteBrowserFunction(HtmlWindow browser, string function, object[] parameters) { // Check for the parameters string input = string.Empty; foreach (object argument in parameters) { // Append all the arguments input += input.Length > 0 ? (", '" + argument.ToString() + "'") : ("'" + argument.ToString() + "'"); } // Call the function with the parameters browser.ExecuteJs(function + "(" + input + ");"); }
public static void ExecuteFunctionEvent(object[] args) { // Check for the parameters string input = string.Empty; // Split the function and arguments string function = args[0].ToString(); object[] arguments = args.Skip(1).ToArray(); foreach (object arg in arguments) { // Append all the arguments input += input.Length > 0 ? (", '" + arg.ToString() + "'") : ("'" + arg.ToString() + "'"); } // Call the function with the parameters customBrowser.ExecuteJs(function + "(" + input + ");"); }
/// <summary> /// This is the main method, where the browser gets created in general. /// </summary> /// <param name="args"></param> private void CreateBrowserEvents(string json) { try { this.BrowserModel = JsonConvert.DeserializeObject <Browser>(json); if (BrowserWindow != null) { BrowserWindow.Destroy(); BrowserWindow = null; } BrowserWindow = new HtmlWindow(BrowserModel.Path) { Active = false }; BrowserWindow.Active = true; Cursor.Visible = true; List <IBrowserElement> allElements = new List <IBrowserElement>(); // Dirty allElements.AddRange(BrowserModel.Buttons); allElements.AddRange(BrowserModel.Titles); allElements.AddRange(BrowserModel.Texts); allElements.AddRange(BrowserModel.CheckBoxes); allElements.AddRange(BrowserModel.TextBoxes); allElements.AddRange(BrowserModel.Cards); allElements.AddRange(BrowserModel.DropDowns); allElements.AddRange(BrowserModel.PasswordTextBoxes); allElements.AddRange(BrowserModel.ProgressBars); allElements.AddRange(BrowserModel.Container); allElements.AddRange(BrowserModel.Icons); //this.HiddenValues = new Dictionary<Guid, string>(); //foreach (var element in allElements) //{ // switch (element.Type) // { // case BrowserElementType.DropDown: // var dropDown = element as BrowserDropDown; // if (dropDown == null) // continue; // foreach (var dropValue in dropDown.Values) // { // if (this.TryParseJSON(dropValue.HiddenValue, out JObject obj)) // { // this.HiddenValues.Add(dropValue.Id, dropValue.HiddenValue); // } // } // break; // case BrowserElementType.Button: // //var button = element as BrowserButton; // //if (this.TryParseJSON(button.HiddenValue, out JObject obj)) // //{ // // this.HiddenValues.Add(button.Id, button.); // //} // break; // default: // break; // } //} string backgroundColor = ""; if (!string.IsNullOrEmpty(this.BrowserModel.BackgroundColor)) { backgroundColor = new Stylesheet("background-color", this.BrowserModel.BackgroundColor).ToString(); } string opacity = ""; if (!string.IsNullOrEmpty(this.BrowserModel.Opacity)) { opacity = new Stylesheet("opacity", this.BrowserModel.Opacity).ToString(); } string scrollBarX = ""; if (this.BrowserModel.ScrollBarX) { scrollBarX = new Stylesheet("overflow-x", "scroll").ToString(); } else { scrollBarX = new Stylesheet("overflow-x", "hidden").ToString(); } string scrollBarY = ""; if (this.BrowserModel.ScrollBarY) { scrollBarY = new Stylesheet("overflow-y", "scroll").ToString(); } else { scrollBarY = new Stylesheet("overflow-y", "hidden").ToString(); } string margin = ""; if (!string.IsNullOrEmpty(this.BrowserModel.Margin)) { margin = new Stylesheet("margin", this.BrowserModel.Margin).ToString(); } string padding = ""; if (!string.IsNullOrEmpty(this.BrowserModel.Padding)) { padding = new Stylesheet("padding", this.BrowserModel.Padding).ToString(); } string jsToExecute = $"document.getElementById('DavWebCreator').setAttribute(\"style\",\"text-align:center;{backgroundColor}{margin}{padding}{opacity}{scrollBarX}{scrollBarY}display:block;background-color:transparent;width:{this.BrowserModel.Width};height:{this.BrowserModel.Height}\");"; jsToExecute += $"document.getElementById('DavWebCreator').setAttribute(\"z-index\",\"130;\");"; string align = GetContentAlignment(BrowserModel.ContentPosition); string browserAlignAddClass = $"document.getElementById('DavWebCreator').className +=' p-2 {align}';"; switch (this.BrowserModel.Type) { case BrowserType.Custom: // Default string mid = GetHtmlStringByElements(allElements); //ProvideError(mid); if (!string.IsNullOrEmpty(mid)) { BrowserWindow.ExecuteJs($"{browserAlignAddClass}{jsToExecute}document.getElementById('DavWebCreator').innerHTML = '{mid}';"); } break; case BrowserType.Selection: string selection = GetHtmlStringByElements(allElements); BrowserWindow.ExecuteJs($"document.getElementById('Content').innerHTML ='{selection}';{jsToExecute}"); break; } } catch (Exception e) { //ProvideError(e); } }
private void OnTick(List <Events.TickNametagData> nametags) { if (DateTime.Now > oldDateTime) { var player = RAGE.Elements.Player.LocalPlayer; var rotation = Math.PI / 180 * (player.GetRotation(0).Z * -1); var streamedPlayers = RAGE.Elements.Entities.Players.All; var playerNames = new List <string>(); if (player.GetSharedData("CALLING_PLAYER_NAME") != null && player.GetSharedData("CALL_IS_STARTED") != null && player.GetSharedData("CALL_IS_STARTED").ToString() == "1") { var callingPlayerName = player.GetSharedData("CALLING_PLAYER_NAME").ToString(); if (callingPlayerName != "") { playerNames.Add(callingPlayerName + "~10~0~0~3"); } } for (var i = 0; i < streamedPlayers.Count; i++) { if (streamedPlayers[i] != null && !streamedPlayers[i].Exists) { continue; } if (streamedPlayers[i].GetSharedData("TsName") == null) { continue; } var streamedPlayerPos = streamedPlayers[i].Position; var distance = player.Position.DistanceTo2D(streamedPlayerPos); var voiceRange = "Normal"; if (streamedPlayers[i].GetSharedData("VOICE_RANGE") != null) { voiceRange = streamedPlayers[i].GetSharedData("VOICE_RANGE").ToString(); } float volumeModifier = 0; var range = 12; if (voiceRange == "Weit") { range = 50; gta5voice_ui_cef.ExecuteJs("(document.getElementById('voiceColor')).style.backgroundColor = 'rgba(255, 0, 0, 0.72)';"); } else if (voiceRange == "Normal") { range = 15; gta5voice_ui_cef.ExecuteJs("(document.getElementById('voiceColor')).style.backgroundColor = 'rgba(255, 0, 0, 0.39)';"); } else if (voiceRange == "Kurz") { gta5voice_ui_cef.ExecuteJs("(document.getElementById('voiceColor')).style.backgroundColor = 'rgba(255, 0, 0, 0.21)';"); range = 5; } else if (voiceRange == "Stumm") { gta5voice_ui_cef.ExecuteJs("(document.getElementById('voiceColor')).style.backgroundColor = 'rgba(255, 0, 0, 0)';"); range = 0; } if (distance > 5) { volumeModifier = (distance * -8 / 10); } if (volumeModifier > 0) { volumeModifier = 0; } if (distance < range) { var subPos = streamedPlayerPos.Subtract(player.Position); var x = subPos.X * Math.Cos(rotation) - subPos.Y * Math.Sin(rotation); var y = subPos.X * Math.Sin(rotation) + subPos.Y * Math.Cos(rotation); x = x * 10 / range; y = y * 10 / range; playerNames.Add(streamedPlayers[i].GetSharedData("TsName").ToString() + "~" + (Math.Round(x * 1000) / 1000) + "~" + (Math.Round(y * 1000) / 1000) + "~0~" + (Math.Round(volumeModifier * 1000) / 1000)); } } if (tsBrowser == null) { tsBrowser = new HtmlWindow($"http://localhost:15555/players/{tsname}/{string.Join(";", playerNames)}/"); } else { tsBrowser.Url = $"http://localhost:15555/players/{tsname}/{string.Join(";", playerNames)}/"; } oldDateTime = DateTime.Now.AddMilliseconds(500); } }
private void OpenCarshopBrowser(object[] args) { carsBrowser = new HtmlWindow("package://statics/business/ventaveh.html"); carsBrowser.ExecuteJs($"setCarShopInfo('{args[0].ToString()}', '{args[1].ToString()}', {(int)args[2]})"); Cursor.Visible = true; }
public static void ExecuteModuleMutation(string module, string mutation, object payload) { string type = payload.GetType().Name; switch (type) { case "Int32": { Window.ExecuteJs($"store.commit('{module}/{mutation}', {Convert.ToInt32(payload)})"); break; } case "String": { Window.ExecuteJs($"store.commit('{module}/{mutation}', '{payload.ToString()}')"); break; } case "Boolean": { Window.ExecuteJs($"store.commit('{module}/{mutation}', {payload.ToString().ToLower()})"); break; } default: { RAGE.Ui.Console.Log(ConsoleVerbosity.Error, "CEF-ERROR: Invalid type."); break; } } }
private void OpenBusinessBuyBrowser(object[] args) { busBrowser = new HtmlWindow("package://statics/business/venta.html"); busBrowser.ExecuteJs($"setBusinessInfo('{args[0].ToString()}', {(int)args[1]}, '{args[2].ToString()}')"); Cursor.Visible = true; }