示例#1
0
 private void RefreshOverview()
 {
     Controls.Clear();
     AxisList.Clear();
     foreach (KeyValuePair <Guid, List <Control> > entry in ControlManager.Blocks)
     {
         foreach (Control c in entry.Value)
         {
             try { BlockHandlerController.GetID(c.BlockGUID); } catch { continue; }
             if (c.Axis == null)
             {
                 continue;
             }
             if (!Controls.ContainsKey(c.Axis))
             {
                 Controls[c.Axis] = new List <Control>();
             }
             if (!AxisList.Contains(c.Axis))
             {
                 AxisList.Add(c.Axis);
             }
             if (!Controls[c.Axis].Contains(c))
             {
                 Controls[c.Axis].Add(c);
             }
         }
     }
 }
示例#2
0
        internal static ControlOverview Open(bool onload = false)
        {
            BlockHandlerController.InitializeBuildingBlockIDs();

            foreach (ControlOverview x in ACM.Instance.gameObject.GetComponents <ControlOverview>())
            {
                Destroy(x);
            }

            var instance = ACM.Instance.gameObject.AddComponent <ControlOverview>();

            instance.enabled = false;

            instance.windowRect.x = Screen.width - 280 - 400;
            instance.windowRect.y = 200;

            instance.RefreshOverview();

            if (onload)
            {
                if (instance.AxisList.TrueForAll(name =>
                {
                    var axis = AxisManager.Get(name);
                    return(axis != null && (axis.Status == AxisStatus.OK || axis.Status == AxisStatus.NotRunning));
                }))
                {
                    Destroy(instance);
                    return(null);
                }
            }

            instance.enabled = true;
            return(instance);
        }
示例#3
0
 /// <summary>
 /// Handles starting and stopping of the simulation.
 /// </summary>
 /// <param name="isSimulating"></param>
 internal void OnSimulationToggle(bool isSimulating)
 {
     Functions.ResetTimer();
     BlockHandlerController.DestroyBlockHandlers();
     if (enableScript && PythonEnvironment.Loaded)
     {
         DestroyScriptingEnvironment();
         CreateScriptingEnvironment();
     }
     ScriptOptions.Instance.SuccessMessage = null;
     ScriptOptions.Instance.NoteMessage    = null;
     ScriptOptions.Instance.ErrorMessage   = null;
 }
示例#4
0
        /// <summary>
        /// Is called on OnInitialisation to retrieve BlockHandler reference.
        /// If the control has no associated block, it is deleted.
        /// </summary>
        protected virtual void Initialise()
        {
            try
            {
                Block = BlockHandlerController.GetBlock(BlockGUID);

                var axis = AxisManager.Get(Axis);
                if (Enabled && Block != null && axis != null && axis.Status == AxisStatus.OK)
                {
                    ClearKeys();
                }
            }
            catch (BlockNotFoundException)
            {
                Block = null;
                ControlManager.Blocks.Remove(BlockGUID);
            }
        }
示例#5
0
        private void DoWindow(int id)
        {
            // Draw close button
            if (GUI.Button(new Rect(windowRect.width - 38, 8, 30, 30),
                           "×", Elements.Buttons.Red))
            {
                Visible = false;
            }

            string sequential_id;

            try
            {
                sequential_id = BlockHandlerController.GetID(block.Guid);
            }
            catch (KeyNotFoundException)
            {
                Visible = false;
                return;
            }
            // Sequential identifier field
            GUILayout.BeginHorizontal();

            GUILayout.TextField(sequential_id);
            if (GUILayout.Button("✂", Elements.Buttons.Red, GUILayout.Width(30)))
            {
                Clipboard = sequential_id;
            }

            GUILayout.EndHorizontal();

            // GUID field
            GUILayout.BeginHorizontal();

            GUILayout.TextField(block.Guid.ToString());
            if (GUILayout.Button("✂", Elements.Buttons.Red, GUILayout.Width(30)))
            {
                Clipboard = block.Guid.ToString();
            }

            GUILayout.EndHorizontal();

            GUI.DragWindow(new Rect(0, 0, windowRect.width, GUI.skin.window.padding.top));
        }
