示例#1
0
        /// <summary>
        /// Localizes the specified mod assembly.
        /// </summary>
        /// <param name="modAssembly">The assembly to localize.</param>
        /// <param name="locale">The locale file name to be used.</param>
        private static void Localize(Assembly modAssembly, Localization.Locale locale)
        {
            string path    = PUtil.GetModPath(modAssembly);
            string locCode = locale.Code;

            if (string.IsNullOrEmpty(locCode))
            {
                locCode = Localization.GetCurrentLanguageCode();
            }
            var poFile = Path.Combine(Path.Combine(path, TRANSLATIONS_DIR), locCode +
                                      PLibLocalization.TRANSLATIONS_EXT);

            try {
                Localization.OverloadStrings(Localization.LoadStringsFile(poFile, false));
                RewriteStrings(modAssembly);
            } catch (FileNotFoundException) {
                // No localization available for this locale
#if DEBUG
                PDatabaseUtils.LogDatabaseDebug("No {0} localization available for mod {1}".F(
                                                    locCode, modAssembly.GetNameSafe() ?? "?"));
#endif
            } catch (DirectoryNotFoundException) {
            } catch (IOException e) {
                PDatabaseUtils.LogDatabaseWarning("Failed to load {0} localization for mod {1}:".
                                                  F(locCode, modAssembly.GetNameSafe() ?? "?"));
                PUtil.LogExcWarn(e);
            }
        }
示例#2
0
        /// <summary>
        /// Fills in the mod info screen, assuming that infoAttr is non-null.
        /// </summary>
        /// <param name="dialog">The dialog to populate.</param>
        private void AddModInfoScreen(PDialog dialog)
        {
            string image = displayInfo.Image;
            var    body  = dialog.Body;

            // Try to load the mod image sprite if possible
            if (modImage == null && !string.IsNullOrEmpty(image))
            {
                string rootDir = PUtil.GetModPath(optionsType.Assembly);
                modImage = PUIUtils.LoadSpriteFile(rootDir == null ? image : Path.Combine(
                                                       rootDir, image));
            }
            var websiteButton = new PButton("ModSite")
            {
                Text    = PLibStrings.MOD_HOMEPAGE, ToolTip = PLibStrings.TOOLTIP_HOMEPAGE,
                OnClick = VisitModHomepage, Margin = PDialog.BUTTON_MARGIN
            }.SetKleiBlueStyle();
            var versionLabel = new PLabel("ModVersion")
            {
                Text      = displayInfo.Version, ToolTip = PLibStrings.TOOLTIP_VERSION,
                TextStyle = PUITuning.Fonts.UILightStyle, Margin = new RectOffset(0, 0,
                                                                                  OUTER_MARGIN, 0)
            };
            // Find mod URL
            string modURL = displayInfo.URL;

            if (modImage != null)
            {
                // 2 rows and 1 column
                if (optionCategories.Count > 0)
                {
                    body.Direction = PanelDirection.Horizontal;
                }
                var infoPanel = new PPanel("ModInfo")
                {
                    FlexSize  = Vector2.up, Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter
                }.AddChild(new PLabel("ModImage")
                {
                    SpriteSize = MOD_IMAGE_SIZE, TextAlignment = TextAnchor.UpperLeft,
                    Margin     = new RectOffset(0, OUTER_MARGIN, 0, OUTER_MARGIN),
                    Sprite     = modImage
                });
                if (!string.IsNullOrEmpty(modURL))
                {
                    infoPanel.AddChild(websiteButton);
                }
                body.AddChild(infoPanel.AddChild(versionLabel));
            }
            else
            {
                if (!string.IsNullOrEmpty(modURL))
                {
                    body.AddChild(websiteButton);
                }
                body.AddChild(versionLabel);
            }
        }
示例#3
0
        /// <summary>
        /// Retrieves the configuration file path used by PLib Options for a specified type.
        /// </summary>
        /// <param name="attr">The config file attribute for that type.</param>
        /// <param name="modAssembly">The assembly to use for determining the path.</param>
        /// <returns>The path to the configuration file that will be used by PLib for that
        /// mod's config.</returns>
        private static string GetConfigPath(ConfigFileAttribute attr, Assembly modAssembly)
        {
            string path, name = modAssembly.GetNameSafe();

            path = (name != null && (attr?.UseSharedConfigLocation == true)) ?
                   Path.Combine(KMod.Manager.GetDirectory(), SHARED_CONFIG_FOLDER, name) :
                   PUtil.GetModPath(modAssembly);
            return(Path.Combine(path, attr?.ConfigFileName ?? CONFIG_FILE_NAME));
        }