/// <summary>
        /// This is what's shown as the bold green title of the
        /// info panel at right in the parts pane.
        /// </summary>
        /// <returns></returns>
        public string GetModuleTitle()
        {
            string titleTag = isDefault
                ? "#SimpleFuelSwitch_titleFormatDefault"
                : "#SimpleFuelSwitch_titleFormat";

            return(LocalizeUtil.Format(titleTag, selectorFieldName, displayName));
        }
Пример #2
0
        /// <summary>
        /// Given an array of SwitchableResource, get a long title to describe them.
        /// </summary>
        /// <param name="resources"></param>
        /// <returns></returns>
        public static string LongTitleOf(SwitchableResource[] resources)
        {
            if (resources.Length == 0)
            {
                return(LocalizeUtil.GetString("#SimpleFuelSwitch_noResources"));
            }
            StringBuilder builder = new StringBuilder(resources[0].definition.displayName);

            for (int i = 1; i < resources.Length; ++i)
            {
                builder.Append(" + ");
                builder.Append(resources[i].definition.displayName);
            }
            return(builder.ToString());
        }
        /// <summary>
        /// Display the total mass of a resource, in tons.
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        private static string MassOf(SwitchableResource[] resources, int index)
        {
            double mass = 0.0;

            if (index == SUM_INDEX)
            {
                for (int i = 0; i < resources.Length; ++i)
                {
                    mass += resources[i].amount * resources[i].definition.density;
                }
            }
            else
            {
                mass = resources[index].amount * resources[index].definition.density;
            }
            return(LocalizeUtil.Format("#SimpleFuelSwitch_massTonsFormat", mass));
        }
Пример #4
0
        /// <summary>
        /// Here when the game is first loading up.
        /// </summary>
        /// <param name="node"></param>
        private void OnInitialGameLoading(ConfigNode node)
        {
            Loader.Initialize();

            // Load the resources from config.
            resources = SwitchableResource.Load(node);
            longTitle = SwitchableResource.LongTitleOf(resources);

            // If they haven't specified a resources title in the config,
            // use the auto-generated long one.
            if (string.IsNullOrEmpty(displayName))
            {
                displayName = longTitle;
            }

            // Add the resources to the global map. This is how the ModuleSimpleFuelSwitch will
            // control behavior when the player is working with a ship in the editor.
            SwitchableResourceSet.Add(
                part.name,
                resourcesId,
                displayName,
                selectorFieldName,
                ParseLinkedVariants(linkedVariant),
                isDefault,
                resources,
                part.Resources);

            // Everything else in this class is concerned simply with setting up stuff
            // to display appropriate info in the part info window from the parts pane
            // of the vehicle editor.

            info = FormatInfo(resourcesId, resources);
            if (resources.Length == 0)
            {
                primaryField = longTitle;
            }
            else
            {
                primaryField = LocalizeUtil.Format(
                    "#SimpleFuelSwitch_primaryInfoFormat",
                    selectorFieldName,
                    displayName,
                    ResourcePrimaryInfoFormatter.Format(resourcesId, resources));
            }
        }
Пример #5
0
        /// <summary>
        /// Formats the information to display in the info pane on the right side of
        /// the part's pop-up window on the editor.
        /// </summary>
        /// <param name="resourcesId"></param>
        /// <param name="resources"></param>
        /// <returns></returns>
        private static string FormatInfo(string resourcesId, SwitchableResource[] resources)
        {
            if (resources.Length == 0)
            {
                return(LocalizeUtil.GetString("#SimpleFuelSwitch_noResources"));
            }

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < resources.Length; ++i)
            {
                if (i > 0)
                {
                    builder.Append("\n");
                }
                builder.Append(LocalizeUtil.Format(
                                   "#SimpleFuelSwitch_detailedInfoFormat",
                                   resources[i].definition.displayName,
                                   ResourceInfoFormatter.Format(resourcesId, resources[i])));
            }
            return(builder.ToString());
        }
        private static string FormatInfo(SwitchableResource[] resources)
        {
            // For default parts that aren't using this mod, each resource will
            // get one pane, where the title is the resource name and the
            // info consists of three lines: Amount, Mass, Cost.
            //
            // In our case, we're adding one pane for a *set* of resources, so
            // we need to present the info a bit differently.
            //
            // The title is fairly straightforward: the specified resources
            // title for the module (if provided), or a list of resource names
            // (if not).
            //
            // However, we can't really show amount/mass/cost, since there are
            // multiple panes that may have multiple resources each, so we
            // need to be more succinct. For each resource, we'll either display
            // the mass (if it's a resource with density > 0), or the amount
            // (for zero-density resources).
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < resources.Length; ++i)
            {
                SwitchableResource resource     = resources[i];
                string             amountString = (resource.definition.density > 0)
                    ? FormatMassInTons(resource.maxAmount * resource.definition.density)
                    : FormatAmount(resource.maxAmount);
                if (i > 0)
                {
                    builder.Append("\n");
                }
                builder.Append(LocalizeUtil.Format(
                                   "#SimpleFuelSwitch_detailedInfoFormat",
                                   resource.definition.displayName,
                                   amountString));
            }
            return(builder.ToString());
        }
        /// <summary>
        /// Here when the game is first loading up.
        /// </summary>
        /// <param name="node"></param>
        private void OnInitialGameLoading(ConfigNode node)
        {
            // Load the resources from config and add them to the global map. This is how
            // the ModuleSimpleFuelSwitch will control behavior when the player is working
            // with a ship in the editor.
            resources = SwitchableResource.Load(node);
            SwitchableResourceSet.Add(part.name, resourcesId, displayName, selectorFieldName, isDefault, resources);

            // Everything else in this class is concerned simply with setting up stuff
            // to display appropriate info in the part info window from the parts pane
            // of the vehicle editor.

            // Build a long title from the resource names.
            StringBuilder builder = new StringBuilder(resources[0].definition.displayName);

            for (int i = 1; i < resources.Length; ++i)
            {
                builder.Append(" + ");
                builder.Append(resources[i].definition.displayName);
            }
            longTitle = builder.ToString();

            // If they haven't specified a resources title in the config,
            // use the auto-generated long one.
            if (displayName == null)
            {
                displayName = longTitle;
            }

            info         = FormatInfo(resources);
            primaryField = LocalizeUtil.Format(
                "#SimpleFuelSwitch_primaryInfoFormat",
                selectorFieldName,
                displayName,
                FormatPrimaryFieldQuantity(resources));
        }
Пример #8
0
 /// <summary>
 /// Display the mass of a resource, in tons.
 /// </summary>
 /// <param name="resource"></param>
 /// <returns></returns>
 private static string MassOf(SwitchableResource resource)
 {
     return(LocalizeUtil.Format("#SimpleFuelSwitch_massTonsFormat", resource.amount * resource.definition.density));
 }
 /// <summary>
 /// Given a mass in tons, produce a formatted string (with units) suitable
 /// for UI display.
 /// </summary>
 /// <param name="tons"></param>
 /// <returns></returns>
 private static string FormatMassInTons(double tons)
 {
     return(LocalizeUtil.Format("#SimpleFuelSwitch_massTonsFormat", tons));
 }