public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette, World world) { widget.IsVisible = () => palette.TooltipIcon != null; var nameLabel = widget.Get<LabelWidget>("NAME"); var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY"); var timeLabel = widget.Get<LabelWidget>("TIME"); var descLabel = widget.Get<LabelWidget>("DESC"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var timeFont = Game.Renderer.Fonts[timeLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font]; var name = ""; var time = ""; var desc = ""; var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { var icon = palette.TooltipIcon; if (icon == null) return; var sp = icon.Power; if (sp.Info == null) return; // no instances actually exist (race with destroy) var remaining = WidgetUtils.FormatTime(sp.RemainingTime, world.Timestep); var total = WidgetUtils.FormatTime(sp.Info.ChargeTime * 25, world.Timestep); time = "{0} / {1}".F(remaining, total); if (sp == lastPower) return; name = sp.Info.Description; desc = sp.Info.LongDesc.Replace("\\n", "\n"); var hotkey = icon.Hotkey; var hotkeyText = "({0})".F(hotkey.DisplayString()); var hotkeyWidth = hotkey.IsValid() ? nameFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0; hotkeyLabel.GetText = () => hotkeyText; hotkeyLabel.Bounds.X = nameFont.Measure(name).X + 2 * nameLabel.Bounds.X; hotkeyLabel.Visible = hotkey.IsValid(); var timeWidth = timeFont.Measure(time).X; var topWidth = nameFont.Measure(name).X + hotkeyWidth + timeWidth + timeOffset; var descSize = descFont.Measure(desc); widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth; lastPower = sp; }; nameLabel.GetText = () => name; timeLabel.GetText = () => time; descLabel.GetText = () => desc; }
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette) { widget.IsVisible = () => palette.TooltipPower != null; var nameLabel = widget.Get<LabelWidget>("NAME"); var timeLabel = widget.Get<LabelWidget>("TIME"); var descLabel = widget.Get<LabelWidget>("DESC"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var timeFont = Game.Renderer.Fonts[timeLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font]; var name = ""; var time = ""; var desc = ""; var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; SupportPowerManager.SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { var sp = palette.TooltipPower; if (sp == null) return; if (sp.Info == null) return; // no instances actually exist (race with destroy) time = "{0} / {1}".F(WidgetUtils.FormatTime(sp.RemainingTime), WidgetUtils.FormatTime(sp.Info.ChargeTime*25)); if (sp == lastPower) return; name = sp.Info.Description; desc = sp.Info.LongDesc.Replace("\\n", "\n"); var timeWidth = timeFont.Measure(time).X; var topWidth = nameFont.Measure(name).X + timeWidth + timeOffset; var descSize = descFont.Measure(desc); widget.Bounds.Width = 2*nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth; lastPower = sp; }; nameLabel.GetText = () => name; timeLabel.GetText = () => time; descLabel.GetText = () => desc; }
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette) { widget.IsVisible = () => palette.TooltipPower != null; var nameLabel = widget.Get <LabelWidget>("NAME"); var timeLabel = widget.Get <LabelWidget>("TIME"); var descLabel = widget.Get <LabelWidget>("DESC"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var timeFont = Game.Renderer.Fonts[timeLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font]; var name = ""; var time = ""; var desc = ""; var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; SupportPowerManager.SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { var sp = palette.TooltipPower; if (sp == null) { return; } time = "{0} / {1}".F(WidgetUtils.FormatTime(sp.RemainingTime), WidgetUtils.FormatTime(sp.Info.ChargeTime * 25)); if (sp == lastPower) { return; } name = sp.Info.Description; desc = sp.Info.LongDesc.Replace("\\n", "\n"); var timeWidth = timeFont.Measure(time).X; var topWidth = nameFont.Measure(name).X + timeWidth + timeOffset; var descSize = descFont.Measure(desc); widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth; lastPower = sp; }; nameLabel.GetText = () => name; timeLabel.GetText = () => time; descLabel.GetText = () => desc; }
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette) { widget.IsVisible = () => palette.TooltipIcon != null; var nameLabel = widget.Get <LabelWidget>("NAME"); var hotkeyLabel = widget.Get <LabelWidget>("HOTKEY"); var timeLabel = widget.Get <LabelWidget>("TIME"); var descLabel = widget.Get <LabelWidget>("DESC"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var timeFont = Game.Renderer.Fonts[timeLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font]; var name = ""; var time = ""; var desc = ""; var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { var icon = palette.TooltipIcon; if (icon == null) { return; } var sp = icon.Power; if (sp.Info == null) { return; // no instances actually exist (race with destroy) } time = "{0} / {1}".F(WidgetUtils.FormatTime(sp.RemainingTime), WidgetUtils.FormatTime(sp.Info.ChargeTime * 25)); if (sp == lastPower) { return; } name = sp.Info.Description; desc = sp.Info.LongDesc.Replace("\\n", "\n"); var hotkey = icon.Hotkey; var hotkeyText = "({0})".F(hotkey.DisplayString()); var hotkeyWidth = hotkey.IsValid() ? nameFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0; hotkeyLabel.GetText = () => hotkeyText; hotkeyLabel.Bounds.X = nameFont.Measure(name).X + 2 * nameLabel.Bounds.X; hotkeyLabel.Visible = hotkey.IsValid(); var timeWidth = timeFont.Measure(time).X; var topWidth = nameFont.Measure(name).X + hotkeyWidth + timeWidth + timeOffset; var descSize = descFont.Measure(desc); widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth; lastPower = sp; }; nameLabel.GetText = () => name; timeLabel.GetText = () => time; descLabel.GetText = () => desc; }
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Player player, SupportPowersWidget palette, World world, PlayerResources playerResources) { widget.IsVisible = () => palette.TooltipIcon != null && palette.TooltipIcon.Power.Info != null; var nameLabel = widget.Get <LabelWidget>("NAME"); var hotkeyLabel = widget.Get <LabelWidget>("HOTKEY"); var timeLabel = widget.Get <LabelWidget>("TIME"); var descLabel = widget.Get <LabelWidget>("DESC"); var costLabel = widget.Get <LabelWidget>("COST"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var hotkeyFont = Game.Renderer.Fonts[hotkeyLabel.Font]; var timeFont = Game.Renderer.Fonts[timeLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font]; var costFont = Game.Renderer.Fonts[costLabel.Font]; var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; var costOffset = costLabel.Bounds.X; SupportPowerInstance lastPower = null; Hotkey lastHotkey = Hotkey.Invalid; var lastRemainingSeconds = 0; tooltipContainer.BeforeRender = () => { var icon = palette.TooltipIcon; if (icon == null) { return; } var sp = icon.Power; // HACK: This abuses knowledge of the internals of WidgetUtils.FormatTime // to efficiently work when the label is going to change, requiring a panel relayout var remainingSeconds = (int)Math.Ceiling(sp.RemainingTime * world.Timestep / 1000f); var hotkey = icon.Hotkey != null?icon.Hotkey.GetValue() : Hotkey.Invalid; if (sp == lastPower && hotkey == lastHotkey && lastRemainingSeconds == remainingSeconds) { return; } var cost = sp.Info.Cost; var costString = costLabel.Text + cost.ToString(); costLabel.GetText = () => costString; costLabel.GetColor = () => playerResources.Cash + playerResources.Resources >= cost ? Color.White : Color.Red; costLabel.IsVisible = () => cost != 0; nameLabel.Text = sp.Info.Description; var nameSize = nameFont.Measure(nameLabel.Text); descLabel.Text = sp.Info.LongDesc.Replace("\\n", "\n"); var descSize = descFont.Measure(descLabel.Text); var remaining = WidgetUtils.FormatTime(sp.RemainingTime, world.Timestep); var total = WidgetUtils.FormatTime(sp.Info.ChargeTime * 25, world.Timestep); timeLabel.Text = "{0} / {1}".F(remaining, total); var timeSize = timeFont.Measure(timeLabel.Text); var hotkeyWidth = 0; hotkeyLabel.Visible = hotkey.IsValid(); if (hotkeyLabel.Visible) { var hotkeyText = "({0})".F(hotkey.DisplayString()); hotkeyWidth = hotkeyFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X; hotkeyLabel.Text = hotkeyText; hotkeyLabel.Bounds.X = nameSize.X + 2 * nameLabel.Bounds.X; } var timeWidth = timeSize.X; var costWidth = costFont.Measure(costString).X; var topWidth = nameSize.X + hotkeyWidth + timeWidth + timeOffset; if (cost != 0) { topWidth += costWidth + costOffset; } widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth; if (cost != 0) { timeLabel.Bounds.X -= costWidth + costOffset; costLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - costWidth; } lastPower = sp; lastHotkey = hotkey; lastRemainingSeconds = remainingSeconds; }; timeLabel.GetColor = () => palette.TooltipIcon != null && !palette.TooltipIcon.Power.Active ? Color.Red : Color.White; }
public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette, World world, PlayerResources playerResources) { widget.IsVisible = () => palette.TooltipIcon != null; var nameLabel = widget.Get <LabelWidget>("NAME"); var hotkeyLabel = widget.Get <LabelWidget>("HOTKEY"); var timeLabel = widget.Get <LabelWidget>("TIME"); var descLabel = widget.Get <LabelWidget>("DESC"); var costLabel = widget.Get <LabelWidget>("COST"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var timeFont = Game.Renderer.Fonts[timeLabel.Font]; var descFont = Game.Renderer.Fonts[descLabel.Font]; var costFont = Game.Renderer.Fonts[costLabel.Font]; var name = ""; var time = ""; var desc = ""; var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; var costOffset = costLabel.Bounds.X; SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { var icon = palette.TooltipIcon; if (icon == null) { return; } var sp = icon.Power; if (sp.Info == null) { return; // no instances actually exist (race with destroy) } var remaining = WidgetUtils.FormatTime(sp.RemainingTime, world.Timestep); var total = WidgetUtils.FormatTime(sp.Info.ChargeTime * 25, world.Timestep); time = "{0} / {1}".F(remaining, total); if (sp == lastPower) { return; } var cost = sp.Info.Cost; var costString = costLabel.Text + cost.ToString(); costLabel.GetText = () => costString; costLabel.GetColor = () => playerResources.Cash + playerResources.Resources >= cost ? Color.White : Color.Red; costLabel.IsVisible = () => cost != 0; name = sp.Info.Description; desc = sp.Info.LongDesc.Replace("\\n", "\n"); var hotkey = icon.Hotkey; var hotkeyText = "({0})".F(hotkey.DisplayString()); var hotkeyWidth = hotkey.IsValid() ? nameFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0; hotkeyLabel.GetText = () => hotkeyText; hotkeyLabel.Bounds.X = nameFont.Measure(name).X + 2 * nameLabel.Bounds.X; hotkeyLabel.Visible = hotkey.IsValid(); var timeWidth = timeFont.Measure(time).X; var costWidth = costFont.Measure(costString).X; var topWidth = nameFont.Measure(name).X + hotkeyWidth + timeWidth + timeOffset; if (cost != 0) { topWidth += costWidth + costOffset; } var descSize = descFont.Measure(desc); widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth; if (cost != 0) { timeLabel.Bounds.X -= costWidth + costOffset; costLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - costWidth; } lastPower = sp; }; nameLabel.GetText = () => name; timeLabel.GetText = () => time; descLabel.GetText = () => desc; }