internal static void IdentifyItem(bool selected = false) { if (!selected) { DungeonGameEngine.ProcessMessageQueue(false, "What do you want to identify?"); currentSelectionAction = SelectionActions.Identify; } else { DungeonGameEngine.ProcessMessageQueue(true); // Acknowledge the "What do you want to identify" prompt // Get old text before item gets renamed var listKey = currentItem.SortingValue; // Retrieving this property should cause the item to be identified as well DungeonGameEngine.ProcessMessageQueue(false, currentItem.IdentifyText); currentSelectionAction = SelectionActions.None; // Update inventory list text GameText textItem = inventoryList[listKey]; textItem.Text = currentItem.InventoryTitle; inventoryList.Remove(listKey); inventoryList.Add(currentItem.SortingValue, textItem); closingWindow = true; } }
public void TestEmptyLineSelectionBehaviorMoveDown() { var data = CreateData("\n\n\n"); data.Caret.Location = new DocumentLocation(2, 3); SelectionActions.MoveDown(data); Assert.AreEqual(new DocumentLocation(3, 3), data.Caret.Location); Assert.AreEqual(new DocumentLocation(3, 3), data.MainSelection.Lead); Assert.AreEqual(new DocumentLocation(2, 3), data.MainSelection.Anchor); }
internal static void InitNewGame() { inventoryList.Clear(); inventoryContents.Clear(); selectedIndex = -1; window.InitNewGame(); //firstIndexToShowOnScreen = 0; currentSelectionAction = SelectionActions.None; weight = 0; }
public void TestBug5067() { var data = CreateData("\n\n\t\tFoo ();\n"); data.Caret.Location = new DocumentLocation(2, 3); SelectionActions.MoveDown(data); DeleteActions.Delete(data); Assert.AreEqual("\n\t\tFoo ();\n", data.Document.Text); }
public void ClearSelection() { _actionButtonsTimer.Stop(); SelectionActions.Hide(); FirstSelectionText = LastSelectionText = null; SelectionPolygon.Visibility = Visibility.Collapsed; RightSelectionItem.Visibility = LeftSelectionItem.Visibility = Visibility.Collapsed; }
void IEditorOperations.MoveToNextCharacter(bool extendSelection) { if (extendSelection) { SelectionActions.MoveLeft(TextEditor.GetTextEditorData()); } else { CaretMoveActions.Left(TextEditor.GetTextEditorData()); } }
public void TestMoveUp() { TextEditorData data = CaretMoveActionTests.Create(@"1234567890 1234567890 1234$567890 1234567890 1234567890"); SelectionActions.MoveUp(data); Assert.AreEqual(new Selection(2, 4, 1, 4), data.MainSelection); }
void IEditorOperations.MoveToEndOfLine(bool extendSelection) { if (extendSelection) { SelectionActions.MoveLineEnd(TextEditor.GetTextEditorData()); } else { CaretMoveActions.LineEnd(TextEditor.GetTextEditorData()); } }
void IEditorOperations.MoveLineUp(bool extendSelection) { if (extendSelection) { SelectionActions.MoveUp(TextEditor.GetTextEditorData()); } else { CaretMoveActions.Up(TextEditor.GetTextEditorData()); } }
public void TestMoveToDocumentStart() { TextEditorData data = CaretMoveActionTests.Create(@"1234567890 1234567890 1234$567890 1234567890 1234567890"); SelectionActions.MoveToDocumentStart(data); Assert.AreEqual(new Selection(DocumentLocation.MinLine + 2, DocumentLocation.MinColumn + 4, DocumentLocation.MinLine, DocumentLocation.MinColumn), data.MainSelection); }
public void TestSelectAllBug362983() { TextEditorData data = new Mono.TextEditor.TextEditorData(); data.Document.Text = "Test"; Assert.IsFalse(data.IsSomethingSelected); SelectionActions.SelectAll(data); Assert.IsTrue(data.IsSomethingSelected); data.Caret.Offset++; Assert.IsFalse(data.IsSomethingSelected); }
public void TestMoveToDocumentStart() { TextEditorData data = CaretMoveActionTests.Create(@"1234567890 1234567890 1234$567890 1234567890 1234567890"); SelectionActions.MoveToDocumentStart(data); Assert.AreEqual(new Selection(2, 4, 0, 0), data.MainSelection); }
public void TestDeleteSelectionBehavior() { var data = CreateData("\n\t\ttest\n\n"); data.Caret.Location = new DocumentLocation(2, 3); SelectionActions.MoveUp(data); Assert.AreEqual(new DocumentLocation(1, 3), data.Caret.Location); Assert.IsTrue(data.IsSomethingSelected); DeleteActions.Delete(data); Assert.AreEqual(new DocumentLocation(1, 3), data.Caret.Location); Assert.AreEqual("\t\ttest\n\n", data.Document.Text); }
public void SetSelection(TextRenderData wa, TextRenderData wb) { SelectionActions.Hide(); Rect rect = wa.Rect; Rect lastSelectionRect = wb.Rect; Polygon currentPolygon = SelectionPolygon; if (currentPolygon == null) { return; } if (rect.Top > lastSelectionRect.Top || Math.Abs(rect.Top - lastSelectionRect.Top) < 0.0001 && rect.Left > lastSelectionRect.Left) { TextRenderData textContext = wa; wa = wb; wb = textContext; } if (FirstSelectionText == wa && LastSelectionText == wb) { return; } FirstSelectionText = wa; LastSelectionText = wb; Rect firstSelectionRect = wa.Rect; lastSelectionRect = wb.Rect; PointCollection selectionPolygon = GetSelectionPolygon(firstSelectionRect, lastSelectionRect, GetCurrentPagePanel().ActualWidth); currentPolygon.Points = selectionPolygon; currentPolygon.Fill = AppSettings.Default.ColorScheme.SelectionBrush; currentPolygon.Visibility = Visibility.Visible; BuildSelectionItem(LeftSelectionItem, firstSelectionRect.Left - 11, firstSelectionRect.Top, firstSelectionRect.Height); BuildSelectionItem(RightSelectionItem, lastSelectionRect.Right - 11, lastSelectionRect.Top, lastSelectionRect.Height); var tmp = (firstSelectionRect.Left + SelectionActions.Width + OffsetX) - GetCurrentPagePanel().ActualWidth; tmp = tmp < 0 ? 0 : tmp; var leftMargin = firstSelectionRect.Left - tmp; var topMargin = firstSelectionRect.Top - SelectionActions.Height - 12; topMargin = topMargin < 0 ? 0 : topMargin; SelectionActions.Margin = new Thickness(leftMargin, topMargin, 0, 0); }
public void TestClearSelection() { var data = Create(@"1234567890 1234567890 12345$<-67890 ->1234567890 1234567890"); SelectionActions.ClearSelection(data); Check(data, @"1234567890 1234567890 12345$67890 1234567890 1234567890"); }
public void ExpandSelectionToLineWithSelectionCase2() { var data = Create(@"1234567890 1234567890 12345$<-67890 ->1234567890 1234567890"); SelectionActions.ExpandSelectionToLine(data); Check(data, @"1234567890 1234567890 <-1234567890 ->$1234567890 1234567890"); }
public void Clear() { foreach (Panel p in RootGrid.Children) { p.Children.Clear(); } if (Manipulator != null) { Manipulator.Dispose(); } SelectionActions.Hide(); SelectionPolygon.Visibility = Visibility.Collapsed; LeftSelectionItem.Visibility = Visibility.Collapsed; RightSelectionItem.Visibility = Visibility.Collapsed; }
public void TestSelectAll() { TextEditorData data = new Mono.TextEditor.TextEditorData(); data.Document.Text = @"123456789 123456789 123456789 123456789 123456789 123456789"; Assert.IsFalse(data.IsSomethingSelected); SelectionActions.SelectAll(data); Assert.IsTrue(data.IsSomethingSelected); Assert.AreEqual(data.SelectionRange.Offset, 0); Assert.AreEqual(data.SelectionRange.EndOffset, data.Document.TextLength); }
public void TestSelectAllCaretMovement() { TextEditorData data = new Mono.TextEditor.TextEditorData(); data.Document.Text = @"123456789 123456789 123456789 123456789 123456789 123456789"; Assert.IsFalse(data.IsSomethingSelected); var loc = new DocumentLocation(3, 3); data.Caret.Location = loc; SelectionActions.SelectAll(data); Assert.IsTrue(data.IsSomethingSelected); Assert.AreEqual(data.SelectionRange.Offset, 0); Assert.AreEqual(data.SelectionRange.EndOffset, data.Document.TextLength); Assert.AreEqual(loc, data.Caret.Location); }
protected override void HandleKeypress(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier) { // Reset on Esc, Ctrl-C, Ctrl-[ if (key == Gdk.Key.Escape) { if (currentMacro != null) { // Record Escapes into the macro since it actually does something ViMacro.KeySet toAdd = new ViMacro.KeySet(); toAdd.Key = key; toAdd.Modifiers = modifier; toAdd.UnicodeKey = unicodeKey; currentMacro.KeysPressed.Enqueue(toAdd); } Reset(string.Empty); return; } else if (((key == Gdk.Key.c || key == Gdk.Key.bracketleft) && (modifier & Gdk.ModifierType.ControlMask) != 0)) { Reset(string.Empty); if (currentMacro != null) { // Otherwise remove the macro from the pool macros.Remove(currentMacro.MacroCharacter); currentMacro = null; } return; } else if (currentMacro != null && !((char)unicodeKey == 'q' && modifier == Gdk.ModifierType.None)) { ViMacro.KeySet toAdd = new ViMacro.KeySet(); toAdd.Key = key; toAdd.Modifiers = modifier; toAdd.UnicodeKey = unicodeKey; currentMacro.KeysPressed.Enqueue(toAdd); } Action <TextEditorData> action = null; bool lineAction = false; switch (state) { case State.Unknown: Reset(string.Empty); goto case State.Normal; case State.Normal: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0)) { if (key == Gdk.Key.Delete) { unicodeKey = 'x'; } switch ((char)unicodeKey) { case '?': case '/': case ':': state = State.Command; commandBuffer.Append((char)unicodeKey); Status = commandBuffer.ToString(); return; case 'A': RunAction(CaretMoveActions.LineEnd); goto case 'i'; case 'I': RunAction(CaretMoveActions.LineFirstNonWhitespace); goto case 'i'; case 'a': //use CaretMoveActions so that we can move past last character on line end RunAction(CaretMoveActions.Right); goto case 'i'; case 'i': Caret.Mode = CaretMode.Insert; Status = "-- INSERT --"; state = State.Insert; return; case 'R': Caret.Mode = CaretMode.Underscore; Status = "-- REPLACE --"; state = State.Replace; return; case 'V': Status = "-- VISUAL LINE --"; Data.SetSelectLines(Caret.Line, Caret.Line); state = State.VisualLine; return; case 'v': Status = "-- VISUAL --"; state = State.Visual; RunAction(ViActions.VisualSelectionFromMoveAction(ViActions.Right)); return; case 'd': Status = "d"; state = State.Delete; return; case 'y': Status = "y"; state = State.Yank; return; case 'Y': state = State.Yank; HandleKeypress(Gdk.Key.y, (int)'y', Gdk.ModifierType.None); return; case 'O': RunAction(ViActions.NewLineAbove); goto case 'i'; case 'o': RunAction(ViActions.NewLineBelow); goto case 'i'; case 'r': Caret.Mode = CaretMode.Underscore; Status = "-- REPLACE --"; state = State.WriteChar; return; case 'c': Caret.Mode = CaretMode.Insert; Status = "c"; state = State.Change; return; case 'x': if (Data.Caret.Column == Data.Document.GetLine(Data.Caret.Line).Length + 1) { return; } Status = string.Empty; if (!Data.IsSomethingSelected) { RunActions(SelectionActions.FromMoveAction(CaretMoveActions.Right), ClipboardActions.Cut); } else { RunAction(ClipboardActions.Cut); } ViActions.RetreatFromLineEnd(Data); return; case 'X': if (Data.Caret.Column == DocumentLocation.MinColumn) { return; } Status = string.Empty; if (!Data.IsSomethingSelected && 0 < Caret.Offset) { RunActions(SelectionActions.FromMoveAction(CaretMoveActions.Left), ClipboardActions.Cut); } else { RunAction(ClipboardActions.Cut); } return; case 'D': RunActions(SelectionActions.FromMoveAction(CaretMoveActions.LineEnd), ClipboardActions.Cut); return; case 'C': RunActions(SelectionActions.FromMoveAction(CaretMoveActions.LineEnd), ClipboardActions.Cut); goto case 'i'; case '>': Status = ">"; state = State.Indent; return; case '<': Status = "<"; state = State.Unindent; return; case 'n': Search(); return; case 'N': searchBackward = !searchBackward; Search(); searchBackward = !searchBackward; return; case 'p': PasteAfter(false); return; case 'P': PasteBefore(false); return; case 's': if (!Data.IsSomethingSelected) { RunAction(SelectionActions.FromMoveAction(CaretMoveActions.Right)); } RunAction(ClipboardActions.Cut); goto case 'i'; case 'S': if (!Data.IsSomethingSelected) { RunAction(SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd)); } else { Data.SetSelectLines(Data.MainSelection.Anchor.Line, Data.Caret.Line); } RunAction(ClipboardActions.Cut); goto case 'i'; case 'g': Status = "g"; state = State.G; return; case 'H': Caret.Line = System.Math.Max(DocumentLocation.MinLine, Editor.PointToLocation(0, Editor.LineHeight - 1).Line); return; case 'J': RunAction(ViActions.Join); return; case 'L': int line = Editor.PointToLocation(0, Editor.Allocation.Height - Editor.LineHeight * 2 - 2).Line; if (line < DocumentLocation.MinLine) { line = Document.LineCount; } Caret.Line = line; return; case 'M': line = Editor.PointToLocation(0, Editor.Allocation.Height / 2).Line; if (line < DocumentLocation.MinLine) { line = Document.LineCount; } Caret.Line = line; return; case '~': RunAction(ViActions.ToggleCase); return; case 'z': Status = "z"; state = State.Fold; return; case 'm': Status = "m"; state = State.Mark; return; case '`': Status = "`"; state = State.GoToMark; return; case '@': Status = "@"; state = State.PlayMacro; return; case 'q': if (currentMacro == null) { Status = "q"; state = State.NameMacro; return; } currentMacro = null; Reset("Macro Recorded"); return; case '*': SearchWordAtCaret(); return; } } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action == null) { action = ViActionMaps.GetCommandCharAction((char)unicodeKey); } if (action != null) { RunAction(action); } //undo/redo may leave MD with a selection mode without activating visual mode CheckVisualMode(); return; case State.Delete: if (((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == 'd')) { action = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd); lineAction = true; } else { action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { action = SelectionActions.FromMoveAction(action); } } if (action != null) { if (lineAction) { RunActions(action, ClipboardActions.Cut, CaretMoveActions.LineFirstNonWhitespace); } else { RunActions(action, ClipboardActions.Cut); } Reset(""); } else { Reset("Unrecognised motion"); } return; case State.Yank: int offset = Caret.Offset; if (((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == 'y')) { action = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd); lineAction = true; } else { action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { action = SelectionActions.FromMoveAction(action); } } if (action != null) { RunAction(action); if (Data.IsSomethingSelected && !lineAction) { offset = Data.SelectionRange.Offset; } RunAction(ClipboardActions.Copy); Reset(string.Empty); } else { Reset("Unrecognised motion"); } Caret.Offset = offset; return; case State.Change: //copied from delete action if (((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == 'c')) { action = SelectionActions.LineActionFromMoveAction(CaretMoveActions.LineEnd); lineAction = true; } else { action = ViActionMaps.GetEditObjectCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { action = SelectionActions.FromMoveAction(action); } } if (action != null) { if (lineAction) { RunActions(action, ClipboardActions.Cut, ViActions.NewLineAbove); } else { RunActions(action, ClipboardActions.Cut); } Status = "-- INSERT --"; state = State.Insert; Caret.Mode = CaretMode.Insert; } else { Reset("Unrecognised motion"); } return; case State.Insert: case State.Replace: action = GetInsertAction(key, modifier); if (action != null) { RunAction(action); } else if (unicodeKey != 0) { InsertCharacter(unicodeKey); } return; case State.VisualLine: if (key == Gdk.Key.Delete) { unicodeKey = 'x'; } switch ((char)unicodeKey) { case 'p': PasteAfter(true); return; case 'P': PasteBefore(true); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action == null) { action = ViActionMaps.GetCommandCharAction((char)unicodeKey); } if (action != null) { RunAction(SelectionActions.LineActionFromMoveAction(action)); return; } ApplyActionToSelection(modifier, unicodeKey); return; case State.Visual: if (key == Gdk.Key.Delete) { unicodeKey = 'x'; } switch ((char)unicodeKey) { case 'p': PasteAfter(false); return; case 'P': PasteBefore(false); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action == null) { action = ViActionMaps.GetCommandCharAction((char)unicodeKey); } if (action != null) { RunAction(ViActions.VisualSelectionFromMoveAction(action)); return; } ApplyActionToSelection(modifier, unicodeKey); return; case State.Command: switch (key) { case Gdk.Key.Return: case Gdk.Key.KP_Enter: Status = RunExCommand(commandBuffer.ToString()); commandBuffer.Length = 0; state = State.Normal; break; case Gdk.Key.BackSpace: case Gdk.Key.Delete: case Gdk.Key.KP_Delete: if (0 < commandBuffer.Length) { commandBuffer.Remove(commandBuffer.Length - 1, 1); Status = commandBuffer.ToString(); if (0 == commandBuffer.Length) { Reset(Status); } } break; default: if (unicodeKey != 0) { commandBuffer.Append((char)unicodeKey); Status = commandBuffer.ToString(); } break; } return; case State.WriteChar: if (unicodeKey != 0) { RunAction(SelectionActions.StartSelection); int roffset = Data.SelectionRange.Offset; InsertCharacter((char)unicodeKey); Reset(string.Empty); Caret.Offset = roffset; } else { Reset("Keystroke was not a character"); } return; case State.Indent: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0 && unicodeKey == '>')) { RunAction(MiscActions.IndentSelection); Reset(""); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { RunActions(SelectionActions.FromMoveAction(action), MiscActions.IndentSelection); Reset(""); } else { Reset("Unrecognised motion"); } return; case State.Unindent: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0 && ((char)unicodeKey) == '<')) { RunAction(MiscActions.RemoveIndentSelection); Reset(""); return; } action = ViActionMaps.GetNavCharAction((char)unicodeKey); if (action == null) { action = ViActionMaps.GetDirectionKeyAction(key, modifier); } if (action != null) { RunActions(SelectionActions.FromMoveAction(action), MiscActions.RemoveIndentSelection); Reset(""); } else { Reset("Unrecognised motion"); } return; case State.G: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0)) { switch ((char)unicodeKey) { case 'g': Caret.Offset = 0; Reset(""); return; } } Reset("Unknown command"); return; case State.Mark: { char k = (char)unicodeKey; ViMark mark = null; if (!char.IsLetterOrDigit(k)) { Reset("Invalid Mark"); return; } if (marks.ContainsKey(k)) { mark = marks [k]; } else { mark = new ViMark(k); marks [k] = mark; } RunAction(mark.SaveMark); Reset(""); return; } case State.NameMacro: { char k = (char)unicodeKey; if (!char.IsLetterOrDigit(k)) { Reset("Invalid Macro Name"); return; } currentMacro = new ViMacro(k); currentMacro.KeysPressed = new Queue <ViMacro.KeySet> (); macros [k] = currentMacro; Reset(""); return; } case State.PlayMacro: { char k = (char)unicodeKey; if (k == '@') { k = macros_lastplayed; } if (macros.ContainsKey(k)) { Reset(""); macros_lastplayed = k; // FIXME play nice when playing macros from inside macros? ViMacro macroToPlay = macros [k]; foreach (ViMacro.KeySet keySet in macroToPlay.KeysPressed) { HandleKeypress(keySet.Key, keySet.UnicodeKey, keySet.Modifiers); // FIXME stop on errors? essential with multipliers and nowrapscan } /* Once all the keys have been played back, quickly exit. */ return; } else { Reset("Invalid Macro Name '" + k + "'"); return; } } case State.GoToMark: { char k = (char)unicodeKey; if (marks.ContainsKey(k)) { RunAction(marks [k].LoadMark); Reset(""); } else { Reset("Unknown Mark"); } return; } case State.Fold: if (((modifier & (Gdk.ModifierType.ControlMask)) == 0)) { switch ((char)unicodeKey) { case 'A': // Recursive fold toggle action = FoldActions.ToggleFoldRecursive; break; case 'C': // Recursive fold close action = FoldActions.CloseFoldRecursive; break; case 'M': // Close all folds action = FoldActions.CloseAllFolds; break; case 'O': // Recursive fold open action = FoldActions.OpenFoldRecursive; break; case 'R': // Expand all folds action = FoldActions.OpenAllFolds; break; case 'a': // Fold toggle action = FoldActions.ToggleFold; break; case 'c': // Fold close action = FoldActions.CloseFold; break; case 'o': // Fold open action = FoldActions.OpenFold; break; default: Reset("Unknown command"); break; } if (null != action) { RunAction(action); Reset(string.Empty); } } return; } }
public static Action <TextEditorData> VisualSelectionFromMoveAction(Action <TextEditorData> moveAction) { return(delegate(TextEditorData data) { //get info about the old selection state DocumentLocation oldCaret = data.Caret.Location, oldAnchor = oldCaret, oldLead = oldCaret; if (data.IsSomethingSelected) { oldLead = data.MainSelection.Lead; oldAnchor = data.MainSelection.Anchor; } //do the action, preserving selection SelectionActions.StartSelection(data); moveAction(data); SelectionActions.EndSelection(data); DocumentLocation newCaret = data.Caret.Location, newAnchor = newCaret, newLead = newCaret; if (data.IsSomethingSelected) { newLead = data.MainSelection.Lead; newAnchor = data.MainSelection.Anchor; } //Console.WriteLine ("oc{0}:{1} oa{2}:{3} ol{4}:{5}", oldCaret.Line, oldCaret.Column, oldAnchor.Line, oldAnchor.Column, oldLead.Line, oldLead.Column); //Console.WriteLine ("nc{0}:{1} na{2}:{3} nl{4}:{5}", newCaret.Line, newCaret.Line, newAnchor.Line, newAnchor.Column, newLead.Line, newLead.Column); //pivot the anchor around the anchor character if (oldAnchor < oldLead && newAnchor >= newLead) { data.SetSelection(new DocumentLocation(newAnchor.Line, newAnchor.Column + 1), newLead); } else if (oldAnchor > oldLead && newAnchor <= newLead) { data.SetSelection(new DocumentLocation(newAnchor.Line, newAnchor.Column - 1), newLead); } //pivot the lead about the anchor character if (newAnchor == newLead) { if (oldAnchor < oldLead) { SelectionActions.FromMoveAction(Left) (data); } else { SelectionActions.FromMoveAction(Right) (data); } } //pivot around the anchor line else { if (oldAnchor < oldLead && newAnchor > newLead && ( (newLead.Line == newAnchor.Line && oldLead.Line == oldAnchor.Line + 1) || (newLead.Line == newAnchor.Line - 1 && oldLead.Line == oldAnchor.Line))) { SelectionActions.FromMoveAction(Left) (data); } else if (oldAnchor > oldLead && newAnchor < newLead && ( (newLead.Line == newAnchor.Line && oldLead.Line == oldAnchor.Line - 1) || (newLead.Line == newAnchor.Line + 1 && oldLead.Line == oldAnchor.Line))) { SelectionActions.FromMoveAction(Right) (data); } } }); }
/// <summary> /// Takes player keyboard input and either updates selection change or activates an action on /// the selected item. If the rename window is open, control is passed over and directed to /// that window. Handles timing for when player holds a key while using Inventory window. /// </summary> /// <param name="key"></param> /// <param name="gameTime"></param> /// <param name="dropped"></param> /// <param name="showRenameItemScreen"></param> /// <returns></returns> internal static bool ProcessPlayerInputs(Keys key, GameTime gameTime, out List <InventoryItem> dropped, out bool showRenameItemScreen) { dropped = nothingToDrop; // Prevents creating a new list with every loop showRenameItemScreen = usingRenameItemScreen; elapsedTime += gameTime.ElapsedGameTime.Milliseconds; if (firstLoop) { UpdateCurrentItem(); } if (firstLoop && key != Keys.None) { return(false); // Forces keys to be released upon entry of first loop } firstLoop = false; // If no key pressed, or input passes directly to the RenameScreen, there should be no more delay in this class if (key == Keys.None || key != lastKey || usingRenameItemScreen) { currentDelay = GameConstants.NO_DELAY; } #region Using Rename Item Screen if (usingRenameItemScreen) { Debug.Assert(currentItem != null); string reservedText = (GetItem(inventoryList.ElementAt(selectedIndex).Key) as INamable).ReservedTextForTitle; if (RenameItemScreen.ProcessPlayerInputs(key, gameTime, resetInputWindow, reservedText, out response)) { // Screen closed usingRenameItemScreen = false; firstLoop = true; } resetInputWindow = false; if (response != string.Empty) { Rename(currentItem, true); } lastKey = key; return(false); // The inventory window stays open } #endregion #region Key press for Inventory Screen else if (key != Keys.None && elapsedTime > currentDelay) { elapsedTime = 0; // When a key is first pressed, the initial delay should be set if (key != lastKey) { currentDelay = GameConstants.INITIAL_KEY_DELAY; } // Once the initial delay is over, if the key is still held down, then repeating is allowed else { currentDelay = GameConstants.HOLD_KEY_DELAY; } switch (key) { case Keys.Up: selectedIndex--; window.SelectPrev(); break; case Keys.Down: selectedIndex++; window.SelectNext(); break; case Keys.Enter: if (currentItem != null && currentSelectionAction == SelectionActions.None) { if (currentItem is IWearable && !(currentItem as IWearable).Equipped) { Equip(currentItem); } else if (currentItem is Weapon && !(currentItem as Weapon).Wielded) { Wield(currentItem); } else if (currentItem is IConsumable) { Consume(currentItem); } } else if (currentSelectionAction == SelectionActions.Identify) { IdentifyItem(true); } break; case Keys.Delete: if (currentItem != null && currentSelectionAction == SelectionActions.None) { if (currentItem is IWearable && (currentItem as IWearable).Equipped) { Unequip(currentItem); } else if (currentItem is Weapon && (currentItem as Weapon).Wielded) { Unwield(currentItem); } else { Drop(currentItem); } } break; case Keys.R: if (currentItem != null && currentSelectionAction == SelectionActions.None && currentItem is INamable) { Rename(currentItem); } break; case Keys.Escape: if (currentSelectionAction == SelectionActions.Identify) { DungeonGameEngine.ProcessMessageQueue(false, "It is your breath (and not a very good one at that)."); currentSelectionAction = SelectionActions.None; } closingWindow = true; break; } UpdateCurrentItem(); UpdateKeyboardInstructions(); } #endregion lastKey = key; if (closingWindow) { dropped = dropList.ToList(); dropList.Clear(); firstLoop = true; // Reset for next time window opens closingWindow = false; return(true); } else { return(false); // Does not allow inventory menu to exit yet } }
private void ShowActionButtonsOnTick(object sender, EventArgs eventArgs) { _actionButtonsTimer.Stop(); SelectionActions.Show(); }
public void ShowActionButtons() { SelectionActions.Hide(); _actionButtonsTimer.Stop(); _actionButtonsTimer.Start(); }