private void HandleClosing() { if (editLvlEditor.IsLoaded) { DialogResult dr = MessageBox.Show( "Closing the editor makes you lose the unsaved progress of your previous level.\n" + "\"Yes\" will save your level, \"No\" will make you lose the unsaved progress, \"Cancel\" will not quit the editor.", "Saving current level?", MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { if (editLvlEditor.IsABonusLevel) { editLvlEditor.SaveCurLevel(GameApp.CurDir() + @"\BONUSLEVELS"); } else { editLvlEditor.SaveCurLevel(GameApp.CurDir() + @"\LEVELS"); } } else if (dr == DialogResult.Cancel) { return; } } Application.Exit(); }
private static void pickLevel() { tryFileName = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.AddExtension = false; ofd.DefaultExt = ".bin"; ofd.Filter = "binary files (*.bin) | *.bin"; ofd.FilterIndex = 1; ofd.ReadOnlyChecked = true; ofd.ValidateNames = true; ofd.Title = "Pick a level"; ofd.RestoreDirectory = true; ofd.InitialDirectory = GameApp.CurDir() + GameConstraints.OtherPaths.Levels + @"\"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { string bonDir = GameApp.CurDir() + GameConstraints.OtherPaths.Bonuses + @"\"; string lvlDir = GameApp.CurDir() + GameConstraints.OtherPaths.Levels + @"\"; if ((ofd.FileName.StartsWith(bonDir) || ofd.FileName.StartsWith(lvlDir)) && ofd.FileName.EndsWith(".bin")) { int lastSlash = ofd.FileName.LastIndexOf(@"\"); tryFileName = ofd.FileName.Substring(lastSlash + 1); } else { MessageBox.Show("Il file deve essere in formato .bin e deve stare nei seguenti path:\n- " + bonDir + "\n- " + lvlDir); } } }
private void LoadEntireTheme(string Theme) { if (Theme != null && Theme != "") { if (GameConstraints.GameThemes.ThemeLogicDirectories.Contains(Theme)) { int i = GameConstraints.GameThemes.ThemeLogicDirectories.IndexOf(Theme); string realPath = GameApp.CurDir() + GameConstraints.GameThemes.ThemePaths.ElementAt <string>(i) + "\\"; string logicPath = Theme; if (!root.ContainsDirectory(logicPath)) { root.NewDirectory(logicPath); } loadMediaFiles(logicPath, realPath); if (!IsCaching) { AddThemeToKeep(Theme); } } else { throw new Exception(Theme + " theme is not known!"); } } }
private void tsmiSaveLevel_Click(object sender, EventArgs e) { if (editLvlEditor.IsLoaded) { if (editLvlEditor.IsABonusLevel) { if (editLvlEditor.SaveCurLevel(GameApp.CurDir() + @"\BONUSLEVELS")) { lblMessageViewer.Text = "Bonus level saved."; } else { lblMessageViewer.Text = "Bonus level saving aborted."; } } else { if (editLvlEditor.SaveCurLevel(GameApp.CurDir() + @"\LEVELS")) { lblMessageViewer.Text = "Regular level saved."; } else { lblMessageViewer.Text = "Regular level saving aborted."; } } } else { lblMessageViewer.Text = "Level Save aborted: no levels to save."; } }
/// <summary> /// Carica un file con un dialog che parte dal path specificato. /// </summary> /// <param name="path">Path da cui partirà il dialog.</param> /// <returns></returns> public bool LoadNewLevel(string loadPath) { if (!isLoaded) { return(LoadLevel(loadPath)); } else { DialogResult dr = MessageBox.Show( "Loading another level makes you lose the unsaved progress of your previous level.\n" + "\"Yes\" will save your level, \"No\" will make you lose the unsaved progress, \"Cancel\" will not load another level.", "Saving current level?", MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { if (this.IsABonusLevel) { SaveLevel(GameApp.CurDir() + @"\BONUSLEVELS"); } else { SaveLevel(GameApp.CurDir() + @"\LEVELS"); } return(LoadLevel(loadPath)); } else if (dr == DialogResult.No) { return(LoadLevel(loadPath)); } else { return(false); } } }
private void btnSpecificProp7_Click(object sender, EventArgs e) { if (editLvlEditor.Mode == EditorMode.LvlPropMode) { OpenFileDialog d = new OpenFileDialog(); d.AddExtension = false; d.DefaultExt = ".bin"; d.Filter = "binary files (*.bin) | *.bin"; d.FilterIndex = 1; d.InitialDirectory = GameApp.CurDir() + @"\LEVELS"; d.RestoreDirectory = true; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtSpecificProp7.Text = d.SafeFileName; } else { txtSpecificProp7.Text = ""; R.r("The level has been unbound. It hasn't now any next level.\n"); } PrepareToLvlProp(); } else if (editLvlEditor.Mode == EditorMode.InsertMode || editLvlEditor.Mode == EditorMode.SelectMode) { } }
/// <summary> /// Inizializza una schermata iniziale a partire dall'id da attribuire /// </summary> /// <param name="ID">byte da attribuire alla schermata iniziale</param> public BeginScreen(byte ID) { string ImgPath = GameApp.CurDir() + GameConstraints.BeginScreen.Path; this.ConstructorsMutualPart(ImgPath + @"\Background.bmp", ID); this.loadAudio(ImgPath + @"\loop.mp3"); }
/// <summary> /// Restituisce un menù di pausa che sarà collegato al contenitore di scene. /// </summary> /// <param name="sc">Contenitore di scene da collegare al menù di pausa.</param> public PauseMenu(SceneContainer sc) { curPath = GameApp.CurDir() + GameConstraints.PauseMenu.Path; curName = GameConstraints.PauseMenu.LogicDir; GameMenuMutualPart(sc); ItemsSetup(); updateText(); LoadAndGatherResources(); }
private void tsmiOpenBonus_Click(object sender, EventArgs e) { if (editLvlEditor.LoadNewLevel(GameApp.CurDir() + @"\BONUSLEVELS")) { lblMessageViewer.Text = "Bonus level loaded: editor ready."; } else { lblMessageViewer.Text = "Bonus level loading aborted."; } }
private void GameScreenLoading() { ResourceDirectory root = this.container.getResourceDirectory; string itsPath = GameApp.CurDir() + GameConstraints.GameScreen.Path; string itsName = GameConstraints.GameScreen.LogicDir; root.NewDirectory(itsName); loadMediaFiles(itsName, itsPath + @"\"); game = new GameScreen(container); container.addScene(GameConstraints.GameScreen.ID, game); }
private void tsmiNewLevel_Click(object sender, EventArgs e) { if (editLvlEditor.NewKulaLevel(GameApp.CurDir())) { lblMessageViewer.Text = "New level created: editor ready."; } else { lblMessageViewer.Text = "New level creation aborted."; } }
private void ConstructorsMutualPart(SceneContainer sc) { Container = sc; ResourceDirectory root = sc.getResourceDirectory; string itsPath = GameApp.CurDir() + GameConstraints.LoadingScreen.Path; string itsName = GameConstraints.LoadingScreen.LogicDir; root.NewDirectory(itsName); loadMediaFiles(itsName, itsPath + @"\"); remainingLoadingLevels = 10; timer = new Stopwatch(); layers = new List <Bitmap>(); loader = new BackgroundWorker(); isActive = false; loader.DoWork += loader_DoWork; loader.RunWorkerCompleted += loader_RunWorkerCompleted; ImageResourceItem a = (ImageResourceItem)Container.getResourceDirectory.GetFile(GameConstraints.LoadingScreen.LogicDir, "Background.bmp"); if (a != null) { Bitmap img = a.Content; layers.Add(GameApp.ResizeImg(img, 800, 600)); } SoundResourceItem s = (SoundResourceItem)Container.getResourceDirectory.GetFile(GameConstraints.LoadingScreen.LogicDir, "loop.mp3"); bgMusic = s.Content; table = (LoadResourceItem)sc.getResourceDirectory.GetFile ( GameConstraints.OtherPaths.MetadataLogicDir, GameConstraints.OtherPaths.LoaderResourceName ); table.IsBatchLoading = true; table.IsCaching = false; table.SetNextNormalLevelToLoad(FileNames.FirstLevelFilename); foreach (string bonLvl in FileNames.AllBonusLevelsFileName) { table.SetNextBonusLevelToLoad(bonLvl); table.ProcessBonusLevel(); } loader_DoWork(null, null); table.IsCaching = true; progress = 0; }
/// <summary> /// Imposta il filename del prossimo livello bonus da caricare. /// </summary> /// <param name="name">Filename del prossimo livello bonus da caricare</param> public void SetNextBonusLevelToLoad(string name) { if (name == null) { return; } else { nextBonusToLoad = new ResourceInfo( GameConstraints.OtherPaths.BonusLevelsDir, name, GameApp.CurDir() + GameConstraints.OtherPaths.Bonuses + "\\" + name ); } }
/// <summary> /// Crea un menù principale di gioco a partire dal contenitore di scene /// </summary> /// <param name="sc">Contenitore di scene a cui collegare la scena corrente</param> public GameMainMenu(SceneContainer sc) { curPath = GameApp.CurDir() + GameConstraints.GameMainMenu.Path; curName = GameConstraints.GameMainMenu.LogicDir; GameMenuMutualPart(sc); ItemsSetup(); updateText(); LoadAndGatherResources(); LoadingScreenSetup(); GameScreenLoading(); PauseMenuLoading(); ResourceDirectory root = this.container.getResourceDirectory; HighScoresResourceItem hsri = (HighScoresResourceItem)root.GetFile(GameConstraints.OtherPaths.MetadataLogicDir, FileNames.HighscoresFileName); tabellone = hsri.Content; }
//Costruttori /// <summary> /// Resitituisce un livello utilizzando i due file utili per definirlo. Inoltre va specificato se il livello è un bonus o no. /// (Se è bonus, i files vengono cercati in «CurrentDir»\BONUSLEVELS, altrimenti in «CurrentDir»\LEVELS) /// </summary> /// <param name="filesname">Nome dei due file da cercare, estensione esclusa. (I due file devono quindi avere lo stesso nome)</param> /// <param name="isBonus">True se e solo se il livello è un bonus</param> public KulaLevel(string filesname, bool isBonus) { string gameDir = GameApp.CurDir(); string folder; if (isBonus) { folder = GameConstraints.OtherPaths.Bonuses + "\\"; } else { folder = GameConstraints.OtherPaths.Levels + "\\"; } string filename = gameDir + folder + filesname; tryLoadLevel(filename); }
/// <summary> /// Salva lo stato del tabellone dei punteggi alti nella memoria secondaria: se ciò ha successo viene restituito true /// </summary> /// <returns></returns> public bool SaveHighscores() { //Prima, sistemo il tabellone while (records.Count > length) { records.Remove(records.Max); } try { Stream saver = File.Create(GameApp.CurDir() + "\\" + FileNames.HighscoresFileName); //Preparo lo stream dove scrivere BinaryFormatter serz = new BinaryFormatter(); //Preparo il serializzatore serz.Serialize(saver, this); //Scrivo l'oggetto serializzato nel file saver.Close(); saver.Dispose(); } catch (Exception e) { MessageBox.Show("Sembrano esserci problemi nel salvataggio, infatti l'eccezione scaturita dice: \n" + e.ToString()); return(false); } return(true); }
/// <summary> /// Restituisce un oggetto tabellone dalla memoria secondaria: se non ci fosse il file, viene restiuito un nuovo oggetto /// </summary> /// <returns></returns> public static Highscores LoadHighscores() { Highscores ret = null; string scoretable = GameApp.CurDir() + "\\" + FileNames.HighscoresFileName; if (File.Exists(scoretable)) { try { Stream loader = File.OpenRead(scoretable); BinaryFormatter deserz = new BinaryFormatter(); ret = (Highscores)deserz.Deserialize(loader); loader.Close(); loader.Dispose(); return(ret); } catch (Exception e) { MessageBox.Show("Sembrano esserci problemi nel caricamento, infatti l'eccezione scaturita dice: \n" + e.ToString()); } } return(new Highscores()); }
/// <summary> /// Imposta il filename del successivo livello da caricare. /// </summary> /// <param name="name">Stringa che rappresenta il filename del livello successivo da caricare.</param> public void SetNextNormalLevelToLoad(string name) { if (name == null) { return; } else if (IsCaching) { nextNormalToLoad = new ResourceInfo( GameConstraints.OtherPaths.CachedLevelsDir, name, GameApp.CurDir() + GameConstraints.OtherPaths.Levels + "\\" + name ); } else if (!IsCaching) { nextNormalToLoad = new ResourceInfo( GameConstraints.OtherPaths.PermanentLevelsDir, name, GameApp.CurDir() + GameConstraints.OtherPaths.Levels + "\\" + name ); } }
/// <summary> /// Gestisce la scelta di un item del menù /// </summary> /// <param name="chosen">Menuitem scelto</param> protected override void HandleChoice(MenuItem chosen) { base.HandleChoice(chosen); if (chosen != null) { string dscr = chosen.description; switch (dscr) { case ("Back"): { this.AscendMenu(); break; } case ("FPS Ceiling"): { this.container.ChangeFPSCap((byte)chosen.int32Value.Value); break; } case ("Music"): { this.container.VolumeMusic = chosen.int32Value.Value; if (bgMusic != null) { bgMusic.PlayLooping(this.container.VolumeMusic); } break; } case ("Sound Effects"): { this.container.VolumeFX = chosen.int32Value.Value; if (selectSound != null) { selectSound.SetVolume(this.container.VolumeFX); } break; } case ("Try Level"): { //TOCHECK Thread t = new Thread(pickLevel); //Creo un thread in sta, sarà lui a gestirmi il dialog t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); string lvl = tryFileName; if (lvl != null) { game.NewGame(lvl, true); this.Container.changeScene(GameConstraints.GameScreen.ID); } break; } case ("Level Editor"): { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = GameApp.CurDir() + "\\LvlEditor.exe"; psi.WindowStyle = ProcessWindowStyle.Normal; psi.CreateNoWindow = false; MessageBox.Show("Now starting the level editor: the game is now shutting down."); System.Diagnostics.Process.Start(psi); Application.Exit(); break; } case ("New Game"): { game.NewGame(); this.container.changeScene(GameConstraints.GameScreen.ID); break; } case ("High Scores"): { tabellone.ShowHighscores(); break; } } } }