Ejemplo n.º 1
0
 protected T LoadConfig <T>() where T : TweakConfig
 {
     try {
         var configDirectory = PluginInterface.GetPluginConfigDirectory();
         var configFile      = Path.Combine(configDirectory, this.Key + ".json");
         if (!File.Exists(configFile))
         {
             return(default);
Ejemplo n.º 2
0
        public void TryCreateTeleporterWatcher(DalamudPluginInterface pi, bool useTeleport)
        {
            const string teleporterPluginConfigFile = "TeleporterPlugin.json";

            _teleporterLanguage = _language;
            if (!useTeleport || _teleporterWatcher != null)
            {
                _teleporterWatcher?.Dispose();
                _teleporterWatcher = null;
                return;
            }

            var dir = new DirectoryInfo(pi.GetPluginConfigDirectory());

            if (!dir.Exists || (dir.Parent?.Exists ?? false))
            {
                return;
            }

            dir = dir.Parent;

            var file = new FileInfo(Path.Combine(dir !.FullName, teleporterPluginConfigFile));

            if (file.Exists)
            {
                ParseTeleporterFile(file.FullName);
            }

            void OnTeleporterConfigChange(object source, FileSystemEventArgs args)
            {
                PluginLog.Verbose("Reloading Teleporter Config.");
                if (args.ChangeType != WatcherChangeTypes.Changed && args.ChangeType != WatcherChangeTypes.Created)
                {
                    return;
                }

                ParseTeleporterFile(args.FullPath);
            }

            _teleporterWatcher = new FileSystemWatcher
            {
                Path         = dir.FullName,
                NotifyFilter = NotifyFilters.LastWrite,
                Filter       = teleporterPluginConfigFile,
            };
            _teleporterWatcher.Changed += OnTeleporterConfigChange;
            _teleporterWatcher !.EnableRaisingEvents = true;
        }
Ejemplo n.º 3
0
        // private TitleScreenMenu _titleScreenMenu;

        public TitleEditPlugin(
            [RequiredVersion("1.0")] DalamudPluginInterface pluginInterface,
            [RequiredVersion("1.0")] CommandManager commandManager,
            [RequiredVersion("1.0")] DataManager dataManager,
            [RequiredVersion("1.0")] ClientState clientState,
            [RequiredVersion("1.0")] Framework framework,
            [RequiredVersion("1.0")] KeyState keyState,
            [RequiredVersion("1.0")] SigScanner sigScanner,
            [RequiredVersion("1.0")] GameGui gameGui,
            [RequiredVersion("1.0")] TitleScreenMenu titleScreenMenu)
        {
            PluginLog.Log("===== T I T L E E D I T =====");
            _pluginInterface = pluginInterface;
            _commandManager  = commandManager;
            _dataManager     = dataManager;
            _clientState     = clientState;
            _framework       = framework;
            _keyState        = keyState;

            // Load menu_icon.png from dll resources
            var assembly       = Assembly.GetExecutingAssembly();
            var resourceStream = assembly.GetManifestResourceStream("TitleEdit.menu_icon.png");

            if (resourceStream != null)
            {
                var imageBytes = new byte[resourceStream.Length];
                resourceStream.Read(imageBytes, 0, (int)resourceStream.Length);
                PluginLog.Information($"image is {imageBytes.Length} bytes");
                try
                {
                    var image = pluginInterface.UiBuilder.LoadImage(imageBytes);
                    titleScreenMenu.AddEntry("Title Edit Menu", image, () => { _isImguiTitleEditOpen = true; });
                }
                catch (Exception e)
                {
                    PluginLog.Error(e, "Title Edit encountered an error loading menu icon");
                }
            }

            _commandManager.AddHandler(TitleEditCommand, new CommandInfo(OnTitleEditCommand)
            {
                HelpMessage = "Display the Title Edit configuration interface."
            });

            _configuration = pluginInterface.GetPluginConfig() as TitleEditConfiguration ?? new TitleEditConfiguration();
            _configuration.Initialize(pluginInterface);

            _titleScreenFolder = _pluginInterface.GetPluginConfigDirectory();
            if (!Directory.Exists(_titleScreenFolder))
            {
                Directory.CreateDirectory(_titleScreenFolder);
            }
            PrepareAssets();
            EnumerateTitleScreenFiles();

            _territoryPaths = dataManager.GetExcelSheet <TerritoryType>()
                              .ToDictionary(row => row.RowId, row => row);
            _weathers = dataManager.GetExcelSheet <Weather>()
                        .ToDictionary(row => row.RowId, row => row.Name.ToString());
            var bgms = dataManager.GetExcelSheet <BGM>()
                       .ToDictionary(row => (ushort)row.RowId, row => row.File.ToString());

            _bgmSheet = new BgmSheetManager(_titleScreenFolder, bgms);

            _titleEdit = new TitleEdit(sigScanner, clientState, gameGui, dataManager, _pluginInterface, _configuration, _titleScreenFolder);
            _titleEdit.Enable();

            _pluginInterface.UiBuilder.Draw += UiBuilder_OnBuildUi;
            _framework.Update += CheckHotkey;
            _pluginInterface.UiBuilder.OpenConfigUi += () => _isImguiTitleEditOpen = true;
            PluginLog.Log("Init complete.");
        }