Skip to content

Commit

Permalink
Finally working kludge version of travel line for taskgroups
Browse files Browse the repository at this point in the history
It works, but I should do it in a less bad way.
  • Loading branch information
NathanH- committed Jan 5, 2014
1 parent 21ed14d commit 5f64d73
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 27 deletions.
9 changes: 9 additions & 0 deletions Pulsar4X/Pulsar4X.Lib/Entities/SimEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,16 @@ public void AdvanceSim(BindingList<Faction> P, Random RNG, int tickValue)
/// Adding new taskgroups means adding a loop here to run through them all.
/// </summary>
if (P[loop].TaskGroups[loop2].TaskGroupOrders.Count != 0)
{
P[loop].TaskGroups[loop2].FollowOrders((uint)(CurrentTick - lastTick));
}
else if(P[loop].TaskGroups[loop2].DrawTravelLine == 1)
{
P[loop].TaskGroups[loop2].Contact.LastXSystem = P[loop].TaskGroups[loop2].Contact.XSystem;
P[loop].TaskGroups[loop2].Contact.LastYSystem = P[loop].TaskGroups[loop2].Contact.YSystem;

P[loop].TaskGroups[loop2].DrawTravelLine = 2;
}
}
}

Expand Down
16 changes: 14 additions & 2 deletions Pulsar4X/Pulsar4X.Lib/Entities/TaskGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ public override double Mass
public BindingList<TaskGroupTN> TaskGroupsOrdered { get; set; }



/// <summary>
/// Controls whether or not the travel line will be set. 0 means draw the line, 1 means set last position to current position. 2 means that last position has been set to current position.
/// 3 means that the line has been updated on the system map as being not drawn, so do not display it again.
/// This is referenced in SimEntity and SystemMap as well as here.
/// </summary>
public byte DrawTravelLine { get; set; }
/// <summary>
/// Constructor for the taskgroup, sets name, faction, planet the TG starts in orbit of.
/// </summary>
Expand All @@ -205,8 +210,11 @@ public TaskGroupTN(string Title, Faction FID, OrbitingEntity StartingBody, StarS
Contact.XSystem = OrbitingBody.XSystem;
Contact.YSystem = OrbitingBody.YSystem;
Contact.ZSystem = OrbitingBody.ZSystem;
Contact.LastXSystem = Contact.XSystem;
Contact.LastYSystem = Contact.YSystem;
Contact.CurrentSystem = StartingSystem;
StartingSystem.AddContact(Contact);
DrawTravelLine = 2;

m_dMass = 0.0;

Expand Down Expand Up @@ -1165,8 +1173,11 @@ public void UseFuel(uint TimeSlice)
/// <param name="Secondary">Secondary will be an enum ID for facility type,component,troop formation, or tractorable ship/shipyard. -1 if not present.</param>
public void IssueOrder(Orders OrderToTaskGroup)
{
if(TaskGroupOrders.Count == 0)
if (TaskGroupOrders.Count == 0)
{
NewOrders = true;
DrawTravelLine = 0;
}

TaskGroupOrders.Add(OrderToTaskGroup);

Expand Down Expand Up @@ -1407,6 +1418,7 @@ public void FollowOrders(uint TimeSlice)
}
else
{
DrawTravelLine = 1;
CanOrder = Constants.ShipTN.OrderState.AcceptOrders;
}
}
Expand Down
15 changes: 8 additions & 7 deletions Pulsar4X/Pulsar4X.UI/Handlers/SystemMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,16 +938,17 @@ private void DrawTaskGroups()
m_oCurrentSceen.ShipMarkers[CurrentStarSystem.SystemContactList[loop].TaskGroup.MapMarkerId].Lable.Position = WC;

Vector3 LC = new Vector3((float)CurrentStarSystem.SystemContactList[loop].TaskGroup.Contact.LastXSystem, (float)CurrentStarSystem.SystemContactList[loop].TaskGroup.Contact.LastYSystem, 0.0f);
if (LC != WC)

if (CurrentStarSystem.SystemContactList[loop].TaskGroup.DrawTravelLine != 3)
{
m_oCurrentSceen.ShipMarkers[CurrentStarSystem.SystemContactList[loop].TaskGroup.MapMarkerId].Primitives[1].Position = WC;
GLLine Temp = m_oCurrentSceen.ShipMarkers[CurrentStarSystem.SystemContactList[loop].TaskGroup.MapMarkerId].Primitives[1] as GLLine;
if (Temp != null)
{
Temp.PosEnd = LC;
}
m_oCurrentSceen.ShipMarkers[CurrentStarSystem.SystemContactList[loop].TaskGroup.MapMarkerId].SetMeasurementStartPos(LC);
m_oCurrentSceen.ShipMarkers[CurrentStarSystem.SystemContactList[loop].TaskGroup.MapMarkerId].SetMeasurementEndPos(WC);
}

if (CurrentStarSystem.SystemContactList[loop].TaskGroup.DrawTravelLine == 2)
{
CurrentStarSystem.SystemContactList[loop].TaskGroup.DrawTravelLine = 3;
}
}
else
{
Expand Down
86 changes: 74 additions & 12 deletions Pulsar4X/Pulsar4X.UI/SceenGraph/MapMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@ public override GameEntity SceenEntity
{
if (m_oGameEntity != value)
{
if(m_oGameEntity!= null)
if (m_oGameEntity != null)
m_oGameEntity.PropertyChanged -= m_oGameEntity_PropertyChanged;
m_oGameEntity = value;
if(value != null)
if (value != null)
m_oGameEntity.PropertyChanged += m_oGameEntity_PropertyChanged;
}
}
}

