Пример #1
0
        public OvenInfo GetOvenInfo(BaseOven oven)
        {
            using (TimeWarning.New("FurnaceSplitter.GetOvenInfo", 0.01f))
            {
                var result     = new OvenInfo();
                var smeltTimes = GetSmeltTimes(oven);

                if (smeltTimes.Count > 0)
                {
                    var   longestStack = smeltTimes.OrderByDescending(kv => kv.Value).First();
                    var   fuelUnits    = oven.fuelType.GetComponent <ItemModBurnable>().fuelAmount;
                    float neededFuel   = (float)Math.Ceiling(longestStack.Value * (BaseOven.cookingTemperature / 200.0f) / fuelUnits);

                    result.FuelNeeded = neededFuel;
                    result.ETA        = longestStack.Value;
                }

                return(result);
            }
        }
Пример #2
0
        private void OnTick()
        {
            while (queuedUiUpdates.Count > 0)
            {
                BaseOven oven = queuedUiUpdates.Pop();

                if (!oven || oven.IsDestroyed)
                {
                    continue;
                }

                OvenInfo ovenInfo = GetOvenInfo(oven);

                GetLooters(oven)?.ForEach(plr =>
                {
                    if (plr && !plr.IsDestroyed)
                    {
                        CreateUi(plr, oven, ovenInfo);
                    }
                });
            }
        }
        /// <summary>
        /// 根据名字查询烤炉信息
        /// </summary>
        /// <param name="oven_name"></param>
        /// <returns></returns>
        public IActionResult GetOvenInfoByName(string oven_name)
        {
            OvenInfo entity = _ovenInfoService.Queryable().Where(x => x.oven_name == oven_name)?.First();

            return(Json(entity));
        }
