本文整理汇总了C#中int2类的典型用法代码示例。如果您正苦于以下问题:C# int2类的具体用法?C# int2怎么用?C# int2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
int2类属于命名空间,在下文中一共展示了int2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateActorSelectionPriority
static long CalculateActorSelectionPriority(ActorInfo info, Rectangle bounds, int2 selectionPixel)
{
var centerPixel = new int2(bounds.X, bounds.Y);
var pixelDistance = (centerPixel - selectionPixel).Length;
return ((long)-pixelDistance << 32) + info.SelectionPriority();
}
示例2: Draw
public override void Draw()
{
SpriteFont font;
if (!Game.Renderer.Fonts.TryGetValue(Font, out font))
throw new ArgumentException("Requested font '{0}' was not found.".F(Font));
var text = GetText();
if (text == null)
return;
var textSize = font.Measure(text);
var position = RenderOrigin;
if (VAlign == TextVAlign.Middle)
position += new int2(0, (Bounds.Height - textSize.Y) / 2);
if (VAlign == TextVAlign.Bottom)
position += new int2(0, Bounds.Height - textSize.Y);
if (Align == TextAlign.Center)
position += new int2((Bounds.Width - textSize.X) / 2, 0);
if (Align == TextAlign.Right)
position += new int2(Bounds.Width - textSize.X, 0);
if (WordWrap)
text = WidgetUtils.WrapText(text, Bounds.Width, font);
var color = GetColor();
var contrast = GetContrastColor();
if (Contrast)
font.DrawTextWithContrast(text, position, color, contrast, 2);
else
font.DrawText(text, position, color);
}
示例3: MoveFlash
public MoveFlash( World world, int2 cell )
{
this.pos = Game.CellSize * (cell + new float2(0.5f, 0.5f));
anim.PlayThen( "idle",
() => world.AddFrameEndTask(
w => w.Remove( this ) ) );
}
示例4: Building
public Building(ActorInitializer init)
{
this.self = init.self;
this.topLeft = init.Get<LocationInit,int2>();
this.Info = self.Info.Traits.Get<BuildingInfo>();
this.PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
}
示例5: GetUnitsAt
public IEnumerable<Actor> GetUnitsAt( int2 a )
{
if (!map.IsInMap(a)) yield break;
for( var i = influence[ a.X, a.Y ] ; i != null ; i = i.next )
yield return i.actor;
}
示例6: IssueOrder
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (mi.Button == MouseButton.Right && self == underCursor)
return new Order("DeployTransform", self);
return null;
}
示例7: GetBridge
// Used to check for neighbouring bridges
public Bridge GetBridge(int2 cell)
{
if (!world.Map.IsInMap(cell.X, cell.Y))
return null;
return Bridges[ cell.X, cell.Y ];
}
示例8: Order
public IEnumerable<Order> Order( World world, int2 xy, MouseInput mi )
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.HasTrait<ITargetable>())
.OrderByDescending(
a =>
a.Info.Traits.Contains<SelectableInfo>()
? a.Info.Traits.Get<SelectableInfo>().Priority
: int.MinValue)
.FirstOrDefault();
var orders = world.Selection.Actors
.Select(a => OrderForUnit(a, xy, mi, underCursor))
.Where(o => o != null)
.ToArray();
var actorsInvolved = orders.Select(o => o.self).Distinct();
if (actorsInvolved.Any())
yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false)
{
TargetString = string.Join(",", actorsInvolved.Select(a => a.ActorID.ToString()).ToArray())
};
foreach (var o in orders)
yield return CheckSameOrder(o.iot, o.trait.IssueOrder(o.self, o.iot, o.target, mi.Modifiers.HasModifier(Modifiers.Shift)));
}
示例9: AddSmudge
public void AddSmudge(int2 loc)
{
if (!world.GetTerrainInfo(loc).AcceptSmudge)
return;
if (Game.CosmeticRandom.Next(0,100) <= Info.SmokePercentage)
world.AddFrameEndTask(w => w.Add(new Smoke(w, Traits.Util.CenterOfCell(loc), Info.SmokeType)));
// No smudge; create a new one
if (!tiles.ContainsKey(loc))
{
byte st = (byte)(1 + world.SharedRandom.Next(Info.Types.Length - 1));
tiles.Add(loc, new TileReference<byte,byte>(st,(byte)0));
return;
}
var tile = tiles[loc];
// Existing smudge; make it deeper
int depth = Info.Depths[tile.type-1];
if (tile.index < depth - 1)
{
tile.index++;
tiles[loc] = tile; // struct semantics.
}
}
示例10: DrawInner
public override void DrawInner(World world)
{
int margin = 5;
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var cursor = (showCursor && Focused) ? "|" : "";
var textSize = font.Measure(Text + "|");
var pos = RenderOrigin;
WidgetUtils.DrawPanel("dialog3",
new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));
// Inset text by the margin and center vertically
var textPos = pos + new int2(margin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);
// Right align when editing and scissor when the text overflows
if (textSize.X > Bounds.Width - 2 * margin)
{
if (Focused)
textPos += new int2(Bounds.Width - 2 * margin - textSize.X, 0);
Game.Renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2 * margin, Bounds.Bottom);
}
font.DrawText(Text + cursor, textPos, Color.White);
if (textSize.X > Bounds.Width - 2 * margin)
{
Game.Renderer.RgbaSpriteRenderer.Flush();
Game.Renderer.Device.DisableScissor();
}
}
示例11: SetPreview
public void SetPreview(ActorInfo actor, TypeDictionary td)
{
var init = new ActorPreviewInitializer(actor, worldRenderer, td);
preview = actor.TraitInfos<IRenderActorPreviewInfo>()
.SelectMany(rpi => rpi.RenderPreview(init))
.ToArray();
// Calculate the preview bounds
PreviewOffset = int2.Zero;
IdealPreviewSize = int2.Zero;
var r = preview
.SelectMany(p => p.Render(worldRenderer, WPos.Zero))
.OrderBy(WorldRenderer.RenderableScreenZPositionComparisonKey)
.Select(rr => rr.PrepareRender(worldRenderer));
if (r.Any())
{
var b = r.First().ScreenBounds(worldRenderer);
foreach (var rr in r.Skip(1))
b = Rectangle.Union(b, rr.ScreenBounds(worldRenderer));
IdealPreviewSize = new int2(b.Width, b.Height);
PreviewOffset = -new int2(b.Left, b.Top) - IdealPreviewSize / 2;
}
}
示例12: Initialize
public override void Initialize(WidgetArgs args)
{
base.Initialize(args);
var width = world.Map.Bounds.Width;
var height = world.Map.Bounds.Height;
var size = Math.Max(width, height);
var rb = RenderBounds;
previewScale = Math.Min(rb.Width * 1f / width, rb.Height * 1f / height);
previewOrigin = new int2((int)(previewScale * (size - width) / 2), (int)(previewScale * (size - height) / 2));
mapRect = new Rectangle(previewOrigin.X, previewOrigin.Y, (int)(previewScale * width), (int)(previewScale * height));
// Only needs to be done once
using (var terrainBitmap = Minimap.TerrainBitmap(world.Map.Rules.TileSets[world.Map.Tileset], world.Map))
{
var r = new Rectangle(0, 0, width, height);
var s = new Size(terrainBitmap.Width, terrainBitmap.Height);
var terrainSheet = new Sheet(s, false);
terrainSheet.Texture.SetData(terrainBitmap);
terrainSprite = new Sprite(terrainSheet, r, TextureChannel.Alpha);
// Data is set in Tick()
customTerrainSprite = new Sprite(new Sheet(s, false), r, TextureChannel.Alpha);
actorSprite = new Sprite(new Sheet(s, false), r, TextureChannel.Alpha);
shroudSprite = new Sprite(new Sheet(s, false), r, TextureChannel.Alpha);
}
}
示例13: Draw
public override void Draw()
{
if (world == null) return;
if( world.LocalPlayer.WinState != WinState.Undefined ) return;
var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight)/2);
var s = new float2(mapRect.Size.Width, mapRect.Size.Height*radarMinimapHeight);
var rsr = Game.Renderer.RgbaSpriteRenderer;
rsr.DrawSprite(terrainSprite, o, s);
rsr.DrawSprite(customTerrainSprite, o, s);
rsr.DrawSprite(actorSprite, o, s);
rsr.DrawSprite(shroudSprite, o, s);
// Draw viewport rect
if (hasRadar && !animating)
{
var wr = Game.viewport.WorldRect;
var wro = new int2(wr.X, wr.Y);
var tl = CellToMinimapPixel(wro);
var br = CellToMinimapPixel(wro + new int2(wr.Width, wr.Height));
Game.Renderer.EnableScissor((int)mapRect.Left, (int)mapRect.Top, (int)mapRect.Width, (int)mapRect.Height);
Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White);
Game.Renderer.DisableScissor();
}
}
示例14: R8Frame
public R8Frame(Stream s)
{
// Scan forward until we find some data
var type = s.ReadUInt8();
while (type == 0)
type = s.ReadUInt8();
var width = s.ReadInt32();
var height = s.ReadInt32();
var x = s.ReadInt32();
var y = s.ReadInt32();
Size = new Size(width, height);
Offset = new int2(width / 2 - x, height / 2 - y);
/*var imageOffset = */
s.ReadInt32();
var paletteOffset = s.ReadInt32();
var bpp = s.ReadUInt8();
if (bpp != 8)
throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));
var frameHeight = s.ReadUInt8();
var frameWidth = s.ReadUInt8();
FrameSize = new Size(frameWidth, frameHeight);
// Skip alignment byte
s.ReadUInt8();
Data = s.ReadBytes(width * height);
// Ignore palette
if (type == 1 && paletteOffset != 0)
s.Seek(520, SeekOrigin.Current);
}
示例15: Viewport
public Viewport(WorldRenderer wr, Map map)
{
worldRenderer = wr;
var grid = Game.ModData.Manifest.Get<MapGrid>();
// Calculate map bounds in world-px
if (wr.World.Type == WorldType.Editor)
{
// The full map is visible in the editor
var width = map.MapSize.X * grid.TileSize.Width;
var height = map.MapSize.Y * grid.TileSize.Height;
if (wr.World.Map.Grid.Type == MapGridType.RectangularIsometric)
height /= 2;
mapBounds = new Rectangle(0, 0, width, height);
CenterLocation = new int2(width / 2, height / 2);
}
else
{
var tl = wr.ScreenPxPosition(map.ProjectedTopLeft);
var br = wr.ScreenPxPosition(map.ProjectedBottomRight);
mapBounds = Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y);
CenterLocation = (tl + br) / 2;
}
Zoom = Game.Settings.Graphics.PixelDouble ? 2 : 1;
tileSize = grid.TileSize;
}