static int QPYX_GetHashCode_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 1); UnityEngine.Rect QPYX_obj_YXQP = (UnityEngine.Rect)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Rect)); int QPYX_o_YXQP = QPYX_obj_YXQP.GetHashCode(); LuaDLL.lua_pushinteger(L_YXQP, QPYX_o_YXQP); ToLua.SetBack(L_YXQP, 1, QPYX_obj_YXQP); return(1); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int GetHashCode(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.Rect obj = (UnityEngine.Rect)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rect)); int o = obj.GetHashCode(); LuaDLL.lua_pushinteger(L, o); ToLua.SetBack(L, 1, obj); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
// GUI system workaround about a GUI control layered on top of a button // see e.g. http://forum.unity3d.com/threads/96563-corrected-GUI.Button-code-%28works-properly-with-layered-controls%29 public static bool goodButton (Rect bounds, string caption) { GUIStyle btnStyle = GUI.skin.FindStyle ("button"); int controlID = GUIUtility.GetControlID (bounds.GetHashCode (), FocusType.Passive); bool isMouseOver = bounds.Contains (UnityEngine.Event.current.mousePosition); bool isDown = GUIUtility.hotControl == controlID; if (GUIUtility.hotControl != 0 && !isDown) { // ignore mouse while some other control has it // (this is the key bit that GUI.Button appears to be missing) isMouseOver = false; } if (UnityEngine.Event.current.type == EventType.Repaint) { btnStyle.Draw (bounds, new GUIContent (caption), isMouseOver, isDown, false, false); } switch (UnityEngine.Event.current.GetTypeForControl (controlID)) { case EventType.mouseDown: if (isMouseOver) { // (note: isMouseOver will be false when another control is hot) GUIUtility.hotControl = controlID; } // GUIUtility.hotControl = controlID; // button is broken: we get slider AND button ( which is what we want ) break; case EventType.mouseUp: if (GUIUtility.hotControl == controlID) GUIUtility.hotControl = 0; if (bounds.Contains (UnityEngine.Event.current.mousePosition)) return true; break; } return false; }
public void Draw(Rect rect, ThingWithComps ownerPawn) { Text.Font = GameFont.Small; string value = "-"; switch (oType) { case objectType.Stat: Text.Anchor = TextAnchor.MiddleCenter; StatDef stat = (StatDef)displayObject; string statValue = (stat.ValueToString(ownerPawn.GetStatValue((StatDef)displayObject, true))); Widgets.Label(rect, statValue); if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(stat.LabelCap); stringBuilder.AppendLine(); stringBuilder.AppendLine(stat.description); TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder.ToString(), rect.GetHashCode())); break; case objectType.Skill: if ((ownerPawn is Pawn) && (ownerPawn as Pawn).RaceProps.Humanlike) DrawSkill(rect, ownerPawn as Pawn); break; case objectType.Need: if (ownerPawn is Pawn) DrawNeed(rect, ownerPawn as Pawn); break; case objectType.Age: Text.Anchor = TextAnchor.MiddleCenter; string ageValue = ((ownerPawn as Pawn).ageTracker.AgeBiologicalYears.ToString()); Widgets.Label(rect, ageValue); if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } break; case objectType.Gear: DrawGear(rect, ownerPawn); break; case objectType.ControlPrisonerGetsFood: if (ownerPawn is Pawn) { if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } bool getsFood = (ownerPawn as Pawn).guest.GetsFood; Widgets.CheckboxLabeled(new Rect(rect.x + 8f, rect.y + 3f, 27f, 27f), "", ref getsFood, false); (ownerPawn as Pawn).guest.GetsFood = getsFood; } break; case objectType.ControlPrisonerInteraction: if (ownerPawn is Pawn) { if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } float x = 8f; GUI.BeginGroup(rect); IEnumerator enumerator = Enum.GetValues(typeof(PrisonerInteractionMode)).GetEnumerator(); try { while (enumerator.MoveNext()) { PrisonerInteractionMode prisonerInteractionMode = (PrisonerInteractionMode)((byte)enumerator.Current); if (Widgets.RadioButton(new Vector2(x, 3f), (ownerPawn as Pawn).guest.interactionMode == prisonerInteractionMode)) { (ownerPawn as Pawn).guest.interactionMode = prisonerInteractionMode; } TooltipHandler.TipRegion(new Rect(x, 0f, 30f, 30f), new TipSignal(prisonerInteractionMode.GetLabel())); x += 30f; } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } GUI.EndGroup(); } break; case objectType.ControlMedicalCare: if (ownerPawn is Pawn) MedicalCareSetter(rect, ref (ownerPawn as Pawn).playerSettings.medCare); break; case objectType.AnimalMilkFullness: Text.Anchor = TextAnchor.MiddleCenter; if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.milkable) { var comp = ((Pawn)ownerPawn).AllComps.Where<ThingComp>(x => x is CompMilkable).FirstOrDefault(); if(comp != null) value = ((CompMilkable)comp).Fullness.ToStringPercent(); } Widgets.Label(rect, value); break; case objectType.AnimalWoolGrowth: Text.Anchor = TextAnchor.MiddleCenter; if (ownerPawn is Pawn && ((Pawn)ownerPawn).ageTracker.CurLifeStage.shearable) { var comp = ((Pawn)ownerPawn).AllComps.Where<ThingComp>(x => x is CompShearable).FirstOrDefault(); if (comp != null) value = ((CompShearable)comp).Fullness.ToStringPercent(); } Widgets.Label(rect, value); break; case objectType.CurrentJob: if(ownerPawn is Pawn) { string text = ((Pawn)ownerPawn).jobs.curDriver.GetReport(); Text.Anchor = TextAnchor.MiddleLeft; Rect tRect = new Rect(rect.xMin + 2, rect.yMin + 3, rect.width - 2, rect.height); GenText.SetTextSizeToFit(text, tRect); if (Text.Font == GameFont.Tiny) Widgets.Label(tRect, text); else { Rect sRect = new Rect(rect.xMin + 2, rect.yMin, rect.width - 2, rect.height); Widgets.Label(sRect, text); } if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } } break; } }
private void DrawNeed(Rect rect, Pawn ownerPawn) { if (ownerPawn.RaceProps.IsMechanoid) return; if (ownerPawn.needs == null) return; //TODO: rebuild using code in DrawOnGUI Need need = ownerPawn.needs.TryGetNeed((NeedDef)displayObject); if (need == null) return; if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } TooltipHandler.TipRegion(rect, new TipSignal(() => need.GetTipString(), rect.GetHashCode())); float num2 = 14f; float num3 = num2 + 15f; if (rect.height < 50f) { num2 *= Mathf.InverseLerp(0f, 50f, rect.height); } Text.Font = ((rect.height <= 55f) ? GameFont.Tiny : GameFont.Small); Text.Anchor = TextAnchor.UpperLeft; Rect rect3 = new Rect(rect.x, rect.y + rect.height / 2f, rect.width, rect.height / 2f); rect3 = new Rect(rect3.x + num3, rect3.y, rect3.width - num3 * 2f, rect3.height - num2); Widgets.FillableBar(rect3, need.CurLevelPercentage); Widgets.FillableBarChangeArrows(rect3, need.GUIChangeArrow); List<float> threshPercents = (List<float>)needThreshPercent.GetValue(need); if (threshPercents != null) { for (int i = 0; i < threshPercents.Count; i++) { needDrawBarThreshold(rect3, threshPercents[i], need.CurLevelPercentage); } } float curInstantLevel = need.CurInstantLevelPercentage; if (curInstantLevel >= 0f) { needDrawBarInstantMarkerAt(rect3, curInstantLevel); } Text.Font = GameFont.Small; }
public static bool Button(Rect bounds, string caption, GUIStyle btnStyle = null ) { int controlID = GUIUtility.GetControlID(bounds.GetHashCode(), FocusType.Passive); bool isMouseOver = bounds.Contains(Event.current.mousePosition); int depth = (1000 - GUI.depth) * 1000 + controlID; if ( isMouseOver && depth > highestDepthID ) highestDepthID = depth; bool isTopmostMouseOver = (highestDepthID == depth); bool paintMouseOver = isTopmostMouseOver; if ( btnStyle == null ) { btnStyle = new GUIStyle(HighLogic.Skin.button); } if ( Event.current.type == EventType.Layout && lastEventType != EventType.Layout ) { highestDepthID = 0; } lastEventType = Event.current.type; if ( Event.current.type == EventType.Repaint ) { bool isDown = (GUIUtility.hotControl == controlID); btnStyle.Draw(bounds, new GUIContent(caption), paintMouseOver, isDown, false, false); } switch ( Event.current.GetTypeForControl(controlID) ) { case EventType.mouseDown: { if ( isTopmostMouseOver) { GUIUtility.hotControl = controlID; } break; } case EventType.mouseUp: { if ( isTopmostMouseOver) { GUIUtility.hotControl = 0; return true; } break; } } return false; }
static bool Rect_GetHashCode(JSVCall vc, int argc) { int len = argc; if (len == 0) { UnityEngine.Rect argThis = (UnityEngine.Rect)vc.csObj; JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(argThis.GetHashCode())); JSMgr.changeJSObj(vc.jsObjID, argThis); } return(true); }
public void Draw(Rect rect, Pawn ownerPawn) { switch (oType) { case objectType.Stat: Text.Anchor = TextAnchor.MiddleCenter; StatDef stat = (StatDef)displayObject; string statValue = (stat.ValueToString(ownerPawn.GetStatValue((StatDef)displayObject, true))); Widgets.Label(rect, statValue); if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(stat.LabelCap); stringBuilder.AppendLine(); stringBuilder.AppendLine(stat.description); TooltipHandler.TipRegion(rect, new TipSignal(stringBuilder.ToString(), rect.GetHashCode())); break; case objectType.Skill: DrawSkill(rect, ownerPawn); break; case objectType.Need: DrawNeed(rect, ownerPawn); break; case objectType.Gear: DrawGear(rect, ownerPawn); break; case objectType.ControlPrisonerGetsFood: if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } bool getsFood = ownerPawn.guest.GetsFood; Widgets.LabelCheckbox(new Rect(rect.x + 8f, rect.y + 3f, 27f, 27f), "", ref getsFood, false); ownerPawn.guest.GetsFood = getsFood; break; case objectType.ControlPrisonerInteraction: if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, TexUI.HighlightTex); } float x = 8f; GUI.BeginGroup(rect); IEnumerator enumerator = Enum.GetValues(typeof(PrisonerInteractionMode)).GetEnumerator(); try { while (enumerator.MoveNext()) { PrisonerInteractionMode prisonerInteractionMode = (PrisonerInteractionMode)((byte)enumerator.Current); if (Widgets.RadioButton(new Vector2(x, 3f), ownerPawn.guest.interactionMode == prisonerInteractionMode)) { ownerPawn.guest.interactionMode = prisonerInteractionMode; } TooltipHandler.TipRegion(new Rect(x,0f,30f,30f), new TipSignal(prisonerInteractionMode.GetLabel())); x += 30f; } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } GUI.EndGroup(); break; case objectType.ControlMedicalCare: MedicalCareSetter(rect, ref ownerPawn.playerSettings.medCare); break; } }
public override void DoWindowContents(Rect r) { maxWindowWidth = Screen.width; base.DoWindowContents(r); if (pawnListUpdateNext < Find.TickManager.TicksGame) isDirty = true; if (isDirty) { UpdatePawnList(); } Rect position = new Rect(0f, 0f, r.width, 115f); GUI.BeginGroup(position); float x = 0f; Text.Font = GameFont.Small; //pawn/prisoner list switch Rect sourceButton = new Rect(x, 0f, buttonWidth, PawnRowHeight); if (Widgets.ButtonText(sourceButton, ("koisama.pawntype." + chosenPawnType.ToString()).Translate())) { PawnSelectOptionsMaker(); } x += buttonWidth + 10; TooltipHandler.TipRegion(sourceButton, new TipSignal("koisama.Numbers.ClickToToggle".Translate(), sourceButton.GetHashCode())); //stats btn Rect addColumnButton = new Rect(x, 0f, buttonWidth, PawnRowHeight); if (Widgets.ButtonText(addColumnButton, "koisama.Numbers.AddColumnLabel".Translate())) { StatsOptionsMaker(); } x += buttonWidth + 10; //skills btn if (new[] { pawnType.Colonists, pawnType.Prisoners, pawnType.Enemies }.Contains(chosenPawnType)) { Rect skillColumnButton = new Rect(x, 0f, buttonWidth, PawnRowHeight); if (Widgets.ButtonText(skillColumnButton, "koisama.Numbers.AddSkillColumnLabel".Translate())) { SkillsOptionsMaker(); } x += buttonWidth + 10; } //needs btn Rect needsColumnButton = new Rect(x, 0f, buttonWidth, PawnRowHeight); if (Widgets.ButtonText(needsColumnButton, "koisama.Numbers.AddNeedsColumnLabel".Translate())) { NeedsOptionsMaker(); } x += buttonWidth + 10; Rect otherColumnBtn = new Rect(x, 0f, buttonWidth, PawnRowHeight); if (Widgets.ButtonText(otherColumnBtn, "koisama.Numbers.AddOtherColumnLabel".Translate())) { OtherOptionsMaker(); } x += buttonWidth + 10; //TODO: implement /* Rect addPresetBtn = new Rect(x, 0f, buttonWidth, PawnRowHeight); if (Widgets.ButtonText(addPresetBtn, "koisama.Numbers.SetPresetLabel".Translate())) { PresetOptionsMaker(); } x += buttonWidth + 10; */ Rect thingCount = new Rect(10f, 45f, 200f, 30f); Widgets.Label(thingCount, "koisama.Numbers.Count".Translate() + ": " + this.things.Count().ToString()); x = 0; //names Rect nameLabel = new Rect(x, 75f, NameColumnWidth, PawnRowHeight); Text.Anchor = TextAnchor.LowerCenter; Widgets.Label(nameLabel, "koisama.Numbers.Name".Translate()); if (Widgets.ButtonInvisible(nameLabel)) { if (chosenOrderBy == orderBy.Name) { pawnListDescending = !pawnListDescending; } else { chosenOrderBy = orderBy.Name; pawnListDescending = false; } isDirty = true; } TooltipHandler.TipRegion(nameLabel, "koisama.Numbers.SortByTooltip".Translate("koisama.Numbers.Name".Translate())); Widgets.DrawHighlightIfMouseover(nameLabel); x += NameColumnWidth; //header //TODO: better interface - auto width calculation bool offset = true; kListDesiredWidth = 175f; Text.Anchor = TextAnchor.MiddleCenter; for (int i=0;i<kList.Count; i++) { float colWidth = kList[i].minWidthDesired; if(colWidth + kListDesiredWidth + cFreeSpaceAtTheEnd > maxWindowWidth) { break; } kListDesiredWidth += colWidth; Rect defLabel = new Rect(x-35, 25f + (offset ? 10f : 50f), colWidth+70 , 40f); Widgets.DrawLine(new Vector2(x + colWidth/2 , 55f + (offset ? 15f : 55f)), new Vector2(x + colWidth/2 , 113f), Color.gray, 1); Widgets.Label(defLabel, kList[i].label); StringBuilder labelSB = new StringBuilder(); labelSB.AppendLine("koisama.Numbers.SortByTooltip".Translate(kList[i].label)); labelSB.AppendLine("koisama.Numbers.RemoveTooltip".Translate()); TooltipHandler.TipRegion(defLabel, labelSB.ToString()); Widgets.DrawHighlightIfMouseover(defLabel); if (Widgets.ButtonInvisible(defLabel)) { if (Event.current.button == 1) { kList.RemoveAt(i); } else { if (chosenOrderBy == orderBy.Column && kList[i].Equals(sortObject)) { pawnListDescending = !pawnListDescending; } else { sortObject = kList[i]; chosenOrderBy = orderBy.Column; pawnListDescending = false; } } isDirty = true; } offset = !offset; x += colWidth; } GUI.EndGroup(); //content Rect content = new Rect(0f, position.yMax, r.width, r.height - position.yMax); GUI.BeginGroup(content); base.DrawRows(new Rect(0f, 0f, content.width, content.height)); GUI.EndGroup(); }