Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ca535f32c970
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5661950b9460
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Aug 8, 2021

  1. Copy the full SHA
    6a0b9f7 View commit details
  2. delay

    eggrobin committed Aug 8, 2021
    Copy the full SHA
    f71742d View commit details
  3. Merge pull request #3086 from eggrobin/tooltip

    Add support for tooltips popping up near the pointer
    eggrobin authored Aug 8, 2021
    Copy the full SHA
    5661950 View commit details
Showing with 44 additions and 6 deletions.
  1. +44 −6 ksp_plugin_adapter/window_renderer.cs
50 changes: 44 additions & 6 deletions ksp_plugin_adapter/window_renderer.cs
Original file line number Diff line number Diff line change
@@ -124,11 +124,12 @@ public void RenderWindow() {
}
UnityEngine.GUI.skin = skin_;
if (show_) {
rectangle_ = UnityEngine.GUILayout.Window(id : this.GetHashCode(),
screenRect : rectangle_,
func : RenderWindow,
text : Title,
options : options_);
rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode(),
screenRect : rectangle_,
func : RenderWindowAndRecordTooltip,
text : Title,
options : options_);

// The first time a window is shown, we have a moral duty to place it at
// the centre of the screen. This is tricky because we don't know its
@@ -146,11 +147,12 @@ public void RenderWindow() {
y : (float)UnityEngine.Screen.height / 3f,
width : 0,
height : 0),
func : RenderWindow,
func : RenderWindowAndRecordTooltip,
text : Title,
options : options_);
must_centre_ = false;
}
ShowTooltip();
EnsureOnScreen();
InputLock();
} else {
@@ -170,6 +172,39 @@ private void EnsureOnScreen() {
UnityEngine.Screen.height - min_height_on_screen);
}

private void RenderWindowAndRecordTooltip(int window_id) {
RenderWindow(window_id);
if (UnityEngine.Event.current.type == UnityEngine.EventType.Repaint &&
tooltip_ != UnityEngine.GUI.tooltip) {
if (tooltip_ == "") {
tooltip_begin_ = DateTime.UtcNow;
}
tooltip_ = UnityEngine.GUI.tooltip;
var height = Style.Multiline(UnityEngine.GUI.skin.textArea).CalcHeight(
new UnityEngine.GUIContent(tooltip_), Width(8));
tooltip_rectangle_ = new UnityEngine.Rect(
UnityEngine.Input.mousePosition.x + Width(1) / 2,
UnityEngine.Screen.height -
(UnityEngine.Input.mousePosition.y - Width(1) / 2),
Width(8), height);
}
}

private void ShowTooltip() {
if (tooltip_ != "" &&
(DateTime.UtcNow - tooltip_begin_).TotalMilliseconds > 500) {
var tooltip_style = Style.Multiline(UnityEngine.GUI.skin.textArea);
tooltip_style.font = UnityEngine.GUI.skin.font;
UnityEngine.GUI.Window(
tooltip_.GetHashCode(),
tooltip_rectangle_,
(int window_id) => {},
tooltip_,
tooltip_style);
UnityEngine.GUI.BringWindowToFront(tooltip_.GetHashCode());
}
}

public void Shrink() {
rectangle_.height = 0.0f;
rectangle_.width = 0.0f;
@@ -233,6 +268,9 @@ public virtual void Save(ConfigNode node) {
private bool must_centre_ = true;
private bool show_ = false;
private UnityEngine.Rect rectangle_;
private DateTime tooltip_begin_;
private string tooltip_ = "";
private UnityEngine.Rect tooltip_rectangle_;
}

// The supervisor of a window decides when to clear input locks, when to render