/// <summary> /// Crée un stage /// </summary> /// <param name="pWidth"></param> /// <param name="pHeight"></param> /// <returns></returns> public static VO_Stage CreateStage(int width, int height) { //Création de l'objet VO_Stage stage = new VO_Stage(Guid.NewGuid()) { Title = GlobalConstants.STAGE_NEW_STAGE, Dimensions = new Size(width, height), ListLayers = new List <VO_Layer>(), ListHotSpots = new List <VO_StageHotSpot>(), ListRegions = new List <VO_StageRegion>(), Music = new VO_Music(), Color = new VO_ColorTransformation(), EndingFirstScript = CreateScript(Enums.ScriptType.StageEvents), StartingFirstScript = CreateScript(Enums.ScriptType.StageEvents), EndingScript = CreateScript(Enums.ScriptType.StageEvents), StartingScript = CreateScript(Enums.ScriptType.StageEvents), ListCharacters = new List <VO_StageCharacter>(), Region = 100 }; //Insertion de l'objet GameCore.Instance.Game.Stages.Add(stage); //Ajout d'un calque clé CreateLayer(stage, GlobalConstants.STAGE_NEW_LAYER, 0, true); return(stage); }
public static void CreateCharacter(VO_Stage stage, Point position, Guid charId) { if (stage.ListCharacters.Count < GlobalConstants.PERF_MAX_CHARACTERS_PER_LAYERS) { VO_Character character = GameCore.Instance.GetCharacterById(charId); VO_StageCharacter newChar = new VO_StageCharacter(); //Animation standing VO_Animation standingAnim = character.GetAnimationById(character.StandingAnim); newChar.AnimationId = standingAnim.Id; newChar.Id = Guid.NewGuid(); newChar.Title = character.Title; newChar.Location = position; newChar.Size = new Size(standingAnim.SpriteWidth, standingAnim.SpriteHeight); newChar.CharacterId = charId; newChar.ObjectType = Enums.StageObjectType.Characters; newChar.Stage = stage.Id; newChar.PlayerPositionPoint = new VO_Coords(); newChar.Event = CreateEvent(Enums.EventType.Character, character.Id); stage.ListCharacters.Add(newChar); } else { MessageBox.Show(string.Format(Errors.STAGE_MAX_CHARACTERS, GlobalConstants.PERF_MAX_CHARACTERS_PER_LAYERS), Errors.ERROR_BOX_TITLE); } }
/// <summary> /// Charge une matrice de régions /// </summary> /// <param name="dimensions">Dimensions de la scène</param> /// <param name="hotspots">Liste de hotspots</param> /// <param name="matrixPrecision"></param> /// <returns>Matrice d'octets</returns> public void CreateRegionMatrix(VO_Stage stage, System.Drawing.Size dimensions, List <VO_StageRegion> hotspots, int matrixPrecision) { if (!Directory.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes))) { Directory.CreateDirectory(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes)); } StreamWriter sw = new StreamWriter(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_r"); byte[,] matrix = new byte[4096, 4096]; int height = dimensions.Height / matrixPrecision; int width = dimensions.Width / matrixPrecision; for (int y = 0; y <= height; y++) { for (int x = 0; x < width; x++) { matrix[x, y] = (byte)stage.Region; foreach (VO_StageRegion hotspot in hotspots) { if (FormsTools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points))) { matrix[x, y] = (byte)ConvertTools.CastInt(hotspot.Ratio); } } sw.Write(GetValueFromByte(matrix[x, y])); } sw.Write("\r\n"); } sw.Close(); }
/// <summary> /// Charge les informations lourdes du stage /// </summary> public void PreLoadStage(VO_Stage stage, int matrixPrecision) { RunServiceTask(delegate { _Business.PreLoadStage(stage, matrixPrecision); }, ViewerErrors.STAGE_LOAD_MENU, stage.Title, matrixPrecision.ToString()); }
/// <summary> /// Charge un stage en fonction d'un fichier pStage dont le contenu est en mémoire. /// </summary> /// <param name="stage">Nom du fichier stage</param> /// <param name="layer">Id du calque à charger en même temps</param> public void LoadStage(Guid stage, Guid layer) { //Attente Cursor.Current = Cursors.WaitCursor; this.SuspendLayout(); MainSurface.Paint -= new PaintEventHandler(MainSurface_Paint); //Chargement Scène et Calque VO_Stage voStage = GameCore.Instance.GetStageById(stage); EditorHelper.Instance.CurrentStage = stage; EditorHelper.Instance.CurrentLayer = layer; //Redimmenssionnements int stageWidth = (voStage.Dimensions.Width + (2 * EditorSettings.Instance.StagePadding)); int stageHeight = (voStage.Dimensions.Height + (2 * EditorSettings.Instance.StagePadding)); this.Width = stageWidth * EditorHelper.Instance.CurrentZoom; this.Height = stageHeight * EditorHelper.Instance.CurrentZoom; //Mise en mémoire du background. _Service.LoadEmptyBackground(new Size(stageWidth, stageHeight), voStage.Dimensions); //Fin de l'attente MainSurface.Paint += new PaintEventHandler(MainSurface_Paint); this.ResumeLayout(); Cursor.Current = DefaultCursor; RefreshStage(); _PreviousScrollPosition = new Point(); }
/// <summary> /// Charge les décors de la map /// </summary> private Image LoadMapDecors(Guid map) { VO_Stage stage = GameCore.Instance.GetStageById(map); Image output = new Bitmap(stage.Dimensions.Width, stage.Dimensions.Height); Graphics graphics = Graphics.FromImage(output); graphics.FillRectangle(Brushes.Black, new Rectangle(new Point(), stage.Dimensions)); foreach (VO_Layer layer in stage.ListLayers) { LoadNewMatrix(layer); foreach (VO_StageDecor decor in layer.ListDecors) { Image decorImage = ImageManager.GetImageStageDecor(GameCore.Instance.Game.Project.RootPath + GlobalConstants.PROJECT_DIR_RESOURCES + decor.Filename); graphics.DrawImage(decorImage, new Rectangle(decor.Location, decor.Size), 0, 0, decorImage.Width, decorImage.Height, GraphicsUnit.Pixel, _Opacity); } } foreach (VO_Layer layer in stage.ListLayers) { foreach (VO_StageHotSpot hotSpot in layer.ListWalkableAreas) { if (hotSpot.Points.Length > 1) { graphics.FillPolygon(_TransparentFillBrush, (Point[])hotSpot.Points); } } } return(output); }
/// <summary> /// Commande CharSay /// </summary> /// <param name="command"></param> private static void CommandCharSay(string[] command) { if (ScriptManager.CurrentScript == null) { string message = string.Join(" ", command, 3, command.Length - 3); string characterName = command[1]; VO_Stage currentStage = _Service.GetCurrentStage(); VO_StageCharacter character = currentStage.ListCharacters.Find(p => p.Title.ToLower() == characterName); if (character != null) { VO_RunningScript runningScript = new VO_RunningScript(); runningScript.ScriptType = Enums.ScriptType.Events; runningScript.Lines = new List <VO_Line>(); VO_Script_Message messageScript = new VO_Script_Message(); messageScript.Dialog = new VO_Dialog(); messageScript.Dialog.Messages = new List <VO_Message>(); messageScript.Dialog.Messages.Add(new VO_Message() { Character = character.Id, Duration = message.Length, FontSize = 14, Text = message }); runningScript.Lines.Add(messageScript); runningScript.CurrentLine = runningScript.Lines[0]; ScriptManager.CurrentScript = runningScript; } else { AddConsoleLine(string.Format("{0}: {1} not found", ConsoleConstants.C_SAY, command[1])); } } }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection collection = new PropertyDescriptorCollection(null); Stage = (VO_Stage)value; collection = Stage.GetProperties(); return(collection); }
/// <summary> /// Rafraichi le ProjectPanel /// </summary> public void RefreshStageObjectsPanel() { if (EditorHelper.Instance.CurrentStage == Guid.Empty) { StageObjectsTreeView.Nodes.Clear(); return; } StageObjectsTreeView.Nodes.Clear(); VO_Layer currentLayer = EditorHelper.Instance.GetCurrentLayerInstance(); VO_Stage currentStage = EditorHelper.Instance.GetCurrentStageInstance(); switch (EditorHelper.Instance.CurrentStageState) { case Enums.StagePanelState.Decors: foreach (VO_StageDecor decor in currentLayer.ListDecors) { StageObjectsTreeView.Nodes.Add(decor.Id.ToString(), decor.Title, EditorConstants.STAGEOBJECTSPANEL_DECOR_INACTIVE, EditorConstants.STAGEOBJECTSPANEL_DECOR_ACTIVE); } break; case Enums.StagePanelState.Objects: foreach (VO_StageAnimation anim in currentLayer.ListAnimations) { StageObjectsTreeView.Nodes.Add(anim.Id.ToString(), anim.Title, EditorConstants.STAGEOBJECTSPANEL_ANIMATION_INACTIVE, EditorConstants.STAGEOBJECTSPANEL_ANIMATION_ACTIVE); } break; case Enums.StagePanelState.Characters: foreach (VO_StageCharacter character in currentStage.ListCharacters) { StageObjectsTreeView.Nodes.Add(character.Id.ToString(), character.Title, EditorConstants.STAGEOBJECTSPANEL_CHARACTER_INACTIVE, EditorConstants.STAGEOBJECTSPANEL_CHARACTER_ACTIVE); } break; case Enums.StagePanelState.HotSpots: foreach (VO_StageHotSpot decor in currentStage.ListHotSpots) { StageObjectsTreeView.Nodes.Add(decor.Id.ToString(), decor.Title, EditorConstants.STAGEOBJECTSPANEL_HOTSPOT_INACTIVE, EditorConstants.STAGEOBJECTSPANEL_HOTSPOT_ACTIVE); } break; case Enums.StagePanelState.WalkableAreas: foreach (VO_StageHotSpot decor in currentLayer.ListWalkableAreas) { StageObjectsTreeView.Nodes.Add(decor.Id.ToString(), decor.Title, EditorConstants.STAGEOBJECTSPANEL_WALK_INACTIVE, EditorConstants.STAGEOBJECTSPANEL_WALK_ACTIVE); } break; case Enums.StagePanelState.Regions: foreach (VO_StageHotSpot decor in currentStage.ListRegions) { StageObjectsTreeView.Nodes.Add(decor.Id.ToString(), decor.Title, EditorConstants.STAGEOBJECTSPANEL_REGION_INACTIVE, EditorConstants.STAGEOBJECTSPANEL_REGION_ACTIVE); } break; } }
/// <summary> /// La map source change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ddpMap_SelectedIndexChanged(object sender, EventArgs e) { DestinationObject.Map = (Guid)ddpMap.SelectedValue; Guid ensuredMapGuid = Guid.Empty; if (UseStages) { VO_Stage stage = GameCore.Instance.Game.Stages.Find(p => p.Id == DestinationObject.Map); if (stage != null) { ensuredMapGuid = stage.Id; } if (ensuredMapGuid != Guid.Empty) { SourceResolution = GameCore.Instance.GetStageById(DestinationObject.Map).Dimensions; } else { SourceResolution = new Size(GameCore.Instance.Game.Project.Resolution.Width, GameCore.Instance.Game.Project.Resolution.Height); } } this.Preview.Width = SourceResolution.Width; this.Preview.Height = SourceResolution.Height; //Créer le décor if (_StageImage != null) { _StageImage.Dispose(); } if (ensuredMapGuid == Guid.Empty) { Preview.Image = _Service.LoadBackground(new Size(this.Preview.Width, this.Preview.Height), false); } else { _StageImage = LoadMapDecors(ensuredMapGuid); Preview.Image = _StageImage; } //Désactive les eventhandlers ddpX.ValueChanged -= new EventHandler(ddpX_ValueChanged); ddpY.ValueChanged -= new EventHandler(ddpY_ValueChanged); //Binding des infos ddpX.Maximum = SourceResolution.Width - 1; ddpY.Maximum = SourceResolution.Height - 1; DestinationObject.Location = new Point(0, 0); ddpX.Value = 0; ddpY.Value = 0; //Réactive les eventhandlers ddpX.ValueChanged += new EventHandler(ddpX_ValueChanged); ddpY.ValueChanged += new EventHandler(ddpY_ValueChanged); }
/// <summary> /// Récupère une nouvelle instance d'un item /// </summary> /// <param name="id">ID de l'action</param> /// <returns>VO_Action</returns> public VO_Stage GetStageById(Guid id) { VO_Stage stage = Game.Stages.Find(p => p.Id == id); if (stage != null) { return(stage); } return((VO_Stage)ValidationTools.CreateEmptyRessource(new VO_Stage())); }
/// <summary> /// Commande CharSay /// </summary> /// <param name="command"></param> private static void CommandCharMove(string[] command) { if (ScriptManager.CurrentScript == null) { if (command.Length != 5) { AddConsoleLine(string.Format("{0}: coords format is incorrect", ConsoleConstants.C_MOVE)); } else { int x = 0; int y = 0; try { x = Convert.ToInt32(command[3]); } catch { AddConsoleLine(string.Format("{0}: coords format is incorrect", ConsoleConstants.C_MOVE)); return; } try { y = Convert.ToInt32(command[4]); } catch { AddConsoleLine(string.Format("{0}: coords format is incorrect", ConsoleConstants.C_MOVE)); return; } string characterName = command[1]; VO_Stage currentStage = _Service.GetCurrentStage(); VO_StageCharacter character = currentStage.ListCharacters.Find(p => p.Title.ToLower() == characterName); if (character != null) { VO_RunningScript runningScript = new VO_RunningScript(); runningScript.ScriptType = Enums.ScriptType.Events; runningScript.Lines = new List <VO_Line>(); VO_Script_MoveCharacter moveCharacter = new VO_Script_MoveCharacter(); moveCharacter.Character = character.Id; moveCharacter.Coords = new VO_Coords(new System.Drawing.Point(x, y), _Service.GetCurrentStage().Id); runningScript.Lines.Add(moveCharacter); runningScript.CurrentLine = runningScript.Lines[0]; ScriptManager.CurrentScript = runningScript; } else { AddConsoleLine(string.Format("{0}: {1} not found", ConsoleConstants.C_MOVE, command[1])); } } } }
/// <summary> /// Charge une scène /// </summary> /// <param name="id">Id de la scène</param> /// <returns>VO_Stage</returns> public VO_Stage GetStageData(Guid id) { VO_Stage stage = null; RunServiceTask(delegate { stage = _Business.GetStageData(id); }, ViewerErrors.STAGE_LOAD_MENU, id.ToString()); return(stage); }
/// <summary> /// Récupère le stage courant /// </summary> /// <returns></returns> public VO_Stage GetCurrentStage() { VO_Stage stage = null; RunServiceTask(delegate { stage = _Business.GetCurrentStage(); }, ViewerErrors.STAGE_LOAD_MENU, false); return(stage); }
public static bool CheckMapExistence(VO_Coords CurrentValidation) { if (CurrentValidation.Map == Guid.Empty) { return(false); } VO_Stage CurrentStage = GameCore.Instance.GetStageById(CurrentValidation.Map); if (CurrentStage == null || CurrentStage.Id == Guid.Empty) { return(false); } return(true); }
/// <summary> /// Charge une matrice /// </summary> /// <param name="dimensions">Dimensions de la scène</param> /// <param name="hotspots">Liste de hotspots</param> /// <returns>Matrice d'octets</returns> public void LoadWalkableMatrix(System.Drawing.Size dimensions, VO_Stage stage, int matrixPrecision) { if (!_WalkableCreated) { int height = dimensions.Height / matrixPrecision; int width = dimensions.Width / matrixPrecision; if (File.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_w")) { StreamReader myFile = new StreamReader(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_w"); for (int y = 0; y < height; y++) { string line = myFile.ReadLine(); for (int x = 0; x < width; x++) { int nX = 3 * x; _WalkableMatrix[x, y] = Convert.ToByte(line[nX].ToString() + line[nX + 1].ToString() + line[nX + 2].ToString()); } } myFile.Close(); } else { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { _WalkableMatrix[x, y] = 0; byte i = 1; foreach (VO_Layer layer in stage.ListLayers) { foreach (VO_StageHotSpot hotspot in layer.ListWalkableAreas) { if (Tools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points))) { _WalkableMatrix[x, y] = i; break; } } i++; } } } } _WalkAlgo = new PathFinderFast(MatrixManager.CurrentStage.WalkableMatrix); _WalkAlgo.Formula = HeuristicFormula.Manhattan; _WalkAlgo.SearchLimit = ViewerConstants.PATHFINDER_SEARCHLIMIT; _WalkAlgo.Diagonals = true; _WalkableCreated = true; } }
/// <summary> /// Click sur OK /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtTitle.Text)) { MessageBox.Show(Errors.STAGE_TITLE_EMPTY, Errors.ERROR_BOX_TITLE); } else { VO_Stage stage = ObjectsFactory.CreateStage(Convert.ToInt32(ddpWidth.Value), Convert.ToInt32(ddpHeight.Value)); stage.Title = txtTitle.Text; EditorHelper.Instance.CurrentStage = stage.Id; DialogResult = DialogResult.OK; this.Close(); } }
/// <summary> /// Commande Teleport /// </summary> /// <param name="command"></param> private static void CommandTeleport(string[] command) { if (command.Length != 4) { AddConsoleLine(string.Format("{0}: command format is incorrect", ConsoleConstants.C_TELEPORT)); return; } VO_Stage stage = GameCore.Instance.Game.Stages.Find(p => p.Title.ToLower() == command[1]); if (stage != null) { int x = 0; int y = 0; try { x = Convert.ToInt32(command[2]); } catch { AddConsoleLine(string.Format("{0}: coords format is incorrect", ConsoleConstants.C_TELEPORT)); return; } try { y = Convert.ToInt32(command[3]); } catch { AddConsoleLine(string.Format("{0}: coords format is incorrect", ConsoleConstants.C_TELEPORT)); return; } VO_RunningScript runningScript = new VO_RunningScript(); runningScript.ScriptType = Enums.ScriptType.Events; runningScript.Lines = new List <VO_Line>(); VO_Script_Teleport teleportScript = new VO_Script_Teleport(); teleportScript.Coords = new VO_Coords(new System.Drawing.Point(x, y), stage.Id); runningScript.Lines.Add(teleportScript); runningScript.CurrentLine = runningScript.Lines[0]; ScriptManager.CurrentScript = runningScript; } else { AddConsoleLine(string.Format("{0}: stage {1} not found", ConsoleConstants.C_TELEPORT, command[1])); } }
/// <summary> /// Charge un stage en fonction d'un fichier pStage dont le contenu est en mémoire. /// </summary> /// <param name="stage">Nom du fichier stage</param> public void LoadStage(Guid stage) { UnloadStage(); //Chargement Scène et Calque VO_Stage voStage = GameCore.Instance.GetStageById(stage); foreach (VO_Layer layer in voStage.ListLayers) { if (layer.MainLayer) { LoadStage(stage, layer.Id); break; } } }
public static VO_Layer CreateLayer(VO_Stage stage, string pTitle, int pLastOrdinal, bool pMain) { VO_Layer vLayer = new VO_Layer(); vLayer.Id = Guid.NewGuid(); vLayer.MainLayer = pMain; vLayer.Ordinal = pLastOrdinal; vLayer.ColorTransformations = new VO_ColorTransformation(); vLayer.ListAnimations = new List <VO_StageAnimation>(); vLayer.ListWalkableAreas = new List <VO_StageWalkable>(); vLayer.Title = pTitle; vLayer.ListDecors = new List <VO_StageDecor>(); vLayer.Stage = stage.Id; stage.ListLayers.Add(vLayer); return(vLayer); }
/// <summary> /// Load Stage screen /// </summary> public override void LoadScreen() { base.LoadScreen(); #region Debug DebugConsole.InitializeConsole((Viewer)this.Game, _SpriteBatch, _Service); #endregion //Reset de certaines propriétés _Interface.EscapeMenuOpened = false; //Stage _Stage = _Service.GetStageData(CurrentStageGuid); ScriptManager.InitScriptManager(_Service, _Game, _Stage, _Interface, _SpriteBatch); ScriptManager.ScriptDefaultCamera(); //Configuration de l'image manager ImageManager.SetCurrentStage(_Stage.Id); MatrixManager.SetCurrentStage(_Stage.Id); //Chargements graphiques _Service.PreLoadStage(_Stage, _ProjectData.Resolution.MatrixPrecision); //Chargement sauvegarde courante if (GameState.State.CurrentStagePNJ != null) { GameState.LoadGamePNJ(); GameState.State.CurrentStagePNJ = null; } //Musique _Music = PathTools.GetProjectPath(Enums.ProjectPath.Musics) + _Stage.Music.Filename; _MusicFrequency = _Stage.Music.Frequency; //Chargement du perso player float ratio = _Service.GetRatioFromMatrix(PlayableCharactersManager.CurrentPlayerCharacter.CharacterSprite.Location, _ProjectData.Resolution.MatrixPrecision); PlayableCharactersManager.CurrentPlayerCharacter.CharacterSprite.SetScale(new Vector2(ratio, ratio)); PlayableCharactersManager.CurrentPlayerCharacter.CharacterSprite.SetPosition(StartingPosition.X, StartingPosition.Y); PlayableCharactersManager.CurrentPlayerCharacter.CurrentStage = CurrentStageGuid; //Execution du script de démarrage _LaunchedEndingScripts = false; LaunchStartingScript(); }
public static VO_StageHotSpot CreateHotSpot(VO_Stage stage, Point position) { if (stage.ListHotSpots.Count < GlobalConstants.PERF_MAX_HOTSPOT_PER_STAGE) { VO_StageHotSpot newHotSpot = new VO_StageHotSpot(); newHotSpot.Id = Guid.NewGuid(); newHotSpot.Title = GlobalConstants.HOTSPOT_NEW_ITEM; newHotSpot.ObjectType = Enums.StageObjectType.HotSpots; newHotSpot.Stage = stage.Id; newHotSpot.Points = new Point[1]; newHotSpot.Points[0] = position; newHotSpot.Event = CreateEvent(Enums.EventType.Event, newHotSpot.Id); newHotSpot.PlayerPositionPoint = new VO_Coords(); stage.ListHotSpots.Add(newHotSpot); return(newHotSpot); } MessageBox.Show(string.Format(Errors.STAGE_MAX_HOTSPOT, GlobalConstants.PERF_MAX_HOTSPOT_PER_STAGE), Errors.ERROR_BOX_TITLE); return(null); }
public static VO_StageRegion CreateRegion(VO_Stage stage, Point position) { if (stage.ListHotSpots.Count < GlobalConstants.PERF_MAX_REGIONS_PER_STAGE) { VO_StageRegion newHotSpot = new VO_StageRegion(); newHotSpot.Id = Guid.NewGuid(); newHotSpot.Title = GlobalConstants.REGION_NEW_ITEM; newHotSpot.ObjectType = Enums.StageObjectType.Regions; newHotSpot.Stage = stage.Id; newHotSpot.Ratio = GlobalConstants.CHARACTERS_NORMAL_RATIO; newHotSpot.Points = new Point[1]; newHotSpot.Points[0] = position; newHotSpot.Event = null; newHotSpot.PlayerPositionPoint = new VO_Coords(); stage.ListRegions.Add(newHotSpot); return(newHotSpot); } MessageBox.Show(string.Format(Errors.STAGE_MAX_REGION, GlobalConstants.PERF_MAX_REGIONS_PER_STAGE), Errors.ERROR_BOX_TITLE); return(null); }
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { VO_Stage stage = Stage; if (propertyValues["Title"] != null) { stage.Title = propertyValues["Title"].ToString(); } if (propertyValues["Region"] != null) { stage.Region = Convert.ToInt32(propertyValues["Region"]); } if (propertyValues["Music"] != null) { stage.Music = (VO_Music)propertyValues["Music"]; } if (propertyValues["Dimensions"] != null) { stage.Dimensions = (Size)propertyValues["Dimensions"]; } if (propertyValues["EndingScript"] != null) { stage.EndingScript = (VO_Script)propertyValues["EndingScript"]; } if (propertyValues["EndingFirstScript"] != null) { stage.EndingFirstScript = (VO_Script)propertyValues["EndingFirstScript"]; } if (propertyValues["StartingScript"] != null) { stage.StartingScript = (VO_Script)propertyValues["StartingScript"]; } if (propertyValues["StartingFirstScript"] != null) { stage.StartingFirstScript = (VO_Script)propertyValues["StartingFirstScript"]; } return(stage); }
/// <summary> /// Créer matrix walkable /// </summary> /// <param name="dimensions"></param> /// <param name="stage"></param> /// <param name="matrixPrecision"></param> private void CreateWalkableMatrix(System.Drawing.Size dimensions, VO_Stage stage, int matrixPrecision) { if (!Directory.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes))) { Directory.CreateDirectory(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes)); } StreamWriter sw = new StreamWriter(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_w"); byte[,] matrix = new byte[4096, 4096]; int height = dimensions.Height / matrixPrecision; int width = dimensions.Width / matrixPrecision; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { matrix[x, y] = 0; byte i = 1; foreach (VO_Layer layer in stage.ListLayers) { foreach (VO_StageHotSpot hotspot in layer.ListWalkableAreas) { if (FormsTools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points))) { matrix[x, y] = i; break; } } i++; } sw.Write(GetValueFromByte(matrix[x, y])); } sw.Write("\r\n"); } sw.Close(); }
/// <summary> /// Charge les informations lourdes du stage /// </summary> public void PreLoadStage(VO_Stage stage, int matrixPrecision) { _CurrentStage = stage; _Animations = new Dictionary <Guid, VO_AnimatedSprite>(); _Characters = new Dictionary <Guid, VO_CharacterSprite>(); foreach (VO_Layer layer in stage.ListLayers) { //Decors foreach (VO_StageDecor item in layer.ListDecors) { SpriteManager.CreateScreenSprite(item.Id, PathTools.GetProjectPath(Enums.ProjectPath.Resources) + item.Filename, new Vector2(item.Location.X, item.Location.Y), new Rectangle(0, 0, item.Size.Width, item.Size.Height)); //SpriteManager.ChangeScreenSpriteColor(item.Id, layer.ColorTransformations); } //Animations foreach (VO_StageAnimation item in layer.ListAnimations) { _Animations.Add(item.Id, new VO_AnimatedSprite(item.AnimationId, Enums.AnimationType.ObjectAnimation, item.Location.X, item.Location.Y)); _Animations[item.Id].SetColor(layer.ColorTransformations); } } //Characters foreach (VO_StageCharacter item in stage.ListCharacters) { _Characters.Add(item.Id, new VO_CharacterSprite(item)); } //Matrice de déplacement MatrixManager.CurrentStage.LoadWalkableMatrix(stage.Dimensions, stage, matrixPrecision); //Matrice de région MatrixManager.CurrentStage.LoadRegionMatrix(stage.Dimensions, stage.ListRegions, matrixPrecision); //Matrice d'events MatrixManager.CurrentStage.LoadEventsMatrix(stage.Dimensions, stage.ListHotSpots, matrixPrecision); }
public static bool CheckCurrentProjectIntegrity() { #region Check Event Stage Integrity ProjectValid = true; ErrorList = new List <string>(); #region Verification des nécessités de démarrage VO_Project project = GameCore.Instance.Game.Project; VO_PlayableCharacter character = GameCore.Instance.GetPlayableCharacterById(project.StartingCharacter); if (character == null) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STARTING_CHARACTER_NEEDED); ErrorList.Add(FormatedResult); } else { VO_Stage stage = GameCore.Instance.GetStageById(character.CoordsCharacter.Map); if (stage == null) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STARTING_STAGE_NEEDED); ErrorList.Add(FormatedResult); } } if (string.IsNullOrEmpty(project.GuiResource)) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.GUI_SYSTEM_NEEDED); ErrorList.Add(FormatedResult); } #endregion #region Verification des GlobalEvents ErrorList.Add(Culture.Language.ProjectIntegrity.INTEGRITY_DATABASEZONE + "\r\n\r\n"); foreach (VO_GlobalEvent CurrentEvent in GameCore.Instance.Game.GlobalEvents) { #region Verification des pages if (CurrentEvent.Script != null) { if (EventScriptIntegrity(CurrentEvent.Script) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.SCRIPT_GLOBALEVENT, CurrentEvent.Title); ErrorList.Add(FormatedResult); } } #endregion } #endregion #region Verification de GameOver VO_Script GameOverScript = project.GameOver; if (EventScriptIntegrity(GameOverScript) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.SCRIPT_GAMEOVER); ErrorList.Add(FormatedResult); } #endregion #region Verification des Items foreach (VO_Item CurrentItem in GameCore.Instance.Game.Items) { #region Verification des Action sur Item if (CurrentItem.Scripts != null) { foreach (VO_ActionOnItemScript CurrentItemScript in CurrentItem.Scripts) { if (EventScriptIntegrity(CurrentItemScript.Script) == false) { VO_Action CurrentAction = GameCore.Instance.GetActionById(CurrentItemScript.Id); ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.SCRIPT_ITEM, CurrentItem.Title, CurrentAction.Title); ErrorList.Add(FormatedResult); } } } #endregion } #endregion #region Verification des ItemsInteraction foreach (VO_Script CurrentItemInteraction in GameCore.Instance.Game.InteractionScripts) { #region Verification de l'ItemInteraction if (CurrentItemInteraction != null) { if (EventScriptIntegrity(CurrentItemInteraction) == false) { ProjectValid = false; int FoundItem = 0; List <VO_Item> AssociatedItems = new List <VO_Item>(); foreach (VO_Item CurrentItem in GameCore.Instance.Game.Items) { if (CurrentItem.ItemInteraction.Find(p => p.Script == CurrentItemInteraction.Id) != null) { AssociatedItems.Add(CurrentItem); if (FoundItem == 2) { break; } else { FoundItem = FoundItem + 1; } } } string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.SCRIPT_ITEMINTERACTION, AssociatedItems[0].Title, AssociatedItems[1].Title); ErrorList.Add(FormatedResult); } } #endregion } #endregion #region Verification des Personnages de la Database List <VO_PlayableCharacter> PlayableCharacterList = GameCore.Instance.Game.PlayableCharacters; foreach (VO_PlayableCharacter CurrentPlayableCharacter in PlayableCharacterList) { if (ValidationTools.CheckMapExistence(CurrentPlayableCharacter.CoordsCharacter) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.CHECK_PLAYABLECHARACTER_MAP, CurrentPlayableCharacter.Title); ErrorList.Add(FormatedResult); } } #endregion ErrorList.Add("\r\n\r\n" + Culture.Language.ProjectIntegrity.INTEGRITY_STAGE + "\r\n\r\n"); List <VO_Base> StageList = GameCore.Instance.GetStages(); foreach (VO_Stage CurrentStage in StageList) { #region Verification du Script de démarrage (Premiere fois) if (EventScriptIntegrity(CurrentStage.StartingFirstScript) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STAGE_SCRIPT_START_FIRST, CurrentStage.Title); ErrorList.Add(FormatedResult); } #endregion #region Verification du Script de démarrage if (EventScriptIntegrity(CurrentStage.StartingScript) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STAGE_SCRIPT_START, CurrentStage.Title); ErrorList.Add(FormatedResult); } #endregion #region Verification du Script de fin (Premiere fois) if (EventScriptIntegrity(CurrentStage.EndingFirstScript) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STAGE_SCRIPT_END_FIRST, CurrentStage.Title); ErrorList.Add(FormatedResult); } #endregion #region Verification du Script de fin if (EventScriptIntegrity(CurrentStage.EndingScript) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STAGE_SCRIPT_END, CurrentStage.Title); ErrorList.Add(FormatedResult); } #endregion #region Verification des Hotspot foreach (VO_StageHotSpot CurrentHotSpot in CurrentStage.ListHotSpots) { #region Verification des pages if (CurrentHotSpot.Event != null) { foreach (VO_Page CurrentPage in CurrentHotSpot.Event.PageList) { #region Verification du Script Courant if (EventScriptIntegrity(CurrentPage.Script) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STAGE_SCRIPT_HOTSPOT, CurrentStage.Title, CurrentHotSpot.Title, CurrentPage.PageNumber + 1); ErrorList.Add(FormatedResult); } #endregion } } #endregion } #endregion #region Verification des Personnages foreach (VO_StageCharacter CurrentCharacter in CurrentStage.ListCharacters) { #region Verification des pages if (CurrentCharacter.Event != null) { foreach (VO_Page CurrentPage in CurrentCharacter.Event.PageList) { #region Verification du Script Courant if (EventScriptIntegrity(CurrentPage.Script) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.STAGE_SCRIPT_CHARACTER, CurrentStage.Title, CurrentCharacter.Title, CurrentPage.PageNumber + 1); ErrorList.Add(FormatedResult); } #endregion } } #endregion } #endregion #region Verification des Animation foreach (VO_Layer CurrentLayer in CurrentStage.ListLayers) { #region Verification des pages List <VO_StageAnimation> StageAnimationList = CurrentLayer.ListAnimations; if (StageAnimationList != null) { foreach (VO_StageAnimation CurrentStageAnimation in StageAnimationList) { foreach (VO_Page CurrentPage in CurrentStageAnimation.Event.PageList) { #region Verification du Script Courant if (EventScriptIntegrity(CurrentPage.Script) == false) { ProjectValid = false; string FormatedResult = System.String.Format(Culture.Language.ProjectIntegrity.SCRIPT_ANIMATION, CurrentStage.Title, CurrentLayer.Title, CurrentStageAnimation.Title, CurrentPage.PageNumber); ErrorList.Add(FormatedResult); } #endregion } } } #endregion } #endregion } #endregion return(ProjectValid); }
/// <summary> /// Sauvegarde une partie /// </summary> /// <param name="path"></param> public static void SaveGameState(string path) { //Enregistrement des personnages List <VO_Player> players = PlayableCharactersManager.GetPlayers(); State.Players = new List <VO_GameStateCharacter>(); foreach (VO_Player player in players) { VO_GameStateCharacter gameCharacter = new VO_GameStateCharacter(); gameCharacter.Id = player.Id; gameCharacter.CharacterId = player.CharacterSprite.CharacterId; gameCharacter.Coords = new VO_Coords(new System.Drawing.Point(player.CharacterSprite.Location.X, player.CharacterSprite.Location.Y), player.CurrentStage); gameCharacter.CurrentAnim = player.CharacterSprite.CurrentAnimationType; gameCharacter.CurrentDirection = player.CharacterSprite.CurrentDirection; gameCharacter.Actions = new List <Guid>(); gameCharacter.Items = new List <Guid>(); gameCharacter.CurrentExecutingPage = player.CharacterSprite.CurrentExecutingPage; gameCharacter.IsTalking = player.CharacterSprite.IsTalking; gameCharacter.CurrentPath = player.CharacterSprite.CurrentPath; foreach (Guid action in player.Actions) { gameCharacter.Actions.Add(action); } for (int i = 0; i < GameCore.Instance.Game.Menu.GridHeight; i++) { for (int j = 0; j < GameCore.Instance.Game.Menu.GridWidth; j++) { if (player.Items[j, i] != Guid.Empty) { gameCharacter.Items.Add(player.Items[j, i]); } } } GameState.State.Players.Add(gameCharacter); } //Enregistrement de stages VO_Stage stage = GameCore.Instance.GetStageById(PlayableCharactersManager.CurrentPlayerCharacter.CurrentStage); State.CurrentStagePNJ = new List <VO_GameStateCharacter>(); foreach (VO_StageCharacter character in stage.ListCharacters) { VO_CharacterSprite characterSprite = _Service.GetCharacterSprite(character.Id); VO_GameStateCharacter gameCharacter = new VO_GameStateCharacter(); gameCharacter.Id = character.Id; gameCharacter.CharacterId = character.CharacterId; gameCharacter.Coords = new VO_Coords(new System.Drawing.Point(characterSprite.Location.X, character.Location.Y), Guid.Empty); gameCharacter.CurrentAnim = characterSprite.CurrentAnimationType; gameCharacter.CurrentDirection = characterSprite.CurrentDirection; gameCharacter.Actions = new List <Guid>(); gameCharacter.Items = new List <Guid>(); gameCharacter.CurrentExecutingPage = characterSprite.CurrentExecutingPage; gameCharacter.IsTalking = characterSprite.IsTalking; gameCharacter.CurrentPath = characterSprite.CurrentPath; GameState.State.CurrentStagePNJ.Add(gameCharacter); } //Enregistrement des Script courants if (ScriptManager.ParallelScripts != null) { foreach (VO_RunningScript runningScript in ScriptManager.ParallelScripts) { VO_GameStateRunningScript runningScriptState = new VO_GameStateRunningScript(); runningScriptState.CurrentLine = runningScript.Id; runningScriptState.ObjectState = runningScript.ObjectState; runningScriptState.Script = runningScript.Id; runningScriptState.WaitFrames = runningScript.WaitFrames; State.RunningScripts.Add(runningScriptState); } } AppTools.SaveObjectToFile(GameState.State, GameCore.Instance.Game.Project.RootPath + "\\" + path); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (IsAdd == true) { CurrentCharacterId = Guid.Empty; } ddpMovements.SelectedIndexChanged += new EventHandler(ddpMovements_SelectedIndexChanged); //Character List VO_Stage CurrentStage = GameCore.Instance.GetStageById(EditorHelper.Instance.CurrentStage); cmbCharacterSelection.Items.Clear(); cmbCharacterSelection.DisplayMember = "Title"; cmbCharacterSelection.ValueMember = "Id"; cmbCharacterSelection.Enabled = true; foreach (VO_StageCharacter item in CurrentStage.ListCharacters) { cmbCharacterSelection.Items.Add(item); cmbCharacterSelection.SelectedItem = item; } if (cmbCharacterSelection.Items.Count <= 0) { cmbCharacterSelection.Enabled = false; return; } if (IsAdd == false) { foreach (VO_StageCharacter CurrentCharacter in CurrentStage.ListCharacters) { if (CurrentCharacter.Id == CurrentCharacterId) { cmbCharacterSelection.SelectedItem = CurrentCharacter; } } } // Movement List List <VO_ListItem> list = FormsTools.GetMovementsList(); ddpMovements.Items.Clear(); ddpMovements.DisplayMember = "Title"; ddpMovements.ValueMember = "Id"; int i = 0; foreach (VO_ListItem item in list) { ddpMovements.Items.Add(item); if (item.Id == (int)Direction) { ddpMovements.SelectedItem = item; } i++; } ddpMovements.SelectedIndexChanged += new EventHandler(ddpMovements_SelectedIndexChanged); }
/// <summary> /// Survient à l'ouverture de la fenetre /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); //Maximiser l'écran this.WindowState = FormWindowState.Maximized; this.Stop(); //Si UseStages, UseStageBackground doit être activé. if (UseStages) { UseStageBackground = true; } //Désactive les eventhandlers ddpX.ValueChanged -= new EventHandler(ddpX_ValueChanged); ddpY.ValueChanged -= new EventHandler(ddpY_ValueChanged); if (UseStages) { ddpMap.SelectedIndexChanged -= new EventHandler(ddpMap_SelectedIndexChanged); } //Adapter la preview à la taille de la resolution source DestinationObject = new VO_Coords(); Guid ensuredMapGuid = Guid.Empty; if (UseStages) { LoadStages(); DestinationObject = new VO_Coords(SourceFullObject.Location, SourceFullObject.Map); VO_Stage stage = GameCore.Instance.Game.Stages.Find(p => p.Id == SourceFullObject.Map); if (stage != null) { ensuredMapGuid = stage.Id; } if (ensuredMapGuid != Guid.Empty) { SourceResolution = GameCore.Instance.GetStageById(SourceFullObject.Map).Dimensions; } else { SourceResolution = new Size(GameCore.Instance.Game.Project.Resolution.Width, GameCore.Instance.Game.Project.Resolution.Height); } SourceObject = new Rectangle(SourceFullObject.Location, new Size(SourceObject.Width, SourceObject.Height)); } else if (UseStageBackground) { SourceResolution = EditorHelper.Instance.GetCurrentStageInstance().Dimensions; } this.Preview.Width = SourceResolution.Width; this.Preview.Height = SourceResolution.Height; //Créer le décor if (_StageImage != null) { _StageImage.Dispose(); } if (ensuredMapGuid != Guid.Empty) { _StageImage = LoadMapDecors(ensuredMapGuid); Preview.Image = _StageImage; } else if (UseStageBackground && EditorHelper.Instance.CurrentStage != Guid.Empty) { _StageImage = LoadMapDecors(EditorHelper.Instance.CurrentStage); Preview.Image = _StageImage; } else { Preview.Image = _Service.LoadBackground(new Size(this.Preview.Width, this.Preview.Height), false); } //Si Anim, on lance un timer if (UseAnimations) { _CurrentSprite.Width = this.SourceAnim.SpriteWidth; _CurrentSprite.Height = this.SourceAnim.SpriteHeight; _CurrentSprite.X = 0; _CurrentSprite.Y = 0; this.Start(); } //Gère map ou non if (UseStages) { grpMaps.Visible = true; btnCancel.Location = new Point(97, 270); btnOK.Location = new Point(13, 270); } else { grpMaps.Visible = false; btnCancel.Location = new Point(97, 188); btnOK.Location = new Point(13, 188); } //Destination = source if (SourceObject.X > SourceResolution.Width - 1 || SourceObject.Y > SourceResolution.Height - 1) { SourceObject = new Rectangle(0, 0, SourceObject.Width, SourceObject.Height); } DestinationObject.Location = new Point(SourceObject.X, SourceObject.Y); //Binding des infos ddpX.Minimum = 0; ddpY.Minimum = 0; ddpX.Maximum = SourceResolution.Width - 1; ddpY.Maximum = SourceResolution.Height - 1; ddpX.Value = DestinationObject.Location.X; ddpY.Value = DestinationObject.Location.Y; //Réactive les eventhandlers ddpX.ValueChanged += new EventHandler(ddpX_ValueChanged); ddpY.ValueChanged += new EventHandler(ddpY_ValueChanged); if (UseStages) { ddpMap.SelectedIndexChanged += new EventHandler(ddpMap_SelectedIndexChanged); } }