Ejemplo n.º 1
0
        private void Start()
        {
            gameManager  = interfaceFactory.GameManager;
            errorHandler = interfaceFactory.ErrorHandler;
            uiManager    = interfaceFactory.UIManager;
            if (gameManager == null || errorHandler == null || uiManager == null)
            {
                gameObject.SetActive(false);
            }
            else
            {
                touristManager = gameManager.TouristManager;
                if (touristManager == null)
                {
                    errorHandler.ReportError("Tourist Manager missing", ErrorState.restart_scene);
                }

                inventoryUI = uiManager.InventoryUI;
                if (inventoryUI == null)
                {
                    errorHandler.ReportError("Inventory UI missing", ErrorState.restart_scene);
                }

                started = true;
            }
        }
Ejemplo n.º 2
0
 private static void ExchangeItem(ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args)
 {
     if (fromIn.CanExchange(old, ip) && fromIn.IsCanDrop(old, args))
     {
         fromIn.ExchangeItemPosition(old, ip);
         HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, true);
         HandleMoveAction(toIn, fromIn, toUI, fromUI, old, args, true);
         HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, false);
         HandleMoveAction(toIn, fromIn, toUI, fromUI, old, args, false);
         if (fromIn == toIn)
         {
             fromUI.UpdateItem(args, fromIn, old);
             fromUI.UpdateItem(args, fromIn, ip);
         }
         else
         {
             fromUI.AddItem(args, fromIn, old);
             toUI.AddItem(args, toIn, ip);
         }
     }
     else
     {
         fromIn.ChangePosition(ip, fromIn, ip.GetX(), ip.GetY());
         if (fromUI.CanNotMoveAction != null)
         {
             fromUI.CanNotMoveAction.Act(args);
         }
         fromUI.UpdateItem(args, fromIn, ip);
     }
 }
Ejemplo n.º 3
0
        public void Init(IInventoryUI invManager, Canvas canvas, int id)
        {
            this.assignedUI = invManager;
            if (invManager.TryRegisterSlotView(this, id))
            {
                slotID = id;
            }
            else
            {
                throw new System.Exception("Could not add UI representation of inventory slot.");
            }
            UpdateItemSlot(null);
            dragging = false;

            if (dragObject == null)
            {
                dragObject = new GameObject("Drag Object", typeof(RectTransform), typeof(Image));
                dragObject.transform.SetParent(canvas.transform);
                dragObject.SetActive(false);
                dragObject.GetComponent <Image>().raycastTarget = false;
                dragObject.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 50.0f);
                dragObject.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50.0f);
            }
            this.eventCamera = invManager.eventCamera;
        }
