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 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; }
/*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); }
protected ListViewElementProject CreateListViewElement(SharedProject proj) { ListViewElementProject newElement = null; if (null != ListViewElementPool) { newElement = ListViewElementPool.GetObject(); } if (null == newElement) { newElement = GameObject.Instantiate <ListViewElementProject>(ListViewElementPrefab); MousePointerEvents events = newElement.GetComponent <MousePointerEvents>(); SubscribeToMouseEventPointers(events, proj, TooltipComponent); } else { MousePointerEvents events = newElement.GetComponent <MousePointerEvents>(); events.RemoveAllListeners(); SubscribeToMouseEventPointers(events, proj, TooltipComponent); } newElement.Project = proj; newElement.gameObject.SetActive(true); return(newElement); }
/// <summary> /// Used to display text in tooltip component /// </summary> protected void SubscribeToMouseEventPointers(MousePointerEvents events, SharedProject proj, Tooltip tooltipComponent) { events.PointerEntered += () => { tooltipComponent.gameObject.SetActive(true); string tooltipText = string.Format("Used technologies:\n{0}", GetProjectTechnologiesString(proj)); tooltipComponent.Text = tooltipText; }; events.PointerExited += () => { tooltipComponent.gameObject.SetActive(false); }; }
private void OnProjectsMarketProjectAdded(SharedProject proj) { ListViewElementProject newElement = CreateListViewElement(proj); MousePointerEvents mousePtrEvts = newElement.GetComponent <MousePointerEvents>(); mousePtrEvts.PointerDoubleClick += () => { OnButtonTakeProjectClicked(); }; ButtonSelectorProjects.AddButton(newElement.Button); ListViewMarketProjects.AddControl(newElement.gameObject); newElement.Text.text = GetProjectListViewElementText(proj); newElement.FrontImage.sprite = proj.Icon; SetListViewMarketProjectsText(); proj.CompletionTimeUpdated += OnMarketProjectCompletionTimeUpdated; }