public WithTextDecoration(Actor self, WithTextDecorationInfo info) : base(info) { font = Game.Renderer.Fonts[info.Font]; decorationBounds = self.TraitsImplementing <IDecorationBounds>().ToArray(); color = Info.UsePlayerColor ? self.Owner.Color : Info.Color; }
public TextRenderable(SpriteFontMSDF font, WPos pos, int zOffset, Color color, string text) : this(font, pos, zOffset, color, ChromeMetrics.Get <Color>("TextContrastColorDark"), ChromeMetrics.Get <Color>("TextContrastColorLight"), text) { }
public FloatingText(WPos pos, Color color, string text, int duration) { font = Game.Renderer.Fonts["TinyBold"]; this.pos = pos; this.color = color; this.text = text; remaining = duration; }
public TextRenderable(SpriteFontMSDF font, WPos pos, int zOffset, Color color, Color bgDark, Color bgLight, string text) { this.font = font; this.pos = pos; this.zOffset = zOffset; this.color = color; this.bgDark = bgDark; this.bgLight = bgLight; this.text = text; }
public override void Display() { if (r == null || loadTimer.Elapsed.TotalSeconds < 0.25) { return; } loadTimer.Restart(); loadTick = ++loadTick % 8; r.BeginFrame(int2.Zero, 1f); r.RgbaSpriteRenderer.DrawSprite(gdiLogo, gdiPos); r.RgbaSpriteRenderer.DrawSprite(nodLogo, nodPos); r.RgbaSpriteRenderer.DrawSprite(evaLogo, evaPos); WidgetUtils.DrawPanelPartial(bounds, PanelSides.Edges, borderTop, borderBottom, borderLeft, borderRight, cornerTopLeft, cornerTopRight, cornerBottomLeft, cornerBottomRight, null); var barY = bounds.Height - 78; // The fonts dictionary may change when switching between the mod and content installer if (r.Fonts != rendererFonts) { rendererFonts = r.Fonts; loadingFont = r.Fonts["BigBold"]; loadingText = loadInfo["Text"]; loadingPos = new float2((bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY); versionFont = r.Fonts["Regular"]; var versionSize = versionFont.Measure(versionText); versionPos = new float2(bounds.Width - 107 - versionSize.X / 2, 115 - versionSize.Y / 2); } if (loadingFont != null) { loadingFont.DrawText(loadingText, loadingPos, Color.Gray); } if (versionFont != null) { versionFont.DrawTextWithContrast(versionText, versionPos, Color.White, Color.Black, 2); } for (var i = 0; i <= 8; i++) { var block = loadTick == i ? brightBlock : dimBlock; r.RgbaSpriteRenderer.DrawSprite(block, new float2(bounds.Width / 2 - 114 - i * 32, barY)); r.RgbaSpriteRenderer.DrawSprite(block, new float2(bounds.Width / 2 + 114 + i * 32 - 16, barY)); } r.EndFrame(nih); }
public MapPreviewWidget() { tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer)); spawnClaimed = ChromeProvider.GetImage("lobby-bits", "spawn-claimed"); spawnUnclaimed = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed"); spawnFont = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")]; spawnColor = ChromeMetrics.Get <Color>("SpawnColor"); spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor"); spawnLabelOffset = ChromeMetrics.Get <int2>("SpawnLabelOffset"); }
public RenderDebugState(Actor self, RenderDebugStateInfo info) { var buildingInfo = self.Info.TraitInfoOrDefault <BuildingInfo>(); var yOffset = buildingInfo == null ? 1 : buildingInfo.Dimensions.Y; offset = new WVec(0, 512 * yOffset, 0); this.self = self; color = GetColor(); font = Game.Renderer.Fonts[info.Font]; debugVis = self.World.WorldActor.TraitOrDefault <DebugVisualizations>(); }
public static string WrapText(string text, int width, SpriteFontMSDF font) { var textSize = font.Measure(text); if (textSize.X > width) { var lines = text.Split('\n').ToList(); for (var i = 0; i < lines.Count; i++) { var line = lines[i]; if (font.Measure(line).X <= width) { continue; } // Scan forwards until we find the last word that fits // This guarantees a small bound on the amount of string we need to search before a linebreak var start = 0; while (true) { var spaceIndex = line.IndexOf(' ', start); if (spaceIndex == -1) { break; } var fragmentWidth = font.Measure(line.Substring(0, spaceIndex)).X; if (fragmentWidth > width) { break; } start = spaceIndex + 1; } if (start > 0) { lines[i] = line.Substring(0, start - 1); lines.Insert(i + 1, line.Substring(start)); } } return(string.Join("\n", lines)); } return(text); }
public override void Draw() { var iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset; overlayFont = Game.Renderer.Fonts["TinyBold"]; holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2; readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2; timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0, worldRenderer.World.Timestep)) / 2; // Icons foreach (var p in icons.Values) { WidgetUtils.DrawSHPCentered(p.Sprite, p.Pos + iconOffset, p.Palette); // Charge progress var sp = p.Power; clock.PlayFetchIndex(ClockSequence, () => sp.TotalTime == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTime - sp.RemainingTime) * (clock.CurrentSequence.Length - 1) / sp.TotalTime); clock.Tick(); WidgetUtils.DrawSHPCentered(clock.Image, p.Pos + iconOffset, p.IconClockPalette); } // Overlay foreach (var p in icons.Values) { if (p.Power.Ready) { overlayFont.DrawTextWithContrast(ReadyText, p.Pos + readyOffset, Color.White, Color.Black, 1); } else if (!p.Power.Active) { overlayFont.DrawTextWithContrast(HoldText, p.Pos + holdOffset, Color.White, Color.Black, 1); } else { overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTime, worldRenderer.World.Timestep), p.Pos + timeOffset, Color.White, Color.Black, 1); } } }
public RenderNameTag(Actor self, RenderNameTagInfo info) { font = Game.Renderer.Fonts[info.Font]; color = self.Owner.Color; if (self.Owner.PlayerName.Length > info.MaxLength) { name = self.Owner.PlayerName.Substring(0, info.MaxLength); } else { name = self.Owner.PlayerName; } decorationBounds = self.TraitsImplementing <IDecorationBounds>().ToArray(); }
public ProductionPaletteWidget(ModData modData, OrderManager orderManager, World world, WorldRenderer worldRenderer) { this.modData = modData; this.orderManager = orderManager; World = world; this.worldRenderer = worldRenderer; GetTooltipIcon = () => TooltipIcon; tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer)); cantBuild = new Animation(world, NotBuildableAnimation); cantBuild.PlayFetchIndex(NotBuildableSequence, () => 0); clock = new Animation(world, ClockAnimation); overlayFont = Game.Renderer.Fonts["TinyBold"]; Game.Renderer.Fonts.TryGetValue("Symbols", out symbolFont); }
public static string TruncateText(string text, int width, SpriteFontMSDF font) { var trimmedWidth = font.Measure(text).X; if (trimmedWidth <= width) { return(text); } var trimmed = text; while (trimmedWidth > width && trimmed.Length > 3) { trimmed = text.Substring(0, trimmed.Length - 4) + "..."; trimmedWidth = font.Measure(trimmed).X; } return(trimmed); }
protected MapPreviewWidget(MapPreviewWidget other) : base(other) { Preview = other.Preview; IgnoreMouseInput = other.IgnoreMouseInput; ShowSpawnPoints = other.ShowSpawnPoints; TooltipTemplate = other.TooltipTemplate; TooltipContainer = other.TooltipContainer; SpawnOccupants = other.SpawnOccupants; tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer)); spawnClaimed = ChromeProvider.GetImage("lobby-bits", "spawn-claimed"); spawnUnclaimed = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed"); spawnFont = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")]; spawnColor = ChromeMetrics.Get <Color>("SpawnColor"); spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor"); spawnLabelOffset = ChromeMetrics.Get <int2>("SpawnLabelOffset"); }
public D2MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit) { this.modData = modData; this.onStart = onStart; Game.BeforeGameStart += OnGameStart; missionList = widget.Get <ScrollPanelWidget>("MISSION_LIST"); headerTemplate = widget.Get <ScrollItemWidget>("HEADER"); template = widget.Get <ScrollItemWidget>("TEMPLATE"); var title = widget.GetOrNull <LabelWidget>("MISSIONBROWSER_TITLE"); if (title != null) { title.GetText = () => playingVideo != PlayingVideo.None ? selectedMap.Title : title.Text; } widget.Get("MISSION_INFO").IsVisible = () => selectedMap != null; //var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW"); //previewWidget.Preview = () => selectedMap; //previewWidget.IsVisible = () => playingVideo == PlayingVideo.None; videoPlayer = widget.Get <WsaPlayerWidget>("MISSION_VIDEO"); widget.Get("MISSION_BIN").IsVisible = () => playingVideo != PlayingVideo.None; fullscreenVideoPlayer = Ui.LoadWidget <BackgroundWidget>("FULLSCREEN_PLAYER", Ui.Root, new WidgetArgs { { "world", world } }); descriptionPanel = widget.Get <ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL"); description = descriptionPanel.Get <LabelWidget>("MISSION_DESCRIPTION"); descriptionFont = Game.Renderer.Fonts[description.Font]; difficultyButton = widget.Get <DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); gameSpeedButton = widget.GetOrNull <DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON"); startBriefingVideoButton = widget.Get <ButtonWidget>("START_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton = widget.Get <ButtonWidget>("STOP_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton.IsVisible = () => playingVideo == PlayingVideo.Briefing; stopBriefingVideoButton.OnClick = () => StopVideo(videoPlayer); startInfoVideoButton = widget.Get <ButtonWidget>("START_INFO_VIDEO_BUTTON"); stopInfoVideoButton = widget.Get <ButtonWidget>("STOP_INFO_VIDEO_BUTTON"); stopInfoVideoButton.IsVisible = () => playingVideo == PlayingVideo.Info; stopInfoVideoButton.OnClick = () => StopVideo(videoPlayer); CampaignWidget = widget.Get <CampaignWidget>("campaigndune"); CampaignWidget.OnHouseChooseDelegate = OnHouseChoose; CampaignWidget.OnMapRegionChooseDelegate = OnMapRegionChoose; CampaignWidget.DrawTextDelegate = OnShowUserHelp; CampaignWidget.OnMentatProceedClick = StartMissionClicked; CampaignWidget.OnExit = onExit; allPreviews = new List <MapPreview>(); missionList.RemoveChildren(); // Add a group for each campaign if (modData.Manifest.CampaignDB.Any()) { var yaml = MiniYaml.Merge(modData.Manifest.CampaignDB.Select( m => MiniYaml.FromStream(modData.DefaultFileSystem.Open(m), m))); foreach (var kv in yaml) { var missionMapPaths = kv.Value.Nodes.Select(n => n.Key).ToList(); var previews = modData.MapCache .Where(p => p.Status == MapStatus.Available) .Select(p => new { Preview = p, Index = missionMapPaths.IndexOf(Platform.UnresolvePath(p.Package.Name)) }) .Where(x => x.Index != -1) .OrderBy(x => x.Index) .Select(x => x.Preview); if (previews.Any()) { CreateMissionGroup(kv.Key, previews); allPreviews.AddRange(previews); } } } // Add an additional group for loose missions var loosePreviews = modData.MapCache .Where(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector) && !allPreviews.Any(a => a.Uid == p.Uid)); if (loosePreviews.Any()) { CreateMissionGroup("Missions", loosePreviews); allPreviews.AddRange(loosePreviews); } if (allPreviews.Any()) { SelectMap(allPreviews.First()); } // Preload map preview and rules to reduce jank new Thread(() => { foreach (var p in allPreviews) { p.GetMinimap(); p.PreloadRules(); } }).Start(); var startButton = widget.Get <ButtonWidget>("STARTGAME_BUTTON"); startButton.OnClick = StartMissionClicked; startButton.IsDisabled = () => selectedMap == null || selectedMap.InvalidCustomRules; widget.Get <ButtonWidget>("BACK_BUTTON").OnClick = () => { StopVideo(videoPlayer); Game.Disconnect(); Ui.CloseWindow(); onExit(); }; widget.Get <ButtonWidget>("StartCampaign").OnClick = () => { CampaignWidget.ResetCampaign(); }; widget.Get <ButtonWidget>("CampaignNextLevel").OnClick = () => { CampaignWidget.UpLevelDelegate(); }; widget.Get <ButtonWidget>("CampaignPrevLevel").OnClick = () => { CampaignWidget.DownLevelDelegate(); }; //CampaignWidget.BindLevelOnMap(1); }
public CustomTerrainDebugOverlay(Actor self, CustomTerrainDebugOverlayInfo info) { font = Game.Renderer.Fonts[info.Font]; }