Esempio n. 1
0
        private void AddWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            ListViewElementWorker element = UIWorkers.CreateWorkerListViewElement(worker, WorkerListViewElementPrefab, TooltipComponent);

            Button             buttonComponent = element.GetComponent <Button>();
            MousePointerEvents mousePtrEvts    = element.GetComponent <MousePointerEvents>();

            mousePtrEvts.PointerDoubleClick += () =>
            {
                if (listView == ListViewMarketWorkers &&
                    true == SimulationManagerComponent.ControlledCompany.CanHireWorker)
                {
                    OnHireWorkerButtonClicked();
                }
            };

            if (null == WorkerListViewMap)
            {
                WorkerListViewMap = new Dictionary <SharedWorker, ListViewElementWorker>();
            }

            listView.AddControl(element.gameObject);
            WorkerListViewMap.Add(worker, element);
            WorkersButtonSelector.AddButton(buttonComponent);
            worker.SalaryChanged += OnWorkerSalaryChanged;
        }
        private void AddWorkerListViewElement(SharedWorker playerWorker, ControlListView listView)
        {
            ListViewElementWorker element =
                UIWorkers.CreateWorkerListViewElement(playerWorker, WorkerListViewElementPrefab, TooltipComponent);

            Button buttonComponent = element.GetComponent <Button>();

            if (null == WorkerListViewMap)
            {
                WorkerListViewMap = new Dictionary <SharedWorker, ListViewElementWorker>();
            }

            if (listView == ListViewOtherPlayersWorkers)
            {
                MousePointerEvents mouseEvts = element.GetComponent <MousePointerEvents>();
                mouseEvts.PointerDoubleClick += () =>
                {
                    if (true == SimulationManagerComponent.ControlledCompany.CanHireWorker)
                    {
                        OnButtonHireWorkerClick();
                    }
                };
            }

            WorkerListViewMap.Add(playerWorker, element);
            listView.AddControl(element.gameObject);
            WorkersButtonSelector.AddButton(buttonComponent);
        }
        private void OnControlledCompanyWorkerAdded(LocalWorker companyWorker)
        {
            ListViewElementWorker newElement = CreateWorkerListViewElement(companyWorker);

            ListViewAvailableWorkers.AddControl(newElement.gameObject);
            SetListViewAvailableWorkersText();
        }
Esempio n. 4
0
        /*Public consts fields*/

        /*Public fields*/

        /*Private methods*/

        /*Public methods*/

        public static ListViewElementWorker CreateWorkerListViewElement(SharedWorker worker, ListViewElementWorker prefab, Tooltip tooltipComponent = null)
        {
            ListViewElementWorker element = GameObject.Instantiate <ListViewElementWorker>(prefab);

            if (null != tooltipComponent)
            {
                MousePointerEvents mousePtrEvt = element.gameObject.AddComponent <MousePointerEvents>();

                mousePtrEvt.PointerEntered += () =>
                {
                    tooltipComponent.gameObject.SetActive(true);
                    tooltipComponent.Text = GetWorkerAbilitiesString(worker);
                };

                mousePtrEvt.PointerExited += () =>
                {
                    tooltipComponent.gameObject.SetActive(false);
                };
            }

            element.Text.text         = GetWorkerListViewElementText(worker);
            element.Worker            = worker;
            element.FrontImage.sprite = worker.Avatar;

            return(element);
        }
        private void OnWorkersButtonsSelectorSelectedButtonChanged(Button btn)
        {
            if (null != SelectedWorker)
            {
                UnsubscribeFromWorkerEvents(SelectedWorker);
            }

            if (null != btn)
            {
                ListViewElementWorker element = btn.GetComponent <ListViewElementWorker>();
                SelectedWorker = (LocalWorker)element.Worker;
                SubscribeToWorkerEvents(SelectedWorker);
                ButtonFireWorker.interactable        = true;
                ButtonGiveSalaryRaise.interactable   = true;
                SliderSalaryRaiseAmount.interactable = true;
                SetWorkerText();
                ToggleWorkerInfoText(true);
            }
            else
            {
                if (null != SelectedWorker)
                {
                    UnsubscribeFromWorkerEvents(SelectedWorker);
                }

                SelectedWorker = null;
                ButtonFireWorker.interactable        = false;
                ButtonGiveSalaryRaise.interactable   = false;
                SliderSalaryRaiseAmount.interactable = false;
                ToggleWorkerInfoText(false);
            }
        }
        private void RemoveWorkerListViewElement(SharedWorker companyWorker)
        {
            LocalWorker           worker          = (LocalWorker)companyWorker;
            ControlListViewDrop   workerListView  = (null == worker.AssignedProject) ? ListViewAvailableWorkers : ListViewAssignedWorkers;
            ListViewElementWorker listViewElement = UIWorkers.GetWorkerListViewElement(companyWorker, workerListView);

            RemoveWorkerListViewElement(listViewElement, workerListView);
        }
        public void OnButtonGiveSalaryRaiseClicked()
        {
            int    salaryRaiseAmount            = (int)SliderSalaryRaiseAmount.value;
            Button selectedButton               = WorkersButtonsSelector.GetSelectedButton();
            ListViewElementWorker element       = selectedButton.GetComponent <ListViewElementWorker>();
            LocalWorker           companyWorker = (LocalWorker)element.Worker;

            companyWorker.Salary = companyWorker.Salary + salaryRaiseAmount;
        }
        private void RemoveWorkerListViewElement(LocalWorker worker, ControlListView listView)
        {
            ListViewElementWorker element = UIWorkers.GetWorkerListViewElement(worker, listView);
            Button buttonComponent        = element.GetComponent <Button>();

            WorkersButtonsSelector.RemoveButton(buttonComponent);
            ListViewWorkers.RemoveControl(element.gameObject);
            worker.SatisfactionChanged -= OnWorkerSatisfactionChanged;
        }
