Skip to content

Commit

Permalink
TargetInfoWindow fixes
Browse files Browse the repository at this point in the history
- the TargetInfoWindow now opens right and not after onPositionchanged
is called
- deleted log spamming
  • Loading branch information
Peppie84 committed Jan 8, 2015
1 parent d16d7ec commit af5447f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/RemoteTech/UI/AbstractWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class AbstractWindow
public float mInitialHeight;
/// <summary>Callback trigger for the change in the posistion</summary>
public Action onPositionChanged = delegate { };
private Rect tmpPosition;
public Rect backupPosition;

static AbstractWindow()
{
Expand All @@ -49,7 +49,7 @@ public AbstractWindow(Guid id, String title, Rect position, WindowAlign align)
Title = title;
Alignment = align;
Position = position;
tmpPosition = Position;
backupPosition = position;
mInitialHeight = position.height + 15;
mInitialWidth = position.width + 15;

Expand Down Expand Up @@ -181,13 +181,11 @@ public virtual void Draw()
mLastTime = Time.time;

// Position of the window changed?
if (!tmpPosition.Equals(Position))
if (!backupPosition.Equals(Position))
{
RTLog.Notify("TmpPosition: {0}", tmpPosition);
RTLog.Notify("Position: {0}", Position);
// trigger the onPositionChanged callbacks
onPositionChanged.Invoke();
tmpPosition = Position;
backupPosition = Position;
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/RemoteTech/UI/AntennaWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public override void Show()
mAntennaFragment = mAntennaFragment ?? new AntennaFragment(mSetAntenna);

/// Add callbacks for the onPositionChanged on the AbstractWindow
onPositionChanged += mouseOverAntennaWindow;
onPositionChanged += mTargetInfos.calculatePosition;

/// Add the showTargetInfo callback to the on mouse over/out event
Expand All @@ -76,7 +75,6 @@ public override void Hide()
{
/// Remove callbacks from the onPositionChanged on the AbstractWindow
onPositionChanged -= mTargetInfos.calculatePosition;
onPositionChanged -= mouseOverAntennaWindow;

/// Remove the showTargetInfo callback from the on mouse over/out event
mAntennaFragment.onMouseOverListEntry -= showTargetInfo;
Expand All @@ -93,7 +91,10 @@ public override void Window(int uid)
{
if (mAntennaFragment.Antenna == null) { Hide(); return; }
GUI.skin = HighLogic.Skin;


// check the mouse position on every draw call
mouseOverAntennaWindow();

GUILayout.BeginVertical(GUILayout.Width(300), GUILayout.Height(500));
{
mAntennaFragment.Draw();
Expand All @@ -103,9 +104,13 @@ public override void Window(int uid)
base.Window(uid);
}

/// <summary>
/// Checks whether the mouse is over this window to set
/// the triggerMouseOverListEntry on the AntennaFragment
/// </summary>
public void mouseOverAntennaWindow()
{
mAntennaFragment.triggerMouseOverListEntry = Position.Contains(Event.current.mousePosition);
mAntennaFragment.triggerMouseOverListEntry = backupPosition.Contains(Event.current.mousePosition);
}

public void OnVesselChange(Vessel v)
Expand Down

0 comments on commit af5447f

Please sign in to comment.