public MainWindowWindowsManager(
     SettingsManager settingsManager,
     ConsoleSharedSpace consoleSharedSpace)
 {
     _settingsManager    = settingsManager;
     _consoleSharedSpace = consoleSharedSpace;
     _registeredForms    = new Dictionary <string, Form>();
 }
示例#2
0
        public PckViewForm()
        {
            InitializeComponent();

            #region shared space information

            var consoleSharedSpace = new ConsoleSharedSpace(new SharedSpace());
            console              = consoleSharedSpace.GetNewConsole();
            console.FormClosing += delegate(object sender, FormClosingEventArgs e)
            {
                e.Cancel = true;
                console.Hide();
            };
            FormClosed += (sender, e) => console.Close();

            sharedSpace = SharedSpace.Instance;
            sharedSpace.GetObj("PckView", this);
            sharedSpace.GetObj("AppDir", Environment.CurrentDirectory);
            sharedSpace.GetObj("CustomDir", Environment.CurrentDirectory + "/custom");
            sharedSpace.GetObj("SettingsDir", Environment.CurrentDirectory + "/settings");

            xConsole.AddLine("Current directory: " + sharedSpace["AppDir"]);
            xConsole.AddLine("Custom directory: " + sharedSpace["CustomDir"].ToString());
            #endregion

            _totalViewPck      = new TotalViewPck();
            _totalViewPck.Dock = DockStyle.Fill;
            DrawPanel.Controls.Add(_totalViewPck);

            _totalViewPck.View.DoubleClick     += new EventHandler(doubleClick);
            _totalViewPck.ViewClicked          += new PckViewMouseClicked(viewClicked);
            _totalViewPck.XCImageCollectionSet += new XCImageCollectionHandler(v_XCImageCollectionSet);
            _totalViewPck.ContextMenu           = makeContextMenu();

            SaveMenuItem.Visible = false;

            sharedSpace["Palettes"] = new Dictionary <string, Palette>();
            palMI = new Dictionary <Palette, MenuItem>();

            AddPalette(Palette.UFOBattle, miPalette);
            AddPalette(Palette.UFOGeo, miPalette);
            AddPalette(Palette.UFOGraph, miPalette);
            AddPalette(Palette.UFOResearch, miPalette);
            AddPalette(Palette.TFTDBattle, miPalette);
            AddPalette(Palette.TFTDGeo, miPalette);
            AddPalette(Palette.TFTDGraph, miPalette);
            AddPalette(Palette.TFTDResearch, miPalette);

            currPal = Palette.UFOBattle;
//			currPal = Palette.TFTDBattle;

            palMI[currPal].Checked = true;              // kL_ufoPalette
            _totalViewPck.Pal      = currPal;           // kL_ufoPalette

            editor          = new Editor(null);
            editor.Closing += new CancelEventHandler(editorClosing);

            if (editor != null)                                 // kL_ufoPalette
            {
                editor.Palette = currPal;                       // kL_ufoPalette
            }
            RegistryInfo ri = new RegistryInfo(this, "PckView");
            ri.AddProperty("FilterIndex");
            ri.AddProperty("SelectedPalette");

            if (!File.Exists("hq2xa.dll"))
            {
                miHq2x.Visible = false;
            }

            loadedTypes         = new LoadOfType <IXCImageFile>();
            loadedTypes.OnLoad += new LoadOfType <IXCImageFile> .TypeLoadDelegate(loadedTypes_OnLoad);

            sharedSpace["ImageMods"] = loadedTypes.AllLoaded;

//			loadedTypes.OnLoad += new LoadOfType<IXCFile>.TypeLoadDelegate(sortLoaded);

            loadedTypes.LoadFrom(Assembly.GetExecutingAssembly());
            loadedTypes.LoadFrom(Assembly.GetAssembly(typeof(XCom.Interfaces.IXCImageFile)));

            if (Directory.Exists(sharedSpace["CustomDir"].ToString()))
            {
                //Console.WriteLine("Custom directory exists: " + sharedSpace["CustomDir"].ToString());
                xConsole.AddLine("Custom directory exists: " + sharedSpace["CustomDir"].ToString());
                foreach (string s in Directory.GetFiles(sharedSpace["CustomDir"].ToString()))
                {
                    if (s.EndsWith(".dll"))
                    {
                        xConsole.AddLine("Loading dll: " + s);
                        loadedTypes.LoadFrom(Assembly.LoadFrom(s));
                    }
                    else if (s.EndsWith(xcProfile.PROFILE_EXT))
                    {
                        foreach (xcProfile ip in ImgProfile.LoadFile(s))
                        {
                            loadedTypes.Add(ip);
                        }
                    }
                }
            }

            osFilter = new OpenSaveFilter();
            osFilter.SetFilter(IXCImageFile.Filter.Open);

            openDictionary = new Dictionary <int, IXCImageFile>();
            saveDictionary = new Dictionary <int, IXCImageFile>();

            osFilter.SetFilter(IXCImageFile.Filter.Open);
            string filter = loadedTypes.CreateFilter(osFilter, openDictionary);
            openFile.Filter = filter;
        }
 public ConsoleWarningHandler(ConsoleSharedSpace consoleSharedSpace)
 {
     _consoleSharedSpace = consoleSharedSpace;
 }