Ejemplo n.º 4
0
 protected override void Start()
 {
     base.Start();
     if (gameObject.activeSelf)
     {
         uiManager = interfaceFactory.UIManager;
         if (uiManager == null)
         {
             gameObject.SetActive(false);
         }
         else
         {
             inventoryUI = uiManager.InventoryUI;
             if (inventoryUI == null)
             {
                 errorHandler.ReportError("Inventory UI missing", ErrorState.restart_scene);
             }
             IPlayerManager playerManager = gameManager.PlayerManager;
             if (playerManager == null)
             {
                 errorHandler.ReportError("Player manager missing", ErrorState.restart_scene);
             }
             else
             {
                 playerCharacter = gameManager.PlayerManager.PlayerCharacter;
                 if (playerCharacter == null)
                 {
                     errorHandler.ReportError("Player Character missing", ErrorState.restart_scene);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        public static void MovePosition(ItemPosition ip, ItemInventory toIn, int x, int y, ISkillArgs args)
        {
            ItemInventory     fromIn = ip.GetInventory();
            IInventoryUI      fromUI = fromIn.GetInventoryUI();
            IInventoryUI      toUI   = toIn.GetInventoryUI();
            FreeRuleEventArgs fr     = (FreeRuleEventArgs)args;

            Move(fromIn, toIn, ip, x, y, args, fr, fromUI, toUI);
        }
Ejemplo n.º 6
0
        private void Start()
        {
            gameManager  = interfaceFactory.GameManager;
            errorHandler = interfaceFactory.ErrorHandler;
            uiManager    = interfaceFactory.UIManager;
            if (gameManager == null || errorHandler == null || uiManager == null)
            {
                gameObject.SetActive(false);
            }
            else
            {
                if (componentMissing)
                {
                    errorHandler.ReportError("Tourist Manager component missing", ErrorState.restart_scene);
                }

                inventoryUI = uiManager.InventoryUI;
                if (inventoryUI == null)
                {
                    errorHandler.ReportError("Inventory UI missing", ErrorState.restart_scene);
                }
                turnsManager = gameManager.TurnsManager;
                if (turnsManager == null)
                {
                    errorHandler.ReportError("Turns Manager missing", ErrorState.restart_scene);
                }
                else
                {
                    if (turnsManager.TurnBasedObjects == null)
                    {
                        errorHandler.ReportError("Turn based objects list not initialized", ErrorState.restart_scene);
                    }
                    else
                    {
                        turnsManager.TurnBasedObjects.Add(this);
                    }
                }

                playerManager = gameManager.PlayerManager;
                if (playerManager == null)
                {
                    errorHandler.ReportError("Player Manager missing", ErrorState.restart_scene);
                }
            }
        }
Ejemplo n.º 7
0
        public static bool MoveOut(ItemInventory fromIn, ItemInventory toIn, ItemPosition ip, int countX, int countY, ISkillArgs args, FreeRuleEventArgs fr, IInventoryUI fromUI, IInventoryUI toUI)
        {
            if (fromIn == toIn)
            {
                // 竖格超出
                if (countY >= toIn.GetRow() || countY < 0)
                {
                    if (toUI.MoveOutAction != null)
                    {
                        ip.GetKey().SetCount(ip.GetCount());
                        fr.TempUse(PARA_ITEM, ip.GetKey());
                        fr.Resume(PARA_ITEM);
                        RemoveItem(fromIn, ip, args);

                        toUI.MoveOutAction.Act(args);
                        return(true);
                    }
                }
            }
            if (fromIn == toIn)
            {
                // 横格超出
                if (countX >= toIn.GetColumn() || countX < 0)
                {
                    if (toUI.MoveOutAction != null)
                    {
                        ip.GetKey().SetCount(ip.GetCount());
                        fr.TempUse(PARA_ITEM, ip.GetKey());
                        fr.Resume(PARA_ITEM);
                        RemoveItem(fromIn, ip, args);

                        toUI.MoveOutAction.Act(args);
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 8
0
        public static void HandleMoveAction(ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, IEventArgs args, bool remove)
        {
            args.TempUse(PARA_ITEM, ip);
            args.GetDefault().GetParameters().TempUse(new StringPara(PARA_ITEM_MOVE_FROM, fromIn.GetName()));
            args.GetDefault().GetParameters().TempUse(new StringPara(PARA_ITEM_MOVE_TO, toIn.GetName()));
            if (remove)
            {
                if (fromUI.MoveAction != null)
                {
                    fromUI.MoveAction.Act(args);
                }
            }
            else
            {
                if (toUI != fromUI)
                {
                    if (toUI.MoveAction != null)
                    {
                        toUI.MoveAction.Act(args);
                    }
                }
            }

            args.Resume(PARA_ITEM);
            args.GetDefault().GetParameters().Resume(PARA_ITEM_MOVE_FROM);
            args.GetDefault().GetParameters().Resume(PARA_ITEM_MOVE_TO);
        }
Ejemplo n.º 9
0
 private static void HandleMoveAction(ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, IEventArgs args)
 {
     HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, true);
     HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, false);
 }
Ejemplo n.º 10
0
        private static void ChangeItemStack(int delta, ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args)
        {
            if (ip.GetCount() <= delta)
            {
                RemoveItem(fromIn, ip, args);
                HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, true);

                old.SetCount(old.GetCount() + (int)MyMath.Min(delta, ip.GetCount()));
                toUI.UpdateItem(args, toIn, old);
            }
            else
            {
                old.SetCount(old.GetKey().GetItemStack());
                ip.SetCount(ip.GetCount() - delta);
                toUI.UpdateItem(args, toIn, old);
                fromUI.UpdateItem(args, fromIn, ip);
            }
        }
Ejemplo n.º 11
0
 private static void MoveItem(int countX, int countY, ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args)
 {
     if (fromIn.CanMoveTo(ip, toIn, countX, countY))
     {
         fromIn.ChangePosition(ip, toIn, countX, countY);
         HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args);
         if (fromIn == toIn)
         {
             fromUI.UpdateItem(args, fromIn, ip);
         }
         else
         {
             fromUI.DeleteItem(args, fromIn, ip);
             toUI.AddItem(args, toIn, ip);
         }
     }
     else
     {
         fromIn.ChangePosition(ip, fromIn, ip.GetX(), ip.GetY());
         if (fromUI.CanNotMoveAction != null)
         {
             fromUI.CanNotMoveAction.Act(args);
         }
         fromUI.UpdateItem(args, fromIn, ip);
     }
 }
Ejemplo n.º 12
0
        public static void Move(ItemInventory fromIn, ItemInventory toIn, ItemPosition ip, int countX, int countY, ISkillArgs args, FreeRuleEventArgs fr, IInventoryUI fromUI, IInventoryUI toUI)
        {
            if (fromIn != toIn)
            {
                fr.TempUse(PARA_ITEM, ip);
                bool canDrop = toIn.IsCanDrop(ip, args);
                // 如果toIn 不可以拖入物品
                if (!canDrop)
                {
                    fromUI.UpdateItem(args, fromIn, ip);
                    if (toIn.GetDropAction() != null)
                    {
                        toIn.GetDropAction().Act(args);
                    }
                    //HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args);
                    fr.Resume(PARA_ITEM);
                    return;
                }
                fr.Resume(PARA_ITEM);
            }
            // 已有
            ItemPosition[] olds = toIn.GetItem(countX, countY, ip.GetKey().GetGridWidth(), ip.GetKey().GetGridHeight());
            ItemPosition   old  = null;

            if (olds.Length == 1)
            {
                old = olds[0];
                if (old != ip)
                {
                    fr.TempUse(PARA_ITEM, ip);
                    if (old.GetKey().GetKey().Equals(ip.GetKey().GetKey()))
                    {
                        int delta = old.GetKey().GetItemStack() - old.GetCount();
                        if (delta > 0)
                        {
                            // 堆叠物品
                            ChangeItemStack(delta, fromIn, toIn, fromUI, toUI, ip, old, args);
                        }
                        else
                        {
                            // 交换物品位置
                            ExchangeItem(fromIn, toIn, fromUI, toUI, ip, old, args);
                        }
                    }
                    else
                    {
                        if (!ip.DragTo(args, old))
                        {
                            ExchangeItem(fromIn, toIn, fromUI, toUI, ip, old, args);
                        }
                        else
                        {
                            if (ip.GetInventory() != null)
                            {
                                fromUI.UpdateItem(args, fromIn, ip);
                            }
                        }
                    }
                    fr.Resume(PARA_ITEM);
                    return;
                }
            }
            fr.TempUse(PARA_ITEM, ip);
            MoveItem(countX, countY, fromIn, toIn, fromUI, toUI, ip, old, args);
            fr.Resume(PARA_ITEM);
        }
Ejemplo n.º 13
0
 public void Init(IInventoryUI inventoryUi, IResourceLoader resourceLoader)
 {
     _resourceLoader        = resourceLoader;
     _attachedUi            = inventoryUi;
     _attachedUi.ItemAdded += UpdateItemView;
 }
Ejemplo n.º 14
0
 public virtual void MoveItemPosition(IInventoryUI toInventory, int x, int y, ISkillArgs args)
 {
 }
Ejemplo n.º 15
0
 public virtual void SetInventoryUI(IInventoryUI redraw)
 {
     this.inventoryUI = redraw;
 }