void OpenToolOptionsDialog(string toolname) { if (toolOptionsDialog != null) { toolOptionsDialog.TryClose(); } int index = Array.FindIndex(toolBarsettings.Rows[0].Elements[0].Values, w => w.Equals(toolname.ToLowerInvariant())); string code = toolBarsettings.Rows[0].Elements[0].Icons[index]; toolOptionsDialog?.TryClose(); capi.Assets.Reload(AssetCategory.dialog); toolOptionsSettings = capi.Assets.TryGet("dialog/worldedit-tooloptions-" + code + ".json")?.ToObject <JsonDialogSettings>(); if (toolOptionsSettings == null) { return; } toolOptionsSettings.OnSet = (elem, newval) => { OnSetValueToolOptions(code, elem, newval); }; toolOptionsSettings.OnGet = OnGetValueToolOptions; isComposing = true; toolOptionsDialog = new GuiJsonDialog(toolOptionsSettings, capi); toolOptionsDialog.TryOpen(); isComposing = false; }
private void OnConfigEventClient(string eventName, ref EnumHandling handling, IAttribute data) { capi.Assets.Reload(AssetCategory.dialog); dialogSettings = capi.Assets.Get <JsonDialogSettings>(new AssetLocation("dialog/tpmanager.json")); dialogSettings.OnGet = OnGetValuesDialog; dialogSettings.OnSet = OnSetValuesDialog; dialog = new GuiJsonDialog(dialogSettings, capi); dialog.TryOpen(); }
private void OnSetValueToolOptions(string code, string elem, string newval) { if (isComposing) { return; } toolOptionsSettings = capi.Assets.TryGet("dialog/worldedit-tooloptions-" + code + ".json")?.ToObject <JsonDialogSettings>(); if (toolOptionsSettings == null) { return; } DialogRow[] rows = toolOptionsSettings.Rows; int index = 0; int row = 0; for (row = 0; row < rows.Length; row++) { index = Array.FindIndex(rows[row].Elements, el => el.Code.Equals(elem)); if (index != -1) { break; } } string cmd = rows[row].Elements[index].Param; capi.SendChatMessage(cmd + " " + newval); if (ownWorkspace.FloatValues.ContainsKey(elem)) { float val = 0; if (float.TryParse(newval, out val)) { ownWorkspace.FloatValues[elem] = val; } } if (ownWorkspace.IntValues.ContainsKey(elem)) { int val = 0; if (int.TryParse(newval, out val)) { ownWorkspace.IntValues[elem] = val; } } if (ownWorkspace.StringValues.ContainsKey(elem)) { ownWorkspace.StringValues[elem] = newval; } }
private void TriggerWorldEditDialog() { if (capi.World.Player.WorldData.CurrentGameMode != EnumGameMode.Creative) { return; } try { if (toolBarDialog == null || !toolBarDialog.IsOpened()) { clientChannel.SendPacket(new RequestWorkSpacePacket()); if (toolBarsettings == null || capi.Settings.Bool.Get("developerMode", false)) { capi.Assets.Reload(AssetCategory.dialog); toolBarsettings = capi.Assets.Get <JsonDialogSettings>(new AssetLocation("dialog/worldedit-toolbar.json")); toolBarsettings.OnGet = OnGetValueToolbar; toolBarsettings.OnSet = OnSetValueToolbar; } toolBarDialog = new GuiJsonDialog(toolBarsettings, capi); toolBarDialog.TryOpen(); if (toolBarDialog != null) { toolBarDialog.OnClosed += () => { toolOptionsDialog?.TryClose(); settingsDialog?.TryClose(); controlsDialog?.TryClose(); clientChannel.SendPacket(new RequestWorkSpacePacket()); }; } if (ownWorkspace != null && ownWorkspace.ToolName != null && ownWorkspace.ToolName.Length > 0 && ownWorkspace.ToolsEnabled) { OpenToolOptionsDialog("" + ownWorkspace.ToolName); } JsonDialogSettings dlgsettings = capi.Assets.Get <JsonDialogSettings>(new AssetLocation("dialog/worldedit-settings.json")); dlgsettings.OnGet = OnGetValueSettings; dlgsettings.OnSet = OnSetValueSettings; settingsDialog = new GuiJsonDialog(dlgsettings, capi); settingsDialog.TryOpen(); JsonDialogSettings controlsSettings = capi.Assets.Get <JsonDialogSettings>(new AssetLocation("dialog/worldedit-controls.json")); controlsSettings.OnSet = OnSetValueControls; controlsDialog = new GuiJsonDialog(controlsSettings, capi); controlsDialog.TryOpen(); } else { toolBarDialog?.TryClose(); toolOptionsDialog?.TryClose(); settingsDialog?.TryClose(); controlsDialog?.TryClose(); } } catch (Exception e) { capi.World.Logger.Error("Unable to load json dialogs: {0}", e); } }