public void RefreshIcons() { icons = new Dictionary <Rectangle, ProductionIcon>(); var producer = CurrentQueue != null?CurrentQueue.MostLikelyProducer() : default(TraitPair <Production>); if (CurrentQueue == null || producer.Trait == null) { if (DisplayedIconCount != 0) { OnIconCountChanged(DisplayedIconCount, 0); DisplayedIconCount = 0; } return; } var oldIconCount = DisplayedIconCount; DisplayedIconCount = 0; var rb = RenderBounds; var faction = producer.Trait.Faction; foreach (var item in AllBuildables.Skip(IconRowOffset * Columns).Take(MaxIconRowOffset * Columns)) { var x = DisplayedIconCount % Columns; var y = DisplayedIconCount / Columns; var rect = new Rectangle(rb.X + x * (IconSize.X + IconMargin.X), rb.Y + y * (IconSize.Y + IconMargin.Y), IconSize.X, IconSize.Y); var rsi = item.TraitInfo <RenderSpritesInfo>(); var icon = new Animation(World, rsi.GetImage(item, World.Map.Rules.Sequences, faction)); var bi = item.TraitInfo <BuildableInfo>(); icon.Play(bi.Icon); var palette = bi.IconPaletteIsPlayerPalette ? bi.IconPalette + producer.Actor.Owner.InternalName : bi.IconPalette; var pi = new ProductionIcon() { Actor = item, Name = item.Name, Hotkey = DisplayedIconCount < HotkeyCount ? hotkeys[DisplayedIconCount] : null, Sprite = icon.Image, Palette = worldRenderer.Palette(palette), IconClockPalette = worldRenderer.Palette(ClockPalette), IconDarkenPalette = worldRenderer.Palette(NotBuildablePalette), Pos = new float2(rect.Location), Queued = currentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(), ProductionQueue = currentQueue }; icons.Add(rect, pi); DisplayedIconCount++; } eventBounds = icons.Keys.Union(); if (oldIconCount != DisplayedIconCount) { OnIconCountChanged(oldIconCount, DisplayedIconCount); } }
public override void PrepareRenderables() { var voxel = GetVoxel(); var palette = GetPalette(); var playerPalette = GetPlayerPalette(); var normalsPalette = GetNormalsPalette(); var shadowPalette = GetShadowPalette(); var scale = GetScale(); var lightAmbientColor = GetLightAmbientColor(); var lightDiffuseColor = GetLightDiffuseColor(); var lightPitch = GetLightPitch(); var lightYaw = GetLightYaw(); if (voxel == null || palette == null) { return; } if (voxel != cachedVoxel) { offset = 0.5f * (new float2(RenderBounds.Size) - new float2(voxel.Size[0], voxel.Size[1])); cachedVoxel = voxel; } if (palette != cachedPalette) { if (string.IsNullOrEmpty(palette) && string.IsNullOrEmpty(playerPalette)) { return; } string paletteName = string.IsNullOrEmpty(palette) ? playerPalette : palette; pr = WorldRenderer.Palette(paletteName); cachedPalette = paletteName; } if (playerPalette != cachedPlayerPalette) { prPlayer = WorldRenderer.Palette(playerPalette); cachedPlayerPalette = playerPalette; } if (normalsPalette != cachedNormalsPalette) { prNormals = WorldRenderer.Palette(normalsPalette); cachedNormalsPalette = normalsPalette; } if (shadowPalette != cachedShadowPalette) { prShadow = WorldRenderer.Palette(shadowPalette); cachedShadowPalette = shadowPalette; } if (scale != cachedScale) { //offset *= scale; cachedScale = scale; } if (lightPitch != cachedLightPitch) { cachedLightPitch = lightPitch; } if (lightYaw != cachedLightYaw) { cachedLightYaw = lightYaw; } if (cachedLightAmbientColor[0] != lightAmbientColor[0] || cachedLightAmbientColor[1] != lightAmbientColor[1] || cachedLightAmbientColor[2] != lightAmbientColor[2]) { cachedLightAmbientColor = lightAmbientColor; } if (cachedLightDiffuseColor[0] != lightDiffuseColor[0] || cachedLightDiffuseColor[1] != lightDiffuseColor[1] || cachedLightDiffuseColor[2] != lightDiffuseColor[2]) { cachedLightDiffuseColor = lightDiffuseColor; } if (cachedVoxel == null) { return; } var size = new float2(cachedVoxel.Size[0] * cachedScale, cachedVoxel.Size[1] * cachedScale); ModelAnimation animation = new ModelAnimation( cachedVoxel, () => WVec.Zero, () => new List <WRot>() { new WRot( new WAngle(-45), new WAngle(-30), new WAngle(360) ) }, () => false, () => 0, true); ModelPreview preview = new ModelPreview( new ModelAnimation[] { animation }, WVec.Zero, 0, cachedScale, new WAngle(cachedLightPitch), new WAngle(cachedLightYaw), cachedLightAmbientColor, cachedLightDiffuseColor, new WAngle(), pr, prNormals, prShadow); List <ModelPreview> previews = new List <ModelPreview>() { preview }; // Calculate the preview bounds PreviewOffset = int2.Zero; IdealPreviewSize = int2.Zero; var rs = previews.SelectMany(p => ((IActorPreview)p).ScreenBounds(WorldRenderer, WPos.Zero)); if (rs.Any()) { var b = rs.First(); foreach (var rr in rs.Skip(1)) { b = OpenRA.Primitives.Rectangle.Union(b, rr); } IdealPreviewSize = new int2(b.Width, b.Height); PreviewOffset = -new int2(b.Left, b.Top) - IdealPreviewSize / 2; } renderables = previews .SelectMany(p => ((IActorPreview)p).Render(WorldRenderer, WPos.Zero)) .OrderBy(WorldRenderer.RenderableScreenZPositionComparisonKey) .Select(r => r.PrepareRender(WorldRenderer)) .ToArray(); }
public void LoadPalettes(WorldRenderer wr) { var remap = new ScaledPaletteRemap(info.Scale, info.Offset); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers); }
public override void Draw() { productionIcons.Clear(); productionIconsBounds.Clear(); var player = GetPlayer(); if (player == null) { return; } var queues = world.ActorsWithTrait <ProductionQueue>() .Where(a => a.Actor.Owner == player) .Select((a, i) => new { a.Trait, i }); foreach (var queue in queues) { if (!clocks.ContainsKey(queue.Trait)) { clocks.Add(queue.Trait, new Animation(world, ClockAnimation)); } } var currentItemsByItem = queues .Select(a => a.Trait.CurrentItem()) .Where(pi => pi != null) .GroupBy(pr => pr.Item) .OrderBy(g => g.First().Queue.Info.DisplayOrder) .ThenBy(g => g.First().BuildPaletteOrder) .ToList(); Game.Renderer.EnableAntialiasingFilter(); var queueCol = 0; foreach (var currentItems in currentItemsByItem) { var queued = currentItems .OrderBy(pi => pi.Done ? 0 : (pi.Paused ? 2 : 1)) .ThenBy(q => q.RemainingTimeActual) .ToList(); var current = queued.First(); var queue = current.Queue; var faction = queue.Actor.Owner.Faction.InternalName; var actor = queue.AllItems().FirstOrDefault(a => a.Name == current.Item); if (actor == null) { continue; } var rsi = actor.TraitInfo <RenderSpritesInfo>(); var icon = new Animation(world, rsi.GetImage(actor, world.Map.Rules.Sequences, faction)); var bi = actor.TraitInfo <BuildableInfo>(); icon.Play(bi.Icon); var topLeftOffset = new float2(queueCol * (IconWidth + IconSpacing), 0); var iconTopLeft = RenderOrigin + topLeftOffset; var centerPosition = iconTopLeft + 0.5f * iconSize; WidgetUtils.DrawSHPCentered(icon.Image, centerPosition, worldRenderer.Palette(bi.IconPalette), 0.5f); var rect = new Rectangle((int)iconTopLeft.X, (int)iconTopLeft.Y, (int)iconSize.X, (int)iconSize.Y); productionIcons.Add(new ProductionIcon { Actor = actor, Pos = new float2(rect.Location), Queued = queued, ProductionQueue = current.Queue }); productionIconsBounds.Add(rect); var pio = queue.Actor.Owner.PlayerActor.TraitsImplementing <IProductionIconOverlay>() .FirstOrDefault(p => p.IsOverlayActive(actor)); if (pio != null) { WidgetUtils.DrawSHPCentered(pio.Sprite, centerPosition + pio.Offset(iconSize), worldRenderer.Palette(pio.Palette), 0.5f); } var clock = clocks[queue]; clock.PlayFetchIndex(ClockSequence, () => current.TotalTime == 0 ? 0 : (current.TotalTime - current.RemainingTime) * (clock.CurrentSequence.Length - 1) / current.TotalTime); clock.Tick(); WidgetUtils.DrawSHPCentered(clock.Image, centerPosition, worldRenderer.Palette(ClockPalette), 0.5f); queueCol++; } var newWidth = Math.Max(queueCol * (IconWidth + IconSpacing), MinWidth); if (newWidth != Bounds.Width) { var wasInBounds = EventBounds.Contains(Viewport.LastMousePos); Bounds.Width = newWidth; var isInBounds = EventBounds.Contains(Viewport.LastMousePos); // HACK: Ui.MouseOverWidget is normally only updated when the mouse moves // Call ResetTooltips to force a fake mouse movement so the checks in Tick will work properly if (wasInBounds != isInBounds) { Game.RunAfterTick(Ui.ResetTooltips); } } Game.Renderer.DisableAntialiasingFilter(); var tiny = Game.Renderer.Fonts["Tiny"]; var bold = Game.Renderer.Fonts["Small"]; foreach (var icon in productionIcons) { var current = icon.Queued.First(); var text = GetOverlayForItem(current, timestep); tiny.DrawTextWithContrast(text, icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0), Color.White, Color.Black, 1); if (icon.Queued.Count > 1) { text = icon.Queued.Count.ToString(); bold.DrawTextWithContrast(text, icon.Pos + new float2(16, 0) - new float2(bold.Measure(text).X / 2, 0), Color.White, Color.Black, 1); } } var parentWidth = Bounds.X + Bounds.Width; Parent.Bounds.Width = parentWidth; var gradient = Parent.Get <GradientColorBlockWidget>("PLAYER_GRADIENT"); var offset = gradient.Bounds.X - Bounds.X; var gradientWidth = Math.Max(MinWidth - offset, currentItemsByItem.Count * (IconWidth + IconSpacing)); gradient.Bounds.Width = gradientWidth; var widestChildWidth = Parent.Parent.Children.Max(x => x.Bounds.Width); Parent.Parent.Bounds.Width = Math.Max(25 + widestChildWidth, Bounds.Left + MinWidth); }
public override void Draw() { var player = GetPlayer(); if (player == null) { return; } var queues = world.ActorsWithTrait <ProductionQueue>() .Where(a => a.Actor.Owner == player) .Select((a, i) => new { a.Trait, i }); if (renderBounds != RenderBounds) { renderBounds = RenderBounds; InitIcons(renderBounds); } else { for (var i = 0; i < icons.Length; i++) { icons[i].Actor = null; } } foreach (var queue in queues) { if (!clocks.ContainsKey(queue.Trait)) { clocks.Add(queue.Trait, new Animation(world, ClockAnimation)); } var current = queue.Trait.CurrentItem(); if (current == null || queue.i >= icons.Length) { continue; } var faction = queue.Trait.Actor.Owner.Faction.InternalName; var actor = queue.Trait.AllItems().FirstOrDefault(a => a.Name == current.Item); if (actor == null) { continue; } var rsi = actor.TraitInfo <RenderSpritesInfo>(); var icon = new Animation(world, rsi.GetImage(actor, world.Map.Rules.Sequences, faction)); var bi = actor.TraitInfo <BuildableInfo>(); icon.Play(bi.Icon); var location = new float2(iconRects[queue.i].Location); WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f); icons[queue.i].Actor = actor; icons[queue.i].ProductionQueue = queue.Trait; var pio = queue.Trait.Actor.Owner.PlayerActor.TraitsImplementing <IProductionIconOverlay>() .FirstOrDefault(p => p.IsOverlayActive(actor)); if (pio != null) { WidgetUtils.DrawSHPCentered(pio.Sprite, location + 0.5f * iconSize + pio.Offset(0.5f * iconSize), worldRenderer.Palette(pio.Palette), 0.5f); } var clock = clocks[queue.Trait]; clock.PlayFetchIndex(ClockSequence, () => current.TotalTime == 0 ? 0 : ((current.TotalTime - current.RemainingTime) * (clock.CurrentSequence.Length - 1) / current.TotalTime)); clock.Tick(); WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f); var tiny = Game.Renderer.Fonts["Tiny"]; var text = GetOverlayForItem(current, timestep); tiny.DrawTextWithContrast(text, location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0), Color.White, Color.Black, 1); } }
IEnumerable <IRenderable> IEffectAnnotation.RenderAnnotation(WorldRenderer wr) { var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPxPosition(pos)); return(anim.RenderUI(wr, screenPos, WVec.Zero, 0, wr.Palette(palette), 1f)); }
public void LoadPalettes(WorldRenderer wr) { var remap = new PlayerColorRemap(info.RemapIndex, info.Color, info.Ramp); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.Base).Palette, remap), info.AllowModifiers); }
public IEnumerable <IRenderable> Render(WorldRenderer wr) { return(anim.Render(firedBy.PlayerActor, target.CenterPosition, wr.Palette(palette))); }
public IEnumerable <IRenderable> Render(WorldRenderer wr) { return(anim.Render(target.CenterPosition, wr.Palette(palette))); }
public override void Draw() { supportPowerIconsIcons.Clear(); supportPowerIconsBounds.Clear(); var player = GetPlayer(); if (player == null) { return; } var powers = player.PlayerActor.Trait <SupportPowerManager>().Powers .Where(x => !x.Value.Disabled && x.Value.GetLevel() != 0) .OrderBy(p => p.Value.Info.SupportPowerPaletteOrder) .Select((a, i) => new { a, i }) .ToList(); foreach (var power in powers) { if (!clocks.ContainsKey(power.a.Key)) { clocks.Add(power.a.Key, new Animation(world, ClockAnimation)); } } Bounds.Width = powers.Count() * (IconWidth + IconSpacing); Game.Renderer.EnableAntialiasingFilter(); var iconSize = new float2(IconWidth, IconHeight); foreach (var power in powers) { var item = power.a.Value; if (item == null || item.Info == null || item.Info.Icons == null) { continue; } var level = item.GetLevel(); icon = new Animation(worldRenderer.World, item.Info.IconImage); icon.Play(item.Info.Icons.First(i => i.Key == level).Value); var location = new float2(RenderBounds.Location) + new float2(power.i * (IconWidth + IconSpacing), 0); supportPowerIconsIcons.Add(new SupportPowersWidget.SupportPowerIcon { Power = item, Pos = location }); supportPowerIconsBounds.Add(new Rectangle((int)location.X, (int)location.Y, (int)iconSize.X, (int)iconSize.Y)); WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(item.Info.IconPalette), 0.5f); var clock = clocks[power.a.Key]; clock.PlayFetchIndex(ClockSequence, () => item.TotalTicks == 0 ? 0 : ((item.TotalTicks - item.RemainingTicks) * (clock.CurrentSequence.Length - 1) / item.TotalTicks)); clock.Tick(); WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f); } Game.Renderer.DisableAntialiasingFilter(); var tiny = Game.Renderer.Fonts["Tiny"]; foreach (var icon in supportPowerIconsIcons) { var text = GetOverlayForItem(icon.Power, timestep); tiny.DrawTextWithContrast(text, icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0), Color.White, Color.Black, 1); } }
IEnumerable <IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr, TerrainTemplateInfo t, int2 origin, float scale) { if (!(t is DefaultTerrainTemplateInfo template)) { yield break; } var ts = map.Grid.TileSize; var gridType = map.Grid.Type; var i = 0; for (var y = 0; y < template.Size.Y; y++) { for (var x = 0; x < template.Size.X; x++) { var tile = new TerrainTile(template.Id, (byte)i++); if (!terrainInfo.TryGetTileInfo(tile, out var tileInfo)) { continue; } var sprite = tileCache.TileSprite(tile, 0); var u = gridType == MapGridType.Rectangular ? x : (x - y) / 2f; var v = gridType == MapGridType.Rectangular ? y : (x + y) / 2f; var offset = (new float2(u * ts.Width, (v - 0.5f * tileInfo.Height) * ts.Height) - 0.5f * sprite.Size.XY).ToInt2(); var palette = template.Palette ?? terrainInfo.Palette; yield return(new UISpriteRenderable(sprite, WPos.Zero, origin + offset, 0, wr.Palette(palette), scale)); } } }
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr) { render = new TerrainSpriteLayer(w, wr, terrainRenderer.MissingTile, BlendMode.Alpha, wr.World.Type != WorldType.Editor); paletteReference = wr.Palette(info.Palette); }
protected virtual PaletteReference GetPalette(Actor self, WorldRenderer wr) { return(wr.Palette(Info.Palette + (Info.IsPlayerPalette ? self.Owner.InternalName : ""))); }
public IEnumerable <IRenderable> Render(Actor self, WorldRenderer wr) { if (info.ShadowImage == null) { yield break; } if (IsTraitDisabled) { yield break; } if (self.IsDead || !self.IsInWorld) { yield break; } if (self.World.FogObscures(self)) { yield break; } shadow.Tick(); var pos = self.CenterPosition - new WVec(0, 0, self.CenterPosition.Z); yield return(new SpriteRenderable(shadow.Image, pos, info.ShadowOffset, info.ShadowZOffset, wr.Palette(info.ShadowPalette), 1, true)); }
IEnumerable <IRenderable> RenderInner(Actor self, WorldRenderer wr) { if (IsTraitDisabled || self.IsDead || !self.IsInWorld || Anim == null) { return(Enumerable.Empty <IRenderable>()); } if (!ShouldRender(self) || self.World.FogObscures(self)) { return(Enumerable.Empty <IRenderable>()); } var bounds = self.VisualBounds; var halfSize = (0.5f * Anim.Image.Size.XY).ToInt2(); var boundsOffset = new int2(bounds.Left + bounds.Right, bounds.Top + bounds.Bottom) / 2; var sizeOffset = -halfSize; if (Info.ReferencePoint.HasFlag(ReferencePoints.Top)) { boundsOffset -= new int2(0, bounds.Height / 2); sizeOffset += new int2(0, halfSize.Y); } else if (Info.ReferencePoint.HasFlag(ReferencePoints.Bottom)) { boundsOffset += new int2(0, bounds.Height / 2); sizeOffset -= new int2(0, halfSize.Y); } if (Info.ReferencePoint.HasFlag(ReferencePoints.Left)) { boundsOffset -= new int2(bounds.Width / 2, 0); sizeOffset += new int2(halfSize.X, 0); } else if (Info.ReferencePoint.HasFlag(ReferencePoints.Right)) { boundsOffset += new int2(bounds.Width / 2, 0); sizeOffset -= new int2(halfSize.X, 0); } var pxPos = wr.Viewport.WorldToViewPx(wr.ScreenPxPosition(self.CenterPosition) + boundsOffset) + sizeOffset; return(new IRenderable[] { new UISpriteRenderable(Anim.Image, self.CenterPosition, pxPos, Info.ZOffset, wr.Palette(Info.Palette), 1f) }); }
public IEnumerable <IRenderable> Render(WorldRenderer wr) { return(anim.Render(pos, wr.Palette("effect"))); }
public IEnumerable <IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset); var centerPosition = world.Map.CenterOfCell(topLeft) + centerOffset; var rules = world.Map.Rules; foreach (var dec in actorInfo.TraitInfos <IPlaceBuildingDecorationInfo>()) { foreach (var r in dec.Render(wr, world, actorInfo, centerPosition)) { yield return(r); } } var cells = new Dictionary <CPos, CellType>(); var plugInfo = actorInfo.TraitInfoOrDefault <PlugInfo>(); if (plugInfo != null) { if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1) { throw new InvalidOperationException("Plug requires a 1x1 sized Building"); } cells.Add(topLeft, MakeCellType(AcceptsPlug(topLeft, plugInfo))); } else if (actorInfo.HasTraitInfo <LineBuildInfo>()) { // Linebuild for walls. if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1) { throw new InvalidOperationException("LineBuild requires a 1x1 sized Building"); } if (!Game.GetModifierKeys().HasModifier(Modifiers.Shift)) { foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, actorInfo, buildingInfo)) { cells.Add(t.First, MakeCellType(buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, actorInfo, t.First), true)); } } cells[topLeft] = MakeCellType(buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, actorInfo, topLeft)); } else { if (!initialized) { var td = new TypeDictionary() { new FactionInit(faction), new OwnerInit(queue.Actor.Owner), }; foreach (var api in actorInfo.TraitInfos <IActorPreviewInitInfo>()) { foreach (var o in api.ActorPreviewInits(actorInfo, ActorPreviewType.PlaceBuilding)) { td.Add(o); } } var init = new ActorPreviewInitializer(actorInfo, wr, td); preview = actorInfo.TraitInfos <IRenderActorPreviewInfo>() .SelectMany(rpi => rpi.RenderPreview(init)) .ToArray(); initialized = true; } var previewRenderables = preview .SelectMany(p => p.Render(wr, centerPosition)) .OrderBy(WorldRenderer.RenderableScreenZPositionComparisonKey); foreach (var r in previewRenderables) { yield return(r); } var res = world.WorldActor.TraitOrDefault <ResourceLayer>(); var isCloseEnough = buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, actorInfo, topLeft); foreach (var t in buildingInfo.Tiles(topLeft)) { cells.Add(t, MakeCellType(isCloseEnough && world.IsCellBuildable(t, actorInfo, buildingInfo) && (res == null || res.GetResource(t) == null))); } } var cellPalette = wr.Palette(placeBuildingInfo.Palette); var linePalette = wr.Palette(placeBuildingInfo.LineBuildSegmentPalette); var topLeftPos = world.Map.CenterOfCell(topLeft); foreach (var c in cells) { var tile = !c.Value.HasFlag(CellType.Invalid) ? buildOk : buildBlocked; var pal = c.Value.HasFlag(CellType.LineBuild) ? linePalette : cellPalette; var pos = world.Map.CenterOfCell(c.Key); yield return(new SpriteRenderable(tile, pos, new WVec(0, 0, topLeftPos.Z - pos.Z), -511, pal, 1f, true)); } }
public void WorldLoaded(World w, WorldRenderer wr) { render = new TerrainSpriteLayer(w, wr, terrainRenderer.Sheet, BlendMode.Alpha, wr.Palette(info.Palette), wr.World.Type != WorldType.Editor); }
public IEnumerable <IRenderable> Render(WorldRenderer wr) { var palette = info.DoorPaletteIsPlayerPalette ? info.DoorPalette + launcher.Owner.InternalName : info.DoorPalette; return(doors.Render(pos, wr.Palette(palette))); }
public IEnumerable <Renderable> Render(WorldRenderer wr) { yield return(new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude), wr.Palette("effect"), (int)pos.Y)); }
IEnumerable <IRenderable> IRenderModifier.ModifyRender(Actor self, WorldRenderer wr, IEnumerable <IRenderable> r) { if (remainingTime > 0 || IsTraitDisabled || IsTraitPaused) { return(r); } if (Cloaked && IsVisible(self, self.World.RenderPlayer)) { var palette = string.IsNullOrEmpty(Info.Palette) ? null : Info.IsPlayerPalette ? wr.Palette(Info.Palette + self.Owner.InternalName) : wr.Palette(Info.Palette); if (palette == null) { return(r); } else { return(r.Select(a => a.IsDecoration ? a : a.WithPalette(palette))); } } else { return(SpriteRenderable.None); } }
public void WorldLoaded(World w, WorldRenderer wr) { Palette = wr.Palette(Info.Palette); }
public void CachePalette(WorldRenderer wr, Player owner) { PaletteReference = wr.Palette(IsPlayerPalette ? Palette + owner.InternalName : Palette); }
public void LoadPalettes(WorldRenderer wr) { var remap = new AlphaPaletteRemap(info.Alpha, info.Premultiply); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers); }
public IEnumerable <IRenderable> Render(WorldRenderer wr) { return(anim.Render(pos, wr.Palette(weaponPalette))); }
public IEnumerable <IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { // Draw chrono range yield return(new RangeCircleRenderable( self.CenterPosition, WDist.FromCells(self.Trait <StructureChrono>().Info.MaxDistance), 0, Color.FromArgb(128, Color.LawnGreen), Color.FromArgb(96, Color.Black))); var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo); var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, buildingInfo); var rules = world.Map.Rules; var actorInfo = self.Info; // rules.Actors[building]; foreach (var dec in actorInfo.TraitInfos <IPlaceBuildingDecorationInfo>()) { foreach (var r in dec.Render(wr, world, actorInfo, offset)) { yield return(r); } } // Cells, we are about to construct and occupy. var cells = new Dictionary <CPos, bool>(); if (!initialized) { var td = new TypeDictionary() { //new OpenRA.Mods.Common.FactionInit(faction), new OpenRA.Mods.Common.FactionInit(""), new OwnerInit(self.Owner), new HideBibPreviewInit() }; var init = new ActorPreviewInitializer(actorInfo, wr, td); preview = actorInfo.TraitInfos <IRenderActorPreviewInfo>() .SelectMany(rpi => rpi.RenderPreview(init)) .ToArray(); initialized = true; } var previewRenderables = preview .SelectMany(p => p.Render(wr, offset)) .OrderBy(WorldRenderer.RenderableScreenZPositionComparisonKey); foreach (var r in previewRenderables) { yield return(r); } var res = world.WorldActor.Trait <ResourceLayer>(); var selfPos = self.Trait <IOccupySpace>().TopLeft; var isCloseEnough = ((topLeft - selfPos).Length) <= info.MaxDistance; foreach (var t in FootprintUtils.Tiles(rules, building, buildingInfo, topLeft)) { cells.Add(t, isCloseEnough && world.IsCellBuildable(t, buildingInfo) && res.GetResource(t) == null); } var placeBuildingInfo = self.Owner.PlayerActor.Info.TraitInfo <PlaceBuildingInfo>(); var pal = wr.Palette(placeBuildingInfo.Palette); var topLeftPos = world.Map.CenterOfCell(topLeft); // draw red or white buildable cell indicator. foreach (var c in cells) { var tile = c.Value ? buildOk : buildBlocked; var pos = world.Map.CenterOfCell(c.Key); yield return(new SpriteRenderable(tile, pos, new WVec(0, 0, topLeftPos.Z - pos.Z), -511, pal, 1f, true)); } }
public static void DrawSHPCentered(Sprite s, float2 pos, WorldRenderer wr, float scale) { Game.Renderer.SpriteRenderer.DrawSprite(s, pos - 0.5f * scale * s.Size, wr.Palette("chrome"), scale * s.Size); }
public override void Initialize(WidgetArgs args) { base.Initialize(args); preview = worldRenderer.Palette(PaletteName).Palette; }
void IWorldLoaded.WorldLoaded(World world, WorldRenderer wr) { theater = wr.Theater; foreach (var template in map.Rules.TileSet.Templates) { var palette = template.Value.Palette ?? TileSet.TerrainPaletteInternalName; spriteLayers.GetOrAdd(palette, pal => new TerrainSpriteLayer(world, wr, theater.Sheet, BlendMode.Alpha, wr.Palette(palette), world.Type != WorldType.Editor)); } foreach (var cell in map.AllCells) { UpdateCell(cell); } map.Tiles.CellEntryChanged += UpdateCell; map.Height.CellEntryChanged += UpdateCell; }
public void InitPalette(WorldRenderer wr) { var remap = new PlayerColorRemap(info.RemapIndex, owner.Color, info.Ramp); wr.AddPalette(info.BaseName + owner.InternalName, new Palette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers); }