public void MouseDown(MouseEventArgs e, RoomEditorState state) { int xClick = (e.X + state.ScrollOffsetX) / state.ScaleFactor; int yClick = (e.Y + state.ScrollOffsetY) / state.ScaleFactor; _selectedCharacter = null; foreach (Character character in _game.Characters) { if (_room.Number == character.StartingRoom) { AgsView view = _game.FindViewByID(character.NormalView); if (view != null && view.Loops.Count > 0) { SelectCharacter(view, character, xClick, yClick, state); } } } if (_selectedCharacter != null) { Factory.GUIController.SetPropertyGridObject(_selectedCharacter); } else { Factory.GUIController.SetPropertyGridObject(_room); } }
private void SelectCharacter(AgsView view, Character character, int xClick, int yClick, RoomEditorState state) { int spriteNum = 0; if (view.Loops[0].Frames.Count > 0) { ViewFrame thisFrame = view.Loops[0].Frames[0]; spriteNum = thisFrame.Image; } int width = GetSpriteWidthForGameResolution(spriteNum); int height = GetSpriteHeightForGameResolution(spriteNum); if ((xClick >= character.StartX - (width / 2)) && (xClick < character.StartX + (width / 2)) && (yClick >= character.StartY - height) && (yClick < character.StartY)) { if (!state.DragFromCenter) { _offsetX = xClick - character.StartX; _offsetY = yClick - character.StartY; } else { _offsetX = 0; _offsetY = 0; } _selectedCharacter = character; _movingCharacter = true; } }
private void DrawCharacter(Character character, RoomEditorState state) { AgsView view = _game.FindViewByID(character.NormalView); if (view != null && view.Loops.Count > 0) { int scale = state.ScaleFactor; int spriteNum = 0; //this is a check to make certain that loop 0 frame 0 of the character normalview has an image; //if not, it defaults to using spriteNum 0 if (view.Loops[0].Frames.Count > 0) { ViewFrame thisFrame = view.Loops[0].Frames[0]; spriteNum = thisFrame.Image; } int xPos = AdjustXCoordinateForWindowScroll(character.StartX, state); // character.StartX* scale; int yPos = AdjustYCoordinateForWindowScroll(character.StartY, state); // character.StartY* scale; int spriteWidth = GetSpriteWidthForGameResolution(spriteNum) * scale; // Factory.NativeProxy.GetRelativeSpriteWidth(spriteNum) * scale; int spriteHeight = GetSpriteHeightForGameResolution(spriteNum) * scale; // Factory.NativeProxy.GetRelativeSpriteHeight(spriteNum) * scale; Factory.NativeProxy.DrawSpriteToBuffer(spriteNum, xPos - spriteWidth / 2, yPos - spriteHeight, scale); } }
private void DrawCharacter(Character character, RoomEditorState state) { AgsView view = _game.FindViewByID(character.NormalView); if (view != null && view.Loops.Count > 0) { int spriteNum = 0; //this is a check to make certain that loop 0 frame 0 of the character normalview has an image; //if not, it defaults to using spriteNum 0 if (view.Loops[0].Frames.Count > 0) { ViewFrame thisFrame = view.Loops[0].Frames[0]; spriteNum = thisFrame.Image; } int xPos = state.RoomXToWindow(character.StartX); int yPos = state.RoomYToWindow(character.StartY); int spriteWidth, spriteHeight; Utilities.GetSizeSpriteWillBeRenderedInGame(spriteNum, out spriteWidth, out spriteHeight); spriteWidth = state.RoomSizeToWindow(spriteWidth); spriteHeight = state.RoomSizeToWindow(spriteHeight); Factory.NativeProxy.DrawSpriteToBuffer(spriteNum, xPos - spriteWidth / 2, yPos - spriteHeight, state.Scale); } }
private void PopulateLoopList(int selectedLoopNumber) { int numLoops = DEFAULT_LOOPS_IN_VIEW; AGS.Types.View selectedView = Factory.AGSEditor.CurrentGame.FindViewByID(_viewNumber); if (selectedView != null) { numLoops = Math.Max(selectedView.Loops.Count, numLoops); } cmbLoop.Items.Clear(); for (int i = 0; i < numLoops; i++) { string description = string.Empty; if (i < ViewLoop.DirectionNames.Length) { description = "(" + ViewLoop.DirectionNames[i] + ")"; } cmbLoop.Items.Add("Loop " + i + " " + description); } if (selectedLoopNumber < cmbLoop.Items.Count) { cmbLoop.SelectedIndex = selectedLoopNumber; } else { cmbLoop.SelectedIndex = 0; } }
private void SelectCharacter(AgsView view, Character character, int xClick, int yClick, RoomEditorState state) { int spriteNum = 0; if (view.Loops[0].Frames.Count > 0) { ViewFrame thisFrame = view.Loops[0].Frames[0]; spriteNum = thisFrame.Image; } int width = GetSpriteWidthForGameResolution(spriteNum); int height = GetSpriteHeightForGameResolution(spriteNum); if ((xClick >= character.StartX - (width / 2)) && (xClick < character.StartX + (width / 2)) && (yClick >= character.StartY - height) && (yClick < character.StartY)) { if (!state.DragFromCenter) { _mouseOffsetX = xClick - character.StartX; _mouseOffsetY = yClick - character.StartY; } else { _mouseOffsetX = 0; _mouseOffsetY = 0; } _selectedCharacter = character; _movingCharacterWithMouse = true; } }
private Character GetCharacter(int x, int y, RoomEditorState state) { foreach (Character character in _game.RootCharacterFolder.AllItemsFlat) { if (_room.Number != character.StartingRoom) { continue; } if (!VisibleItems.Contains(character.ScriptName) || LockedItems.Contains(character.ScriptName)) { continue; } AgsView view = _game.FindViewByID(character.NormalView); if (view != null && view.Loops.Count > 0) { if (HitTest(x, y, character, view)) { return(character); } } } return(null); }
private Character GetCharacter(int x, int y, RoomEditorState state) { foreach (Character character in _game.RootCharacterFolder.AllItemsFlat) { DesignTimeProperties p; if (!DesignItems.TryGetValue(GetItemID(character), out p)) { continue; // character is not in the room } if (!p.Visible || p.Locked) { continue; } AgsView view = _game.FindViewByID(character.NormalView); if (view != null && view.Loops.Count > 0) { if (HitTest(x, y, character, view)) { return(character); } } } return(null); }
private void UpdateFromView(AGS.Types.View view) { if (view == null) { udLoop.Enabled = false; udFrame.Enabled = false; chkAnimate.Enabled = false; chkAnimate.Checked = false; StopTimer(); previewPanel.Invalidate(); } else { udLoop.Enabled = true; udFrame.Enabled = true; chkAnimate.Enabled = true; udLoop.Minimum = 0; udLoop.Maximum = (view.Loops.Count == 0) ? 0 : view.Loops.Count - 1; udFrame.Minimum = 0; udFrame.Maximum = 99; udDelay.Minimum = 1; udDelay.Maximum = 100; udLoop_ValueChanged(null, null); } }
private void btnChooseView_Click(object sender, EventArgs e) { AGS.Types.View chosen = ViewChooser.ShowViewChooser(this, (int)udView.Value); if (chosen != null) { udView.Value = chosen.ID; } }
private void View_ViewUpdated(AGS.Types.View view) { foreach (ViewLoopEditor pane in _loopPanes) { editorPanel.Controls.Remove(pane); pane.Dispose(); } _loopPanes.Clear(); InitializeControls(); viewPreview.ViewUpdated(); }
public static AGS.Types.View ShowViewChooser(IWin32Window owner, int currentView) { AGS.Types.View chosenView = null; ViewChooser chooser = new ViewChooser(currentView); if (chooser.ShowDialog(owner) == DialogResult.OK) { chosenView = chooser.SelectedView; } chooser.Dispose(); return(chosenView); }
public ViewEditor(AGS.Types.View viewToEdit) { _guiController = Factory.GUIController; _guiController.OnPropertyObjectChanged += new GUIController.PropertyObjectChangedHandler(GUIController_OnPropertyObjectChanged); _viewUpdateHandler = new AGS.Types.View.ViewUpdatedHandler(View_ViewUpdated); viewToEdit.ViewUpdated += _viewUpdateHandler; InitializeComponent(); _editingView = viewToEdit; InitializeControls(); viewPreview.DynamicUpdates = true; chkShowPreview.Checked = Factory.AGSEditor.Preferences.ShowViewPreviewByDefault; UpdateWhetherPreviewIsShown(); }
private bool HitTest(int x, int y, Character character, AgsView view) { int spriteNum = 0; if (view.Loops[0].Frames.Count > 0) { ViewFrame thisFrame = view.Loops[0].Frames[0]; spriteNum = thisFrame.Image; } int width = GetSpriteWidthForGameResolution(spriteNum); int height = GetSpriteHeightForGameResolution(spriteNum); return((x >= character.StartX - (width / 2)) && (x < character.StartX + (width / 2)) && (y >= character.StartY - height) && (y < character.StartY)); }
private Rectangle GetCharacterRect(Character character, int scale, RoomEditorState state) { AgsView view = _game.FindViewByID(character.NormalView); int xPos = AdjustXCoordinateForWindowScroll(character.StartX, state); // character.StartX* scale; int yPos = AdjustYCoordinateForWindowScroll(character.StartY, state); // character.StartY* scale; int spriteNum = 0; if (view.Loops[0].Frames.Count > 0) { spriteNum = _game.FindViewByID(character.NormalView).Loops[0].Frames[0].Image; } int spriteWidth = GetSpriteWidthForGameResolution(spriteNum) * scale; // Factory.NativeProxy.GetRelativeSpriteWidth(spriteNum) * scale; int spriteHeight = GetSpriteHeightForGameResolution(spriteNum) * scale; // Factory.NativeProxy.GetRelativeSpriteHeight(spriteNum) * scale; return(new Rectangle(xPos - spriteWidth / 2, yPos - spriteHeight, spriteWidth, spriteHeight)); }
private bool HitTest(int x, int y, Character character, AgsView view) { int spriteNum = 0; if (view.Loops[0].Frames.Count > 0) { ViewFrame thisFrame = view.Loops[0].Frames[0]; spriteNum = thisFrame.Image; } int width, height; Utilities.GetSizeSpriteWillBeRenderedInGame(spriteNum, out width, out height); return((x >= character.StartX - (width / 2)) && (x < character.StartX + (width / 2)) && (y >= character.StartY - height) && (y < character.StartY)); }
private Rectangle GetCharacterRect(Character character, RoomEditorState state) { AgsView view = _game.FindViewByID(character.NormalView); int xPos = state.RoomXToWindow(character.StartX); int yPos = state.RoomYToWindow(character.StartY); if (view == null || view.Loops.Count == 0) { return(new Rectangle(xPos - 5, yPos - 5, 10, 10)); } int spriteNum = 0; if (view.Loops[0].Frames.Count > 0) { spriteNum = _game.FindViewByID(character.NormalView).Loops[0].Frames[0].Image; } int spriteWidth = state.RoomSizeToWindow(GetSpriteWidthForGameResolution(spriteNum)); int spriteHeight = state.RoomSizeToWindow(GetSpriteHeightForGameResolution(spriteNum)); return(new Rectangle(xPos - spriteWidth / 2, yPos - spriteHeight, spriteWidth, spriteHeight)); }
private static void EnsureViewNameIsUnique(View view, Game game) { string scriptNameBase = view.Name; int suffix = 0; while (game.IsScriptNameAlreadyUsed(view.Name.ToUpper(), view)) { suffix++; view.Name = scriptNameBase + suffix; } }
private static void WriteOldStyleView(BinaryWriter writer, View view) { if (view.Loops.Count > 16) { throw new AGS.Types.InvalidDataException("This view has more than 16 loops and cannot be exported in a format compatible with previous AGS versions."); } foreach (ViewLoop loop in view.Loops) { if (loop.Frames.Count > 20) { throw new AGS.Types.InvalidDataException("This view has a loop with more than 20 frames and cannot be exported in a format compatible with previous AGS versions."); } } short loopCount = Math.Min((short)view.Loops.Count, (short)16); writer.Write(loopCount); foreach (ViewLoop loop in view.Loops) { short frameCount = (short)loop.Frames.Count; if (loop.RunNextLoop) { frameCount++; } frameCount = Math.Min(frameCount, (short)20); writer.Write(frameCount); } WriteZeros(writer, (16 - view.Loops.Count) * 2); WriteZeros(writer, 16 * 4 + 2); for (int i = 0; i < 16; i++) { for (int j = 0; j < 20; j++) { if ((i < view.Loops.Count) && (j < view.Loops[i].Frames.Count)) { ViewFrame frame = view.Loops[i].Frames[j]; writer.Write(frame.Image); writer.Write((int)0); writer.Write((short)frame.Delay); WriteZeros(writer, 2); writer.Write((frame.Flipped) ? 1 : 0); writer.Write(frame.Sound); WriteZeros(writer, 8); } else if ((i < view.Loops.Count) && (j == view.Loops[i].Frames.Count) && (view.Loops[i].RunNextLoop)) { // Write the "Run Next Loop" flag writer.Write((int)-1); writer.Write((int)0); writer.Write((short)0); WriteZeros(writer, 2); writer.Write(0); writer.Write(0); WriteZeros(writer, 8); } else { WriteZeros(writer, 28); } } } foreach (ViewLoop loop in view.Loops) { foreach (ViewFrame frame in loop.Frames) { WriteOldStyleViewFrame(writer, frame); } if (loop.RunNextLoop) { writer.Write((int)200); } } }
private static void WriteNewStyleView(XmlTextWriter writer, View view, Dictionary<int, object> spritesWritten) { view.ToXml(writer); foreach (ViewLoop loop in view.Loops) { foreach (ViewFrame frame in loop.Frames) { if (!spritesWritten.ContainsKey(frame.Image)) { WriteSpriteToXML(frame.Image, writer); spritesWritten.Add(frame.Image, null); } } } }
private static void UpdateViewWithSpriteMapping(View view, Dictionary<int, int> spriteMapping) { foreach (ViewLoop loop in view.Loops) { foreach (ViewFrame frame in loop.Frames) { if (spriteMapping.ContainsKey(frame.Image)) { frame.Image = spriteMapping[frame.Image]; } } } }
private static View ReadOldStyleView(BinaryReader reader, Game game, SpriteFolder folder, Color[] palette) { View view = new View(); int i; int numLoops = reader.ReadInt16(); int[] numFrames = new int[numLoops]; for (i = 0; i < numLoops; i++) { view.AddNewLoop(); numFrames[i] = reader.ReadInt16(); } if (numLoops < 16) { reader.ReadBytes((16 - numLoops) * 2); } reader.ReadBytes(16 * 4 + 2); for (i = 0; i < 16; i++) { for (int j = 0; j < 20; j++) { ViewFrame frame = new ViewFrame(); frame.ID = j; frame.Image = reader.ReadInt32(); reader.ReadInt32(); frame.Delay = reader.ReadInt16(); reader.ReadBytes(2); frame.Flipped = (reader.ReadInt32() == 1); frame.Sound = reader.ReadInt32(); reader.ReadBytes(8); if ((i < numLoops) && (j < numFrames[i])) { view.Loops[i].Frames.Add(frame); } } } foreach (ViewLoop loop in view.Loops) { foreach (ViewFrame frame in loop.Frames) { Sprite newSprite = ReadOldStyleViewFrame(reader, loop, frame, palette); if (newSprite == null) { break; } folder.Sprites.Add(newSprite); frame.Image = newSprite.Number; } } return view; }
private static int ReadAndAddNewStyleView(XmlNode parentOfViewNode, Game game, Dictionary<int, int> spriteMapping, PaletteEntry[] palette, SpriteFolder newFolder) { View newView = new View(parentOfViewNode.SelectSingleNode("View")); newView.ID = game.FindAndAllocateAvailableViewID(); ImportSpritesFromXML(parentOfViewNode, palette, newFolder, spriteMapping); UpdateViewWithSpriteMapping(newView, spriteMapping); EnsureViewNameIsUnique(newView, game); game.RootViewFolder.Views.Add(newView); return newView.ID; }
public View CreateNewView(IViewFolder createInFolder) { if (createInFolder == null) { createInFolder = _views; } View newView = new View(); newView.ID = FindAndAllocateAvailableViewID(); newView.Name = "View" + newView.ID; createInFolder.Views.Add(newView); NotifyClientsViewsUpdated(); return newView; }
private static void WriteOldStyleView(BinaryWriter writer, View view) { if (view.Loops.Count > 16) { throw new AGS.Types.InvalidDataException("Cette vue contient plus de 16 séquences d'animation et ne peut être exportée dans un format compatible avec les précédentes versions d'AGS."); } foreach (ViewLoop loop in view.Loops) { if (loop.Frames.Count > 20) { throw new AGS.Types.InvalidDataException("Cette vue a une séquence d'animation contenant plus de 20 vignettes et ne peut être exportée dans un format compatible avec les précédentes versions d'AGS."); } } short loopCount = Math.Min((short)view.Loops.Count, (short)16); writer.Write(loopCount); foreach (ViewLoop loop in view.Loops) { short frameCount = (short)loop.Frames.Count; if (loop.RunNextLoop) { frameCount++; } frameCount = Math.Min(frameCount, (short)20); writer.Write(frameCount); } WriteZeros(writer, (16 - view.Loops.Count) * 2); WriteZeros(writer, 16 * 4 + 2); for (int i = 0; i < 16; i++) { for (int j = 0; j < 20; j++) { if ((i < view.Loops.Count) && (j < view.Loops[i].Frames.Count)) { ViewFrame frame = view.Loops[i].Frames[j]; writer.Write(frame.Image); writer.Write((int)0); writer.Write((short)frame.Delay); WriteZeros(writer, 2); writer.Write((frame.Flipped) ? 1 : 0); writer.Write(frame.Sound); WriteZeros(writer, 8); } else if ((i < view.Loops.Count) && (j == view.Loops[i].Frames.Count) && (view.Loops[i].RunNextLoop)) { // Write the "Run Next Loop" flag writer.Write((int)-1); writer.Write((int)0); writer.Write((short)0); WriteZeros(writer, 2); writer.Write(0); writer.Write(0); WriteZeros(writer, 8); } else { WriteZeros(writer, 28); } } } foreach (ViewLoop loop in view.Loops) { foreach (ViewFrame frame in loop.Frames) { WriteOldStyleViewFrame(writer, frame); } if (loop.RunNextLoop) { writer.Write((int)200); } } }
private void btnOK_Click(object sender, EventArgs e) { _selectedView = (AGS.Types.View)viewTree.SelectedNode.Tag; this.DialogResult = DialogResult.OK; this.Close(); }