public InteractiveObject2D Add(InteractiveObject iobj) { InteractiveObject2D obj = new InteractiveObject2D(iobj); list.Add(obj); return(obj); }
//========================================================================================================================= public void Init(int side, FVector2 pos, float rotation) { this.Side = side; this.Position = pos; IntObj3D = new InteractiveObject3D(this); ForegroundGame.IntObjs3D.Add(IntObj3D); IntObj2D = ForegroundGame.IntObjsManager.Add(this); proximityToken = BackgroundGame.IntObjsLQDB.AllocateToken(this); proximityToken.UpdateForNewPosition(new Point3D(pos.X.ToInt(), 0, pos.Y.ToInt())); onInitialize(); Initialized = true; }
public void Select(InteractiveObject2D selectedObj, ref List <InteractiveObject2D> result) { if (selectedObj == null) { return; } foreach (InteractiveObject2D obj in list) { if (!obj.onScreen) { continue; } if (selectedObj.entity.GetType() == obj.entity.GetType()) { result.Add(obj); } } }
public InteractiveObject2D Select(Vector2 point) { InteractiveObject2D returnObj = null; float nearestDist = float.MaxValue; foreach (InteractiveObject2D obj in list) { if (obj.rect.Contains((int)point.X, (int)point.Y)) { float dist = (obj.position - point).LengthSquared(); if (dist < nearestDist) { nearestDist = dist; returnObj = obj; } } } return(returnObj); }
public void Remove(InteractiveObject2D obj) { list.Remove(obj); }
public void Render2D() { Vector2 pos; float length = 0; Vector2 pos2D; for (int i = 0; i < list.Count; i++) { InteractiveObject2D obj = list[i]; CameraHelper.Convert3DPointTo2D(obj.entity.IntObj3D.Position, out pos); obj.position.X = (int)pos.X; obj.position.Y = (int)pos.Y; if (!StrategicMode) { length = Vector3.Distance(SceneManager.Camera.eyePosition, obj.entity.IntObj3D.Position); obj.rect.Width = obj.rect.Height = (int)(16 * (obj.bracketSize * 120 / length)); obj.rect.X = (int)(pos.X - (float)obj.rect.Height / 2); obj.rect.Y = (int)(pos.Y - (float)obj.rect.Height / 2); } else { obj.rect.Width = obj.rect.Height = 16; obj.rect.X = (int)pos.X - 7; obj.rect.Y = (int)pos.Y - 7; } obj.onScreen = obj.rect.Right > 0 && obj.rect.Bottom > 0 && obj.rect.Left < Display.Width && obj.rect.Top < Display.Height; if (!obj.onScreen) { continue; } //DEBUG SELECTION RECTANGLE //QuadRenderer.Draw(Resources.GetEmptyTexture(), new SharpDX.Rectangle(obj.rect.X, obj.rect.Y, obj.rect.Width, obj.rect.Height), new Color4(0, 1, 1, 0.2f)); if (!StrategicMode) { // DRAW PROGRESS BARS /*if (obj.progress != -1) { * //if (obj.side != Main.network.me.id) continue; * float size = obj.bracketSize * 1000 / length; * Vector2 posBar = new Vector2(pos.X - size, pos.Y + 5 + size); * Vector2 sizeBar = new Vector2(size * 2, 2); * Vector2 progressBar = new Vector2(size * 2 * ((float)obj.progress / 10000), 2)*0.25f; * QuadRenderer.Draw(Resources.GetEmptyTexture(), posBar - new Vector2(1, 1), (sizeBar + new Vector2(2, 2))*0.25f, Color.Black); * * QuadRenderer.Draw(Resources.GetEmptyTexture(), posBar, progressBar, Color.Cyan); * posBar.Y += 2; * FontRenderer.Draw("default", obj.progress_text, posBar + new Vector2(1, 1), Color.Black); * FontRenderer.Draw("default", obj.progress_text, posBar, Color.White); * }*/ if (obj.selected || obj.focused) { SharpDX.Rectangle rect = new SharpDX.Rectangle(obj.rect.X, obj.rect.Y + obj.rect.Height, obj.rect.Width, 3); QuadRenderer.Draw(Resources.GetEmptyTexture(), rect, Color.Black); rect.Right = (int)(rect.Right * ((float)obj.entity.Health / obj.entity.HealthMax)); QuadRenderer.Draw(Resources.GetEmptyTexture(), rect, Color.LightGreen); } } else { // DRAW STRATEGIC ICON OUTLINES pos2D.X = pos.X - 7; pos2D.Y = pos.Y - 7; if (obj.iconId != -1 && !obj.selected && !obj.focused) { QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 32, 16, 16), Color.Black); } } } if (!StrategicMode) { return; } // STRATEGIC ICONS with over the outlines //------------------------------------------ foreach (InteractiveObject2D obj in list) { if (!obj.onScreen || obj.iconId == -1) { continue; } pos2D.X = obj.position.X - 7; pos2D.Y = obj.position.Y - 7; Color4 color = Color.LimeGreen;//Main.network.players.GetColor(obj.side); QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 0, 16, 16), color); } // SELECTED UNITS HAVE TO BE RENDERED ON TOP //------------------------------------------ foreach (InteractiveObject2D obj in list) { if (!obj.onScreen || obj.iconId == -1 || (!obj.selected && !obj.focused)) { continue; } pos2D.X = obj.position.X - 7; pos2D.Y = obj.position.Y - 7; Color4 color = Color.Black; if (obj.selected) { color = Color.White; } else if (obj.focused) { color = Color.LimeGreen; //Main.network.players.GetColor(obj.side); } QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 32, 16, 16), color); } foreach (InteractiveObject2D obj in list) { if (!obj.onScreen || obj.iconId == -1 || (!obj.selected && !obj.focused)) { continue; } pos2D.X = obj.position.X - 7; pos2D.Y = obj.position.Y - 7; Color4 color = Color.LimeGreen; //Main.network.players.GetColor(obj.side); QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 0, 16, 16), color); } }