Example #1
0
        private void OnCombatantGridKeyDown(object sender, KeyEventArgs e)
        {
            if (!IsEditing && CombatantsGrid.SelectedItem is CombatantData)
            {
                if ((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && (e.Key == Key.D || e.Key == Key.C))
                {
                    CombatantData dupeData = (CombatantData)CombatantsGrid.SelectedItem;
                    int           idx      = CombatantList.IndexOf(dupeData) + 1;
                    string        name     = dupeData.CombatantName;

                    string[] tok = name.Split(' ');

                    if (tok.Length > 1 && int.TryParse(tok[1], out int count))
                    {
                        CombatantList.Insert(idx, new CombatantData {
                            CombatantName = tok[0] + " " + (count + 1), HitPoints = dupeData.HitPoints, Initiative = dupeData.Initiative, InitModifier = dupeData.InitModifier, Notes = dupeData.Notes
                        });
                    }
                    else
                    {
                        CombatantList.Insert(idx, new CombatantData {
                            CombatantName = dupeData.CombatantName, HitPoints = dupeData.HitPoints, Initiative = dupeData.Initiative, InitModifier = dupeData.InitModifier, Notes = dupeData.Notes
                        });
                    }

                    //CombatantsGrid.SelectedIndex = idx;
                    //CombatantsGrid.SelectedItem = CombatantList[idx];
                    SelectRowByIndex(CombatantsGrid, idx);
                }
                else if (e.Key == Key.Delete || e.Key == Key.Back)
                {
                    DeleteEntry((CombatantData)CombatantsGrid.SelectedItem);
                }
            }
        }
Example #2
0
        private void OnInsertKeyUp(object sender, KeyEventArgs e)
        {
            if (!IsEditing)
            {
                if (((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && e.Key == Key.A) || e.Key == Key.Insert)
                {
                    if (CombatantsGrid.SelectedItem is CombatantData)
                    {
                        int idx = CombatantList.IndexOf((CombatantData)CombatantsGrid.SelectedItem) + 1;

                        CombatantList.Insert(idx, new CombatantData {
                            CombatantName = "Combatant " + (CombatantList.Count + 1)
                        });

                        SelectRowByIndex(CombatantsGrid, idx);
                    }
                    else
                    {
                        CombatantList.Add(new CombatantData {
                            CombatantName = "Combatant " + (CombatantList.Count + 1)
                        });

                        SelectRowByIndex(CombatantsGrid, CombatantList.Count - 1);
                    }
                }
            }
        }
Example #3
0
        private void DeleteEntry(CombatantData toDelete)
        {
            int idx = CombatantList.IndexOf(toDelete);

            CombatantList.Remove(toDelete);

            if (idx >= CombatantList.Count)
            {
                SelectRowByIndex(CombatantsGrid, CombatantList.Count - 1);
            }
            else
            {
                SelectRowByIndex(CombatantsGrid, idx);
            }
        }
Example #4
0
        /// <summary>
        /// Completes a drag/drop operation.
        /// </summary>
        private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!IsDragging || IsEditing)
            {
                return;
            }

            //get the target item
            CombatantData targetItem = (CombatantData)CombatantsGrid.SelectedItem;

            if (targetItem == null || !ReferenceEquals(DraggedItem, targetItem))
            {
                //get target index
                int targetIndex = CombatantList.IndexOf(targetItem);

                //remove the source from the list
                CombatantList.Remove(DraggedItem);

                //move source at the target's location
                CombatantList.Insert(Math.Max(targetIndex - 1, 0), DraggedItem);

                //select the dropped item
                //CombatantsGrid.SelectedItem = DraggedItem;
                //CombatantList.CurrentTurn = targetIndex;

                if (CombatantList.CurrentTurn == targetIndex)
                {
                    CombatantList.CurrentTurn = targetIndex - 1;
                    SetTurnText(DraggedItem.CombatantName, TurnLength);
                }
                else if (CombatantList.CurrentTurn > targetIndex)
                {
                    CombatantList.CurrentTurn++;
                }

                SelectRowByIndex(CombatantsGrid, Math.Max(targetIndex - 1, 0));
                //currentTurn = targetIndex;
                //nextTurn = (currentTurn + 1) % CombatantList.Count;
            }

            //reset
            ResetDragDrop();
        }