예제 #1
0
        private static void SpawnedDeployablesRemove(int id, JDeployable instance)
        {
            spawnedDeployables.Remove(id);

            Type type;

            if (!TryGetType(instance.ToString(), out type))
            {
                return;
            }

            if (spawnedDeployablesByType.ContainsKey(type))
            {
                spawnedDeployablesByType[type].Remove(instance);
            }

            JInfoAttribute info;

            if (!DeployableTypes.TryGetValue(type, out info))
            {
                return;
            }

            if (spawnedDeployablesByPlugin.ContainsKey(info.PluginInfo.Title))
            {
                spawnedDeployablesByPlugin[info.PluginInfo.Title].Remove(instance);
            }
        }
예제 #2
0
        //private static char[] bglut = new char[] {' ','.',':','-','=','+','*','#','%','@'};
        //private static char[] bglut = "@@@@@@@######MMMBBHHHAAAA&&GGhh9933XXX222255SSSiiiissssrrrrrrr;;;;;;;;:::::::,,,,,,,........".ToCharArray();
        //private static char[] bglut = "@MBHENR#KWXDFPQASUZbdehx*8Gm&04LOVYkpq5Tagns69owz$CIu23Jcfry%1v7l+it[] {}?j|()=~!-/<>\"^_';,:`.".ToCharArray();

        //public static string ASCIIbg(int width, int height, float scalex, float scaley, Color white, Color black) {

        //	List<string> lines = new List<string>();
        //	for (int y = 0; y < height; y++) {
        //		string line = "";
        //		for (int x = 0; x < width; x++) {
        //			//int r = Mathf.FloorToInt(Mathf.Clamp(UnityEngine.Mathf.PerlinNoise(x / scalex, y / scaley) * bglut.Length, 0, bglut.Length - 1));
        //			float r = UnityEngine.Mathf.PerlinNoise(x / scalex, y / scaley);

        //			UnityEngine.Color color = Color.Lerp(black, white, r*0.5f);

        //			//line += $"<color=#{ColorUtility.ToHtmlStringRGB(color)}> × </color>";
        //			line += " × ";
        //		}
        //		lines.Add(line);
        //	}
        //	return string.Join("", lines.ToArray());
        //	//return string.Join("\n", lines.ToArray());
        //}

        public static CuiButton CreateMenuButton(JDeployable dep, ButtonInfo info, string anchorMin = "0 0", string anchorMax = "1 1", int fontSize = 15, string color = "", string textcolor = "")
        {
            return(CreateMenuButton(
                       info.State == ButtonInfo.ButtonState.Enabled ? $"jtech.menubutton {dep.Id} {info.Value}" : "",
                       info.Label, anchorMin, anchorMax, fontSize,
                       color != string.Empty ? color : info.GetColor(),
                       textcolor != string.Empty ? textcolor : info.GetTextColor()));
        }
예제 #3
0
        /// <summary>
        /// Show overlay menu for parent player
        /// </summary>
        public void ShowMenu(JDeployable deployable)
        {
            HideMenu();             // just in case
            CancelPlacing();        // cancel placing
            HideOverlay();

            var elements = new CuiElementContainer();

            menu = Cui.Menu.CreateMenu(elements, this, deployable);

            CuiHelper.AddUi(player, elements);

            isMenuOpen = true;
        }
예제 #4
0
        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);
        }
예제 #5
0
        private static void SpawnedDeployablesAdd(int id, JDeployable instance, Type type)
        {
            spawnedDeployables.Add(id, instance);

            if (!spawnedDeployablesByType.ContainsKey(type))
            {
                spawnedDeployablesByType.Add(type, new List <JDeployable>());
            }
            spawnedDeployablesByType[type].Add(instance);

            JInfoAttribute info;

            if (!DeployableTypes.TryGetValue(type, out info))
            {
                return;
            }

            if (!spawnedDeployablesByPlugin.ContainsKey(info.PluginInfo.Title))
            {
                spawnedDeployablesByPlugin.Add(info.PluginInfo.Title, new List <JDeployable>());
            }
            spawnedDeployablesByPlugin[info.PluginInfo.Title].Add(instance);
        }
예제 #6
0
 public static bool TryGetJDeployable(int id, out JDeployable deployable)
 {
     return(spawnedDeployables.TryGetValue(id, out deployable));
 }
예제 #7
0
 public static void UnloadJDeployable(JDeployable dep)
 {
     dep.Kill(BaseNetworkable.DestroyMode.None, false);
 }
예제 #8
0
        /// <summary>
        /// Distributed JDeployable Update
        /// </summary>
        public static void Update()
        {
            long now = DateTime.Now.Ticks;

            foreach (var deployablebytype in spawnedDeployablesByType)               // for each type of deployable
            {
                if (deployablebytype.Value.Count > 0)
                {
                    JUpdateAttribute updateinfo;
                    if (DeployableTypeUpdates.TryGetValue(deployablebytype.Key, out updateinfo))                       // get update attribute for type

                    // get timeslot for type
                    {
                        int curtimeslot;
                        if (!CurrentUpdateTimeslot.TryGetValue(deployablebytype.Key, out curtimeslot))
                        {
                            CurrentUpdateTimeslot.Add(deployablebytype.Key, 0);
                            curtimeslot = 0;
                        }

                        int updateDelay = updateinfo.updateDelay;

                        // max concurrent updates
                        // Max number of updates called at the same time for this deployable.  When exceeded, updateDelay is increased
                        if (updateinfo.maxConcurrentUpdates > 0)
                        {
                            double concurrent = (double)Math.Ceiling(((double)deployablebytype.Value.Count) / (updateDelay));
                            if (concurrent > updateinfo.maxConcurrentUpdates)
                            {
                                updateDelay *= (int)Math.Ceiling(concurrent / updateinfo.maxConcurrentUpdates);
                            }
                        }

                        //JInfoAttribute info;
                        //DeployableTypes.TryGetValue(deployablebytype.Key, out info);
                        //Interface.Oxide.LogInfo($"[JDeployableManager] --- {info.Name} timeslot {curtimeslot + 1} of {updateDelay} ---");

                        // update deployables for current time slot
                        for (int i = curtimeslot; i < deployablebytype.Value.Count; i += updateDelay)
                        {
                            JDeployable dep = deployablebytype.Value[i];

                            if (dep.Update((now - dep._lastUpdate) * 0.0000001f))                               // convert ticks to seconds

                            //Interface.Oxide.LogInfo($"[JDeployableManager] {info.Name} {i+1} of {deployablebytype.Value.Count} updated with delta {(now - dep._lastUpdate) * 0.0000001f}s");

                            {
                                dep._lastUpdate = now;                                 // if true, set last update
                            }
                        }

                        // set timeslot for next update
                        if (curtimeslot + 1 < updateDelay)
                        {
                            CurrentUpdateTimeslot[deployablebytype.Key]++;
                        }
                        else
                        {
                            CurrentUpdateTimeslot[deployablebytype.Key] = 0;
                        }
                    }
                }
            }
        }
예제 #9
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);
            }
예제 #10
0
 /// <summary>
 /// Show JDeployable menu for the given BasePlayer
 /// </summary>
 public static void ShowMenu(BasePlayer basePlayer, JDeployable deployable) => Get(basePlayer).ShowMenu(deployable);