public ShortcutModel() { while (ShortcutKeys.Count() < 2) { ShortcutKeys.Add(new Keys()); } }
private void AddElement(ShortcutKeys ele) { ShortcutKeyControlElement keyControlElement = new ShortcutKeyControlElement(this.ParentWindow, this.ParentSettingsWindow); BlueStacksUIBinding.Bind(keyControlElement.mShortcutNameTextBlock, ele.ShortcutName, ""); string[] strArray = ele.ShortcutKey.Split(new char[2] { '+', ' ' }, StringSplitOptions.RemoveEmptyEntries); string str = string.Empty; foreach (string key in strArray) { str = str + LocaleStrings.GetLocalizedString(Constants.ImapLocaleStringsConstant + IMAPKeys.GetStringForUI(key), "") + " + "; } this.mShortcutUIElements[ele.ShortcutCategory].Item2.Add(keyControlElement); if (!string.IsNullOrEmpty(str)) { keyControlElement.mShortcutKeyTextBox.Text = str.Substring(0, str.Length - 3); } keyControlElement.mUserDefinedConfigList = new List <ShortcutKeys>() { ele }; if (!ele.ReadOnlyTextbox) { return; } keyControlElement.mShortcutKeyTextBox.IsEnabled = false; }
private const int cCaption = 32; // Caption bar height public Form1() { InitializeComponent(); mybrush = new SolidBrush(this.BackColor); // Adds a new shortcut key that will invoke CreateNewForm every time Ctrl+F is pressed ShortcutKeys.Add(Keys.Control | Keys.F, CreateNewForm); this.FormBorderStyle = FormBorderStyle.None; this.DoubleBuffered = true; this.SetStyle(ControlStyles.ResizeRedraw, true); }
public override string ToString() { var output = string.Empty; var key1 = ShortcutKeys.Count() >= 1 ? ShortcutKeys[0].ToString() : ""; var key2 = ShortcutKeys.Count() >= 2 ? ShortcutKeys[1].ToString() : ""; output += !string.IsNullOrWhiteSpace(key1) ? key1 : ""; output += !string.IsNullOrWhiteSpace(key2) ? (", " + key2) : ""; return(output); }
/// <summary> /// Override the process command key method so that we can implement global keyboard /// shortcuts. /// </summary> /// <param name="msg">The windows message to process</param> /// <param name="keyData">The key to process</param> /// <returns>True if command key was processed.</returns> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (ShortcutKeyPressed != null && ShortcutKeys != null && ShortcutKeys.Contains(keyData)) { ShortcutKeyPressed.Invoke(this, new KeysArgs() { Keys = keyData }); return(true); } return(base.ProcessCmdKey(ref msg, keyData)); }
/* ----------------------------------------------------------------- */ /// /// OnBind /// /// <summary> /// Invokes the binding to the specified object. /// </summary> /// /* ----------------------------------------------------------------- */ protected override void OnBind(IPresentable src) { base.OnBind(src); if (src is not MainViewModel vm) { return; } MainBindingSource.DataSource = vm; var ctx = new FileContextMenu(() => SelectedIndices.Count() > 0); ctx.PreviewMenu.Click += (s, e) => vm.Preview(SelectedIndices); ctx.UpMenu.Click += (s, e) => vm.Move(SelectedIndices, -1); ctx.DownMenu.Click += (s, e) => vm.Move(SelectedIndices, 1); ctx.RemoveMenu.Click += (s, e) => vm.Remove(SelectedIndices); FileListView.ContextMenuStrip = ctx; FileListView.DataSource = vm.Files; Shown += (s, e) => vm.Setup(); MergeButton.Click += (s, e) => vm.Merge(); SplitButton.Click += (s, e) => vm.Split(); FileButton.Click += (s, e) => vm.Add(); UpButton.Click += (s, e) => vm.Move(SelectedIndices, -1); DownButton.Click += (s, e) => vm.Move(SelectedIndices, 1); RemoveButton.Click += (s, e) => vm.Remove(SelectedIndices); ClearButton.Click += (s, e) => vm.Clear(); TitleButton.Click += (s, e) => vm.About(); FileListView.DoubleClick += (s, e) => vm.Preview(SelectedIndices); ShortcutKeys.Clear(); ShortcutKeys.Add(Keys.Control | Keys.Shift | Keys.D, vm.Clear); ShortcutKeys.Add(Keys.Control | Keys.O, vm.Add); ShortcutKeys.Add(Keys.Control | Keys.H, vm.About); ShortcutKeys.Add(Keys.Control | Keys.K, () => vm.Move(SelectedIndices, -1)); ShortcutKeys.Add(Keys.Control | Keys.J, () => vm.Move(SelectedIndices, 1)); ShortcutKeys.Add(Keys.Control | Keys.M, () => vm.Invokable.Then(vm.Merge)); ShortcutKeys.Add(Keys.Control | Keys.S, () => vm.Invokable.Then(vm.Split)); Behaviors.Add(new CloseBehavior(vm, this)); Behaviors.Add(new DialogBehavior(vm)); Behaviors.Add(new OpenFileBehavior(vm)); Behaviors.Add(new OpenDirectoryBehavior(vm)); Behaviors.Add(new SaveFileBehavior(vm)); Behaviors.Add(new FileDropBehavior(vm, this)); Behaviors.Add(new ShowDialogBehavior <PasswordWindow, PasswordViewModel>(vm)); Behaviors.Add(new ShowDialogBehavior <VersionWindow, VersionViewModel>(vm)); Behaviors.Add(vm.Subscribe <CollectionMessage>(e => vm.Files.ResetBindings(false))); Behaviors.Add(vm.Subscribe <SelectMessage>(e => Select(e.Value))); Behaviors.Add(vm.Subscribe <PreviewMessage>(e => Process.Start(e.Value))); }
/// <summary> /// Override WndProc to handle incoming Windows messages. /// </summary> /// <param name="m">Message from Windows</param> protected override void WndProc(ref Message m) { this.lblMinQuestionController.Text = this.questionControllerText; // TODO if (m.Msg == Win32Usb.WM_DEVICECHANGE) // we got a device change message! A USB device was inserted or removed { switch (m.WParam.ToInt32()) // Check the W parameter to see if a device was inserted or removed { case Win32Usb.DEVICE_ARRIVAL: // inserted OnDeviceArrived(new EventArgs()); break; case Win32Usb.DEVICE_REMOVECOMPLETE: // removed OnDeviceRemoved(new EventArgs()); break; } } else if (m.Msg == WindowsShell.WM_HOTKEY) { if (!this.isModalDialogOpen) { int id = m.WParam.ToInt32(); ShortcutKeys key = (ShortcutKeys)id; switch (key) { case ShortcutKeys.Reset: this.Reset(); break; case ShortcutKeys.NextBuzz: this.NextBuzz(); break; case ShortcutKeys.LightCheck: this.LightCheck(); break; case ShortcutKeys.Countdown: this.StartBonusCountdown(); break; case ShortcutKeys.PreviousBuzz: this.LightPreviousBuzz(); break; } } } base.WndProc(ref m); // pass message on to base form }
/* ----------------------------------------------------------------- */ /// /// CustomizeWindow /// /// <summary> /// Initiaizes a new instance of the CustomizeWindow class. /// </summary> /// /* ----------------------------------------------------------------- */ public CustomizeWindow() { InitializeComponent(); _menu = new(SourceTreeView, DestinationTreeView); _menu.Updated += (s, e) => { RenameButton.Enabled = _menu.Editable; RemoveButton.Enabled = _menu.Editable; UpButton.Enabled = _menu.Editable; DownButton.Enabled = _menu.Editable; }; ShortcutKeys.Add(Keys.F2, () => _menu.RenameMenu.Execute()); }
/// <summary> /// Override the process command key method so that we can implement global keyboard /// shortcuts. /// </summary> /// <param name="msg">The windows message to process</param> /// <param name="keyData">The key to process</param> /// <returns>True if command key was processed.</returns> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (ShortcutKeyPressed != null && ShortcutKeys != null) { KeysConverter kc = new KeysConverter(); string keyName = kc.ConvertToString(keyData); if (ShortcutKeys.Contains(keyName)) { ShortcutKeyPressed.Invoke(this, new KeysArgs() { Keys = keyData }); return(true); } } return(base.ProcessCmdKey(ref msg, keyData)); }
/* ----------------------------------------------------------------- */ /// /// CustomizeForm /// /// <summary> /// オブジェクトを初期化します。 /// </summary> /// /* ----------------------------------------------------------------- */ public CustomizeForm() { InitializeComponent(); _menu = new CustomizeMenu(SourceTreeView, DestinationTreeView); _menu.Updated += (s, e) => UpdateMenu(); ApplyButton.Click += (s, e) => Close(); ExitButton.Click += (s, e) => Close(); RenameButton.Click += (s, e) => _menu.RenameMenu.Execute(); AddButton.Click += (s, e) => _menu.AddMenu.Execute(); NewCategoryButton.Click += (s, e) => _menu.NewCategoryMenu.Execute(); RemoveButton.Click += (s, e) => _menu.RemoveMenu.Execute(); UpButton.Click += (s, e) => _menu.UpMenu.Execute(); DownButton.Click += (s, e) => _menu.DownMenu.Execute(); ShortcutKeys.Add(Keys.F2, () => _menu.RenameMenu.Execute()); }
/* ----------------------------------------------------------------- */ /// /// MainForm /// /// <summary> /// オブジェクトを初期化します。 /// </summary> /// /* ----------------------------------------------------------------- */ public MainForm() { InitializeComponent(); // Event handlers ExitButton.Click += (s, e) => Close(); OpenButton.Click += (s, e) => RaiseOpen(); AttachButton.Click += (s, e) => RaiseAttach(); DetachButton.Click += (s, e) => RaiseDetach(); ResetButton.Click += (s, e) => RaiseReset(); SaveButton.Click += (s, e) => RaiseSave(); VersionButton.Click += (s, e) => RaiseVersion(); MyClipDataView.RowsAdded += WhenRowCountChanged; MyClipDataView.RowsRemoved += WhenRowCountChanged; SourceTextBox.TextChanged += WhenSourceChanged; // Shortcut keys ShortcutKeys.Add(Keys.Delete, RaiseDetach); ShortcutKeys.Add(Keys.Control | Keys.D, RaiseDetach); ShortcutKeys.Add(Keys.Control | Keys.H, RaiseVersion); ShortcutKeys.Add(Keys.Control | Keys.N, RaiseAttach); ShortcutKeys.Add(Keys.Control | Keys.O, RaiseOpen); ShortcutKeys.Add(Keys.Control | Keys.R, RaiseReset); ShortcutKeys.Add(Keys.Control | Keys.S, RaiseSave); // Properties Source = "WhenSourceChanged(object, EventArgs)"; Source = string.Empty; Text = $"{ProductName} {ProductVersion} ({ProductPlatform})"; // ToolTip var tips = new ToolTip { InitialDelay = 200, AutoPopDelay = 5000, ReshowDelay = 1000 }; tips.SetToolTip(VersionButton, Properties.Resources.VersionTitle); tips.SetToolTip(OpenButton, Properties.Resources.SourceTitle); }
public static Keys ToKeys(ShortcutKeys shortcutKeys) { Keys equivalentShortcut = (Keys)shortcutKeys.Key; KeyModifiers code = shortcutKeys.Modifiers; if (code.HasFlag(KeyModifiers.Shift)) { equivalentShortcut |= Keys.Shift; } if (code.HasFlag(KeyModifiers.Control)) { equivalentShortcut |= Keys.Control; } if (code.HasFlag(KeyModifiers.Alt)) { equivalentShortcut |= Keys.Alt; } return(equivalentShortcut); }
/* ----------------------------------------------------------------- */ /// /// InitializeEvents /// /// <summary> /// イベントを初期化します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void InitializeEvents() { TitleButton.Click += (s, e) => Aggregator.GetEvents()?.Version.Publish(); FileButton.Click += (s, e) => Aggregator.GetEvents()?.Add.Publish(null); RemoveButton.Click += (s, e) => Aggregator.GetEvents()?.Remove.Publish(); ClearButton.Click += (s, e) => Aggregator.GetEvents()?.Clear.Publish(); UpButton.Click += (s, e) => Aggregator.GetEvents()?.Move.Publish(-1); DownButton.Click += (s, e) => Aggregator.GetEvents()?.Move.Publish(1); MergeButton.Click += (s, e) => Aggregator.GetEvents()?.Merge.Publish(); SplitButton.Click += (s, e) => Aggregator.GetEvents()?.Split.Publish(); ExitButton.Click += (s, e) => Close(); FileMenu.Aggregator = Aggregator; FileListView.ContextMenuStrip = FileMenu; //FileListView.DragEnter += (s, e) => OnDragEnter(e); //FileListView.DragDrop += (s, e) => OnDragDrop(e); ButtonsPanel.DragEnter += (s, e) => OnDragEnter(e); ButtonsPanel.DragDrop += (s, e) => OnDragDrop(e); FooterPanel.DragEnter += (s, e) => OnDragEnter(e); FooterPanel.DragDrop += (s, e) => OnDragDrop(e); ShortcutKeys.Add(Keys.Control | Keys.A, SelectAll); ShortcutKeys.Add(Keys.Control | Keys.D, () => Aggregator?.GetEvents()?.Remove.Publish()); ShortcutKeys.Add(Keys.Control | Keys.H, () => Aggregator?.GetEvents()?.Version.Publish()); ShortcutKeys.Add(Keys.Control | Keys.J, () => Aggregator.GetEvents()?.Move.Publish(1)); ShortcutKeys.Add(Keys.Control | Keys.K, () => Aggregator.GetEvents()?.Move.Publish(-1)); ShortcutKeys.Add(Keys.Control | Keys.M, () => Aggregator?.GetEvents()?.Merge.Publish()); ShortcutKeys.Add(Keys.Control | Keys.O, () => Aggregator.GetEvents()?.Add.Publish(null)); ShortcutKeys.Add(Keys.Control | Keys.R, () => Aggregator.GetEvents()?.Preview.Publish()); ShortcutKeys.Add(Keys.Control | Keys.S, () => Aggregator.GetEvents()?.Split.Publish()); ShortcutKeys.Add(Keys.Control | Keys.Up, () => Aggregator.GetEvents()?.Move.Publish(-1)); ShortcutKeys.Add(Keys.Control | Keys.Down, () => Aggregator.GetEvents()?.Move.Publish(1)); ShortcutKeys.Add(Keys.Control | Keys.Shift | Keys.D, () => Aggregator?.GetEvents()?.Clear.Publish()); ShortcutKeys.Add(Keys.Delete, () => Aggregator?.GetEvents()?.Remove.Publish()); }
public ShortcutModel(string shortcut) { //Console.WriteLine($"input:\t{shortcut}"); foreach (var v in shortcut.Split(',')) { //Console.WriteLine($"\npart:\t{v}"); var keys = new Keys(); foreach (var z in v.Split('+')) { //Console.WriteLine($"\n\nkey:\t{z}"); if (z == "Ctrl") { keys.Control = true; } else if (z == "Alt") { keys.Alt = true; } else if (z == "Shift") { keys.Shift = true; } else { keys.Key = z; } } //Console.WriteLine($"\nkeys:\t{keys.ToString()}"); ShortcutKeys.Add(keys); } //Console.WriteLine($"\ndone:\t{this.ToString()}"); }
// 覆盖OnPaint方法 protected override void OnPaint(PaintEventArgs e) { try { base.OnPaint(e); Graphics g = e.Graphics; Rectangle bounds = new Rectangle(0, 0, Width, Height); bool selected = IsMouseHover; bool hasicon = (!(Image == null)); bool hassubmenu = (DropDown.Items.Count > 0); bool ena = Enabled; DrawBackground(g, bounds, hasicon, IsMouseHover, ena); if (hasicon) { DrawIcon(g, Image, bounds, selected, Enabled, Checked); } else if (Checked) { DrawCheckmark(g, bounds, selected, hasicon); } if ((hassubmenu)) { try { //从项目资源文件中读取 Properties.Resources.Key 同样可以读取到项目资源文件中的值 Image menuArrow = (Image)Properties.Resources.MenuArrow; if ((iconArrow == null)) { DrawSubMenuArrow(g, menuArrow, bounds, selected, Enabled, Checked); } else { DrawSubMenuArrow(g, iconArrow, bounds, selected, Enabled, Checked); } } catch (Exception ex) { //MessageBox.Show(String.Format("hassubmenu got error:{0}", ex.Message)); } } if (Text == "-") { DrawSeparator(g, bounds); } else { if (ShortcutKeys.Equals(Shortcut.None)) { shortcuttext = ""; } else { string text = ""; int key = System.Convert.ToInt32(ShortcutKeys); int ch = key & 0xFF; if ((System.Convert.ToInt32(Keys.Control) & key) > 0) { text += "Ctrl+"; } if ((System.Convert.ToInt32(Keys.Shift) & key) > 0) { text += "Shift+"; } if ((System.Convert.ToInt32(Keys.Alt) & key) > 0) { text += "Alt+"; } if ((ch >= System.Convert.ToInt32(Shortcut.F1)) & (ch <= System.Convert.ToInt32(Shortcut.F12))) { text += "F" + (ch - 111).ToString(); } else if (ShortcutKeys.Equals(Shortcut.Del)) { text += "Del"; } else { text += System.Convert.ToChar(ch); } if ((DropDown.Items.Count > 0)) { } shortcuttext = text; } DrawMenuText(g, bounds, Text, shortcuttext, IsMouseHover, ena); } } catch { } }
private static void LoadObjectDbXml(string file) { var xmlSettings = XElement.Load(file); // Load Colors foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor")) { string name = (string)xElement.Attribute("Name"); XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color")); GlobalColors.Add(name, color); } foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile")) { var curTile = new TileProperty(); // Read XML attributes curTile.Color = ColorFromString((string)xElement.Attribute("Color")); curTile.Name = (string)xElement.Attribute("Name"); curTile.Id = (int?)xElement.Attribute("Id") ?? 0; curTile.IsFramed = (bool?)xElement.Attribute("Framed") ?? false; curTile.IsSolid = (bool?)xElement.Attribute("Solid") ?? false; curTile.IsSolidTop = (bool?)xElement.Attribute("SolidTop") ?? false; curTile.IsLight = (bool?)xElement.Attribute("Light") ?? false; curTile.FrameSize = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1); curTile.Placement = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement")); curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16); curTile.IsGrass = "Grass".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsPlatform = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsCactus = "Cactus".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsStone = (bool?)xElement.Attribute("Stone") ?? false; /* Heathtech */ curTile.CanBlend = (bool?)xElement.Attribute("Blends") ?? false; /* Heathtech */ curTile.MergeWith = (int?)xElement.Attribute("MergeWith") ?? null; /* Heathtech */ foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame")) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = (string)elementFrame.Attribute("Name"); curFrame.Variety = (string)elementFrame.Attribute("Variety"); curFrame.UV = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0); curFrame.Anchor = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor")); // Assign a default name if none existed if (string.IsNullOrWhiteSpace(curFrame.Name)) { curFrame.Name = curTile.Name; } curTile.Frames.Add(curFrame); Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = curFrame.Name + ", " + curFrame.Variety, Origin = curFrame.UV, Size = curTile.FrameSize, Tile = (byte)curTile.Id, TileName = curTile.Name }); if (curTile.FrameSize.X == 0 && curTile.FrameSize.Y == 0) { int z = 0; } } if (curTile.Frames.Count == 0 && curTile.IsFramed) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = curTile.Name; curFrame.Variety = string.Empty; curFrame.UV = new Vector2Short(0, 0); //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor")); // Assign a default name if none existed if (string.IsNullOrWhiteSpace(curFrame.Name)) { curFrame.Name = curTile.Name; } curTile.Frames.Add(curFrame); Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = curFrame.Name + ", " + curFrame.Variety, Origin = curFrame.UV, Size = curTile.FrameSize, Tile = (byte)curTile.Id, TileName = curTile.Name }); } TileProperties.Add(curTile); if (!curTile.IsFramed) { TileBricks.Add(curTile); } } for (int i = TileProperties.Count; i < 255; i++) { TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true)); } foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall")) { var curWall = new WallProperty(); curWall.Color = ColorFromString((string)xElement.Attribute("Color")); curWall.Name = (string)xElement.Attribute("Name"); curWall.Id = (int?)xElement.Attribute("Id") ?? -1; curWall.IsHouse = (bool?)xElement.Attribute("IsHouse") ?? false; WallProperties.Add(curWall); } foreach (var xElement in xmlSettings.Elements("Items").Elements("Item")) { var curItem = new ItemProperty(); curItem.Id = (int?)xElement.Attribute("Id") ?? -1; curItem.Name = (string)xElement.Attribute("Name"); ItemProperties.Add(curItem); _itemLookup.Add(curItem.Id, curItem); } foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); NpcIds.Add(name, id); int frames = (int?)xElement.Attribute("Frames") ?? 16; NpcFrames.Add(id, frames); } foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); ItemPrefix.Add((byte)id, name); } foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut")) { var key = InLineEnumTryParse <Key>((string)xElement.Attribute("Key")); var tool = (string)xElement.Attribute("Tool"); ShortcutKeys.Add(key, tool); } XElement appSettings = xmlSettings.Element("App"); int appWidth = (int?)appSettings.Attribute("Width") ?? 800; int appHeight = (int?)appSettings.Attribute("Height") ?? 600; _appSize = new Vector2(appWidth, appHeight); ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools")); AltC = (string)xmlSettings.Element("AltC"); }
private static void LoadObjectDbXml(string file) { var xmlSettings = XElement.Load(file); // Load Colors foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor")) { string name = (string)xElement.Attribute("Name"); XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color")); GlobalColors.Add(name, color); } foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile")) { var curTile = new TileProperty(); // Read XML attributes curTile.Color = ColorFromString((string)xElement.Attribute("Color")); curTile.Name = (string)xElement.Attribute("Name"); curTile.Id = (int?)xElement.Attribute("Id") ?? 0; curTile.IsFramed = (bool?)xElement.Attribute("Framed") ?? false; curTile.IsSolid = (bool?)xElement.Attribute("Solid") ?? false; curTile.IsSolidTop = (bool?)xElement.Attribute("SolidTop") ?? false; curTile.IsLight = (bool?)xElement.Attribute("Light") ?? false; curTile.FrameSize = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1); curTile.Placement = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement")); curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16); curTile.IsGrass = "Grass".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsPlatform = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsCactus = "Cactus".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsStone = (bool?)xElement.Attribute("Stone") ?? false; /* Heathtech */ curTile.CanBlend = (bool?)xElement.Attribute("Blends") ?? false; /* Heathtech */ curTile.MergeWith = (int?)xElement.Attribute("MergeWith") ?? null; /* Heathtech */ curTile.HasFrameName = curTile.IsFramed && ((bool?)xElement.Attribute("UseFrameName") ?? false); string frameNamePostfix = (string)xElement.Attribute("FrameNamePostfix") ?? null; foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame")) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = (string)elementFrame.Attribute("Name"); curFrame.Variety = (string)elementFrame.Attribute("Variety"); curFrame.UV = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0); curFrame.Anchor = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor")); var frameSize = StringToVector2Short((string)elementFrame.Attribute("FrameSize"), curTile.FrameSize.X, curTile.FrameSize.Y); // Assign a default name if none existed if (string.IsNullOrWhiteSpace(curFrame.Name)) { curFrame.Name = curTile.Name; } curTile.Frames.Add(curFrame); string spriteName = null; if (curFrame.Name == curTile.Name) { if (!string.IsNullOrWhiteSpace(curFrame.Variety)) { spriteName += curFrame.Variety; } } else { spriteName += curFrame.Name; if (!string.IsNullOrWhiteSpace(curFrame.Variety)) { spriteName += " - " + curFrame.Variety; } } Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = spriteName, Origin = curFrame.UV, Size = frameSize, Tile = (ushort)curTile.Id, /* SBlogic */ TileName = curTile.Name }); if (curTile.HasFrameName) { string frameName = curFrame.Name; if (frameNamePostfix != null) { frameName += " (" + frameNamePostfix + ")"; } if (curFrame.Variety != null) { frameName += ", " + curFrame.Variety; } // TODO: There must be a more efficient way than to store each frame... for (int x = 0, mx = curTile.FrameSize.X; x < mx; x++) { for (int y = 0, my = curTile.FrameSize.Y; y < my; y++) { string frameNameKey = GetFrameNameKey(curTile.Id, (short)(curFrame.UV.X + (x * 18)), (short)(curFrame.UV.Y + (y * 18))); if (!FrameNames.ContainsKey(frameNameKey)) { FrameNames.Add(frameNameKey, frameName); } else { System.Diagnostics.Debug.WriteLine(curFrame.Name + " collided with " + frameNameKey); } } } } } if (curTile.Frames.Count == 0 && curTile.IsFramed) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = curTile.Name; curFrame.Variety = string.Empty; curFrame.UV = new Vector2Short(0, 0); //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor")); curTile.Frames.Add(curFrame); Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = null, Origin = curFrame.UV, Size = curTile.FrameSize, Tile = (ushort)curTile.Id, TileName = curTile.Name }); } TileProperties.Add(curTile); if (!curTile.IsFramed) { TileBricks.Add(curTile); } } for (int i = TileProperties.Count; i < 255; i++) { TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true)); } foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall")) { var curWall = new WallProperty(); curWall.Color = ColorFromString((string)xElement.Attribute("Color")); curWall.Name = (string)xElement.Attribute("Name"); curWall.Id = (int?)xElement.Attribute("Id") ?? -1; WallProperties.Add(curWall); } foreach (var xElement in xmlSettings.Elements("Items").Elements("Item")) { var curItem = new ItemProperty(); curItem.Id = (int?)xElement.Attribute("Id") ?? -1; curItem.Name = (string)xElement.Attribute("Name"); curItem.Scale = (float?)xElement.Attribute("Scale") ?? 1f; ItemProperties.Add(curItem); _itemLookup.Add(curItem.Id, curItem); int tally = (int?)xElement.Attribute("Tally") ?? 0; if (tally > 0) { _tallynames.Add(tally, curItem.Name); } int head = (int?)xElement.Attribute("Head") ?? -1; if (head >= 0) { _armorHeadNames.Add(head, curItem.Name); } int body = (int?)xElement.Attribute("Body") ?? -1; if (body >= 0) { _armorBodyNames.Add(body, curItem.Name); } int legs = (int?)xElement.Attribute("Legs") ?? -1; if (legs >= 0) { _armorLegsNames.Add(legs, curItem.Name); } bool rack = (bool?)xElement.Attribute("Rack") ?? false; if (rack) { _rackable.Add(curItem.Id, curItem.Name); } } foreach (var xElement in xmlSettings.Elements("Paints").Elements("Paint")) { var curPaint = new PaintProperty(); curPaint.Id = (int?)xElement.Attribute("Id") ?? -1; curPaint.Name = (string)xElement.Attribute("Name"); curPaint.Color = ColorFromString((string)xElement.Attribute("Color")); PaintProperties.Add(curPaint); } int chestId = 0; foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile")) { string tileName = (string)tileElement.Attribute("Name"); if (tileName == "Chest" || tileName == "Dresser") { ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 21); foreach (var xElement in tileElement.Elements("Frames").Elements("Frame")) { var curItem = new ChestProperty(); curItem.Name = (string)xElement.Attribute("Name"); string variety = (string)xElement.Attribute("Variety"); if (variety != null) { if (tileName == "Dresser") { curItem.Name = variety + " " + "Dresser"; } else { curItem.Name = curItem.Name + " " + variety; } } curItem.ChestId = chestId++; curItem.UV = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0); curItem.TileType = type; ChestProperties.Add(curItem); } } } int signId = 0; foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile")) { string tileName = (string)tileElement.Attribute("Name"); if (tileName == "Sign" || tileName == "Grave Marker" || tileName == "Announcement Box") { ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 55); foreach (var xElement in tileElement.Elements("Frames").Elements("Frame")) { var curItem = new SignProperty(); string variety = (string)xElement.Attribute("Variety"); if (variety != null) { if (tileName == "Sign") { curItem.Name = "Sign " + variety; } else { curItem.Name = variety; } } curItem.SignId = signId++; curItem.UV = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0); curItem.TileType = type; SignProperties.Add(curItem); } } } foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); NpcIds.Add(name, id); NpcNames.Add(id, name); int frames = (int?)xElement.Attribute("Frames") ?? 16; NpcFrames.Add(id, frames); } foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); ItemPrefix.Add((byte)id, name); } foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut")) { var key = InLineEnumTryParse <Key>((string)xElement.Attribute("Key")); var tool = (string)xElement.Attribute("Tool"); ShortcutKeys.Add(key, tool); } XElement appSettings = xmlSettings.Element("App"); int appWidth = (int?)appSettings.Attribute("Width") ?? 800; int appHeight = (int?)appSettings.Attribute("Height") ?? 600; int clipboardSize = (int)XNA.MathHelper.Clamp((int?)appSettings.Attribute("ClipboardRenderSize") ?? 512, 64, 4096); _appSize = new Vector2(appWidth, appHeight); ClipboardBuffer.ClipboardRenderSize = clipboardSize; ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools")); AltC = (string)xmlSettings.Element("AltC"); SteamUserId = (int?)xmlSettings.Element("SteamUserId") ?? null; }
/// <summary> /// Determines if a given shortcut matches a <see cref="ShortcutKeys"/> definition. /// This takes into account alternative shortcut keys which are generally considered equivalent. /// An example is Ctrl+., where there are usually two keys that map to the '.' character. /// </summary> public static bool IsMatch(ShortcutKeys shortcutKeys, Keys shortcut) { if (shortcutKeys.IsEmpty) { return(false); } Keys equivalentShortcut = ToKeys(shortcutKeys); if (shortcut == equivalentShortcut) { return(true); } Keys keyCode = equivalentShortcut & Keys.KeyCode; Keys modifiers = equivalentShortcut & Keys.Modifiers; bool shift = equivalentShortcut.HasFlag(Keys.Shift); if (keyCode >= Keys.D0 && keyCode <= Keys.D9) { if (shortcut == equivalentShortcut - Keys.D0 + Keys.NumPad0) { return(true); } } else if (keyCode >= Keys.NumPad0 && keyCode <= Keys.NumPad9) { if (shortcut == equivalentShortcut - Keys.NumPad0 + Keys.D0) { return(true); } } else if (keyCode == Keys.Add) { if (!shift && shortcut == (modifiers | Keys.Shift | Keys.Oemplus)) { return(true); } } else if (keyCode == Keys.Oemplus) { if (shift && shortcut == (modifiers | Keys.Add)) { return(true); } } else if (keyCode == Keys.Subtract) { if (shortcut == (modifiers | Keys.OemMinus)) { return(true); } } else if (keyCode == Keys.OemMinus) { if (shortcut == (modifiers | Keys.Subtract)) { return(true); } } else if (keyCode == Keys.Multiply) { if (!shift && shortcut == (modifiers | Keys.Shift | Keys.D8)) { return(true); } } else if (keyCode == Keys.D8) { if (shift && shortcut == (modifiers | Keys.Multiply)) { return(true); } } else if (keyCode == Keys.Divide) { if (shortcut == (modifiers | Keys.OemQuestion)) { return(true); } } else if (keyCode == Keys.OemQuestion) { if (shortcut == (modifiers | Keys.Divide)) { return(true); } } return(false); }
public static int RegisterShortcut(ShortcutKeys modifiers, Keys key) { RegisterHotKey(Handle, id++, (uint)modifiers, (uint)key); return id; }
public ShortcutEventArgs(IntPtr param) { Modifiers = (ShortcutKeys)((int)param & 0xffff); Key = (Keys)(((int)param >> 16) & 0xffff); }
public ShortcutEventArgs(ShortcutKeys modifiers, Keys key) { Modifiers = modifiers; Key = key; }
private static void LoadObjectDbXml(string file) { var xmlSettings = XElement.Load(file); // Load Colors foreach (var xElement in xmlSettings.Elements("GlobalColors").Elements("GlobalColor")) { string name = (string)xElement.Attribute("Name"); XNA.Color color = XnaColorFromString((string)xElement.Attribute("Color")); GlobalColors.Add(name, color); } foreach (var xElement in xmlSettings.Elements("Tiles").Elements("Tile")) { var curTile = new TileProperty(); // Read XML attributes curTile.Color = ColorFromString((string)xElement.Attribute("Color")); curTile.Name = (string)xElement.Attribute("Name"); curTile.Id = (int?)xElement.Attribute("Id") ?? 0; curTile.IsFramed = (bool?)xElement.Attribute("Framed") ?? false; curTile.IsSolid = (bool?)xElement.Attribute("Solid") ?? false; curTile.IsSolidTop = (bool?)xElement.Attribute("SolidTop") ?? false; curTile.IsLight = (bool?)xElement.Attribute("Light") ?? false; curTile.IsAnimated = (bool?)xElement.Attribute("IsAnimated") ?? false; curTile.FrameSize = StringToVector2ShortArray((string)xElement.Attribute("Size"), 1, 1); // curTile.FrameSize = StringToVector2Short((string)xElement.Attribute("Size"), 1, 1); curTile.Placement = InLineEnumTryParse <FramePlacement>((string)xElement.Attribute("Placement")); curTile.TextureGrid = StringToVector2Short((string)xElement.Attribute("TextureGrid"), 16, 16); curTile.FrameGap = StringToVector2Short((string)xElement.Attribute("FrameGap"), 0, 0); curTile.IsGrass = "Grass".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsPlatform = "Platform".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsCactus = "Cactus".Equals((string)xElement.Attribute("Special")); /* Heathtech */ curTile.IsStone = (bool?)xElement.Attribute("Stone") ?? false; /* Heathtech */ curTile.CanBlend = (bool?)xElement.Attribute("Blends") ?? false; /* Heathtech */ curTile.MergeWith = (int?)xElement.Attribute("MergeWith") ?? null; /* Heathtech */ string frameNamePostfix = (string)xElement.Attribute("FrameNamePostfix") ?? null; foreach (var elementFrame in xElement.Elements("Frames").Elements("Frame")) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = (string)elementFrame.Attribute("Name"); curFrame.Variety = (string)elementFrame.Attribute("Variety"); curFrame.UV = StringToVector2Short((string)elementFrame.Attribute("UV"), 0, 0); curFrame.Anchor = InLineEnumTryParse <FrameAnchor>((string)elementFrame.Attribute("Anchor")); var frameSize = StringToVector2Short((string)elementFrame.Attribute("FrameSize"), curTile.FrameSize[0].X, curTile.FrameSize[0].Y); // Assign a default name if none existed if (string.IsNullOrWhiteSpace(curFrame.Name)) { curFrame.Name = curTile.Name; } curTile.Frames.Add(curFrame); string spriteName = null; if (curFrame.Name == curTile.Name) { if (!string.IsNullOrWhiteSpace(curFrame.Variety)) { spriteName += curFrame.Variety; } } else { spriteName += curFrame.Name; if (!string.IsNullOrWhiteSpace(curFrame.Variety)) { spriteName += " - " + curFrame.Variety; } } Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = spriteName, Origin = curFrame.UV, Size = frameSize, Tile = (ushort)curTile.Id, /* SBlogic */ TileName = curTile.Name }); } if (curTile.Frames.Count == 0 && curTile.IsFramed) { var curFrame = new FrameProperty(); // Read XML attributes curFrame.Name = curTile.Name; curFrame.Variety = string.Empty; curFrame.UV = new Vector2Short(0, 0); //curFrame.Anchor = InLineEnumTryParse<FrameAnchor>((string)xElement.Attribute("Anchor")); curTile.Frames.Add(curFrame); Sprites.Add(new Sprite { Anchor = curFrame.Anchor, IsPreviewTexture = false, Name = null, Origin = curFrame.UV, Size = curTile.FrameSize[0], Tile = (ushort)curTile.Id, TileName = curTile.Name }); } TileProperties.Add(curTile); if (!curTile.IsFramed) { TileBricks.Add(curTile); } } for (int i = TileProperties.Count; i < 255; i++) { TileProperties.Add(new TileProperty(i, "UNKNOWN", Color.FromArgb(255, 255, 0, 255), true)); } foreach (var xElement in xmlSettings.Elements("Walls").Elements("Wall")) { var curWall = new WallProperty(); curWall.Color = ColorFromString((string)xElement.Attribute("Color")); curWall.Name = (string)xElement.Attribute("Name"); curWall.Id = (int?)xElement.Attribute("Id") ?? -1; WallProperties.Add(curWall); } foreach (var xElement in xmlSettings.Elements("Items").Elements("Item")) { var curItem = new ItemProperty(); curItem.Id = (int?)xElement.Attribute("Id") ?? -1; curItem.Name = (string)xElement.Attribute("Name"); curItem.Scale = (float?)xElement.Attribute("Scale") ?? 1f; ItemProperties.Add(curItem); _itemLookup.Add(curItem.Id, curItem); int tally = (int?)xElement.Attribute("Tally") ?? 0; if (tally > 0) { _tallynames.Add(tally, curItem.Name); } int head = (int?)xElement.Attribute("Head") ?? -1; if (head >= 0) { _armorHeadNames.Add(head, curItem.Name); } int body = (int?)xElement.Attribute("Body") ?? -1; if (body >= 0) { _armorBodyNames.Add(body, curItem.Name); } int legs = (int?)xElement.Attribute("Legs") ?? -1; if (legs >= 0) { _armorLegsNames.Add(legs, curItem.Name); } bool rack = (bool?)xElement.Attribute("Rack") ?? false; if (rack) { _rackable.Add(curItem.Id, curItem.Name); } bool food = (bool?)xElement.Attribute("IsFood") ?? false; if (food) { _foodNames.Add(curItem.Id, curItem.Name); curItem.IsFood = true; } bool acc = (bool?)xElement.Attribute("Accessory") ?? false; if (acc) { _accessoryNames.Add(curItem.Id, curItem.Name); } if (curItem.Name.Contains("Dye")) { _dyeNames.Add(curItem.Id, curItem.Name); } } foreach (var xElement in xmlSettings.Elements("Paints").Elements("Paint")) { var curPaint = new PaintProperty(); curPaint.Id = (int?)xElement.Attribute("Id") ?? -1; curPaint.Name = (string)xElement.Attribute("Name"); curPaint.Color = ColorFromString((string)xElement.Attribute("Color")); PaintProperties.Add(curPaint); } int chestId = 0; foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile")) { string tileName = (string)tileElement.Attribute("Name"); int type = (int)tileElement.Attribute("Id"); if (Tile.IsChest(type)) { foreach (var xElement in tileElement.Elements("Frames").Elements("Frame")) { var curItem = new ChestProperty(); curItem.Name = (string)xElement.Attribute("Name"); string variety = (string)xElement.Attribute("Variety"); if (variety != null) { if (tileName == "Dresser") { curItem.Name = variety + " " + "Dresser"; } else { curItem.Name = curItem.Name + " " + variety; } } curItem.ChestId = chestId++; curItem.UV = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0); curItem.TileType = (ushort)type; ChestProperties.Add(curItem); } } } int signId = 0; foreach (var tileElement in xmlSettings.Elements("Tiles").Elements("Tile")) { var tileId = (int?)tileElement.Attribute("Id") ?? 0; string tileName = (string)tileElement.Attribute("Name"); if (Tile.IsSign(tileId)) { ushort type = (ushort)((int?)tileElement.Attribute("Id") ?? 55); foreach (var xElement in tileElement.Elements("Frames").Elements("Frame")) { var curItem = new SignProperty(); string variety = (string)xElement.Attribute("Variety"); string anchor = (string)xElement.Attribute("Anchor"); curItem.Name = $"{tileName} {variety} {anchor}"; curItem.SignId = signId++; curItem.UV = StringToVector2Short((string)xElement.Attribute("UV"), 0, 0); curItem.TileType = type; SignProperties.Add(curItem); } } } foreach (var xElement in xmlSettings.Elements("Npcs").Elements("Npc")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); NpcIds[name] = id; NpcNames[id] = name; var frames = StringToVector2Short((string)xElement.Attribute("Size"), 16, 40); NpcFrames[id] = frames; } foreach (var xElement in xmlSettings.Elements("ItemPrefix").Elements("Prefix")) { int id = (int?)xElement.Attribute("Id") ?? -1; string name = (string)xElement.Attribute("Name"); ItemPrefix.Add((byte)id, name); } foreach (var xElement in xmlSettings.Elements("ShortCutKeys").Elements("Shortcut")) { var key = InLineEnumTryParse <Key>((string)xElement.Attribute("Key")); var modifier = InLineEnumTryParse <ModifierKeys>((string)xElement.Attribute("Modifier")); var tool = (string)xElement.Attribute("Action"); ShortcutKeys.Add(tool, key, modifier); } XElement appSettings = xmlSettings.Element("App"); int appWidth = (int?)appSettings.Attribute("Width") ?? 800; int appHeight = (int?)appSettings.Attribute("Height") ?? 600; int clipboardSize = (int)XNA.MathHelper.Clamp((int?)appSettings.Attribute("ClipboardRenderSize") ?? 512, 64, 4096); _appSize = new Vector2(appWidth, appHeight); ClipboardBuffer.ClipboardRenderSize = clipboardSize; ToolDefaultData.LoadSettings(xmlSettings.Elements("Tools")); AltC = (string)xmlSettings.Element("AltC"); SteamUserId = (int?)xmlSettings.Element("SteamUserId") ?? null; }
public HotkeyChangedEventArgs(ShortcutKeys oldValue, ShortcutKeys newValue) { OldValue = oldValue; NewValue = newValue; }
public ShortcutModel(Keys k1, Keys k2) { ShortcutKeys.Add(k1); ShortcutKeys.Add(k2); }