void m_oGameEntity_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == "Name")
if (e.PropertyName == "Name")
{
/// <summary>
/// Change Label here!
/// </summary>
Lable.Text = m_oGameEntity.Name;
/// <summary>
/// Change Label here!
/// </summary>
Lable.Text = m_oGameEntity.Name;

GLUtilities.GLFont oNameLable = new GLUtilities.GLFont(ParentSceen.ParentSystemMap.oGLCanvas.DefaultEffect, Lable.Position,
Lable.Size, System.Drawing.Color.Tan, UIConstants.Textures.DEFAULT_GLFONT2, m_oGameEntity.Name);
GLUtilities.GLFont oNameLable = new GLUtilities.GLFont(ParentSceen.ParentSystemMap.oGLCanvas.DefaultEffect, Lable.Position,
Lable.Size, System.Drawing.Color.Tan, UIConstants.Textures.DEFAULT_GLFONT2, m_oGameEntity.Name);

Lable = oNameLable;
Lable = oNameLable;

ParentSceen.Refresh();
ParentSceen.Refresh();

}
}
Expand All @@ -61,15 +61,38 @@ void m_oGameEntity_PropertyChanged(object sender, System.ComponentModel.Property
/// </summary>
public Sceen ParentSceen { get; set; }



/// <summary>
/// Line from Last Position to Current Position for taskgroups.
/// </summary>
private MeasurementElement TravelLine { get; set; }


public MapMarker()
: base()
{ }

public MapMarker(GLEffect a_oDefaultEffect, System.Drawing.Color MMColor)
{
// Create measurement element:
TravelLine = new MeasurementElement();
TravelLine.PrimaryPrimitive = new GLLine(a_oDefaultEffect, Vector3.Zero, new Vector2(1.0f, 1.0f), MMColor, UIConstants.Textures.DEFAULT_TEXTURE);
TravelLine.AddPrimitive(TravelLine.PrimaryPrimitive);
TravelLine.Lable = new GLUtilities.GLFont(a_oDefaultEffect, Vector3.Zero, UIConstants.DEFAULT_TEXT_SIZE, MMColor, UIConstants.Textures.DEFAULT_GLFONT2, "");

}

public override void Render()
{
foreach (GLPrimitive oPrimitive in m_lPrimitives)
{
oPrimitive.Render();

if (TravelLine != null)
{
TravelLine.Render();
}
}

if (RenderChildren == true)
Expand Down Expand Up @@ -135,8 +158,12 @@ public override void Refresh(float a_fZoomScaler)
}

// Adjust the size of the text so it is always 10 point:
Lable.Size = UIConstants.DEFAULT_TEXT_SIZE / a_fZoomScaler;
Lable.Size = UIConstants.DEFAULT_TEXT_SIZE / a_fZoomScaler;

if (TravelLine != null)
{
TravelLine.Refresh(a_fZoomScaler);
}

// loop through any children:
foreach (SceenElement oElement in m_lChildren)
Expand All @@ -149,5 +176,40 @@ public override string ToString()
{
return Lable.Text;
}

public void SetMeasurementStartPos(Vector3 a_v3Pos)
{

GLLine temp = TravelLine.PrimaryPrimitive as GLLine;

a_v3Pos.X = a_v3Pos.X / 2;
a_v3Pos.Y = a_v3Pos.Y / 2;

if (temp != null)
{
temp.Position = a_v3Pos;
temp.Verticies[0].m_v4Position = new Vector4(a_v3Pos.X, a_v3Pos.Y, a_v3Pos.Z, 1.0f);
temp.UpdateVBOs();
}
}

public void SetMeasurementEndPos(Vector3 a_v3Pos)
{
GLLine temp = TravelLine.PrimaryPrimitive as GLLine;

a_v3Pos.X = a_v3Pos.X / 2;
a_v3Pos.Y = a_v3Pos.Y / 2;

float XAdjust = a_v3Pos.X - TravelLine.Primitives[0].Verticies[0].m_v4Position.X;
float YAdjust = a_v3Pos.Y - TravelLine.Primitives[0].Verticies[0].m_v4Position.Y;

a_v3Pos.X = a_v3Pos.X + XAdjust;
a_v3Pos.Y = a_v3Pos.Y + YAdjust;

if (temp != null)
{
temp.PosEnd = a_v3Pos;
}
}
}
}
7 changes: 1 addition & 6 deletions Pulsar4X/Pulsar4X.UI/SceenGraph/Sceen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public void AddMapMarker(Vector3 a_v3Pos, GLEffect a_oDefaultEffect)
/// <returns>index of marker</returns>
public int AddMapMarker(Vector3 a_v3Pos, GLEffect a_oDefaultEffect, Color MMColor, GameEntity entity)
{
MapMarker oMapMarker = new MapMarker();
MapMarker oMapMarker = new MapMarker(a_oDefaultEffect, MMColor);
oMapMarker.SceenEntity = entity;

GLUtilities.GLQuad oMarkerQuad = new GLUtilities.GLQuad(a_oDefaultEffect,
Expand All @@ -496,11 +496,6 @@ public int AddMapMarker(Vector3 a_v3Pos, GLEffect a_oDefaultEffect, Color MMColo

oMapMarker.ParentSceen = this;

Vector2 LineVect = new Vector2(1.0f, 1.0f);
GLLine oLine = new GLLine(a_oDefaultEffect, a_v3Pos, LineVect, MMColor);

oMapMarker.AddPrimitive(oLine);

m_lTempShipMarkers.Add(oMapMarker);


Expand Down

0 comments on commit 5f64d73

Please sign in to comment.