Esempio n. 9
0
        private void RemoveWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            ListViewElementWorker element = WorkerListViewMap.First(x => x.Key == worker).Value;
            Button buttonComponent        = element.GetComponent <Button>();

            listView.RemoveControl(element.gameObject);
            WorkerListViewMap.Remove(worker);
            WorkersButtonSelector.RemoveButton(buttonComponent);
            worker.SalaryChanged -= OnWorkerSalaryChanged;
        }
        private void RemoveWorkerListViewElement(ListViewElementWorker element, ControlListView listView)
        {
            listView.RemoveControl(element.gameObject, false);
            element.gameObject.SetActive(false);

            if (null == WorkerListViewElementsPool)
            {
                WorkerListViewElementsPool = new ObjectPool <ListViewElementWorker>();
            }

            WorkerListViewElementsPool.AddObject(element);
        }
        private void RemoveWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            if (null != WorkerListViewMap)
            {
                ListViewElementWorker element = WorkerListViewMap[worker];
                Button buttonComponent        = element.Button;

                WorkerListViewMap.Remove(worker);
                WorkersButtonSelector.RemoveButton(buttonComponent);
                listView.RemoveControl(element.gameObject);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Returns list view element representing worker
        /// </summary>
        public static ListViewElementWorker GetWorkerListViewElement(SharedWorker worker, ControlListView listView)
        {
            GameObject elementGameObject = listView.Controls.Find(
                x => x.GetComponent <ListViewElementWorker>().Worker == worker);
            ListViewElementWorker element = null;

            if (null != elementGameObject)
            {
                element = elementGameObject.GetComponent <ListViewElementWorker>();
            }

            return(element);
        }
        /*Public methods*/

        public void OnButtonHireWorkerClick()
        {
            Button selectedWorkerButton          = WorkersButtonSelector.GetSelectedButton();
            ListViewElementWorker element        = selectedWorkerButton.GetComponent <ListViewElementWorker>();
            SharedWorker          selectedWorker = WorkerListViewMap.First(x => x.Value == element).Key;

            string infoWindowText = string.Format("Do you want to hire this worker ? It will cost you {0} $", selectedWorker.HireSalary);

            InfoWindowComponent.ShowOkCancel(infoWindowText, () =>
            {
                SimulationManagerComponent.HireOtherPlayerWorker(SelectedPlayer, selectedWorker);
            }, null);
        }
Esempio n. 14
0
        public void OnDrop(PointerEventData eventData)
        {
            ListViewElementWorker e = eventData.pointerDrag.GetComponent <ListViewElementWorker>();

            //Element might be dropped in list view that it was dragged from
            //For some reason sometimes Unity UI system call this even when
            //dropping at same object it was dragged from
            if (false == Controls.Contains(eventData.pointerDrag) &&
                e != null)
            {
                AddControl(eventData.pointerDrag);
            }
        }
        private void OnGameTimeComponentDayChanged()
        {
            foreach (GameObject listViewObject in ListViewAssignedWorkers.Controls)
            {
                ListViewElementWorker element = listViewObject.GetComponent <ListViewElementWorker>();
                element.Text.text = GetWorkerListViewElementText((LocalWorker)element.Worker);
            }

            foreach (GameObject listViewObject in ListViewAvailableWorkers.Controls)
            {
                ListViewElementWorker element = listViewObject.GetComponent <ListViewElementWorker>();
                element.Text.text = GetWorkerListViewElementText((LocalWorker)element.Worker);
            }
        }
        /*Public methods*/

        public void OnButtonFireWorkerClicked()
        {
            Button selectedButton                = WorkersButtonsSelector.GetSelectedButton();
            ListViewElementWorker element        = selectedButton.GetComponent <ListViewElementWorker>();
            LocalWorker           workerToRemove = (LocalWorker)element.Worker;

            string infoWindowMsg = string.Format("Do you really want to fire {0} {1} ?",
                                                 workerToRemove.Name,
                                                 workerToRemove.Surename);

            InfoWindowComponent.ShowOkCancel(infoWindowMsg,
                                             () => { SimulationManagerComponent.ControlledCompany.RemoveWorker(workerToRemove); },
                                             null);
        }
        private void OnProjectWorkerRemoved(SharedWorker companyWorker)
        {
            ListViewElementWorker element = UIWorkers.GetWorkerListViewElement(companyWorker, ListViewAssignedWorkers);

            //Check if list view element was dragged to other list view
            if (null != element)
            {
                RemoveWorkerListViewElement(element, ListViewAssignedWorkers);
                ListViewElementWorker newElement = CreateWorkerListViewElement((LocalWorker)companyWorker);
                ListViewAvailableWorkers.AddControl(newElement.gameObject);
            }

            SetListViewAssignedWorkersText();
            SetListViewAvailableWorkersText();
            SetProjectInfo();
        }
        private ListViewElementWorker CreateWorkerListViewElement(LocalWorker companyWorker)
        {
            ListViewElementWorker element =
                UIWorkers.CreateWorkerListViewElement(companyWorker, WorkerListViewElementPrefab, TooltipComponent);

            element.Text.text = GetWorkerListViewElementText(companyWorker);
            Button buttonComponent = element.GetComponent <Button>();

            WorkersButtonsSelector.AddButton(buttonComponent);
            ListViewWorkers.AddControl(element.gameObject);

            //List view element contains information about satisfaction so it should be updated whenever it changes
            companyWorker.SatisfactionChanged += OnWorkerSatisfactionChanged;

            return(element);
        }
Esempio n. 19
0
        private void OnSelectedWorkerButtonChanged(Button workerButton)
        {
            if (null != workerButton)
            {
                ListViewElementWorker selectedElement = workerButton.gameObject.GetComponent <ListViewElementWorker>();
                SelectedWorker = WorkerListViewMap.First(x => x.Value == selectedElement).Key;

                SetActionButtonsState(SelectedWorker);
                SetWorkerInfoText(SelectedWorker);
            }
            else
            {
                SetWorkerInfoText(null);
                SetActionButtonsState(null);
                RectTransform textObjectTransform = TextAbilities.transform.parent.GetComponent <RectTransform>();
                textObjectTransform.sizeDelta = TextAbilitiesSize;
            }
        }
        private void OnWorkerSalaryChanged(SharedWorker companyWorker)
        {
            if (null != SelectedWorker && companyWorker.ID == SelectedWorker.ID)
            {
                TextSalary.text = UIWorkers.GetWorkerSalaryString(companyWorker);
            }

            ListViewElementWorker elem = null;

            if (companyWorker is LocalWorker)
            {
                elem = UIWorkers.GetWorkerListViewElement(companyWorker, ListViewCompanyWorkers);
            }
            else
            {
                elem = UIWorkers.GetWorkerListViewElement(companyWorker, ListViewOtherPlayersWorkers);
            }

            elem.Text.text = UIWorkers.GetWorkerListViewElementText(companyWorker);
        }
        private ListViewElementWorker CreateWorkerListViewElement(LocalWorker companyWorker)
        {
            ListViewElementWorker newElement = null;

            if (null != WorkerListViewElementsPool)
            {
                newElement = WorkerListViewElementsPool.GetObject();
            }

            if (null == newElement)
            {
                newElement = UIWorkers.CreateWorkerListViewElement(companyWorker, ListViewWorkerElementPrefab, TooltipComponent);
                UIElementDrag drag = newElement.GetComponent <UIElementDrag>();
                drag.DragParentTransform = gameObject.GetComponent <RectTransform>();
            }

            newElement.gameObject.SetActive(true);
            newElement.Text.text = GetWorkerListViewElementText(companyWorker);
            newElement.Worker    = companyWorker;

            return(newElement);
        }
        private void OnProjectListViewSelectedElementChanged(Button btn)
        {
            if (null != SelectedScrum)
            {
                UnsubscribeProjectEvents();

                foreach (LocalWorker worker in SelectedScrum.BindedProject.Workers)
                {
                    ListViewElementWorker element = UIWorkers.GetWorkerListViewElement(worker, ListViewAssignedWorkers);
                    element.gameObject.SetActive(false);
                }
            }

            if (null != btn)
            {
                ListViewElementProject element = btn.GetComponent <ListViewElementProject>();
                SelectedScrum = SimulationManagerComponent.ControlledCompany.ScrumProcesses.Find(x =>
                {
                    return(element.Project == x.BindedProject);
                });

                SetProjectInfo();
                SubscribeProjectEvents();
                SetListViewAssignedWorkersText();
                ListViewAssignedWorkers.transform.parent.gameObject.SetActive(true);

                foreach (LocalWorker worker in SelectedScrum.BindedProject.Workers)
                {
                    ListViewElementWorker elem = UIWorkers.GetWorkerListViewElement(worker, ListViewAssignedWorkers);
                    elem.gameObject.SetActive(true);
                }
            }
            else
            {
                SelectedScrum = null;
                SetProjectInfo();
                ListViewAssignedWorkers.transform.parent.gameObject.SetActive(false);
            }
        }
        private void OnWorkersSelectedButtonChanged(Button selectedButton)
        {
            if (null != SelectedWorker)
            {
                UnsubscribeFromSelectedWorkerEvents();
            }

            if (null != selectedButton)
            {
                ListViewElementWorker element = selectedButton.GetComponent <ListViewElementWorker>();
                SelectedWorker = WorkerListViewMap.First(x => x.Value == element).Key;
                SetWorkerInfoText(SelectedWorker);
                SubscribeToSelectedWorkerEvents();
                ButtonHireWorker.interactable = (false == SelectedWorker is LocalWorker) &&
                                                (PlayerCompany.MAX_WORKERS_PER_COMPANY > SimulationManagerComponent.ControlledCompany.Workers.Count);
            }
            else
            {
                SelectedWorker = null;
                SetWorkerInfoText(null);
                ButtonHireWorker.interactable = false;
            }
        }
Esempio n. 24
0
        private void OnWorkerSalaryChanged(SharedWorker companyWorker)
        {
            ListViewElementWorker el = WorkerListViewMap[companyWorker];

            el.Text.text = UIWorkers.GetWorkerListViewElementText(companyWorker);
        }
        private void OnWorkerSatisfactionChanged(SharedWorker companyWorker)
        {
            ListViewElementWorker element = UIWorkers.GetWorkerListViewElement(companyWorker, ListViewWorkers);

            element.Text.text = GetWorkerListViewElementText((LocalWorker)companyWorker);
        }