public static MenuItem.ItemAction Handler(AttachmentPointId point, string thingName, bool isDelete) { var mih = new MenuItemHandler(); mih.apid = point; mih.isDelete = isDelete; mih.name = thingName; return(mih.Handle); }
public void Begin(AttachmentPointId point, string thingName, float delay, Vector3?newPos = null) { DebugLog.LogTemp("apid={0}, tn={1}, d={2}, np={3}", point, thingName, delay, newPos); apid = point; this.thingName = thingName; this.delay = timeLeft = delay; shouldMove = (newPos.HasValue && point == AttachmentPointId.LegLeft || point == AttachmentPointId.LegRight); if (shouldMove) { start = transform.localPosition; end = newPos.Value; } enabled = true; }
public SavedAttachmentList(AttachmentPointId point, string json = "{}") { AttachmentPoint = point; entries = new Dictionary <string, AttachmentData>(); var jsondict = JsonConvert.DeserializeObject <Dictionary <string, string> >(json); foreach (string k in jsondict.Keys) { entries[k] = JsonUtility.FromJson <AttachmentData>(jsondict[k]); } namesById = new Dictionary <string, string>(); foreach (string name in entries.Keys) { namesById[this[name].thingId] = name; } }
internal static void SetAttachment(AttachmentPointId point, string thingName, bool moveLeg = true) { Person ourPerson = Managers.personManager.ourPerson; GameObject attpoint = ourPerson.GetAttachmentPointById(point); SavedAttachmentList list = config.GetListForAttachmentPoint(point); if (thingName.Length == 0 || thingName.Equals("-")) { Managers.personManager.DoRemoveAttachedThing(attpoint); } else if (list.ContainsName(thingName)) { var comp = attpoint.GetComponent <StartCoroutineAttach>(); if (comp == null) { comp = attpoint.AddComponent <StartCoroutineAttach>(); } comp.Attach(attpoint.GetComponent <AttachmentPoint>(), list[thingName]); if (moveLeg) { try { if (point == AttachmentPointId.LegLeft) { ourPerson.AttachmentPointLegLeft.transform.localPosition = config.LegPosLeft[thingName]; ourPerson.AttachmentPointLegLeft.transform.localEulerAngles = config.LegRotLeft[thingName]; Managers.personManager.SaveOurLegAttachmentPointPositions(); } else if (point == AttachmentPointId.LegRight) { ourPerson.AttachmentPointLegRight.transform.localPosition = config.LegPosRight[thingName]; ourPerson.AttachmentPointLegRight.transform.localEulerAngles = config.LegRotRight[thingName]; Managers.personManager.SaveOurLegAttachmentPointPositions(); } } catch (KeyNotFoundException) { } } } else { DebugLog.Log("\"{0}\" is not a known attachment for {1}.", thingName, point); } }
private static void BodyTellManager_ToldByBody(string data, BodyTellManager.TellEventInfo info) { // TODO: Add a toggle to disable IsTrusted check if (!config.EnableTellControl || !info.IsTrusted) { return; } Match match = regex.Match(data); if (match.Success) { var points = new AttachmentPointId[] { AttachmentPointId.HeadTop, AttachmentPointId.Head, AttachmentPointId.ArmLeft, AttachmentPointId.TorsoUpper, AttachmentPointId.ArmRight, AttachmentPointId.TorsoLower, AttachmentPointId.LegLeft, AttachmentPointId.LegRight, AttachmentPointId.LegLeft, AttachmentPointId.LegRight }; int pointNum = Int32.Parse(match.Groups[1].Value); AttachmentPointId point = points[pointNum]; string thingName = match.Groups[2].Value; float delay = 0.0f; Match matchForIn = regexForIn.Match(thingName); if (matchForIn.Success) { thingName = thingName.Substring(0, matchForIn.Index); float.TryParse(matchForIn.Groups[1].Value, out delay); } bool shouldMove = (pointNum == 6 || pointNum == 7); GameObject ap = Managers.personManager.ourPerson.GetAttachmentPointById(point); if (shouldMove && thingName.Equals("lock")) { FixedWorldPosRot.LockPosRot(ap); } else if (shouldMove && thingName.Equals("unlock")) { FixedWorldPosRot.UnlockPosRot(ap); } else if (delay > 0.0f) { var ds = ap.GetComponent <DelayedSwitch>(); if (ds == null) { ds = ap.AddComponent <DelayedSwitch>(); } var legPosDict = (pointNum == 6) ? config.LegPosLeft : config.LegPosRight; Vector3?targetPos = null; if (shouldMove && legPosDict.TryGetValue(thingName, out Vector3 tpos)) { targetPos = tpos; } ds.Begin(point, thingName, delay, targetPos); } else { SetAttachment(point, thingName, shouldMove); } } }
protected override void InitCustomDialog(object arg = null) { var arg_ = (Argument)arg; apid = arg_.point; isDelete = arg_.isDelete; string title = ""; switch (apid) { case AttachmentPointId.HeadTop: title = "Hat"; break; case AttachmentPointId.Head: title = "Head"; break; case AttachmentPointId.ArmLeft: title = "Left Arm"; break; case AttachmentPointId.ArmRight: title = "Right Arm"; break; case AttachmentPointId.TorsoUpper: title = "Upper Torso"; break; case AttachmentPointId.TorsoLower: title = "Lower Torso"; break; case AttachmentPointId.LegLeft: title = "Left Leg"; break; case AttachmentPointId.LegRight: title = "Right Leg"; break; } var menu = new Menu(title); menu.SetBackButton(Main.pointMenu); menu.TwoColumns = true; menu.DialogClose += Menu_DialogClose; if (isDelete) { var btnConfirmDelete = new MenuButton("confirmDelete", "Confirm"); btnConfirmDelete.Action += BtnConfirmDelete_Action; menu.Add(btnConfirmDelete); var btnCancelDelete = new MenuButton("cancelDelete", "Undo Deletion"); btnCancelDelete.TextColor = TextColor.Gold; btnCancelDelete.Action += BtnCancelDelete_Action; menu.Add(btnCancelDelete); } else { var btnSave = new MenuButton("save", "+ Save"); btnSave.TextColor = TextColor.Green; btnSave.Action += BtnSave_Action; menu.Add(btnSave); var btnDelete = new MenuButton("delete", "- Delete"); btnDelete.TextColor = TextColor.Red; btnDelete.Action += BtnDelete_Action; menu.Add(btnDelete); } var btnDetach = new MenuButton("detach", "(None)"); btnDetach.TextColor = TextColor.Blue; btnDetach.Action += BtnDetach_Action; menu.Add(btnDetach); foreach (string k in Main.config.GetListForAttachmentPoint(apid).ThingNames) { var btn = new MenuButton("attach_" + k, k); if (isDelete) { btn.TextColor = TextColor.Red; btn.Text = "- " + btn.Text; } btn.Action += MenuItemHandler.Handler(apid, k, isDelete); menu.Add(btn); } base.InitCustomDialog(menu); }
public Argument(AttachmentPointId point, bool isDelete = false) { this.point = point; this.isDelete = isDelete; }