public void PopulateTransportLineLabels() { foreach (var index in TransportUtil.GetUsedTransportLineIndices()) { if (TransportUtil.GetTransportLineType(index) != Type) { continue; } var go = new GameObject(Enum.GetName(typeof(TransportInfo.TransportType), Type) + "LineRow"); var uic = go.AddComponent <UITransportLineRow>(); uic.LineID = index; uic.IsLineHidden = TransportUtil.IsTransportLineHidden(index); _transportLineLabels.Add(go); } _transportLineLabels.Sort( (left, right) => String.Compare(left.GetComponent <UITransportLineRow>() .LineName, right.GetComponent <UITransportLineRow>().LineName, StringComparison.OrdinalIgnoreCase) ); bool odd = false; foreach (var go in _transportLineLabels) { AttachUIComponent(go); go.GetComponent <UITransportLineRow>().IsOdd = odd; odd = !odd; } var neededHeight = _transportLineLabels.Count * (16 + 2) + 95; height = Mathf.Clamp(neededHeight, 347, 1000); switch (Type) { case TransportInfo.TransportType.Bus: _title.TitleText = String.Format("Bus Lines ({0})", _transportLineLabels.Count); break; case TransportInfo.TransportType.Metro: _title.TitleText = String.Format("Metro Lines ({0})", _transportLineLabels.Count); break; case TransportInfo.TransportType.Train: _title.TitleText = String.Format("Train Lines ({0})", _transportLineLabels.Count); break; } }
public override void Update() { base.Update(); var residents = TransportUtil.GetResidentPassengerCount(LineID); var tourists = TransportUtil.GetTouristPassengerCount(LineID); LineName = TransportUtil.GetLineName(LineID); _name.text = LineName; _stops.text = TransportUtil.GetStopCount(LineID).ToString(); _passengers.text = String.Format("{0}/{1}", residents, tourists); _trips.text = String.Format("{0}%", TransportUtil.GetTripsSaved(LineID)); _vehicles.text = TransportUtil.GetVehicleCount(LineID).ToString(); _color.selectedColor = TransportUtil.GetLineColor(LineID); }
public void PopulateTransportLineLabels(string sortFieldName = "LineName") { foreach (var index in TransportUtil.GetUsedTransportLineIndices()) { if (TransportUtil.GetTransportLineType(index) != Type) { continue; } var go = new GameObject(Enum.GetName(typeof(TransportInfo.TransportType), Type) + "LineRow"); var uic = go.AddComponent <UITransportLineRow>(); uic.LineID = index; uic.LineNameChanged += id => { ClearTransportLineLabels(); PopulateTransportLineLabels(); }; _transportLineLabels.Add(go); } _transportLineLabels.Sort(new LineComparer(sortFieldName)); bool odd = false; foreach (var go in _transportLineLabels) { _scrollablePanel.AttachUIComponent(go); go.GetComponent <UITransportLineRow>().IsOdd = odd; odd = !odd; } switch (Type) { case TransportInfo.TransportType.Bus: _title.TitleText = String.Format("Bus Lines ({0})", _transportLineLabels.Count); break; case TransportInfo.TransportType.Metro: _title.TitleText = String.Format("Metro Lines ({0})", _transportLineLabels.Count); break; case TransportInfo.TransportType.Train: _title.TitleText = String.Format("Train Lines ({0})", _transportLineLabels.Count); break; } }
public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { var handlers = LineCountChanged; if (handlers == null) { return; } var newCount = TransportUtil.GetUsedTransportLineIndices().Count; if (newCount != _lineCount) { handlers(newCount); _lineCount = newCount; } }
public override void Update() { base.Update(); var residents = TransportUtil.GetResidentPassengerCount(LineID); var tourists = TransportUtil.GetTouristPassengerCount(LineID); var lineName = TransportUtil.GetLineName(LineID); if (lineName != LineName) { var handlers = LineNameChanged; if (handlers != null) { handlers(LineID); } } LineName = lineName; _name.text = LineName.Trim(); /*bool clipped = false; * while (_name.width > 110) * { * _name.text = _name.text.Remove(_name.text.Length - 1); * clipped = true; * } * if (clipped) * _name.text = _name.text.Trim() + "...";*/ _stops.text = Stops.ToString(); _passengers.text = String.Format("{0}/{1}", residents, tourists); _trips.text = String.Format("{0}%", Trips); _vehicles.text = Vehicles.ToString(); _color.selectedColor = TransportUtil.GetLineColor(LineID); IsChecked = !TransportUtil.IsTransportLineHidden(LineID); }
public override void Start() { base.Start(); _checkBox.relativePosition = new Vector3(5, 0); _color.relativePosition = new Vector3(22, 0); _name.relativePosition = new Vector3(43, 0); _stops.relativePosition = new Vector3(170, 0); _passengers.relativePosition = new Vector3(225, 0); _trips.relativePosition = new Vector3(320, 0); _vehicles.relativePosition = new Vector3(401, 0); _name.textColor = new Color32(185, 221, 254, 255); _stops.textColor = new Color32(185, 221, 254, 255); _passengers.textColor = new Color32(185, 221, 254, 255); _trips.textColor = new Color32(185, 221, 254, 255); _vehicles.textColor = new Color32(185, 221, 254, 255); _checkBox.size = new Vector2(12, 12); _checkBox.IsChecked = !IsLineHidden; _color.normalBgSprite = "ColorPickerOutline"; _color.normalFgSprite = "ColorPickerColor"; _color.hoveredBgSprite = "ColorPickerOutlineHovered"; _color.size = new Vector2(15, 15); //_color.triggerButton = _color.AddUIComponent<UIButton>(); /* // Need to attach the ColorPicker somehow, the Button is being setup by ColorField itself (That's what I believe at least) * var panel = UIView.library.Get<PublicTransportWorldInfoPanel>("PublicTransportWorldInfoPanel"); * var fieldInfo = typeof (PublicTransportWorldInfoPanel).GetField("m_ColorField", BindingFlags.NonPublic | BindingFlags.Instance); * var picker = (UIColorField)fieldInfo.GetValue(panel); * _color.colorPicker = Instantiate<UIColorPicker>(picker.colorPicker); */ // event handler _checkBox.eventClick += (component, param) => { _checkBox.IsChecked = !_checkBox.IsChecked; if (!_checkBox.IsChecked) { TransportUtil.HideTransportLine(LineID); } else { TransportUtil.ShowTransportLine(LineID); } }; _name.eventClick += (component, param) => WorldInfoPanel.Show <PublicTransportWorldInfoPanel>(TransportUtil.GetFirstLineStop(LineID), InstanceID); _name.eventMouseHover += (component, param) => { TransportUtil.SelectTransportLine(LineID); _name.textColor = TransportUtil.GetLineColor(LineID); }; _name.eventMouseLeave += (component, param) => { TransportUtil.DeselectTransportLine(LineID); _name.textColor = new Color32(185, 221, 254, 255); }; // scale label texts _name.textScale = 0.8f; _stops.textScale = 0.8f; _passengers.textScale = 0.8f; _trips.textScale = 0.8f; _vehicles.textScale = 0.8f; // zebra stripes background backgroundSprite = "GenericPanelLight"; if (IsOdd) { color = new Color32(150, 150, 150, 255); } else { color = new Color32(130, 130, 130, 255); } // center elements in row UIComponent[] children = GetComponentsInChildren <UIComponent>(); foreach (UIComponent child in children) { if (child == this) { continue; } child.pivot = UIPivotPoint.MiddleLeft; child.transformPosition = new Vector3(child.transformPosition.x, GetBounds().center.y, 0); } }
public void HideLine() { TransportUtil.HideTransportLine(LineID); _checkBox.IsChecked = false; }
public void ShowLine() { TransportUtil.ShowTransportLine(LineID); _checkBox.IsChecked = true; }
private void SetupControls() { _transportLineLabels = new List <GameObject>(); _title = AddUIComponent <UITitleContainer>(); _title.Parent = this; _buttons = AddUIComponent <UIButtonContainer>(); _captions = AddUIComponent <UICaptionContainer>(); switch (Type) { case TransportInfo.TransportType.Bus: _title.IconSprite = "SubBarPublicTransportBus"; _title.TitleText = "Bus Lines"; break; case TransportInfo.TransportType.Metro: _title.IconSprite = "SubBarPublicTransportMetro"; _title.TitleText = "Metro Lines"; break; case TransportInfo.TransportType.Train: _title.IconSprite = "SubBarPublicTransportTrain"; _title.TitleText = "Train Lines"; break; } eventVisibilityChanged += (component, visible) => { if (visible) { foreach (var index in TransportUtil.GetUsedTransportLineIndices()) { if (TransportUtil.GetTransportLineType(index) != Type) { TransportUtil.HideTransportLine(index); } } } else { foreach (var index in TransportUtil.GetUsedTransportLineIndices()) { TransportUtil.ShowTransportLine(index); } } }; // update if lines added or deleted TransportObserver.LineCountChanged += count => { ClearTransportLineLabels(); PopulateTransportLineLabels(); }; _buttons.SelectAll.eventClick += (component, param) => { foreach (var go in _transportLineLabels) { var row = go.GetComponent <UITransportLineRow>(); row.ShowLine(); } }; _buttons.SelectNone.eventClick += (component, param) => { foreach (var go in _transportLineLabels) { var row = go.GetComponent <UITransportLineRow>(); row.HideLine(); } }; }
public void HideLine() { TransportUtil.HideTransportLine(LineID); }
public void ShowLine() { TransportUtil.ShowTransportLine(LineID); }
public override void Start() { base.Start(); _checkBox = AddUIComponent <UICustomCheckbox>(); _colorFieldPanel = AddUIComponent <UIPanel>(); _colorFieldPanel.size = new Vector2(17, 17); _colorFieldPanel.relativePosition = new Vector3(22, 0); _color = Instantiate(FindObjectOfType <UIColorField>().gameObject).GetComponent <UIColorField>(); _colorFieldPanel.AttachUIComponent(_color.gameObject); _color.name = "ColorPickerLine" + LineID; _color.size = new Vector2(17, 17); _color.relativePosition = new Vector3(0, 0); _color.pickerPosition = UIColorField.ColorPickerPosition.RightAbove; _color.eventSelectedColorChanged += (component, value) => TransportUtil.SetLineColor(LineID, value); _name = AddUIComponent <UILabel>(); _stops = AddUIComponent <UILabel>(); _passengers = AddUIComponent <UILabel>(); _trips = AddUIComponent <UILabel>(); _vehicles = AddUIComponent <UILabel>(); _deleteButton = AddUIComponent <UIButton>(); _deleteButton.size = new Vector2(17, 17); _deleteButton.tooltip = "Delete line"; _deleteButton.normalFgSprite = "buttonclose"; _deleteButton.pressedFgSprite = "buttonclosepressed"; _deleteButton.hoveredFgSprite = "buttonclosehover"; _deleteButton.isVisible = true; _checkBox.relativePosition = new Vector3(5, 0); _name.relativePosition = new Vector3(43, 0); _stops.relativePosition = new Vector3(170, 0); _passengers.relativePosition = new Vector3(225, 0); _trips.relativePosition = new Vector3(320, 0); _vehicles.relativePosition = new Vector3(401, 0); _deleteButton.relativePosition = new Vector3(435, 0); _name.textColor = new Color32(185, 221, 254, 255); _stops.textColor = new Color32(185, 221, 254, 255); _passengers.textColor = new Color32(185, 221, 254, 255); _trips.textColor = new Color32(185, 221, 254, 255); _vehicles.textColor = new Color32(185, 221, 254, 255); _checkBox.size = new Vector2(12, 12); // event handler _checkBox.eventClick += (component, param) => { _checkBox.IsChecked = !_checkBox.IsChecked; if (!_checkBox.IsChecked) { TransportUtil.HideTransportLine(LineID); } else { TransportUtil.ShowTransportLine(LineID); } }; _name.eventClick += (component, param) => WorldInfoPanel.Show <PublicTransportWorldInfoPanel>(TransportUtil.GetFirstLineStop(LineID), InstanceID); _name.eventMouseHover += (component, param) => { TransportUtil.SelectTransportLine(LineID); _name.textColor = TransportUtil.GetLineColor(LineID); }; _name.eventMouseLeave += (component, param) => { TransportUtil.DeselectTransportLine(LineID); _name.textColor = new Color32(185, 221, 254, 255); }; _deleteButton.eventClick += (component, param) => Singleton <TransportManager> .instance.ReleaseLine(LineID); // scale label texts _name.textScale = 0.8f; _stops.textScale = 0.8f; _passengers.textScale = 0.8f; _trips.textScale = 0.8f; _vehicles.textScale = 0.8f; _deleteButton.textScale = 0.8f; // zebra stripes background backgroundSprite = "GenericPanelLight"; if (IsOdd) { color = new Color32(150, 150, 150, 255); } else { color = new Color32(130, 130, 130, 255); } // center elements in row UIComponent[] children = GetComponentsInChildren <UIComponent>(); foreach (UIComponent child in children) { if (child == this) { continue; } child.pivot = UIPivotPoint.MiddleLeft; child.transformPosition = new Vector3(child.transformPosition.x, GetBounds().center.y, 0); } }