Vector3 placeParticle(KSProject proj, KSMetric xMetric, KSMetric yMetric) { if (GraphAxis.me.yAxisVisible) { return(new Vector3(metricToValue(proj, xMetric), metricToValue(proj, yMetric))); } else { return(new Vector3(metricToValue(proj, xMetric), 0)); } }
float zValue(KSProject proj, KSMetric zMetric) { return metricToValue(proj, zMetric); }
Vector3 placeParticle(KSProject proj, KSMetric xMetric, KSMetric yMetric) { if(GraphAxis.me.yAxisVisible) return new Vector3(metricToValue(proj, xMetric), metricToValue(proj, yMetric)); else return new Vector3(metricToValue(proj, xMetric), 0); }
float metricToValue(KSProject proj, KSMetric metric, string type) { string label = metric.Name; GeoBounds gb = GeoBounds.List[GA.Geographic]; if(label == "Latitude") return (proj.GetMetric("Lat") - gb.Bottom) * 10 / gb.Scale; if(label == "Longitude") return (proj.GetMetric("Lon") - gb.Left) * 10 / gb.Scale; float zoom = GA.zoom; float s, logValue; if(type == "linear") return proj.GetMetric(label) / metric.Zoom / zoom; else { //s ^ 10 = modifier * zoom * 10 //s ^ x = value s = Mathf.Log(metric.Zoom * zoom, 10); logValue = proj.GetMetric(label) > 0 ? Mathf.Log(proj.GetMetric(label), s) : 0; //Debug.Log(s + " ^ " + logValue + " = " + proj.GetMetric(label)); return logValue; } return 0; /* switch(label.ToLower()) //switch(label) { case "raised": if(type == "linear") return proj.raised / Modifiers["Raised"] / zoom; else { // s ^ 10 = modifier * zoom * 10 // s ^ x = value s = Mathf.Log(Modifiers["Raised"] * zoom, 10); logValue = proj.raised > 0 ? Mathf.Log(proj.raised, s) : 0; //Debug.Log(s + " ^ " + logValue + " = " + proj.raised); return logValue; } break; case "goal": //return proj.goal / Modifiers["Goal"] / zoom; val = proj.goal / Modifiers["Goal"] / zoom; if(type == "linear") return val; else { s = Mathf.Log(Modifiers["Goal"] * zoom, 10); logValue = proj.goal > 0 ? Mathf.Log(proj.goal, s) : 0; //Debug.Log(proj.raised + " ^ " + s + " = " + logValue); return logValue; } break; case "backers": //return proj.backers / Modifiers["Backers"] / zoom; if(type == "linear") return proj.backers / Modifiers["Backers"] / zoom; else { s = Mathf.Log(Modifiers["Backers"] * zoom, 10); logValue = proj.backers > 0 ? Mathf.Log(proj.backers, s) : 0; return logValue; } break; case "comments": //return proj.comments / Modifiers["Comments"] / zoom; if(type == "linear") return proj.comments / Modifiers["Comments"] / zoom; else { s = Mathf.Log(Modifiers["Comments"] * zoom, 10); logValue = proj.comments > 0 ? Mathf.Log(proj.comments, s) : 0; return logValue; } break; case "dpb": //return proj.backers == 0 ? 0 : proj.raised / proj.backers / Modifiers["DpB"] / zoom; if(type == "linear") return Mathf.Min(proj.backers, proj.raised) == 0 ? 0 : proj.raised / proj.backers / Modifiers["DpB"] / zoom; else { s = Mathf.Log(Modifiers["DpB"] * zoom, 10); logValue = proj.backers > 0 ? Mathf.Log(proj.raised / proj.backers, s) : 0; return logValue; } break; case "% raised": //return proj.raised / proj.goal / Modifiers["% Raised"] / zoom; if(type == "linear") return proj.raised / proj.goal / Modifiers["% Raised"] / zoom; else { s = Mathf.Log(Modifiers["DpB"] * zoom, 10); logValue = proj.raised > 0 ? Mathf.Log((proj.raised / proj.goal) + 1, s) : 0; return logValue; } break; case "latitude": return (proj.lat - gb.Bottom) * 10 / gb.Scale; break; case "longitude": return (proj.lon - gb.Left) * 10 / gb.Scale; break; case "zero": default: return 0; break; }*/ }
float metricToValue(KSProject proj, KSMetric metric) { return metricToValue(proj, metric, "linear"); }
void OnGUI() { if (UItype == UIType.IPad || UItype == UIType.Mouse_Key) { bigButton = new GUIStyle(GUI.skin.button); bigButton.font = defaultStyle.font; } else { bigButton = new GUIStyle(defaultStyle); bigButton.alignment = TextAnchor.LowerCenter; } GUIStyle fadedBigButton = new GUIStyle(bigButton); fadedBigButton.normal.textColor = new Color(1, 1, 1, .5f); GUIStyle currentBigButton = new GUIStyle(bigButton); currentBigButton.normal.textColor = new Color(1, 1, 1, .75f); //Get Axis bounds Camera c = Camera.main; Transform t = city.transform; Vector2 origin = c.WorldToScreenPoint(t.position); Vector2 top = c.WorldToScreenPoint(t.position + Vector3.up * t.localScale.y); Vector2 right = c.WorldToScreenPoint(t.position + Vector3.right * t.localScale.x); bool inGraph = (UItype == UIType.IPad || UItype == UIType.Mouse_Key) && new Rect(origin.x, origin.y, Screen.width, top.y).Contains(Input.mousePosition); Vector2 poa = new Vector2(origin.x, Screen.height - Input.mousePosition.y); //Point On Axis int lineheight = 10; //Normalize because its dumb origin.y = Screen.height - origin.y; top.y = Screen.height - top.y; right.y = Screen.height - right.y; float labelHeight = 28f; float labelWidth = 100f; float keysOffset = 27f; float offset; Color faded = new Color(1, 1, 1, 0.5f); GUIStyle yValueStyle = new GUIStyle(defaultStyle); yValueStyle.alignment = TextAnchor.UpperRight; GUIStyle plStyle = new GUIStyle(defaultStyle); plStyle.alignment = TextAnchor.UpperRight; plStyle.normal.textColor = new Color(1, 1, 1, 0.05f); plStyle.fontSize = 300; //Draw Projects Loaded //GUI.Label(new Rect(Screen.width - 250, 0, 250, 150), "Projects Loaded:\n" + ProjectCount, yValueStyle); GUI.Label(new Rect(0, 0, Screen.width, Screen.height), ProjectCount.ToString(), plStyle); GUIHelper.BeginGroup(new Rect(0, 0, Screen.width, Screen.height)); //Draw Axis Numbers if (yAxisVisible) { KSMetric yMetric = KSMetric.List[yLabel]; //New Draw Axis GUIHelper.DrawLine(top, origin, faded); GUIHelper.DrawLine(origin, right, faded); if (inGraph) { GUIHelper.DrawLine( new Vector2(origin.x - lineheight / 2, Screen.height - Input.mousePosition.y), new Vector2(origin.x + lineheight / 2, Screen.height - Input.mousePosition.y), Color.white ); GUIStyle ypValueStyle = new GUIStyle(defaultStyle); ypValueStyle.alignment = TextAnchor.MiddleRight; GUI.Label( new Rect(poa.x - 150, poa.y - 50, 150 - lineheight / 2 - 20, 100), string.Format(yMetric.Format, yMetric.Zoom * zoom * 10 * (poa.y - origin.y) / (top.y - origin.y)), ypValueStyle ); } //Draw tick value GUILayout.BeginArea(new Rect(top.x - labelWidth, top.y, labelWidth, 100)); { GUILayout.BeginVertical(); { GUILayout.Label( string.Format(yMetric.Format, yMetric.Zoom * zoom * 10), yValueStyle, GUILayout.Height(labelHeight) ); if (GUILayout.Button(yMetric.Name.ToUpper(), yValueStyle)) { xAxisClicked = false; zoomClicked = false; yAxisClicked = !yAxisClicked; } if (UItype == UIType.Rockband) { Rect temp = GUILayoutUtility.GetLastRect(); drawKeys(new Vector2(temp.x, temp.y + keysOffset), 0, yAxisClicked); } } GUILayout.EndVertical(); } GUILayout.EndArea(); //actual tick GUIHelper.DrawLine(top - Vector2.right * lineheight, top, faded); if (yAxisClicked) { string[] labels = KSMetric.ListNames; for (int i = 0; i < labels.Length; i++) { if (UItype == UIType.IPad) { offset = labelHeight * (i + 1); } else { offset = labelHeight * (i + 1 - yLabelNew); } if (GUI.Button( new Rect(top.x - labelWidth * 2, top.y + offset, labelWidth, labelHeight), labels[i].ToUpper(), yValueStyle )) { yAxisClicked = false; yLabelNew = i; city.GetComponent <City>().RotateY(); } } } } if (xAxisVisible) { KSMetric xMetric = KSMetric.List[xLabel]; //Metric name and tick value GUILayout.BeginArea(new Rect(right.x - labelWidth, right.y + 10, labelWidth, 100)); { GUILayout.BeginVertical(); { GUILayout.Label( string.Format(xMetric.Format, xMetric.Zoom * zoom * 10), yValueStyle, GUILayout.Height(labelHeight) ); if (GUILayout.Button(xMetric.Name.ToUpper(), yValueStyle)) { yAxisClicked = false; zoomClicked = false; xAxisClicked = !xAxisClicked; } if (UItype == UIType.Rockband) { Rect temp = GUILayoutUtility.GetLastRect(); drawKeys(new Vector2(temp.x, temp.y + keysOffset), 1, xAxisClicked); } } GUILayout.EndVertical(); } GUILayout.EndArea(); //actual tick GUIHelper.DrawLine(right, right + Vector2.up * lineheight, faded); if (!yAxisVisible) { GUI.Label(new Rect(origin.x - 100, origin.y, 100, 100), string.Format(xMetric.Format, "0"), yValueStyle); GUIHelper.DrawLine(origin, origin + Vector2.up * lineheight, faded); } //Draw precise numbers if (inGraph) { GUIStyle xpValueStyle = new GUIStyle(defaultStyle); xpValueStyle.alignment = TextAnchor.UpperCenter; poa = new Vector2(Input.mousePosition.x, origin.y); GUI.Label( new Rect(poa.x - 100, poa.y + lineheight / 2 + 2, 200, 50), string.Format(xMetric.Format, xMetric.Zoom * zoom * 10 * (poa.x - origin.x) / (right.x - origin.x)), xpValueStyle ); GUIHelper.DrawLine( new Vector2(Input.mousePosition.x, origin.y - lineheight / 2), new Vector2(Input.mousePosition.x, origin.y + lineheight / 2), Color.white ); } //draw new metrics list if (xAxisClicked) { string[] labels = KSMetric.ListNames; for (int i = 0; i < labels.Length; i++) { if (UItype == UIType.IPad) { offset = labelHeight * (i + 2 - labels.Length); } else { offset = labelHeight * (i + 1 - xLabelNew); } if (GUI.Button( new Rect(right.x, right.y + 10 + offset, labelWidth, labelHeight), labels[i].ToUpper(), defaultStyle )) { xAxisClicked = false; xLabelNew = i; city.GetComponent <City>().RotateX(); } } } } GUIHelper.EndGroup(); Vector2 zoomOffset, catsOffset; zoomOffset = catsOffset = Vector2.zero; //draw options GUILayout.BeginArea(new Rect(20, 0, Screen.width - 40, Screen.height - 20)); { GUILayout.BeginHorizontal(); { //draw categories if (catsVisible) { GUILayout.BeginVertical(GUILayout.Width(100)); { GUILayout.FlexibleSpace(); if (catsClicked) { for (int i = 0; i < legendTitles.Length; i++) { if (UItype == UIType.Mouse_Key || UItype == UIType.IPad) { if (GUILayout.Button(legendTitles[i], bigButton)) { city.GetComponent <City>().HighlightCategory(legendTitles[i]); selectedLegend = i; } } else { if (i == selectedLegend) { GUILayout.Label(legendTitles[i], bigButton); } else if (i == newLegend) { GUILayout.Label(legendTitles[i], currentBigButton); } else { GUILayout.Label(legendTitles[i], fadedBigButton); } } } } if (GUILayout.Button("CATEGORIES", defaultStyle)) { catsClicked = !catsClicked; } Rect temp = GUILayoutUtility.GetLastRect(); catsOffset = new Vector2(temp.x, temp.y + 25); } GUILayout.EndVertical(); } if (UItype == UIType.Rockband) { GUILayout.FlexibleSpace(); } //draw zoom if (zoomVisible) { GUILayout.BeginVertical(GUILayout.Width(75)); { GUILayout.FlexibleSpace(); if ((UItype == UIType.IPad || UItype == UIType.Mouse_Key) && zoomClicked) { if (GUILayout.RepeatButton("+++", bigButton)) { city.GetComponent <City>().ZoomInstant(1 - Time.deltaTime * 1.5f); } if (GUILayout.RepeatButton("+", bigButton)) { city.GetComponent <City>().ZoomInstant(1 - Time.deltaTime * .3f); } if (GUILayout.RepeatButton("-", bigButton)) { city.GetComponent <City>().ZoomInstant(1 + Time.deltaTime * .3f); } if (GUILayout.RepeatButton("---", bigButton)) { city.GetComponent <City>().ZoomInstant(1 + Time.deltaTime * 1.5f); } } if (GUILayout.Button("ZOOM", defaultStyle)) { zoomClicked = !zoomClicked; } Rect temp = GUILayoutUtility.GetLastRect(); zoomOffset = new Vector2(temp.x, temp.y + 25); } GUILayout.EndVertical(); } if (UItype != UIType.Rockband) { GUILayout.FlexibleSpace(); } } GUILayout.EndHorizontal(); } GUILayout.EndArea(); if (UItype == UIType.Rockband) { if (catsVisible) { drawKeys(catsOffset, 4, catsClicked); } if (zoomVisible) { drawKeys(zoomOffset, 2, zoomClicked); } } // GUI.Label( // new Rect(right.x - 150, right.y + 10, 150, 100), // string.Format(xMetric.Format, xMetric.Zoom * zoom * 10) + "\n" + xMetric.Name.ToUpper(), // yValueStyle // ); //Draw Precise numbers /* * //Draw Scrubbers * float xRot = GUI.VerticalSlider( * new Rect(top.x - 20, top.y, 20, origin.y - top.y), * city.transform.localEulerAngles.x - 360, * 0f,-90f * ); * * float yRot = GUI.HorizontalSlider( * new Rect(origin.x + 10, origin.y, right.x - origin.x, 20), * city.transform.localEulerAngles.y, * 0f,90f * ); * * * city.transform.eulerAngles = new Vector3(xRot, yRot, 0); */ //string label = "X: " + axisNames[xLabel] + "\nY: " + axisNames[yLabel]; /* * GUILayout.BeginArea(new Rect(0,0,Screen.width, Screen.height)); * { * GUILayout.BeginVertical(); * { * //GUILayout.Label(label); * * GUILayout.FlexibleSpace(); * GUILayout.BeginHorizontal(); * { * GUILayout.BeginVertical(); * { * GUILayout.Label("Zoom"); * GUILayout.BeginHorizontal(); * { * if(GUILayout.Button("+")) * city.GetComponent<City>().ZoomIn(); * * if(GUILayout.Button("-")) * city.GetComponent<City>().ZoomOut(); * } * GUILayout.EndHorizontal(); * GUILayout.BeginHorizontal(); * { * if(GUILayout.Button("++")) * city.GetComponent<City>().ZoomInIn(); * * if(GUILayout.Button("--")) * city.GetComponent<City>().ZoomOutOut(); * } * GUILayout.EndHorizontal(); * * GUILayout.Label("\n\nHorizontal Axis"); * int newValue = GUILayout.SelectionGrid(xLabel, KSMetric.ListNames, 2); * if(newValue != xLabel) * { * xLabelNew = newValue; * city.GetComponent<City>().RotateX(); * } * GUILayout.Label("\nVertical Axis"); * newValue = GUILayout.SelectionGrid(yLabel, KSMetric.ListNames, 2); * if(newValue != yLabel) * { * yLabelNew = newValue; * city.GetComponent<City>().RotateY(); * } * * GUILayout.Label("\n\nGeo Bounds"); * newValue = GUILayout.SelectionGrid(Geographic, GeoBounds.ListNames, 2); * if(newValue != Geographic) * { * Geographic = newValue; * city.GetComponent<City>().ZoomNone(); * * } * * GUILayout.Label("\n\nHighlight Category"); * newValue = GUILayout.SelectionGrid(selectedLegend, legendTitles, 2); * if(newValue != selectedLegend) * { * city.GetComponent<City>().HighlightCategory(legendTitles[newValue]); * selectedLegend = newValue; * } * } * GUILayout.EndVertical(); * GUILayout.FlexibleSpace(); * * } * GUILayout.EndHorizontal(); * GUILayout.FlexibleSpace(); * } * GUILayout.EndVertical(); * } * GUILayout.EndArea();*/ }
float metricToValue(KSProject proj, KSMetric metric, string type) { string label = metric.Name; GeoBounds gb = GeoBounds.List[GA.Geographic]; if (label == "Latitude") { return((proj.GetMetric("Lat") - gb.Bottom) * 10 / gb.Scale); } if (label == "Longitude") { return((proj.GetMetric("Lon") - gb.Left) * 10 / gb.Scale); } float zoom = GA.zoom; float s, logValue; if (type == "linear") { return(proj.GetMetric(label) / metric.Zoom / zoom); } else { //s ^ 10 = modifier * zoom * 10 //s ^ x = value s = Mathf.Log(metric.Zoom * zoom, 10); logValue = proj.GetMetric(label) > 0 ? Mathf.Log(proj.GetMetric(label), s) : 0; //Debug.Log(s + " ^ " + logValue + " = " + proj.GetMetric(label)); return(logValue); } return(0); /* * switch(label.ToLower()) * //switch(label) * { * case "raised": * if(type == "linear") * return proj.raised / Modifiers["Raised"] / zoom; * else * { * // s ^ 10 = modifier * zoom * 10 * // s ^ x = value * s = Mathf.Log(Modifiers["Raised"] * zoom, 10); * logValue = proj.raised > 0 ? Mathf.Log(proj.raised, s) : 0; * * //Debug.Log(s + " ^ " + logValue + " = " + proj.raised); * return logValue; * } * break; * * case "goal": * //return proj.goal / Modifiers["Goal"] / zoom; * val = proj.goal / Modifiers["Goal"] / zoom; * if(type == "linear") * return val; * else * { * s = Mathf.Log(Modifiers["Goal"] * zoom, 10); * logValue = proj.goal > 0 ? Mathf.Log(proj.goal, s) : 0; * * //Debug.Log(proj.raised + " ^ " + s + " = " + logValue); * return logValue; * } * break; * * case "backers": * //return proj.backers / Modifiers["Backers"] / zoom; * if(type == "linear") * return proj.backers / Modifiers["Backers"] / zoom; * else * { * s = Mathf.Log(Modifiers["Backers"] * zoom, 10); * logValue = proj.backers > 0 ? Mathf.Log(proj.backers, s) : 0; * return logValue; * } * break; * case "comments": * //return proj.comments / Modifiers["Comments"] / zoom; * if(type == "linear") * return proj.comments / Modifiers["Comments"] / zoom; * else * { * s = Mathf.Log(Modifiers["Comments"] * zoom, 10); * logValue = proj.comments > 0 ? Mathf.Log(proj.comments, s) : 0; * return logValue; * } * break; * case "dpb": * //return proj.backers == 0 ? 0 : proj.raised / proj.backers / Modifiers["DpB"] / zoom; * if(type == "linear") * return Mathf.Min(proj.backers, proj.raised) == 0 ? 0 : proj.raised / proj.backers / Modifiers["DpB"] / zoom; * else * { * s = Mathf.Log(Modifiers["DpB"] * zoom, 10); * logValue = proj.backers > 0 ? Mathf.Log(proj.raised / proj.backers, s) : 0; * return logValue; * } * break; * case "% raised": * //return proj.raised / proj.goal / Modifiers["% Raised"] / zoom; * if(type == "linear") * return proj.raised / proj.goal / Modifiers["% Raised"] / zoom; * else * { * s = Mathf.Log(Modifiers["DpB"] * zoom, 10); * logValue = proj.raised > 0 ? Mathf.Log((proj.raised / proj.goal) + 1, s) : 0; * return logValue; * } * break; * case "latitude": * return (proj.lat - gb.Bottom) * 10 / gb.Scale; * break; * case "longitude": * return (proj.lon - gb.Left) * 10 / gb.Scale; * break; * case "zero": * default: * return 0; * break; * * }*/ }
float metricToValue(KSProject proj, KSMetric metric) { return(metricToValue(proj, metric, "linear")); }
float zValue(KSProject proj, KSMetric zMetric) { return(metricToValue(proj, zMetric)); }