示例#1
0
        public void Broadcast(DarkLightEvent darkLightEvent)
        {
            //Test w/ everything periodic for now
            //var taskType = TaskType.Periodic;
            object target = new object();

            object[] message = new object[1];
            System.Action <object[]> action = null;

            switch (darkLightEvent.EventType)//taskType)
            //TODO: refactor mapping below
            {
            //NOT BEING USED YET
            case (EventType.BacktestRequest):     //TaskType.Background:
                // check if already running
                if (!_baseQueue.ContainsKey(target))
                {
                    var bgTask = _backgroundTaskFactory.StartNew(() => _mediatorAdapter.Publish(darkLightEvent));
                    //_baseQueue.Add(target, bgTask);
                }
                break;

            case (EventType.Trade):
            case EventType.Status:    //TaskType.Periodic:
                var periodicTask = new PeriodicTask(() => _eventAggregator.Publish(darkLightEvent), _budget);
                periodicTask.Start(_preemptiveScheduler);
                break;

            /*
             * case EventType.BacktestRequest://TaskType.Sporadic:
             *  // one Periodic to run all sporadics
             *  var sporadicTask1 = new SporadicTask(() => _mediatorAdapter.Publish(darkLightEvent), _budget);
             *  sporadicTask1.Start(_preemptiveScheduler);
             *  break;
             */
            case EventType.LinkedNavigation:
                // one Periodic to run all sporadics
                var sporadicTask2 = new SporadicTask(() => _eventAggregator.Publish(darkLightEvent), _budget);
                sporadicTask2.Start(_preemptiveScheduler);
                break;

            //NOT BEING USED YET
            case EventType.Result:    //TaskType.LongRunning:
                //UI
                _staTaskFactory.StartNew(() => action.DynamicInvoke(message));
                break;
            }
        }
    private void OnGUI()
    {
        GUI.skin = guiSkin;

        // Set font size according to screen width
        if ((int)Screen.width > 0)
        {
            double fontScaleFactor = (referenceScreenSize.x / Screen.width);
            int    fontSize        = (int)(referenceFontSize / Math.Max(fontScaleFactor, 0.01));
            GUI.skin.button.fontSize = fontSize;
            GUI.skin.box.fontSize    = fontSize;
        }

        if (choosingNode)
        {
            Vector2 boxSize = new Vector2(0.75f, 0.625f);
            GUI.Box(new Rect(ndcToScreen(0.5f - boxSize.x / 2.0f, 0.5f - boxSize.y / 2.0f), ndcToScreen(boxSize)), !choosingFunctionCall ? "Choose a node type to add:" : "Choose function to call");

            if (!choosingFunctionCall)
            {
                // TODO: This could just be reduced to one foreach with a counter variable, instead of a foreach & for-loop. Potential performance boost.
                List <string> nodeTypeStrings = new List <string>();
                foreach (string nodeTypeString in nodePrefabs.Keys)
                {
                    nodeTypeStrings.Add(nodeTypeString);
                }

                for (int i = 0; i < nodeTypeStrings.Count; i++)
                {
                    float buttonHeight = 0.05f;
                    float buttonWidth  = 0.7f;
                    bool  pressed      = GUI.Button(new Rect(ndcToScreen(0.5f - buttonWidth / 2.0f, 0.3f + buttonHeight * i + 0.01f * i), ndcToScreen(buttonWidth, buttonHeight)), nodePrefabs[nodeTypeStrings[i]].Key);
                    if (pressed)
                    {
                        addedNode = AddNode(nodeTypeStrings[i], newNodeInitPos.x, newNodeInitPos.y);
                        if (nodeTypeStrings[i] == "FunctionCallBase")
                        {
                            choosingFunctionCall = true;
                        }
                        else
                        {
                            choosingNode = false;
                        }
                        // Fixes node link renderer
                        addedNode.name = addedNode.name.Replace("(Clone)", $"-{(addedNode.GetInstanceID())}");

                        // Special cases
                        if (nodeTypeStrings[i] == "CreateList")
                        {
                            addedNode.GetComponentInParent <AllocateArray>().InitialiseNode();
                        }
                        break;
                    }
                }
            }
            if (choosingFunctionCall)
            {
                List <string> functionNames = new List <string>();
                foreach (string functionName in programController.functions.Keys)
                {
                    if (programController.hiddenFunctions.Contains(functionName))
                    {
                        continue;
                    }

                    string paramList = "";
                    foreach (System.Reflection.ParameterInfo funcParams in programController.functions[functionName].Method.GetParameters())
                    {
                        paramList += $"{funcParams.Name}, ";
                    }
                    if (!string.IsNullOrWhiteSpace(paramList))
                    {
                        paramList = paramList.Substring(0, paramList.LastIndexOf(','));
                    }
                    functionNames.Add($"{functionName}({paramList})");
                }

                for (int i = 0; i < functionNames.Count; i++)
                {
                    float buttonHeight = 0.05f;
                    float buttonWidth  = 0.7f;
                    bool  pressed      = GUI.Button(new Rect(ndcToScreen(0.5f - buttonWidth / 2.0f, 0.3f + buttonHeight * (float)i + 0.01f * (float)i), ndcToScreen(buttonWidth, buttonHeight)), functionNames[i]);
                    if (pressed)
                    {
                        addedNode.GetComponent <EditorDraggableNode>().FunctionNameEditingFinished(functionNames[i].Substring(0, functionNames[i].IndexOf('(')));
                        choosingNode         = false;
                        choosingFunctionCall = false;
                        break;
                    }
                }
            }
        }

        if (editingNodeProperty)
        {
            GUI.SetNextControlName("editedNodeValue");
            if (editingNodeInPlace)
            {
                float x         = editingNodeInPlaceRect.x;
                float y         = editingNodeInPlaceRect.y;
                float width     = editingNodeInPlaceRect.width;
                float height    = editingNodeInPlaceRect.height;
                float cvsHeight = elementContainer.GetComponentInParent <RectTransform>().rect.height;
                editedNodeValue = GUI.TextArea(new Rect(x, Screen.height - (y + height), width, height), editedNodeValue);
            }
            else
            {
                editedNodeValue = GUI.TextArea(new Rect(ndcToScreen(0.5f - 0.375f / 2.0f, 0.5f - 0.05f / 2.0f), ndcToScreen(0.375f, 0.05f)), editedNodeValue);
            }

            if (!editedNodeFocused)
            {
                GUI.FocusControl("editedNodeValue");
                editedNodeFocused = true;
            }
            else if (string.IsNullOrWhiteSpace(GUI.GetNameOfFocusedControl()))
            {
                editingNodeProperty = false;
                editedNodeFocused   = false;
                editingNodeInPlace  = false;

                clueHud.SetCurrentPrompt(null, null);
            }

            if (editedNodeValue != null && editedNodeValue.Contains("\n"))
            {
                editedNodeValue = editedNodeValue.Replace("\n", "");
                editingNodeFinishedClb.DynamicInvoke(editedNodeValue);
                editingNodeProperty = false;
                editingNodeInPlace  = false;
                editedNodeFocused   = false;

                clueHud.SetCurrentPrompt(null, null);
            }
        }
    }