Пример #4
0
        private CuiElementContainer CreateUi(BasePlayer player, BaseOven oven, OvenInfo ovenInfo)
        {
            var    options    = allPlayerOptions[player.userID];
            int    totalSlots = GetTotalStacksOption(player, oven) ?? oven.inventory.capacity - (oven.allowByproductCreation ? 1 : 2);
            string remainingTimeStr;
            string neededFuelStr;

            if (ovenInfo.ETA <= 0)
            {
                remainingTimeStr = "0s";
                neededFuelStr    = "0";
            }
            else
            {
                remainingTimeStr = FormatTime(ovenInfo.ETA);
                neededFuelStr    = ovenInfo.FuelNeeded.ToString("##,###");
            }

            string contentColor      = "0.7 0.7 0.7 1.0";
            int    contentSize       = 10;
            string toggleStateStr    = (!options.Enabled).ToString();
            string toggleButtonColor = !options.Enabled
                                        ? "0.415 0.5 0.258 0.4"
                                        : "0.8 0.254 0.254 0.4";
            string toggleButtonTextColor = !options.Enabled
                                            ? "0.607 0.705 0.431"
                                            : "0.705 0.607 0.431";
            string buttonColor     = "0.75 0.75 0.75 0.1";
            string buttonTextColor = "0.77 0.68 0.68 1";

            int nextDecrementSlot = totalSlots - 1;
            int nextIncrementSlot = totalSlots + 1;

            DestroyUI(player);

            Vector2 uiPosition = config.UiPosition;
            Vector2 uiSize     = new Vector2(0.1785f, 0.111f);

            var result        = new CuiElementContainer();
            var rootPanelName = result.Add(new CuiPanel
            {
                Image = new CuiImageComponent
                {
                    Color = "0 0 0 0"
                },
                RectTransform =
                {
                    AnchorMin = uiPosition.x + " " + uiPosition.y,
                    AnchorMax = uiPosition.x + uiSize.x + " " + (uiPosition.y + uiSize.y)
                                //AnchorMin = "0.6505 0.022",
                                //AnchorMax = "0.829 0.133"
                }
            }, "Hud.Menu");

            var headerPanel = result.Add(new CuiPanel
            {
                Image = new CuiImageComponent
                {
                    Color = "0.75 0.75 0.75 0.1"
                },
                RectTransform =
                {
                    AnchorMin = "0 0.775",
                    AnchorMax = "1 1"
                }
            }, rootPanelName);

            // Header label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.051 0",
                    AnchorMax = "1 0.95"
                },
                Text =
                {
                    Text     = lang.GetMessage("title", this, player.UserIDString),
                    Align    = TextAnchor.MiddleLeft,
                    Color    = "0.77 0.7 0.7 1",
                    FontSize = 13
                }
            }, headerPanel);

            var contentPanel = result.Add(new CuiPanel
            {
                Image = new CuiImageComponent
                {
                    Color = "0.65 0.65 0.65 0.06"
                },
                RectTransform =
                {
                    AnchorMin = "0 0",
                    AnchorMax = "1 0.74"
                }
            }, rootPanelName);

            // ETA label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.02 0.7",
                    AnchorMax = "0.98 1"
                },
                Text =
                {
                    Text     = string.Format("{0}: " + (ovenInfo.ETA > 0 ? "~" : "") + remainingTimeStr + " (" + neededFuelStr + " " + oven.fuelType.displayName.english.ToLower() + ")", lang.GetMessage("eta", this, player.UserIDString)),
                    Align    = TextAnchor.MiddleLeft,
                    Color    = contentColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Toggle button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.02 0.4",
                    AnchorMax = "0.25 0.7"
                },
                Button =
                {
                    Command = "furnacesplitter.enabled " + toggleStateStr,
                    Color   = toggleButtonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = options.Enabled ? lang.GetMessage("turnoff", this, player.UserIDString) : lang.GetMessage("turnon", this, player.UserIDString),
                    Color    = toggleButtonTextColor,
                    FontSize = 11
                }
            }, contentPanel);

            // Trim button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.27 0.4",
                    AnchorMax = "0.52 0.7"
                },
                Button =
                {
                    Command = "furnacesplitter.trim",
                    Color   = buttonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = lang.GetMessage("trim", this, player.UserIDString),
                    Color    = contentColor,
                    FontSize = 11
                }
            }, contentPanel);

            // Decrease stack button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.02 0.05",
                    AnchorMax = "0.07 0.35"
                },
                Button =
                {
                    Command = "furnacesplitter.totalstacks " + nextDecrementSlot,
                    Color   = buttonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = "<",
                    Color    = buttonTextColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Empty slots label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.08 0.05",
                    AnchorMax = "0.19 0.35"
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = totalSlots.ToString(),
                    Color    = contentColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Increase stack button
            result.Add(new CuiButton
            {
                RectTransform =
                {
                    AnchorMin = "0.19 0.05",
                    AnchorMax = "0.25 0.35"
                },
                Button =
                {
                    Command = "furnacesplitter.totalstacks " + nextIncrementSlot,
                    Color   = buttonColor
                },
                Text =
                {
                    Align    = TextAnchor.MiddleCenter,
                    Text     = ">",
                    Color    = buttonTextColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            // Stack itemType label
            result.Add(new CuiLabel
            {
                RectTransform =
                {
                    AnchorMin = "0.27 0.05",
                    AnchorMax = "1 0.35"
                },
                Text =
                {
                    Align    = TextAnchor.MiddleLeft,
                    Text     = string.Format("({0})", lang.GetMessage("totalstacks", this, player.UserIDString)),
                    Color    = contentColor,
                    FontSize = contentSize
                }
            }, contentPanel);

            openUis.Add(player.userID, rootPanelName);
            CuiHelper.AddUi(player, result);
            return(result);
        }
Пример #5
0
        public JObject Hook_GetOvenInfo(BaseOven oven)
        {
            OvenInfo ovenInfo = GetOvenInfo(oven);

            return(JObject.FromObject(ovenInfo));
        }