private static bool SaveJDeployable(int id, JDeployable d)
        {
            DeployableSaveData sd = new DeployableSaveData {
                t = d.ToString(),
                s = d.data
            };

            JInfoAttribute info = null;

            if (!DeployableTypes.TryGetValue(d.GetType(), out info))
            {
                return(false);
            }

            if (!DataManager.data.p.ContainsKey(info.PluginInfo.Title))
            {
                DataManager.data.p.Add(info.PluginInfo.Title, new Dictionary <int, DeployableSaveData>());
            }

            DataManager.data.p[info.PluginInfo.Title].Add(id, sd);

            return(true);
        }
Esempio n. 2
0
            public static string CreateMenu(CuiElementContainer elements, UserInfo userInfo, JDeployable deployable)
            {
                JInfoAttribute info;

                JDeployableManager.DeployableTypes.TryGetValue(deployable.GetType(), out info);

                float aspect = 0.5625f;                 // use this to scale width values for 1:1 aspect

                float mainheight      = 0.45f;
                float mainwidth       = 0.55f;
                float mainwidthaspect = mainwidth * aspect;
                float mainaspect      = mainheight / mainwidth;
                float mainy           = 0.475f;

                string parent = elements.Add(
                    new CuiPanel {                     // blue background
                    Image         = { Color = $"{Colors.DarkBlue} 0.86" },
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    CursorEnabled = true
                }
                    );

                //elements.Add(
                //	new CuiLabel {
                //		Text = { Text = new StringBuilder().Insert(0, "▀", 10000).ToString(), FontSize = 6, Align = TextAnchor.MiddleCenter, Color = "1 1 1 0.5" },
                //		RectTransform = { AnchorMin = $"{0.5f - mainwidthaspect * 0.5f} {mainy - mainheight * 0.5f}", AnchorMax = $"{0.5f + mainwidthaspect * 0.5f} {mainy + mainheight * 0.5f}" }
                //	}, parent
                //);

                //return parent;

                float gap = 0.0125f;

                float centercontentheight = 0.8f;
                float centercontentwidth  = centercontentheight * mainaspect;                // keep the main content square

                // slight outline around main
                FakeDropShadow(elements, parent, 0.5f - mainwidthaspect * 0.5f, mainy - mainheight * 0.5f, 0.5f + mainwidthaspect * 0.5f, mainy + mainheight * 0.5f, 0.005f * aspect, 0.005f, 1, $"{Colors.DarkBlue} 0.3");

                // close overlay if you click the background
                elements.Add(
                    new CuiButton {
                    Button        = { Command = $"jtech.closemenu", Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" },
                    Text          = { Text = string.Empty }
                }, parent
                    );

                string main = elements.Add(
                    new CuiPanel {
                    Image         = { Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = $"{0.5f - mainwidthaspect * 0.5f} {mainy - mainheight * 0.5f}", AnchorMax = $"{0.5f + mainwidthaspect * 0.5f} {mainy + mainheight * 0.5f}" }
                }, parent
                    );


                // top

                string top = elements.Add(
                    new CuiPanel {
                    Image         = { Color = $"{Colors.Blue} 0.25" },
                    RectTransform = { AnchorMin = $"0 {centercontentheight + gap}", AnchorMax = $"1 1" },
                }, main
                    );

                // deployable name
                elements.Add(
                    AddOutline(
                        new CuiLabel {
                    Text          = { Text = $"{info.Name}", FontSize = 24, Align = TextAnchor.LowerLeft, Color = "1 1 1 1" },
                    RectTransform = { AnchorMin = "0 1", AnchorMax = "1 2" }
                }, top, $"{Colors.DarkBlue} 0.6")
                    );

                float topaspect   = (1 - centercontentheight + gap / 1) * mainaspect - 0.0025f;
                float iconwidth   = topaspect;
                float iconpadding = 0.03f;
                float textpadding = 0.125f;
                float iconleft    = 1 - iconwidth - 0.02f;

                // deployable description
                elements.Add(
                    AddOutline(
                        new CuiLabel {
                    Text          = { Text = info.Description, FontSize = 12, Align = TextAnchor.UpperLeft, Color = "1 1 1 1" },
                    RectTransform = { AnchorMin = $"{textpadding * topaspect} {textpadding}", AnchorMax = $"{iconleft - (textpadding * topaspect)} {1f - textpadding}" }
                }, top, $"{Colors.DarkBlue} 0.8")
                    );

                // deployable icon
                string iconarea = elements.Add(
                    new CuiPanel {
                    Image         = { Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = $"{iconleft} 0", AnchorMax = $"{iconleft + iconwidth - (0.02f * topaspect)} {0.98f}" },
                }, top
                    );

                elements.Add(
                    CreateIcon(iconarea, $"{iconpadding} {iconpadding}", $"{1 - iconpadding} {1 - iconpadding}", info.IconUrl, "1 1 1 1")
                    );



                // content

                string content = elements.Add(
                    new CuiPanel {
                    Image         = { Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = "0 0", AnchorMax = $"{centercontentwidth} {centercontentheight}" },
                }, main
                    );

                string contentinside = elements.Add(
                    new CuiPanel {
                    Image         = { Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = $"0 0", AnchorMax = $"0.994 0.99" },
                }, content
                    );

                deployable.GetMenuContent(elements, contentinside, userInfo);


                // actions

                string buttons = elements.Add(
                    new CuiPanel {
                    Image         = { Color = $"{Colors.Blue} 0" },
                    RectTransform = { AnchorMin = $"{centercontentwidth + gap * mainaspect} 0", AnchorMax = $"1 {centercontentheight}" }
                }, main
                    );

                string buttonsinside = elements.Add(
                    new CuiPanel {
                    Image         = { Color = "0 0 0 0" },
                    RectTransform = { AnchorMin = $"0 0", AnchorMax = $"0.985 0.99" },
                }, buttons
                    );

                List <ButtonInfo> buttoninfos = deployable.GetMenuButtons(userInfo);

                float buttonspacing = 0.015f;
                float maxheight     = 0.2f;
                float buttonratio   = (1 + buttonspacing) / (buttoninfos.Count + 1);
                float buttonheight  = (buttonratio < (1 + buttonspacing) / (1 / maxheight) ? buttonratio : maxheight);

                elements.Add(
                    CreateMenuButton(
                        $"jtech.menuonoffbutton {deployable.Id}", deployable.data.isEnabled ? "Turn Off" : "Turn On",
                        $"0 0", $"1 {buttonheight - buttonspacing}", 15,
                        deployable.data.isEnabled ? Colors.MenuButton.EnabledOff : Colors.MenuButton.EnabledOn,
                        deployable.data.isEnabled ? Colors.MenuButton.EnabledOffText : Colors.MenuButton.EnabledOnText
                        ),
                    buttonsinside
                    );

                for (int i = 0; i < buttoninfos.Count; i++)
                {
                    int yi = i + 1;

                    elements.Add(
                        CreateMenuButton(
                            deployable, buttoninfos[i],
                            $"0 {(buttonheight * yi)}", $"1 {buttonheight * (yi + 1) - buttonspacing}"
                            ),
                        buttonsinside
                        );
                }

                //elements.Add(
                //	CreateIcon(button, $"0 0", $"1 1", "", "1 1 1 1")
                //);

                return(parent);
            }