コード例 #1
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);
            }
        }
コード例 #2
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();
        }
コード例 #3
0
        public void SaveBattle(string filename = null)
        {
            if (string.IsNullOrEmpty(filename))
            {
                using (var dialog = new wforms.SaveFileDialog())
                {
                    dialog.Filter = FILE_DIALOG_FILTER;

                    if (dialog.ShowDialog() == wforms.DialogResult.OK)
                    {
                        SaveBattle(dialog.FileName);
                    }
                }
            }
            else if (CombatantList.Count > 0)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(CombatantCollection));

                FileInfo finfo = new FileInfo(filename);
                finfo.Directory.Create();

                using (FileStream stream = new FileStream(filename, FileMode.Create))
                {
                    CombatantData currentTurn = new CombatantData {
                        CombatantName = CURRENT_TURN_STRING, Initiative = CombatantList.CurrentTurn
                    };
                    CombatantList.Add(currentTurn);
                    CombatantData turnCount = new CombatantData {
                        CombatantName = TURN_COUNT_STRING, Initiative = CombatantList.TurnCount
                    };
                    CombatantList.Add(turnCount);

                    serializer.Serialize(stream, CombatantList);

                    CombatantList.Remove(currentTurn);
                    CombatantList.Remove(turnCount);
                }
            }
        }