示例#1
0
    /// <summary>
    ///
    /// creates an empty path
    ///
    /// </summary>
    /// <returns>VehicleDelivery with an empty customer list</returns>
    protected VehicleDelivery simplePath()
    {
        Vector3 pos = GameObject.Find("base").transform.position;

        DataObjects.VehicleDelivery p = new DataObjects.VehicleDelivery();
        p.warehouse = new Warehouse();
        try
        {
            p.warehouse = scenario.warehouse;
        } catch (Exception e)
        {
            Debug.Log(e);
        }
        return(p);
    }
示例#2
0
    /// <summary>
    ///
    /// GUI controls specific to the planner
    ///
    /// </summary>
    protected override void OnGUICustom()
    {
        // get screen size and set scroll window height
        Rect rect         = Camera.main.pixelRect;
        int  scrollheight = (int)Math.Max(rect.height - 250, 200);

        // right panel where users can select plans to open, add a button to open a plan
        int counter = 0;

        teamPlansRect = new Rect(rect.width - 180, 10, 170, scrollheight + 20);
        GUI.Box(teamPlansRect, new GUIContent("Team Plans", "Select a Plan To Open"));
        scrollPositionOperationplans = GUI.BeginScrollView(new Rect(rect.width - 174, 40, 164, scrollheight),
                                                           scrollPositionOperationplans, new Rect(0, 0, 140, 20 + loadedPlans.Count * 21));

        // for each plan id loaded, add a button to open the plan, if not loaded fully, display it
        // but unhighlight it and remove the event on the button
        foreach (int id in loadedPlans.Keys)
        {
            // check if fully loaded
            bool   loaded = (loadedPlans[id].plan != null);
            string tag    = (!loaded ? " *" : "") + loadedPlans[id].tag;
            GUI.color = loaded ? Color.white : Color.gray;
            if (GUI.Button(new Rect(0, 10 + 20 * counter, 164, 20), tag))
            {
                if (loaded)
                {
                    userSelectedPlan = loadedPlans[id].plan;
                    OpenPlan(loadedPlans[id].plan);
                }
            }
            GUI.color = Color.white;
            counter  += 1;
        }
        GUI.EndScrollView();

        // add a toolbar button to remove all plan paths
        if (GUI.Button(removeAllPathsRect, new GUIContent(GUIHelpers.removeimage, "Remove All Paths")))
        {
            playClick();
            RemovePaths();
            Capture.Log("RemoveAllPaths;" + JsonConvert.SerializeObject(plan) + ";" + planCalculation.getLogString(), Capture.PLANNER);
        }

        // submit plan button to your team, it will open a popup for confirmation
        submitRect = new Rect(192, rect.height - 56, 80, 24);
        if (GUI.Button(submitRect, new GUIContent("Submit", "Submit the Plan to Your Team")))
        {
            // check that the plan has delivery customers
            int totalCustomers = 0;
            foreach (DataObjects.VehicleDelivery p in plan.paths)
            {
                totalCustomers += p.customers.Count;
            }

            // open popup
            if (totalCustomers > 0)
            {
                GUIAssets.PopupButton.showing      = true;
                GUIAssets.PopupButton.popupPanelID = "SubmitCanvas";
                GameObject.Find("SubmitCanvas").GetComponent <Canvas>().enabled = true;
            }
            else
            {
                ShowMsg("Empty Plan", true);
            }
        }

        // add AI button if the session includes it
        if (Startup.isAI)
        {
            aiButtonRect = new Rect(10, rect.height - 210, 32, 32);
            if (GUI.Button(aiButtonRect, new GUIContent(GUIHelpers.aiimage, "AI Agent to Generate Plan Alternatives")))
            {
                vehicleDashboardView = false;
                runAIAgent();
                Capture.Log("RunPathAgent", Capture.PLANNER);
            }
        }

        // add controls for the purchased vehicle list on the left
        int heightVehicleScroll = (int)rect.height - 270;

        // labels for database vehicles
        GUI.Box(new Rect(10, 50, 272, heightVehicleScroll), "Purchased Designs");
        GUI.color = Color.white;
        int yInc = 28;

        // scroll window for all plan vehicles
        vehicleRect            = new Rect(10, 80, 272, heightVehicleScroll - 48);
        scrollPositionVehicles = GUI.BeginScrollView(vehicleRect, scrollPositionVehicles, new Rect(0, 0, 272, 20 + plan.paths.Count * yInc));

        // add GUI controls for vehicle paths
        for (int i = 0; i < plan.paths.Count; i++)
        {
            string vehicletag = plan.paths[i].vehicle.tag;
            double cost       = plan.paths[i].vehicle.cost;
            double range      = plan.paths[i].vehicle.range;
            double velocity   = plan.paths[i].vehicle.velocity;
            double payload    = plan.paths[i].vehicle.payload;

            string tooltipStr = "Selects " + vehicletag + " , range = " + range.ToString("0.0") + " mi , capacity = " + payload.ToString("0") + " lb , $" + cost.ToString("0");

            GUI.color = Color.white;
            if (selectedPathIndex == i)
            {
                GUI.color = Color.cyan;
            }

            // select a vehicle to highlight and edit it
            if (GUI.Button(new Rect(26, 10 + i * yInc, 164, 24), new GUIContent(vehicletag, tooltipStr)))
            {
                vehicleDashboardView = false;
                if (selectedPathIndex == i)
                {
                    selectedPathIndex = -1;
                }
                else
                {
                    selectedPathIndex = i;
                    PlanPathCalculation planPathCalculation = new PlanPathCalculation(plan.paths[i]);
                    planPathCalculation.calculate();
                    manualPathRangeRemaining    = planPathCalculation.getTotalRangeRemaining();
                    manualPathCapacityRemaining = planPathCalculation.getTotalCapacityRemaining();
                }

                RefreshPaths();
                playClick();
                Capture.Log("SelectPath;" + i + ";" + vehicletag, Capture.PLANNER);
            }

            // draw vehicle metrics as bar charts
            GUI.color = Color.white;
            GUI.Box(new Rect(192, 14 + 16 + i * yInc - (float)(16 * range / maxVehicleRange), 12, 16 * (float)(range / maxVehicleRange)), "", Assets.GUIHelpers.whiteStyle);
            GUI.Box(new Rect(206, 14 + 16 + i * yInc - (float)(16 * payload / maxVehicleCapacity), 12, 16 * (float)(payload / maxVehicleCapacity)), "", Assets.GUIHelpers.lightgrayStyle);
            GUI.Box(new Rect(220, 14 + 16 + i * yInc - (float)(16 * cost / maxVehicleCost), 12, 16 * (float)(cost / maxVehicleCost)), "", Assets.GUIHelpers.grayRedStyle);


            GUI.color = Color.white;
            // timing issue in Unity when deleting vehicles, I think this is fixed
            // since the remove button in below this in the code now
            try
            {
                if (plan.paths[i].customers.Count == 0)
                {
                    GUI.color = new Color(0.2f, 0.2f, 0.2f);
                }
            } catch (Exception e)
            {
                Debug.Log(e);
            }

            // add the remove path button
            // only show if the dashboard view is not shown, since mouse actions go through
            if (!vehicleDashboardView)
            {
                // adds the remove button to the view
                if (GUI.Button(new Rect(234, 10 + i * yInc, 24, 24), new GUIContent(GUIHelpers.removeimage, "Remove the Path")))
                {
                    // set the remaining variable to the full values
                    manualPathRangeRemaining    = plan.paths[i].vehicle.range;
                    manualPathCapacityRemaining = plan.paths[i].vehicle.payload;
                    plan.paths[i].customers.Clear();

                    selectedPathIndex = i;

                    // remove and add path to show highlighted path
                    RefreshPaths();

                    playClick();

                    Capture.Log("VehiclePathRemoved;" + i + ";" + plan.paths[i].vehicle.tag + ";" + JsonConvert.SerializeObject(plan) + ";" + planCalculation.getLogString(), Capture.PLANNER);
                }
            }

            GUI.color = Color.white;
            if (GUI.Button(new Rect(0, 10 + i * yInc, 24, 24), new GUIContent("-", "Remove Design from Purchased List")))
            {
                selectedPathIndex = -1;
                plan.paths.RemoveAt(i);

                // refresh the path lines
                RefreshPaths();

                playClick();
                Capture.Log("VehicleRemoved;" + i + ";" + vehicletag + ";" + JsonConvert.SerializeObject(plan) + ";" + planCalculation.getLogString(), Capture.PLANNER);
                ShowMsg(vehicletag + " Removed", false);

                if (plan.paths.Count == 0)
                {
                    vehicleDashboardView = true;
                }
            }
        }
        GUI.EndScrollView();

        // show the dashboard view in the upper center of the window with the range and capacity
        // remaining for the display
        if (selectedPathIndex != -1)
        {
            GUI.Box(new Rect(290, 10, 360, 62), "");
            GUI.Label(new Rect(384, 20, 10, 52), "0");

            float maxRange    = (float)plan.paths[selectedPathIndex].vehicle.range;
            float maxCapacity = (float)plan.paths[selectedPathIndex].vehicle.payload;

            GUI.Label(new Rect(505, 10, 28, 56), "\n" + maxRange.ToString("0.0") + "\n" + maxCapacity.ToString("0.0"));

            GUI.Box(new Rect(399, 30, 1, 36), "", Assets.GUIHelpers.whiteStyle);
            GUI.Box(new Rect(501, 30, 1, 36), "", Assets.GUIHelpers.whiteStyle);
            GUI.Label(new Rect(294, 10, 390, 56), "\n  Range (mi)\n  Weight (lb)");
            GUI.Label(new Rect(542, 10, 390, 56), "\n  Remaining=" + manualPathRangeRemaining.ToString("0.0") + "\n  Remaining=" + manualPathCapacityRemaining.ToString("0"));

            GUI.color = Color.cyan;

            GUI.Label(new Rect(294, 10, 390, 56), plan.paths[selectedPathIndex].vehicle.tag + "\n\n");

            GUI.Box(new Rect(400, 36, (float)(100f * (1 - manualPathRangeRemaining / maxRange)), 10), "", Assets.GUIHelpers.whiteStyle);
            GUI.Box(new Rect(400, 50, (float)(100f * (1 - manualPathCapacityRemaining / maxCapacity)), 10), "", Assets.GUIHelpers.whiteStyle);

            GUI.color = Color.white;
        }

        // add a button to toggle the information help panel
        GUI.color = Color.white;
        if (GUI.Button(infoRect, new GUIContent(GUIHelpers.infoimage, "Toggle Information Panel")))
        {
            showHelpInfoPanel = !showHelpInfoPanel;
            playClick();
            GameObject.Find("helpcanvasplanner").GetComponent <Canvas>().enabled = showHelpInfoPanel;
            Capture.Log("ToggleInfoPanel:" + showHelpInfoPanel, Capture.PLANNER);
        }

        // add a button to toggle the information help panel
        vehicleSelectionRect = new Rect(244, 52, 28, 28);
        if (GUI.Button(vehicleSelectionRect, new GUIContent(GUIHelpers.dashboardimage, "Add a Design From the Design Team")))
        {
            vehicleDashboardView = !vehicleDashboardView;
            if (vehicleDashboardView)
            {
                selectedPathIndex = -1;
            }
            playClick();
            Capture.Log("ShowVehicleList;" + vehicleDashboardView, Capture.PLANNER);
        }

        // add the team design selection list
        if (vehicleDashboardView)
        {
            // multiple boxes adds opacity
            for (int i = 0; i < 4; i++)
            {
                GUI.Box(new Rect(200, 94, 260, 400), "Team Designs");
            }

            scrollPositionVehicleSelection = GUI.BeginScrollView(new Rect(210, 130, 260, 300),
                                                                 scrollPositionVehicleSelection, new Rect(0, 0, 240, 30 * teamVehicles.Count));

            // add all team vehicles to the list
            int counterdash = 0;
            foreach (Vehicle vehicle in teamVehicles)
            {
                string tooltipStr = "Add design " + vehicle.tag + " , range = " + vehicle.range.ToString("0.0") + " mi , capacity = "
                                    + vehicle.payload.ToString("0") + " lb , $" + vehicle.cost.ToString("0");

                // add the plus button to add a vehicle to the purchased list
                if (GUI.Button(new Rect(0, counterdash * 30, 28, 28), new GUIContent("+", tooltipStr)))
                {
                    DataObjects.VehicleDelivery p = simplePath();
                    p.vehicle = vehicle;

                    try
                    {
                        p.warehouse = scenario.warehouse;
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e);
                    }

                    plan.paths.Add(p);
                    RefreshPaths();
                    playClick();
                    Capture.Log("VehicleAdd;" + vehicle.tag + ";" + JsonConvert.SerializeObject(plan) + ";" + planCalculation.getLogString(), Capture.PLANNER);
                    ShowMsg(vehicle.tag + " Added", false);
                }

                // add the vehicle tag
                GUI.Label(new Rect(30, counterdash * 30, 164, 28), vehicle.tag);

                // add the metric bars
                GUI.color = Color.white;
                GUI.Box(new Rect(186, (counterdash + 1) * 30 - 8 - 16 * (float)(vehicle.range / maxVehicleRange), 12, 16 * (float)(vehicle.range / maxVehicleRange)), "", Assets.GUIHelpers.whiteStyle);
                GUI.Box(new Rect(202, (counterdash + 1) * 30 - 8 - 16 * (float)(vehicle.payload / maxVehicleCapacity), 12, 16 * (float)(vehicle.payload / maxVehicleCapacity)), "", Assets.GUIHelpers.lightgrayStyle);
                GUI.Box(new Rect(218, (counterdash + 1) * 30 - 8 - 16 * (float)(vehicle.cost / maxVehicleCost), 12, 16 * (float)(vehicle.cost / maxVehicleCost)), "", Assets.GUIHelpers.grayRedStyle);

                GUI.color    = Color.white;
                counterdash += 1;
            }
            GUI.EndScrollView();

            // add the hide button at the bottom of the view
            if (GUI.Button(new Rect(250, 456, 140, 28), "Hide"))
            {
                vehicleDashboardView = false;
            }
        }

        // lock the camera view if the dashboard view is opened or the user is
        // dragging a selected component
        MoveCamera.lockView = vehicleDashboardView || (selectedConnector != null);
    }