Ejemplo n.º 1
0
        public override void Hurt(Creature whoToHurt)
        {
            if (whoToHurt == null)
            {
                throw new ArgumentNullException(nameof(whoToHurt));
            }

            if (CurrentItem.GetType() == typeof(Weapon))
            {
                if (whoToHurt.GetDamage(((Weapon)CurrentItem).Damage) <= 0)
                {
                    Heal(20);

                    Inventory.Items.Concat(LootController.GetCreatureLoot(whoToHurt));

                    KilledTheCreatureEventArgs args = new KilledTheCreatureEventArgs(whoToHurt);
                    OnKilledTheCreature(args);
                }
            }
            else
            {
                if (whoToHurt.GetDamage(1) <= 0)
                {
                    Heal(25);

                    Inventory.Items.Concat(LootController.GetCreatureLoot(whoToHurt));

                    KilledTheCreatureEventArgs args = new KilledTheCreatureEventArgs(whoToHurt);
                    OnKilledTheCreature(args);
                }
            }
        }
Ejemplo n.º 2
0
 protected override void OnItemSelected(BrushBase item, EventArgs e)
 {
     item.BackColor   = SystemColors.ActiveCaption;
     item.BorderStyle = BorderStyle.Fixed3D;
     GlobalMessage.Add("status", "选中: " + CurrentItem.GetType().Name);
     base.OnItemSelected(item, e);
 }
        // Редактирование стандартных ячеек одним кликом (устанавливает фокус на ячейку и IsSelected)
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            var clickedElement = e.OriginalSource as Visual;
            var cell           = clickedElement.FindVisualParent <DataGridCell>();

            if (lastCell != null && cell != null && lastCell.IsEditing && lastCell != cell)
            {
                CommitEdit(DataGridEditingUnit.Row, true);
            }

            if (cell == null || cell.IsEditing || cell.IsReadOnly)
            {
                return;
            }

            if (cell.IsFocused == false)
            {
                cell.Focus();
            }

            lastCell = cell;

            // Условие обязательно, тупо выделять ячейку нельзя, может возникнуть исключение
            if (SelectionUnit == DataGridSelectionUnit.FullRow)
            {
                var row = cell.FindVisualParent <DataGridRow>();

                if (row?.IsSelected == false)
                {
                    row.IsSelected = true;
                }
            }
            else if (cell.IsSelected == false)
            {
                cell.IsSelected = true;
            }

            // При добавлении новой строки через DataGridTemplateColumn - ячейку нужно переводить в режим редактирования вручную,
            // иначе не создастся экземпляр коллекции элементов DataGrid
            var currentItemName = CurrentItem?.GetType().Name;

            if (currentItemName == "NamedObject")
            {
                BeginEdit();
            }
        }
Ejemplo n.º 4
0
 //================================================================================================================================================
 // Public Methods
 //================================================================================================================================================
 #region UpdateCurrentItem
 public void UpdateCurrentItem()
 {
     if (CurrentItem == null)
     {
         return;
     }
     if (CurrentItem.GetType() == typeof(TreeViewItem))
     {
         TreeViewItem tvi = (TreeViewItem)CurrentItem;
         if (tvi.DataContext.GetType() == typeof(Tool))
         {
             Tool tool = (Tool)tvi.DataContext;
             switch (tool.Language.ToLower())
             {
             case "javascript":
                 ObjectCreator oc = new ObjectCreator(tool);
                 mainRef.main_content.Content = oc;
                 break;
             }
         }
     }
 }
Ejemplo n.º 5
0
        public override ActionResult Index()
        {
            AssertProductsLoaded();
            if (Arguments.Length > 0)
            {
                return(NotFound());
            }

            var vm = new ContentPageViewModel
            {
                PageType = CurrentItem.GetType()
            };


            if (CurrentItem != null)
            {
                SetPageTitleSimple();
                vm.Text = CurrentItem.Text;
            }

            SetPageInfo();
            SetPageMetaData(vm);
            return(View("PageTemplates/ContentPage", vm));
        }
Ejemplo n.º 6
0
        protected void OnAddTool(object parameter)
        {
            if (CurrentItem != null)
            {
                if (CurrentItem.GetType() == typeof(TreeViewItem))
                {
                    TreeViewItem tvItem = (TreeViewItem)CurrentItem;
                    Tool         tool;
                    Project      tempProject = null;
                    if (tvItem.DataContext.GetType() == typeof(Project))
                    {
                        tempProject = (Project)tvItem.DataContext;
                        tool        = new Tool(tempProject);
                        tempProject.Tools.Add(tool);
                    }
                    else
                    {
                        tool = new Tool(null);
                    }

                    NewToolDialog ntd = new NewToolDialog(tool);
                    ntd.ShowDialog();
                    UpdateCurrentItem();
                    OnPropertyChanged("CurrentItem");

                    TreeViewItem tvi = new TreeViewItem();
                    tvi.Header      = tool.Name;
                    tvi.DataContext = tool;

                    TreeViewItem tvi_ = null;
                    if (tempProject != null)
                    {
                        tvi_ = TreeViewItems.Where(x => x.Header.ToString() == tempProject.Name).FirstOrDefault();
                    }

                    if (tvi_ != null)
                    {
                        tvi_.Items.Add(tvi);
                    }
                    else
                    {
                        TreeViewItems.Add(tvi);
                    }

                    Tools.Add(tool);
                    CurrentItem = tvi;
                }
            }
            else
            {
                Tool tool = new Tool();
                //object tool = new object();
                NewToolDialog ntd = new NewToolDialog(tool);
                ntd.ShowDialog();
                UpdateCurrentItem();
                OnPropertyChanged("CurrentItem");

                TreeViewItem tvi = new TreeViewItem();
                tvi.Header      = tool.Name;
                tvi.DataContext = tool;

                //Items.Add(tool);
                TreeViewItems.Add(tvi);
                Tools.Add(tool);
                CurrentItem = tvi;
            }
        }
