Skip to content

Commit

Permalink
Version 1.13f
Browse files Browse the repository at this point in the history
Show related part on mouseover
  • Loading branch information
SirDiazo committed Sep 2, 2014
1 parent 4a99194 commit f77e438
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 21 deletions.
110 changes: 107 additions & 3 deletions AGExt/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public class AGXEditor : PartModule
bool checkShipsExist = false; //flag to check existing ships on load window open
int checkShipsExistDelay = 0;//delay timer to wait after opening load ship window
static bool inVAB = true; //true if in VAB, flase in SPH
bool highlightPartThisFrameSelWin = false;
bool highlightPartThisFrameActsWin = false;
Part partToHighlight = null;
Texture2D PartCenter = new Texture2D(41, 41);
//static Part partLastHighlight = null;
////static Color partHighlighLastColor;
//static Part.HighlightType partHighlightLastType;
//static Material[] partHighlightLastMaterial;



Expand Down Expand Up @@ -292,6 +300,7 @@ public void Start()
byte[] importTxt = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTexture.png");
byte[] importTxtRed = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTextureRed.png");
byte[] importTxtGreen = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTextureGreen.png");
byte[] importPartCenter = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/PartLocationCross.png");
//byte[] testXport = AGXBtnStyle.normal.background.EncodeToPNG();
//File.WriteAllBytes(Application.dataPath + "/SavedScreen.png", testXport);
ButtonTexture.LoadImage(importTxt);
Expand All @@ -308,6 +317,8 @@ public void Start()
AGXBtnStyle.active.background = ButtonTexture;
AGXBtnStyle.focused.background = ButtonTexture;
AGXBtnStyle.hover.background = ButtonTexture;
PartCenter.LoadImage(importPartCenter);
PartCenter.Apply();
//EditorLoadFromFile();
if (HighLogic.LoadedScene == GameScenes.EDITOR)
{
Expand Down Expand Up @@ -638,10 +649,12 @@ private static bool JoySticks(String s)

public void AGXOnDraw()
{

//print("start ondraw draw");
Vector3 RealMousePos = new Vector3();
RealMousePos = Input.mousePosition;
RealMousePos.y = Screen.height - Input.mousePosition.y;



if (!ToolbarManager.ToolbarAvailable)
{
Expand All @@ -666,8 +679,9 @@ public void AGXOnDraw()

if (ShowSelectedWin)
{

//print("start selparts draw");
SelPartsWin = GUI.Window(673467794, SelPartsWin, SelParts, "AGExt Selected parts: " + AGEditorSelectedParts.Count(), AGXWinStyle);
// print("end selparts draw");
ShowCurActsWin = true;
TrapMouse = SelPartsWin.Contains(RealMousePos);
if (AutoHideGroupsWin && !TempShowGroupsWin)
Expand All @@ -692,6 +706,25 @@ public void AGXOnDraw()
TrapMouse |= CurActsWin.Contains(RealMousePos);
}
}
// print("Truth check " + highlightPartThisFrameActsWin + " " + highlightPartThisFrameSelWin);
if (highlightPartThisFrameActsWin || highlightPartThisFrameSelWin)
{
//Camera edCam = EditorCamera.fe
// print("mouse over");
//print("screen pos " + EditorLogic.fetch.editorCamera.WorldToScreenPoint(partToHighlight.transform.position));
//print("orgpos" + partToHighlight.);
Vector3 partScreenPos = EditorLogic.fetch.editorCamera.WorldToScreenPoint(partToHighlight.transform.position);
Rect partCenterWin = new Rect(partScreenPos.x - 20, (Screen.height- partScreenPos.y) - 20, 41, 41);
partCenterWin = GUI.Window(673767790, partCenterWin, PartTarget, "", AGXWinStyle);


}
//print("end ondraw draw");
}

public void PartTarget(int WindowID)
{
GUI.DrawTexture(new Rect(0, 0, 41, 41), PartCenter);
}

public void CurrentActionsWindow(int WindowID)
Expand All @@ -703,11 +736,21 @@ public void CurrentActionsWindow(int WindowID)
CurGroupsWin = GUI.BeginScrollView(new Rect(10, 30, 330, 100), CurGroupsWin, new Rect(0, 0, 310, Math.Max(100,0+(20*(ThisGroupActions.Count)))));
int RowCnt = new int();
RowCnt = 1;

highlightPartThisFrameActsWin = false;
if (ThisGroupActions.Count > 0)
{

while (RowCnt <= ThisGroupActions.Count)
{

if (Mouse.screenPos.y >= CurActsWin.y + 30 && Mouse.screenPos.y <= CurActsWin.y + 130 && new Rect(CurActsWin.x + 10, (CurActsWin.y + 30 + ((RowCnt - 1) * 20)) - CurGroupsWin.y, 300, 20).Contains(Mouse.screenPos))
{
highlightPartThisFrameActsWin = true;
//print("part found to highlight acts " + highlightPartThisFrameActsWin + " " + ThisGroupActions.ElementAt(RowCnt - 1).ba.listParent.part.transform.position);
partToHighlight = ThisGroupActions.ElementAt(RowCnt - 1).ba.listParent.part;
}


TextAnchor TxtAnch4 = new TextAnchor();
TxtAnch4 = GUI.skin.button.alignment;
// GUI.skin.button.alignment = TextAnchor.MiddleLeft;
Expand Down Expand Up @@ -1324,6 +1367,7 @@ public void SelParts(int WindowID)
//AGXPart FirstPart = new AGXPart();
// FirstPart = AGEditorSelectedParts.First().AGPart.name;
GUI.Box(new Rect(SelPartsLeft + 20, 25, 200, 110), "");
highlightPartThisFrameSelWin = false;
if (AGEditorSelectedParts != null && AGEditorSelectedParts.Count > 0)
{

Expand All @@ -1335,6 +1379,15 @@ public void SelParts(int WindowID)
//GUI.Box(new Rect(SelPartsLeft, 25, 200, (20 * Math.Max(5, SelectedPartsCount)) + 10), "");
while (ButtonCount <= SelectedPartsCount)
{
//Rect buttonRect = new Rect(5, 0 + ((ButtonCount - 1) * 20), 190, 20); //need this rectangle twice
if (Mouse.screenPos.y >= SelPartsWin.y + 30 && Mouse.screenPos.y <= SelPartsWin.y + 140 && new Rect(SelPartsWin.x + SelPartsLeft + 25, (SelPartsWin.y + 30 + ((ButtonCount - 1) * 20)) - ScrollPosSelParts.y, 190, 20).Contains(Mouse.screenPos))
{
highlightPartThisFrameSelWin = true;
//print("part found to highlight " + AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.ConstructID);
partToHighlight = AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart;
}



if (GUI.Button(new Rect(5, 0 + ((ButtonCount - 1) * 20), 190, 20), AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.partInfo.title, AGXBtnStyle))
{
Expand Down Expand Up @@ -2264,8 +2317,59 @@ public void Update()
MonitorDefaultActions();
}
//print("count check " + CurrentVesselActions.Count);
//HighlightPartLogic();
}

//public static void HighlightPartLogic()
//{

// //Camera[] allCams =
// //print("Highligh part logic called");
// if (highlightPartThisFrameActsWin || highlightPartThisFrameSelWin)
// {
// //Camera edCam = EditorCamera.fe
// print("screen pos " + EditorLogic.fetch.editorCamera.WorldToScreenPoint(partToHighlight.transform.position));
// Vector3 partScreenPos = EditorLogic.fetch.editorCamera.WorldToScreenPoint(partToHighlight.transform.position);

// }
// if (partLastHighlight != null)
// {
// //partLastHighlight.highlightColor = partHighlighLastColor;
// partLastHighlight.renderer.materials = partHighlightLastMaterial;
// partLastHighlight.highlightType = partHighlightLastType;
// //partLastHighlight.SetHighlight(false);
// //partLastHighlight = null;
// }
// partToHighlight = null;


//}

//if (partToHighlight != partLastHighlight)
//{
// if (partLastHighlight != null)
// {
// //partLastHighlight.highlightColor = partHighlighLastColor;
// partLastHighlight.highlightType = partHighlightLastType;
// partLastHighlight.renderer.materials = partHighlightLastMaterial;
// //partLastHighlight.SetHighlight(false);
// }
// //partHighlighLastColor = partToHighlight.highlightColor;
// //partToHighlight.highlightColor = Color.yellow;
// partHighlightLastMaterial = partToHighlight.renderer.materials;
// foreach (Material mat in partToHighlight.renderer.materials)
// {
// mat.color = Color.yellow;
// }
// partHighlightLastType = partToHighlight.highlightType;
// partToHighlight.highlightType = Part.HighlightType.AlwaysOn;
// //partToHighlight.SetHighlight(true);
// partLastHighlight = partToHighlight;
// partToHighlight.renderer.

//}
//}

public void MonitorDefaultActions()
{
//print("2a");
Expand Down
9 changes: 4 additions & 5 deletions AGExt/External.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ public static bool AGXGroupState(int i)
}

//TO DO LIST
//-Remove ModuleManger dependancy
//-check joystick keybinding assignment


//-add staging
//-shrink FlightWin keybind to Numpad 0
//add option to show/hide flightwin keybind
//add option to size flightwin


67 changes: 54 additions & 13 deletions AGExt/Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public class AGXFlight : PartModule
List<AGXPartVesselCheck> partOldVessel = new List<AGXPartVesselCheck>();
public static bool flightNodeIsLoaded = false;
static List<Vessel> loadedVessels; //loaded vessels list, add vessels to this on OffRails, remove when OnRails
bool highlightPartThisFrameSelWin = false;
bool highlightPartThisFrameActsWin = false;
Part partToHighlight = null;
Texture2D PartCenter = new Texture2D(41, 41);



Expand Down Expand Up @@ -279,6 +283,7 @@ public void Start()
byte[] importTxt = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTexture.png");
byte[] importTxtRed = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTextureRed.png");
byte[] importTxtGreen = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/ButtonTextureGreen.png");
byte[] importPartCenter = File.ReadAllBytes(KSPUtil.ApplicationRootPath + "GameData/Diazo/AGExt/PartLocationCross.png");
//byte[] testXport = AGXBtnStyle.normal.background.EncodeToPNG();
//File.WriteAllBytes(Application.dataPath + "/SavedScreen.png", testXport);
ButtonTexture.LoadImage(importTxt);
Expand All @@ -295,6 +300,8 @@ public void Start()
AGXBtnStyle.active.background = ButtonTexture;
AGXBtnStyle.focused.background = ButtonTexture;
AGXBtnStyle.hover.background = ButtonTexture;
PartCenter.LoadImage(importPartCenter);
PartCenter.Apply();
SettingsWinRect = new Rect(500, 500, 150, 75);
partOldVessel = new List<AGXPartVesselCheck>();
GameEvents.onVesselGoOffRails.Add(VesselOffRails); //triggers when vessel loads at flight scene start also
Expand Down Expand Up @@ -951,9 +958,27 @@ public void AGXOnDraw()
// TrapMouse |= CurActsWin.Contains(RealMousePos);
}

}
if (highlightPartThisFrameActsWin || highlightPartThisFrameSelWin)
{
//Camera edCam = EditorCamera.fe
// print("mouse over");
//print("screen pos " + EditorLogic.fetch.editorCamera.WorldToScreenPoint(partToHighlight.transform.position));
//print("orgpos" + partToHighlight.);
Vector3 partScreenPos = FlightCamera.fetch.mainCamera.WorldToScreenPoint(partToHighlight.transform.position);
//EditorLogic.fetch.editorCamera.WorldToScreenPoint(partToHighlight.transform.position);
Rect partCenterWin = new Rect(partScreenPos.x - 20, (Screen.height - partScreenPos.y) - 20, 41, 41);
partCenterWin = GUI.Window(673767790, partCenterWin, PartTarget, "", AGXWinStyle);


}
}

public void PartTarget(int WindowID)
{
GUI.DrawTexture(new Rect(0, 0, 41, 41), PartCenter);
}

public static void ActivateActionGroup(int group)
{

Expand Down Expand Up @@ -1270,12 +1295,19 @@ public void CurrentActionsWindow(int WindowID)
CurGroupsWin = GUI.BeginScrollView(new Rect(10, 30, 330, 100), CurGroupsWin, new Rect(0, 0, 310, Math.Max(100, 0 + (20 * (ThisGroupActions.Count)))));
int RowCnt = new int();
RowCnt = 1;

highlightPartThisFrameActsWin = false;
if (ThisGroupActions.Count > 0)
{
while (RowCnt <= ThisGroupActions.Count)
{

if (Mouse.screenPos.y >= CurActsWin.y + 30 && Mouse.screenPos.y <= CurActsWin.y + 130 && new Rect(CurActsWin.x + 10, (CurActsWin.y + 30 + ((RowCnt - 1) * 20)) - CurGroupsWin.y, 300, 20).Contains(Mouse.screenPos))
{
highlightPartThisFrameActsWin = true;
//print("part found to highlight acts " + highlightPartThisFrameActsWin + " " + ThisGroupActions.ElementAt(RowCnt - 1).ba.listParent.part.transform.position);
partToHighlight = ThisGroupActions.ElementAt(RowCnt - 1).ba.listParent.part;
}

TextAnchor TxtAnch4 = new TextAnchor();

TxtAnch4 = GUI.skin.button.alignment;
Expand Down Expand Up @@ -1674,7 +1706,7 @@ public void LoadCurrentKeyBindings()


String LoadString = AGExtNode.GetValue("KeySet" + CurrentKeySet.ToString());
print("Keyset load " + CurrentKeySet + " " + LoadString);
//print("Keyset load " + CurrentKeySet + " " + LoadString);

for (int i = 1; i <= 250; i++)
{
Expand Down Expand Up @@ -1725,7 +1757,7 @@ public void LoadCurrentKeyBindings()

public void SaveCurrentKeyBindings()
{
print("Saving current keybinds");
//print("Saving current keybinds");

AGExtNode.SetValue("KeySetName" + CurrentKeySet, CurrentKeySetName);
string SaveString = "";
Expand Down Expand Up @@ -1901,12 +1933,21 @@ public void SelParts(int WindowID)
ButtonCount = 1;

ScrollPosSelParts = GUI.BeginScrollView(new Rect(SelPartsLeft + 20, 30, 220, 110), ScrollPosSelParts, new Rect(0, 0, 200, (20 * Math.Max(5, SelectedPartsCount)) + 10));

highlightPartThisFrameSelWin = false;
//GUI.Box(new Rect(SelPartsLeft, 25, 200, (20 * Math.Max(5, SelectedPartsCount)) + 10), "");
while (ButtonCount <= SelectedPartsCount)
{

if (GUI.Button(new Rect(5, 0 + ((ButtonCount - 1) * 20), 190, 20), AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.partInfo.title,AGXBtnStyle))
if (Mouse.screenPos.y >= SelPartsWin.y + 30 && Mouse.screenPos.y <= SelPartsWin.y + 140 && new Rect(SelPartsWin.x + SelPartsLeft + 25, (SelPartsWin.y + 30 + ((ButtonCount - 1) * 20)) - ScrollPosSelParts.y, 190, 20).Contains(Mouse.screenPos))
{
highlightPartThisFrameSelWin = true;
//print("part found to highlight " + AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.ConstructID);
partToHighlight = AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart;
}


//highlight code here
if (GUI.Button(new Rect(5, 0 + ((ButtonCount - 1) * 20), 190, 20), AGEditorSelectedParts.ElementAt(ButtonCount - 1).AGPart.partInfo.title, AGXBtnStyle))
{

AGEditorSelectedParts.RemoveAt(ButtonCount - 1);
Expand Down Expand Up @@ -2635,15 +2676,15 @@ public void Update()
//loadFinished = false;
if (AGXRoot != null)
{
print("Root part changed, AGX reloadinga");
// print("Root part changed, AGX reloadinga");
ConfigNode oldVsl = new ConfigNode(AGXRoot.vessel.id.ToString());
if(AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString()))
{
print("Root part changed, AGX reloadingb");
//print("Root part changed, AGX reloadingb");
oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString());
AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString());
}
print("Root part changed, AGX reloadingc");
//print("Root part changed, AGX reloadingc");
if(oldVsl.HasValue("name"));
{
oldVsl.RemoveValue("name");
Expand Down Expand Up @@ -2674,18 +2715,18 @@ public void Update()
}
oldVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
AGXFlightNode.AddNode(oldVsl);
print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames"));
//print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames"));
}
print("Root part changed, AGX reloadinge");
//print("Root part changed, AGX reloadinge");
if (flightNodeIsLoaded && AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
{
print("Root part changed, AGX reloadingf");
//print("Root part changed, AGX reloadingf");
ConfigNode currentVessel = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.id.ToString());
CurrentKeySet = Convert.ToInt32(currentVessel.GetValue("currentKeyset"));
LoadGroupNames(currentVessel.GetValue("groupNames"));
LoadGroupVisibility(currentVessel.GetValue("groupVisibility"));
LoadGroupVisibilityNames(currentVessel.GetValue("groupVisibilityNames"));
print("Root part changed, AGX reloadingg");
//print("Root part changed, AGX reloadingg");
}
else
{
Expand Down Expand Up @@ -3357,7 +3398,7 @@ public static string SaveGroupNames(String str)
//}

//print(p.partName + " " + SaveStringNames);
print("Savegroup return " + SaveStringNames);
//print("Savegroup return " + SaveStringNames);
return SaveStringNames;
}
catch (Exception e)
Expand Down

0 comments on commit f77e438

Please sign in to comment.