示例#4
0
        public MainWindow()
        {
            InitializeComponent();

            _mapView = MapViewPanel.Instance;

            _settingsManager   = new SettingsManager();
            _windowMenuManager = new WindowMenuManager(showMenu, miHelp);

            loadDefaults();

            Palette.UFOBattle.SetTransparent(true);
            Palette.TFTDBattle.SetTransparent(true);
            Palette.UFOBattle.Grayscale.SetTransparent(true);
            Palette.TFTDBattle.Grayscale.SetTransparent(true);

            #region Setup SharedSpace information and paths

            var sharedSpace        = SharedSpace.Instance;
            var consoleSharedSpace = new ConsoleSharedSpace(sharedSpace);
            _warningHandler = new ConsoleWarningHandler(consoleSharedSpace);

            MainWindowsManager.MainToolStripButtonsFactory = new MainToolStripButtonsFactory(_mapView);

            _mainWindowsManager       = new MainWindowsManager();
            _mainWindowWindowsManager = new MainWindowWindowsManager(
                _settingsManager,
                consoleSharedSpace);

            var settings = GetSettings();
            _windowMenuManager.SetMenus(consoleSharedSpace.GetNewConsole(), settings);

            MainWindowsManager.MainWindowsShowAllManager = _windowMenuManager.CreateShowAll();
            MainWindowsManager.Initialize();

            sharedSpace.GetObj("MapView", this);
            sharedSpace.GetObj("AppDir", Environment.CurrentDirectory);
            sharedSpace.GetObj("CustomDir", Environment.CurrentDirectory + "/custom");
            sharedSpace.GetObj("SettingsDir", Environment.CurrentDirectory + "/settings");

            var pathsFile    = new PathInfo(SharedSpace.Instance.GetString("SettingsDir"), "Paths", "pth");
            var settingsFile = new PathInfo(SharedSpace.Instance.GetString("SettingsDir"), "MVSettings", "dat");
            var mapeditFile  = new PathInfo(SharedSpace.Instance.GetString("SettingsDir"), "MapEdit", "dat");
            var imagesFile   = new PathInfo(SharedSpace.Instance.GetString("SettingsDir"), "Images", "dat");

            sharedSpace.GetObj("MV_PathsFile", pathsFile);
            sharedSpace.GetObj(SettingsService.FILE_NAME, settingsFile);
            sharedSpace.GetObj("MV_MapEditFile", mapeditFile);
            sharedSpace.GetObj("MV_ImagesFile", imagesFile);

            #endregion

            if (!pathsFile.Exists())
            {
                InstallWindow iw = new InstallWindow();

                if (iw.ShowDialog(this) != DialogResult.OK)
                {
                    Environment.Exit(-1);
                }
            }

            GameInfo.ParseLine += parseLine;

            InitGameInfo(pathsFile);
            LogFile.Instance.WriteLine("GameInfo.Init done");

            _mainWindowWindowsManager.Register();

            MainWindowsManager.TileView.TileViewControl.MapChanged += TileView_MapChanged;

            LogFile.Instance.WriteLine("Palette transparencies set");

            MapViewPanel.ImageUpdate += new EventHandler(update);

            _mapView.Dock = DockStyle.Fill;

            instance = this;

            mapList.TreeViewNodeSorter = new System.Collections.CaseInsensitiveComparer();

            toolStripContainer1.ContentPanel.Controls.Add(_mapView);
            MainWindowsManager.MainToolStripButtonsFactory.MakeToolstrip(toolStrip);
            toolStrip.Enabled = false;
            toolStrip.Items.Add(new ToolStripSeparator());

            LogFile.Instance.WriteLine("Main view window created");
            LogFile.Instance.WriteLine("Default settings loaded");

            try
            {
                _mapView.MapView.CursorSprite = new CursorSprite(GameInfo.CachePck(
                                                                     SharedSpace.Instance.GetString("cursorFile"),
                                                                     "",
                                                                     2,
                                                                     Palette.UFOBattle));
            }
            catch
            {
                try
                {
                    _mapView.MapView.CursorSprite = new CursorSprite(GameInfo.CachePck(
                                                                         SharedSpace.Instance.GetString("cursorFile"),
                                                                         "",
                                                                         4,
                                                                         Palette.TFTDBattle));
                }
                catch
                {
                    _mapView.Cursor = null;
                }
            }

            LogFile.Instance.WriteLine("Cursor loaded");

            initList();

            LogFile.Instance.WriteLine("Map list created");
            LogFile.Instance.WriteLine("Quick help and About created");

            if (settingsFile.Exists())
            {
                _settingsManager.Load(settingsFile.ToString());
                LogFile.Instance.WriteLine("User settings loaded");
            }
            else
            {
                LogFile.Instance.WriteLine("User settings NOT loaded - no settings file to load");
            }

            OnResize(null);
            this.Closing += new CancelEventHandler(closing);

            _lf = new LoadingForm();
            Bmp.LoadingEvent += _lf.Update;

            // I should rewrite the hq2x wrapper for .NET sometime -- not the code it's pretty insane
//			if (!File.Exists("hq2xa.dll"))
            miHq.Visible = false;

//			LogFile.Instance.WriteLine("Loading user-made plugins");

            /****************************************/
            // Copied from PckView
//			loadedTypes = new LoadOfType<IMapDesc>();
//			sharedSpace["MapMods"] = loadedTypes.AllLoaded;

            // There are no currently loadable maps in this assembly so this is more for future use
//			loadedTypes.LoadFrom(Assembly.GetAssembly(typeof(XCom.Interfaces.Base.IMapDesc)));

//			if (Directory.Exists(sharedSpace["CustomDir"].ToString()))
//			{
//				xConsole.AddLine("Custom directory exists: " + sharedSpace["CustomDir"].ToString());
//				foreach (string s in Directory.GetFiles(sharedSpace["CustomDir"].ToString()))
//					if (s.EndsWith(".dll"))
//					{
//						xConsole.AddLine("Loading dll: " + s);
//						loadedTypes.LoadFrom(Assembly.LoadFrom(s));
//					}
//			}
            /****************************************/

            LogFile.Instance.WriteLine("About to show window");
            Show();
            LogFile.Instance.Close();             // TODO: Keep logfile open until the program closes.
        }