示例#6
0
        private void DrawAxis(string axis)
        {
            GUILayout.BeginHorizontal();

            var buttonRect = GUILayoutUtility.GetRect(new GUIContent(" "), Elements.Buttons.Default);
            var a          = AxisManager.Get(axis);

            if (GUI.Button(buttonRect, axis, a != null ? a.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled : Elements.Buttons.Red))
            {
                var callback = new SelectAxisDelegate((InputAxis new_axis) => { AssignAxis(axis, new_axis.Name); });
                if (popup == null)
                {
                    popup = AxisSelector.Open(callback, true);
                }
                else
                {
                    popup.Callback = callback;
                }
                popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                popup.windowRect.y = windowRect.y + GUI.skin.window.padding.top + buttonRect.y - scrollPosition.y - 8;
            }

            if (a != null && GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default)
            {
                fontSize = 20, padding = new RectOffset(-3, 0, 0, 0)
            }, GUILayout.Width(30), GUILayout.MaxHeight(28)))
            {
                var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>();
                Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width,
                                                  -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top);
                Editor.windowRect.y = Mathf.Clamp(windowRect.y, 0, Screen.height - GUI.skin.window.padding.top);
                Editor.EditAxis(a, new SelectAxisDelegate((InputAxis new_axis) => { AssignAxis(axis, new_axis.Name); }));
            }

            GUILayout.EndHorizontal();

            // Draw graph
            string text;

            if (a == null)
            {
                text = "NOT FOUND";
            }
            else if (a.Status != AxisStatus.OK)
            {
                text = InputAxis.GetStatusString(a.Status);
            }
            else
            {
                text = "";
            }

            GUILayout.Label("  <color=#808080><b>" + text + "</b></color>",
                            new GUIStyle(Elements.Labels.Default)
            {
                richText = true, alignment = TextAnchor.MiddleLeft, margin = new RectOffset(8, 8, 8, 8)
            },
                            GUILayout.Height(20));

            var graphRect = GUILayoutUtility.GetLastRect();

            Util.DrawRect(graphRect, Color.gray);
            Util.FillRect(new Rect(
                              graphRect.x + graphRect.width / 2,
                              graphRect.y,
                              1,
                              graphRect.height),
                          Color.gray);

            if (a != null && a.Status == AxisStatus.OK)
            {
                Util.FillRect(new Rect(
                                  graphRect.x + graphRect.width / 2 + graphRect.width / 2 * a.OutputValue,
                                  graphRect.y,
                                  1,
                                  graphRect.height),
                              Color.yellow);
            }

            // Draw assigned controls list
            foreach (Control c in Controls[axis])
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("×", new GUIStyle(Elements.Buttons.Red)
                {
                    margin = new RectOffset(8, 8, 0, 0)
                }, GUILayout.Width(20), GUILayout.Height(20)))
                {
                    c.Axis    = null;
                    c.Enabled = false;
                }
                string block_name;
                try
                {
                    block_name = BlockHandlerController.GetID(c.BlockGUID);
                }
                catch
                {
                    block_name = "...";
                }
                GUILayout.Label("<b>" + c.Name + "</b> for " + block_name, Elements.Labels.LogEntry);
                GUILayout.EndHorizontal();
            }

            GUILayout.Box(GUIContent.none, GUILayout.Height(8));
        }
示例#7
0
        /// <summary>
        /// Mod functionality.
        /// Calls Python functions.
        /// </summary>
        private void Update()
        {
            // Initialize block handlers
            if (Game.IsSimulating && !BlockHandlerController.Initialised)
            {
                BlockHandlerController.InitializeBlockHandlers();
            }

            // Initialize block identifiers
            if (!Game.IsSimulating && rebuildIDs)
            {
                rebuildIDs = false;
                BlockHandlerController.InitializeBuildingBlockIDs();
            }

            // Execute code on first call
            if (Game.IsSimulating && PythonEnvironment.Loaded && enableScript && (scriptFile != null || scriptCode != null))
            {
                LoadScript();
                scriptFile = null;
                scriptCode = null;
            }

            // Toggle watchlist visibility
            if (PythonEnvironment.Loaded && Keybindings.Get("Watchlist").Pressed())
            {
                Watchlist.Instance.Visible = !Watchlist.Instance.Visible;
            }

            // Toggle options visibility
            if (PythonEnvironment.Loaded && Keybindings.Get("Script Options").Pressed())
            {
                ScriptOptions.Instance.Visible = !ScriptOptions.Instance.Visible;
            }

            if (!Game.IsSimulating)
            {
                // Show block identifiers
                if (PythonEnvironment.Loaded && Keybindings.Get("Show Block ID").IsDown())
                {
                    ShowBlockIdentifiers();
                }
            }

            if (!Game.IsSimulating)
            {
                return;
            }

            // Call script update.
            try
            {
                if (!runtime_error)
                {
                    PythonEnvironment.ScripterEnvironment?.CallUpdate();
                }
            }
            catch (Exception e)
            {
                runtime_error = true;
                if (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                ScriptOptions.Instance.ErrorMessage = "Runtime error.\nSee console (Ctrl+K) for more info.";
                Debug.Log("<b><color=#FF0000>Python error: " + e.Message + "</color></b>\n" + PythonEnvironment.FormatException(e));
            }
        }