private void requestTooltip(AGuiElement guiElement, Vector2 mousePosition) { if (this.tooltipSource == guiElement) { return; } if (this.tooltipSource != null) { if (this.tooltipGuiLayer.Contains(this.tooltipElement)) { this.tooltipGuiLayer.RemoveElement(this.tooltipElement); } this.tooltipSource = null; this.tooltipElement = null; } if (guiElement == null) { return; } this.tooltipEta = TooltipDelay; this.tooltipSource = guiElement; this.tooltipElement = guiElement.Tooltip.Make(); this.tooltipElement.Position.TooltipNear(mousePosition, 5, 5); this.tooltipMousePosition = mousePosition; }
protected AScene() { this.normalGuiLayer = new GuiLayer(this.guiLayerThickness, this.guiLayerThickness / 2); this.tooltipGuiLayer = new GuiLayer(this.guiLayerThickness / 2, this.guiLayerThickness / 2); this.mouseHovered = this.normalGuiLayer.Root; }
public void HideElement(AGuiElement element) { if (this.normalGuiLayer.Contains(element)) { this.RemoveElement(element); } }
public OutsidePosition RelativeTo(AGuiElement anchor, float xPortionAnchor, float yPortionAnchor, float xPortionThis, float yPortionThis) { var positioner = new RelativeToPositioner(anchor, xPortionAnchor, yPortionAnchor, xPortionThis, yPortionThis); this.positioners.Add(positioner); return(new OutsidePosition(this, positioner)); }
public RelativeToPositioner(AGuiElement anchor, float xPortionAnchor, float yPortionAnchor, float xPortionThis, float yPortionThis) { this.anchor = anchor; this.xPortionAnchor = xPortionAnchor; this.yPortionAnchor = yPortionAnchor; this.xPortionThis = xPortionThis; this.yPortionThis = yPortionThis; }
public void ShowElement(AGuiElement element) { if (this.normalGuiLayer.Contains(element)) { return; } this.AddElement(element, element.Parent ?? this.normalGuiLayer.Root); }
public void AddElement(AGuiElement element, AGuiElement parent, AScene scene) { this.guiHierarchy[element] = new HashSet <AGuiElement>(); this.guiHierarchy[parent].Add(element); element.Attach(scene, parent); this.updateGuiZ(element); element.RecalculatePosition(true); }
public GuiLayer(float z0, float layerThickness) { this.z0 = z0; this.layerThickness = layerThickness; this.Root = new GuiPanel(); this.guiHierarchy[this.Root] = new HashSet <AGuiElement>(); this.Root.Position.FixedCenter(0, 0); this.Root.SetDepth(z0, layerThickness); }
public IEnumerable <AGuiElement> ElementChildren(AGuiElement element) { var layer = this.guiLayers().FirstOrDefault(x => x.Contains(element)); if (layer == null) { return(new AGuiElement[0]); } return(layer.ElementChildren(element)); }
public void AddElement(AGuiElement element, AGuiElement parent, AScene scene) { var treeRoot = element.Below ?? parent; this.guiHierarchy[element] = new HashSet <AGuiElement>(); this.guiHierarchy[treeRoot].Add(element); element.SetDepth(treeRoot.Z0 - treeRoot.ZRange, treeRoot.ZRange); element.Attach(scene, parent); this.updateGuiZ(element); element.Position.Recalculate(); }
public void ResetTooltipContents() { if (this.tooltipSource == null || !this.tooltipGuiLayer.Contains(this.tooltipElement)) { return; } this.tooltipGuiLayer.RemoveElement(this.tooltipElement); this.tooltipElement = this.tooltipSource.Tooltip.Make(); this.tooltipElement.Position.TooltipNear(this.tooltipMousePosition, 5, 5); this.tooltipGuiLayer.AddElement(this.tooltipElement, this); this.tooltipElement.Position.Recalculate(); }
public void RemoveElement(AGuiElement element) { if (this.guiHierarchy.ContainsKey(element)) { foreach (var child in this.guiHierarchy[element].ToList()) { this.RemoveElement(child); } } this.guiHierarchy[element.Parent].Remove(element); this.guiHierarchy.Remove(element); element.Detach(); }
private IEnumerable <AGuiElement> enumeratePostfix(AGuiElement parent) { if (this.guiHierarchy.ContainsKey(parent)) { foreach (var child in this.guiHierarchy[parent]) { foreach (var element in this.enumeratePostfix(child)) { yield return(element); } } } yield return(parent); }
public void HandleMouseMove(MouseEventArgs e, Keys modiferKeys) { if (this.mousePressed.Values.Any(x => x != null)) { handleMouseDrag(e); return; } var mouseGuiPoint = Vector4.Transform(this.mouseToView(e.X, e.Y), this.guiInvProjection).Xy; AGuiElement handler = null; foreach (var element in this.eventHandlerSearch(mouseGuiPoint)) { if (element.OnMouseMove(mouseGuiPoint, modiferKeys)) { handler = element; break; } } if (handler == null) { this.onMouseMove(this.mouseToView(e.X, e.Y), modiferKeys); handler = this.normalGuiLayer.Root; } if (this.mouseHovered != handler) { if (this.mouseHovered != null) { if (this.mouseHovered != this.normalGuiLayer.Root) { this.mouseHovered.OnMouseLeave(); } else { this.onMouseLeave(); } } this.mouseHovered = handler; } this.requestTooltip( this.eventHandlerSearch(mouseGuiPoint).FirstOrDefault(x => x.Tooltip != null), mouseGuiPoint ); }
private void updateGuiZ(AGuiElement element) { var layers = 2; var subroot = element; var treeParent = subroot.Below ?? subroot.Parent; while (treeParent != this.Root) { subroot = treeParent; treeParent = subroot.Below ?? subroot.Parent; layers++; } var zRange = this.layerThickness / layers; if (subroot.ZRange <= zRange) { return; } /* * Updates Z ranges of a subtree, immediate child of layer root. * Other subtrees should not visually overlap so no update needed. */ subroot.SetDepth(this.z0, zRange); var subtrees = new Queue <AGuiElement>(); subtrees.Enqueue(subroot); while (subtrees.Count > 0) { subroot = subtrees.Dequeue(); if (this.guiHierarchy[subroot].Any()) { foreach (var item in this.guiHierarchy[subroot]) { item.SetDepth(subroot.Z0 - subroot.ZRange, subroot.ZRange); subtrees.Enqueue(item); } } } }
public void HandleMouseScroll(MouseEventArgs e) { var mouseGuiPoint = Vector4.Transform(this.mouseToView(e.X, e.Y), this.guiInvProjection).Xy; AGuiElement handler = null; foreach (var element in this.eventHandlerSearch(mouseGuiPoint)) { if (element.OnMouseScroll(mouseGuiPoint, e.Delta)) { handler = element; break; } } if (handler == null) { this.onMouseScroll(Vector4.Transform(this.mouseToView(e.X, e.Y), this.invProjection).Xy, e.Delta); } }
protected virtual void CleanupPopulationGuiElement(AGuiElement e) { }
protected virtual void CleanupCompositionGuiElement(AGuiElement e) { }
protected virtual void CleanupParticulatesGuiElement(AGuiElement e) { }
protected virtual void CleanupNetIncomeGuiElement(AGuiElement e) { }
protected virtual void CleanupScienceGuiElement(AGuiElement e) { }
protected virtual void CleanupDefensiveStrengthGuiElement(AGuiElement e) { }
protected virtual void CleanupLocationGuiElement(AGuiElement e) { }
private void InitializeScienceGuiElement(AGuiElement e) { _scienceLabel = GetLabel(e); }
public StretchRightToPositioner(AGuiElement anchor, float xPortionAnchor, float marginX) { this.anchor = anchor; this.xPortionAnchor = xPortionAnchor; this.marginX = marginX; }
public IEnumerable <AGuiElement> ElementChildren(AGuiElement element) { return(this.guiHierarchy[element]); }
public ElementPosition StretchRightTo(AGuiElement anchor, float xPortionAnchor, float marginX) { this.positioners.Add(new StretchRightToPositioner(anchor, xPortionAnchor, marginX)); return(this); }
protected virtual void CleanupSpeedGuiElement(AGuiElement e) { }
public void AddElement(AGuiElement element) { this.normalGuiLayer.AddElement(element, this); }
private void InitializeStrategicResourcesGuiElement(AGuiElement e) { _resourcesElement = e as ResourcesGuiElement; }
protected virtual void CleanupHealthGuiElement(AGuiElement e) { }
private void InitializeOffensiveStrengthGuiElement(AGuiElement e) { _offensiveStrengthElement = e as StrengthGuiElement; }
protected virtual void CleanupStrategicResourcesGuiElement(AGuiElement e) { }
private void InitializeHealthGuiElement(AGuiElement e) { _healthElement = e as HealthGuiElement; }
protected virtual void CleanupCultureGuiElement(AGuiElement e) { }
private void InitializeHeroGuiElement(AGuiElement e) { _heroElement = e as HeroGuiElement; }
protected virtual void CleanupOrganicsGuiElement(AGuiElement e) { }
public void AddElement(AGuiElement element, AScene scene) { this.AddElement(element, this.Root, scene); }
protected virtual void CleanupEnergyGuiElement(AGuiElement e) { }
public void RemoveElement(AGuiElement element) { this.guiLayers().First(x => x.Contains(element)).RemoveElement(element); }
protected virtual void CleanupApprovalGuiElement(AGuiElement e) { }
protected override void InitializeNameGuiElement(AGuiElement e) { base.InitializeNameGuiElement(e); MyEventListener.Get(e.gameObject).onDoubleClick += NameDoubleClickEventHandler; }
protected virtual void CleanupProductionGuiElement(AGuiElement e) { }
/// <summary> /// Returns the single UILabel sibling or child of the provided GuiElement. /// </summary> /// <param name="element">The element.</param> /// <returns></returns> protected UILabel GetLabel(AGuiElement element) { return element.gameObject.GetSingleComponentInChildren<UILabel>(); }
private void InitializeGuiElement(AGuiElement e) { switch (e.ElementID) { case GuiElementID.ItemNameLabel: InitializeNameGuiElement(e); break; case GuiElementID.Owner: InitializeOwnerGuiElement(e); break; case GuiElementID.Location: InitializeLocationGuiElement(e); break; case GuiElementID.Hero: InitializeHeroGuiElement(e); break; case GuiElementID.Health: InitializeHealthGuiElement(e); break; case GuiElementID.OffensiveStrength: InitializeOffensiveStrengthGuiElement(e); break; case GuiElementID.DefensiveStrength: InitializeDefensiveStrengthGuiElement(e); break; case GuiElementID.Resources: InitializeStrategicResourcesGuiElement(e); break; case GuiElementID.ScienceLabel: InitializeScienceGuiElement(e); break; case GuiElementID.CultureLabel: InitializeCultureGuiElement(e); break; case GuiElementID.NetIncome: InitializeNetIncomeGuiElement(e); break; case GuiElementID.OrganicsLabel: InitializeOrganicsGuiElement(e); break; case GuiElementID.ParticulatesLabel: InitializeParticulatesGuiElement(e); break; case GuiElementID.EnergyLabel: InitializeEnergyGuiElement(e); break; case GuiElementID.Composition: InitializeCompositionGuiElement(e); break; case GuiElementID.Approval: InitializeApprovalGuiElement(e); break; case GuiElementID.PopulationLabel: InitializePopulationGuiElement(e); break; case GuiElementID.Production: InitializeProductionGuiElement(e); break; case GuiElementID.SpeedLabel: InitializeSpeedGuiElement(e); break; default: throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(e.ElementID)); } }
public void AddElement(AGuiElement element, AGuiElement parent) { this.guiLayers().First(x => x.Contains(parent)).AddElement(element, parent, this); }
protected override void CleanupNameGuiElement(AGuiElement e) { base.CleanupNameGuiElement(e); MyEventListener.Get(e.gameObject).onDoubleClick -= NameDoubleClickEventHandler; }
protected override void InitializeCompositionGuiElement(AGuiElement e) { base.InitializeCompositionGuiElement(e); _compositionElement = e as StarbaseCompositionGuiElement; }
private void InitializeLocationGuiElement(AGuiElement e) { _locationElement = e as LocationGuiElement; }
public void AddInsceneElement(AGuiElement element) { this.insceneGuiLayer.AddElement(element, this); }
private void InitializeOwnerGuiElement(AGuiElement e) { _ownerElement = e as OwnerGuiElement; }
protected virtual void InitializeNameGuiElement(AGuiElement e) { _nameLabel = GetLabel(e); }
public bool Contains(AGuiElement element) { return(this.guiHierarchy.ContainsKey(element)); }
private void CleanupGuiElement(AGuiElement e) { switch (e.ElementID) { case GuiElementID.ItemNameLabel: CleanupNameGuiElement(e); break; case GuiElementID.Owner: CleanupOwnerGuiElement(e); break; case GuiElementID.Location: CleanupLocationGuiElement(e); break; case GuiElementID.Hero: CleanupHeroGuiElement(e); break; case GuiElementID.Health: CleanupHealthGuiElement(e); break; case GuiElementID.OffensiveStrength: CleanupOffensiveStrengthGuiElement(e); break; case GuiElementID.DefensiveStrength: CleanupDefensiveStrengthGuiElement(e); break; case GuiElementID.Resources: CleanupStrategicResourcesGuiElement(e); break; case GuiElementID.ScienceLabel: CleanupScienceGuiElement(e); break; case GuiElementID.CultureLabel: CleanupCultureGuiElement(e); break; case GuiElementID.NetIncome: CleanupNetIncomeGuiElement(e); break; case GuiElementID.OrganicsLabel: CleanupOrganicsGuiElement(e); break; case GuiElementID.ParticulatesLabel: CleanupParticulatesGuiElement(e); break; case GuiElementID.EnergyLabel: CleanupEnergyGuiElement(e); break; case GuiElementID.Composition: CleanupCompositionGuiElement(e); break; case GuiElementID.Approval: CleanupApprovalGuiElement(e); break; case GuiElementID.PopulationLabel: CleanupPopulationGuiElement(e); break; case GuiElementID.Production: CleanupProductionGuiElement(e); break; case GuiElementID.SpeedLabel: CleanupSpeedGuiElement(e); break; default: throw new NotImplementedException(ErrorMessages.UnanticipatedSwitchValue.Inject(e.ElementID)); } }
public override void Attach(AScene scene, AGuiElement parent) { base.Attach(scene, parent); this.updateSliderVisibility(); }
protected virtual void CleanupOwnerGuiElement(AGuiElement e) { }
private void addPlanetElement(AGuiElement element) { this.AddElement(element); this.otherPlanetElements.Add(element); }
public override void Attach(AScene scene, AGuiElement parent) { base.Attach(scene, parent); this.group.Add(this); }