Ejemplo n.º 7
0
    public override void OnDrop(PointerEventData eventData)
    {
        //We only want draggin on left mousebutton
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        ChestItemSlot fromChest;

        if ((fromChest = eventData.pointerDrag.GetComponent <ChestItemSlot>()) != null)
        {
            inventory.AddItemAtIndex(fromChest.CurrentItem.Id, index, fromChest.CurrentItem.StackSize);

            Chest chestReference = ChestUI.Instance.chest;
            if (chestReference != null)
            {
                chestReference.RemoveItemAtIndex(fromChest.index);
            }
        }

        FurnaceItemOutput fromFurnaceOutput;

        if ((fromFurnaceOutput = eventData.pointerDrag.GetComponent <FurnaceItemOutput>()) != null)
        {
            inventory.AddItemAtIndex(fromFurnaceOutput.CurrentItem.Id, index, fromFurnaceOutput.CurrentItem.StackSize);
            fromFurnaceOutput.CurrentItem = null;
        }

        FurnaceItemInput fromFurnaceInput;

        if ((fromFurnaceInput = eventData.pointerDrag.GetComponent <FurnaceItemInput>()) != null)
        {
            inventory.AddItemAtIndex(fromFurnaceInput.CurrentItem.Id, index, fromFurnaceInput.CurrentItem.StackSize);
            fromFurnaceInput.CurrentItem = null;
        }

        FurnaceFuelInput fromFurnaceFuel;

        if ((fromFurnaceFuel = eventData.pointerDrag.GetComponent <FurnaceFuelInput>()) != null)
        {
            inventory.AddItemAtIndex(fromFurnaceFuel.CurrentItem.Id, index, fromFurnaceFuel.CurrentItem.StackSize);
            fromFurnaceFuel.CurrentItem = null;
        }

        CampfireItemOutput fromCampfireOutput;

        if ((fromCampfireOutput = eventData.pointerDrag.GetComponent <CampfireItemOutput>()) != null)
        {
            inventory.AddItemAtIndex(fromCampfireOutput.CurrentItem.Id, index, fromCampfireOutput.CurrentItem.StackSize);
            fromCampfireOutput.CurrentItem = null;
        }

        CampfireItemInput fromCampfireInput;

        if ((fromCampfireInput = eventData.pointerDrag.GetComponent <CampfireItemInput>()) != null)
        {
            inventory.AddItemAtIndex(fromCampfireInput.CurrentItem.Id, index, fromCampfireInput.CurrentItem.StackSize);
            fromCampfireInput.CurrentItem = null;
        }

        CampfireFuelInput fromCampfireFuel;

        if ((fromCampfireFuel = eventData.pointerDrag.GetComponent <CampfireFuelInput>()) != null)
        {
            inventory.AddItemAtIndex(fromCampfireFuel.CurrentItem.Id, index, fromCampfireFuel.CurrentItem.StackSize);
            fromCampfireFuel.CurrentItem = null;
        }

        InventoryItemSlot from;

        //Check what gets dropped on this.
        if (!(@from = eventData.pointerDrag.GetComponent <ItemSlot>() as InventoryItemSlot))
        {
            return;
        }

        //We got an item from our equipment.
        if (@from.index == -1 && CurrentItem != null)
        {
            //We cant swap the items it they arent the same type
            if (@from.CurrentItem.GetType() != CurrentItem.GetType())
            {
                return;
            }

            //Check if our item is an Armor and see if it's the same type of armor, if so we can swap the items around.
            if ((@from.CurrentItem.GetType() == typeof(Armor) && ((Armor)@from.CurrentItem).ArmorType == ((Armor)CurrentItem).ArmorType))
            {
                equipmentManager.EquipArmor(CurrentItem as Armor, index);
            }
        }
        else if (@from.index == -1 && CurrentItem == null)
        {
            //We are dragging an equipment piece on an empty inventory slot.
            equipmentManager.UnequipArmor(@from.CurrentItem as Item, index);
        }
        else
        {
            inventory.SwapItems(index, @from.index);
        }
    }