/// <summary> /// Updates the label on the button /// </summary> /// <param name="name">UI Button name</param> /// <param name="label">New text label</param> public static void UpdateButtonLabel(string name, string label) { try { string key = name + "_label"; //ModLogging.LogError(getPrefix(), "UpdateButtonLabel: key : [" + key + "]"); GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(GenericMachinePanelScript.instance) as GenericMachineManager; int cnt = manager.mWindowContents.Count; //ModLogging.LogError(getPrefix(), "UpdateButtonLabel: manager : [" + manager.mWindowContents.Count + ":" + label + ":" + cnt + "]"); if (cnt > 0) { foreach (GameObject current in manager.mWindowContents) { if (current.name == key) { //ModLogging.LogError(getPrefix(), "UpdateButtonLabel: inside[" + current.name + ":" + key + ":" + cnt + "]"); current.GetComponent <UILabel>().text = label; break; } } } } catch (Exception ex) { Debug.LogError("UpdateButtonLabel: failed : " + ex.Message + " : " + ex.StackTrace); } }
/// <summary> /// Closes out and removes references to .Mod UI entiries /// </summary> /// <param name="name"></param> /// <param name="resetWindow"></param> public static void CleanupUI(string name, bool resetWindow) { try { GenericMachinePanelScript panel = GenericMachinePanelScript.instance; UIManager.RemoveUIRules("Machine"); if (panel == null) { Debug.LogError("CleanupUI: panel=null"); return; } else { UIUtil.TargetMachine = null; if (resetWindow) { UIUtil.TargetWindow = null; } panel.gameObject.SetActive(false); panel.Background_Panel.SetActive(false); panel.currentWindow = null; panel.targetEntity = null; DragAndDropManager.instance.CancelDrag(); DragAndDropManager.instance.DisableDragBackground(); UIUtil.UILock = false; GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(panel) as GenericMachineManager; manager.windows.Remove(eSegmentEntity.Mod); if (manager.windows.ContainsKey(eSegmentEntity.Mod)) { Debug.LogWarning(name + ": was not able to remove the window entry!"); return; } } } catch (Exception ex) { Debug.LogError("CleanupUI: " + ex.Message + " : " + ex.StackTrace); } }
public static bool SetButtonLabelKey(string name) { bool flag = false; string key = name + "_label"; try { GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(GenericMachinePanelScript.instance) as GenericMachineManager; int cnt = manager.mWindowContents.Count; int find = -1; int offset = 1; GameObject gObj = new GameObject(); //ModLogging.LogError(getPrefix(), "SetButtonLabelKey: cnt : [" + cnt + "]"); if (cnt > 0) { for (int idx = 0; idx < cnt; idx++) { gObj = manager.mWindowContents[idx]; //ModLogging.LogError(getPrefix(), "SetButtonLabelKey: cnt : [" + cnt + ":" + idx + ":" + gObj.name + "]"); if (gObj.name == name) { //ModLogging.LogError(getPrefix(), "SetButtonLabelKey: found: " + idx); find = idx; //break; } } //ModLogging.LogError(getPrefix(), "SetButtonLabelKey: test " + find + ":" + offset + ":" + cnt + ":" + key); if (find != -1) { if (find + offset < cnt) { gObj.name = key; flag = true; } } } } catch (Exception ex) { Debug.LogError("SetButtonLabelKey: failed : [" + key + "]" + ex.Message + " : " + ex.StackTrace); } return(flag); }
///// <summary> ///// Call this in GetPopupText to handle your UI Window ///// </summary> ///// <param name="theMachine">Pass the current machine</param> ///// <param name="theWindow">The mod window inherited from BaseMachineWindow</param> ///// <returns></returns> //public static bool HandleThisMachineWindow(SegmentEntity theMachine, BaseMachineWindow theWindow) //{ // try // { // //GenericMachineManager manager = GenericMachinePanelScript.instance.manager; // not yet // GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | // BindingFlags.Instance).GetValue(GenericMachinePanelScript.instance) as GenericMachineManager; // // this will replace with the current machine's window, which is OK as long as each Mod uses this technique // manager.windows[eSegmentEntity.Mod] = theWindow; // UIUtil.TargetMachine = theMachine; // theWindow.manager = manager; // UIUtil.UIdelay = 0; // UIUtil.UILock = true; // } // catch (Exception ex) // { // //this.error = "Window Registration failed : " + ex.Message; // UnityEngine.Debug.LogError("Window Registration failed : " + ex.Message + " : " + ex.StackTrace); // } // GenericMachinePanelScript panel = GenericMachinePanelScript.instance; // try // { // // player looking at this machine // if (WorldScript.instance.localPlayerInstance.mPlayerBlockPicker.selectedEntity == theMachine) // { // if (panel.Background_Panel.activeSelf == true) // window is open // { // panel.gameObject.SetActive(true); // undoes the default handler hiding the window // } // // player interacts with machine // if (Input.GetButtonDown("Interact")) // "E" by default // { // // UIManager.UpdateGenericMachineWindow() -> GenericMachinePanelScript.TryShow() // // default handler will try and fail as intended because our window is not in its dictionary, this is fine // // similarly, the Hide() should not occur because the selectedEntity is this machine (panel.targetEntity) // //Debug.Log("Interacted"); // if (panel.Background_Panel.activeSelf == true) // window is not already opened // { // // Do nothing // } // else // window IS already opened, we pressed to interact again (meaning to close it) // { // Hide(panel); // hide window, since we are not focused on this machine anymore // DragAndDropManager.instance.CancelDrag(); // DragAndDropManager.instance.DisableDragBackground(); // } // } // else if (Input.GetKeyDown(KeyCode.Escape)) // escape should close window also // { // if (panel.isActiveAndEnabled) // UIManager.instance.UnpauseGame(); // Hide(panel); // hide window // DragAndDropManager.instance.CancelDrag(); // DragAndDropManager.instance.DisableDragBackground(); // } // } // else // we are not the selected machine, or no machine is selected; but not due to user input (probably) // { // if (panel.targetEntity == theMachine) // this machine WAS focused with window open a moment ago, so it should handle closing its own window // { // Hide(panel); // hide window, since we are not focused on this machine anymore // DragAndDropManager.instance.CancelDrag(); // DragAndDropManager.instance.DisableDragBackground(); // } // } // } // catch (Exception ex) // { // return false; // } // return (panel.targetEntity == theMachine); // true if machine window is currently open, false otherwise (such as if Hide() called) //} ///// <summary> ///// Internal sub function for hiding the panel ///// </summary> ///// <param name="panel">The working panel</param> //public static void Hide(GenericMachinePanelScript panel) //{ // UIManager.RemoveUIRules("Machine"); // panel.currentWindow.OnClose(panel.targetEntity); // panel.Scroll_Bar.GetComponent<UIScrollBar>().scrollValue = 0f; // panel.targetEntity = null; // panel.currentWindow = null; // GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(panel) as GenericMachineManager; // manager.ClearWindow(); // panel.gameObject.SetActive(false); // panel.Background_Panel.SetActive(false); //} /// <summary> /// Internal sub function for hiding the panel /// </summary> /// <param name="panel">The working panel</param> public static void Hide(GenericMachinePanelScript panel) { try { UIManager.RemoveUIRules("Machine"); if (panel == null) { //Debug.LogError("Hide: panel=null"); return; } else { if (panel.targetEntity == null) { //Debug.LogError("Hide: panel.targetEntity=null"); } else { panel.currentWindow.OnClose(panel.targetEntity); } panel.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0f; panel.targetEntity = null; panel.currentWindow = null; panel.gameObject.SetActive(false); panel.Background_Panel.SetActive(false); GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(panel) as GenericMachineManager; manager.ClearWindow(); } DragAndDropManager.instance.CancelDrag(); DragAndDropManager.instance.DisableDragBackground(); } catch (Exception ex) { Debug.LogError("Hide: " + ex.Message + " : " + ex.StackTrace); } }
/// <summary> /// Call this in HandleThisMachineWindow to handle your UI Window /// </summary> /// <param name="theMachine">Pass the current machine</param> /// <param name="theWindow">The mod window inherited from BaseMachineWindow</param> /// <returns></returns> public static bool SetupMachineWindow(SegmentEntity theMachine) { //ModLogging.LogPlain(debugLocal, getPrefix(), "SetupMachineWindow: Start"); bool flag = false; try { UIUtil.UIdelay = 0; UIUtil.UILock = false; //GenericMachineManager manager = GenericMachinePanelScript.instance.manager; // not yet GenericMachineManager manager = typeof(GenericMachinePanelScript).GetField("manager", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(GenericMachinePanelScript.instance) as GenericMachineManager; // this will replace with the current machine's window, which is OK as long as each Mod uses this technique manager.windows[eSegmentEntity.Mod] = UIUtil.TargetWindow; UIUtil.TargetMachine = theMachine; UIUtil.TargetWindow.manager = manager; UIUtil.UIdelay = 0; UIUtil.UILock = true; flag = true; } catch (Exception ex) { //this.error = "Window Registration failed : " + ex.Message; UnityEngine.Debug.LogError("SetupMachineWindow: failed : " + ex.Message + " : " + ex.StackTrace); } //ModLogging.LogPlain(debugLocal, getPrefix(), "SetupMachineWindow: End"); return(flag); }