public UITabPage (GameConfigDB gameConfigDB , Gtk.ScrolledWindow scrolledWindow , Gtk.Viewport viewport , Gtk.Label label , Gtk.Fixed canvas) { _scrolledWindow = scrolledWindow; _viewport = viewport; _label = label; _canvas = canvas; _canvas.ScrollEvent += OnScrollEvent; _scrolledWindow.ButtonPressEvent += OnMainWindowButtonPressed; _label.Parent.ButtonPressEvent += OnTabButtonPressed; _gameConfigDB = gameConfigDB; _uiSections = new List <UISection>(); Point currentSectionPoint = UISection.DEFAULT_ORIGIN_POINT; foreach (GameConfigSectionDescriptor sectionDescriptor in _gameConfigDB.GetSections()) { UISection newSection = new UISection(this, sectionDescriptor, currentSectionPoint); currentSectionPoint = newSection.GetNextPosition(); _uiSections.Add(newSection); } ResizeCanvas(); }
private void CreateNewTab(GameConfigDB gameConfigDB, bool isInitializing = false) { UITabPage uiTabPage = UITabPageCreator.CreateUICanvasTab(notebook1, gameConfigDB, isInitializing); uiTabPage.OnDeleteTabAcceptEvent += OnDeleteTabAccept; uiTabPage.OnTabSelectedEvent += OnTabSelected; }
private void OnNewTabAcceptButtonPressed(string tabName) { UIUtils.ShutDownWindow(ref _windowAddTab); GamesConfigLoader gamesConfigLoader = MainApp.GetInstance().GetConfig().GetGameConfig(); GameConfigDB newGameConfig = gamesConfigLoader.AddNewGameConfig(tabName); CreateNewTab(newGameConfig); }
protected void OnImportCommandsButtonPress(object sender, EventArgs e) { Gtk.FileChooserDialog fileChooser = new Gtk.FileChooserDialog ("Choose files" , this , FileChooserAction.Open , "Select" , ResponseType.Accept , "Cancel" , ResponseType.Close); Gtk.FileFilter xmlFileFilter = new Gtk.FileFilter(); xmlFileFilter.AddPattern("*.xml"); fileChooser.AddFilter(xmlFileFilter); int response = fileChooser.Run(); if (response == Utils.static_cast <int>(ResponseType.Close)) { UIUtils.ShutDownWindow(ref fileChooser); } else if (response == Utils.static_cast <int>(ResponseType.Accept)) { string fullPath = fileChooser.Filename; UIUtils.ShutDownWindow(ref fileChooser); GameConfigDescriptorLoader loader = new GameConfigDescriptorLoader(fullPath); FileOperationResult fileOperationResult = loader.Load(); if (fileOperationResult.IsSuccess()) { GameConfigDB sourceConfigDB = loader.GetConfig(); UITabPage currentTabPage = GetCurrentTabPage(); GameConfigDB targetConfigDB = currentTabPage.GetGameConfig(); foreach (GameConfigSectionDescriptor sectionDescriptor in sourceConfigDB.GetSections()) { targetConfigDB.AddSection(sectionDescriptor); currentTabPage.AddNewSection(sectionDescriptor); } currentTabPage.RefreshCanvas(); } else { UIUtils.ShutDownWindowSafe(ref _windowPrompt); _windowPrompt = new WindowPrompt(fileOperationResult.GetResult()); _windowPrompt.OnAcceptEvent += OnAlertAccept; _windowPrompt.SetCancelVisible(false); _windowPrompt.Show(); MainApp.GetInstance().MoveWindowToMousePos(_windowPrompt); } } }
public void DeleteGameConfig(GameConfigDB gameConfigDB) { foreach (GameConfigDescriptorLoader loader in _gamesLoader) { if (loader.GetConfig() == gameConfigDB) { loader.DeleteConfig(); _gamesLoader.Remove(loader); return; } } }
public FileOperationResult Export(string fileName, GameConfigDB gameConfigDB) { foreach (GameConfigDescriptorLoader loader in _gamesLoader) { if (loader.GetConfig() == gameConfigDB) { return(loader.Export(fileName)); } } return(new FileOperationResult(false, "not found")); }
public static UITabPage CreateUICanvasTab(Gtk.Notebook parentNotebook, GameConfigDB gameConfigDB, bool isInitializing = false) { Gtk.ScrolledWindow scrolledWindow = new Gtk.ScrolledWindow(); scrolledWindow.Name = "_scrolledWindow" + nextGeneratedTabIndex; scrolledWindow.ShadowType = ((Gtk.ShadowType)(1)); scrolledWindow.ShowAll(); Gtk.Viewport viewport = new Gtk.Viewport(); viewport.ShadowType = ((Gtk.ShadowType)(0)); Gtk.Fixed canvas = new Gtk.Fixed(); canvas.WidthRequest = 800; canvas.HeightRequest = 600; canvas.Name = "_gameCanvas" + nextGeneratedTabIndex; canvas.HasWindow = false; canvas.ShowAll(); viewport.Add(canvas); viewport.ShowAll(); scrolledWindow.Add(viewport); Gtk.Viewport viewportLabel = new Gtk.Viewport(); viewportLabel.ShadowType = ((Gtk.ShadowType)(0)); viewportLabel.WidthRequest = 80; viewportLabel.HeightRequest = 30; Gtk.Label label = new Gtk.Label(); label.Name = "label1"; label.LabelProp = global::Mono.Unix.Catalog.GetString(gameConfigDB.GetName()); label.ShowAll(); viewportLabel.Add(label); if (parentNotebook.NPages <= 0 || isInitializing) { parentNotebook.Add(scrolledWindow); parentNotebook.SetTabLabel(scrolledWindow, viewportLabel); } else { parentNotebook.InsertPage(scrolledWindow, viewportLabel, parentNotebook.NPages - 1); parentNotebook.Page = parentNotebook.NPages - 2; } UITabPage tabPage = new UITabPage(gameConfigDB, scrolledWindow, viewport, label, canvas); tabPage.InitDropEvent(); scrolledWindow.Data.Add("UITabPage", tabPage); return(tabPage); }
public FileOperationResult Load() { try { XmlReader reader = XmlReader.Create(_descriptorFile); while (reader.Read()) { // Only detect start elements. if (reader.IsStartElement()) { // Get element name and switch on it. switch (reader.Name) { case "commands": { _gameConfigDB = new GameConfigDB(); string attribute = reader["name"]; Config.AssertResource(attribute); _gameConfigDB.SetName(attribute); attribute = reader["creationDate"]; Config.AssertResource(attribute); _gameConfigDB.SetCreationDate(Int32.Parse(attribute)); } break; case "section": { if (_currentGameConfigSectionDescriptor != null) { _gameConfigDB.AddSection(_currentGameConfigSectionDescriptor); _currentGameConfigSectionDescriptor = null; } _currentGameConfigSectionDescriptor = new GameConfigSectionDescriptor(); string attribute = reader["tittle"]; Config.AssertResource(attribute); _currentGameConfigSectionDescriptor._tittle = Utils.DecodeHTML(attribute); } break; case "command": { _currentGameConfigButtonDescriptor = new GameConfigButtonDescriptor(); string attribute = reader["type"]; Config.AssertResource(attribute); GameConfigButtonDescriptor.Etype type = Utils.static_cast <GameConfigButtonDescriptor.Etype>(Int32.Parse(attribute)); _currentGameConfigButtonDescriptor._type = type; attribute = reader["tittle"]; Config.AssertResource(attribute); _currentGameConfigButtonDescriptor._tittle = Utils.DecodeHTML(attribute); if (type == GameConfigButtonDescriptor.Etype.MultiCommand) { _currentGameConfigButtonDescriptor._commandList = new List <GameConfigCommandDescriptor>(); } else { attribute = reader["command"]; Config.AssertResource(attribute); _currentGameConfigButtonDescriptor._command = Utils.DecodeHTML(attribute); } if (type == GameConfigButtonDescriptor.Etype.FixedArgument || type == GameConfigButtonDescriptor.Etype.ExposedArgument) { attribute = reader["arguments"]; Config.AssertResource(attribute); _currentGameConfigButtonDescriptor._arguments = Utils.DecodeHTML(attribute); } _currentGameConfigSectionDescriptor._buttons.Add(_currentGameConfigButtonDescriptor); } break; case "command_sequence": { GameConfigCommandDescriptor commandDescriptor = new GameConfigCommandDescriptor(); string attribute = reader["command"]; Config.AssertResource(attribute); commandDescriptor._command = Utils.DecodeHTML(attribute); attribute = reader["arguments"]; Config.AssertResource(attribute); commandDescriptor._arguments = Utils.DecodeHTML(attribute); _currentGameConfigButtonDescriptor._commandList.Add(commandDescriptor); } break; } } } if (_currentGameConfigSectionDescriptor != null) { _gameConfigDB.AddSection(_currentGameConfigSectionDescriptor); _currentGameConfigSectionDescriptor = null; } reader.Close(); return(new FileOperationResult(true)); } catch (System.Exception ex) { return(new FileOperationResult(false, ex.Message)); } }
public void DeleteConfig() { File.Delete(_descriptorFile); _gameConfigDB = null; _descriptorFile = string.Empty; }
public void CreateNew(string name) { _gameConfigDB = new GameConfigDB(); _gameConfigDB.SetName(name); _gameConfigDB.SetCreationDate(GetSecondsFrom1970()); }