/// <summary> /// Konstruktor. Lädt die angegebene Datei. /// </summary> /// <param name="filename">Die zu ladende Datei.</param> public ShipFile(string filename) : this() { // Datei laden RAMBuffer buffer = new RAMBuffer(filename); // Namen lesen Name = buffer.ReadString(buffer.ReadInteger()); // Rumpf-SLP lesen if (buffer.ReadByte() == 1) { BaseSlp = new SLPFile(buffer); } // Schatten-SLP lesen if (buffer.ReadByte() == 1) { ShadowSlp = new SLPFile(buffer); } // Segel lesen int sailCount = buffer.ReadByte(); for (int i = 0; i < sailCount; ++i) { // Lesen Sail.SailType currType = (Sail.SailType)buffer.ReadByte(); Sail currSail = new Sail(buffer); Sails.Add(currType, currSail); } // Invertierte Segeltypen lesen int invSailCount = buffer.ReadByte(); for (int i = 0; i < invSailCount; ++i) { InvertedSails.Add((Sail.SailType)buffer.ReadByte()); } // 0 -> 0, 10 -> 0, 20 -> 10, 30 -> 10, 40 -> 20, 50 -> 20, 60 -> 30, 70 -> 30, 80 -> 40 /*func(Sail.SailType.MainGo, Civ.AS, Properties.Resources.MainGo_AS); * func(Sail.SailType.MainGo, Civ.IN, Properties.Resources.MainGo_IN); * func(Sail.SailType.MainGo, Civ.ME, Properties.Resources.MainGo_ME); * func(Sail.SailType.MainGo, Civ.OR, Properties.Resources.MainGo_OR); * func(Sail.SailType.MainGo, Civ.WE, Properties.Resources.MainGo_WE); * func(Sail.SailType.MainStop, Civ.AS, Properties.Resources.MainStop_AS); * func(Sail.SailType.MainStop, Civ.IN, Properties.Resources.MainStop_IN); * func(Sail.SailType.MainStop, Civ.ME, Properties.Resources.MainStop_ME); * func(Sail.SailType.MainStop, Civ.OR, Properties.Resources.MainStop_OR); * func(Sail.SailType.MainStop, Civ.WE, Properties.Resources.MainStop_WE); * * Save(Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + "_converted.ship"));*/ }
/// <summary> /// Konstruktor. Liest die Daten aus dem gegebenen Puffer. /// </summary> /// <param name="buffer">Der Puffer, aus dem die Segeldaten gelesen werden sollen.</param> public Sail(RAMBuffer buffer) : this() { // Benutzung lesen Used = (buffer.ReadByte() == 1); // SLPs lesen int count = buffer.ReadByte(); for (int i = 0; i < count; ++i) { // Lesen ShipFile.Civ currCiv = (ShipFile.Civ)buffer.ReadByte(); SLPFile currSlp = new SLPFile(buffer); SailSlps.Add(currCiv, currSlp); } }
private void LoadTerrainTexture(byte tex) { var slpFile = new SLPFile(); slpFile.LoadFile("textures/ter" + Configuration.TerrainTextureLookups[tex] + ".slp"); var spritewidth = slpFile.GetFrame(0).m_Width; var spriteheight = slpFile.GetFrame(0).m_Height; List <byte> constructorbot = new List <byte>(spritewidth * spriteheight * slpFile.m_Frames.Count); foreach (var frame in slpFile.m_Frames) { byte[] b = frame.GetRGBAArray(); foreach (byte by in b) { constructorbot.Add(by); } } var img = new Image((uint)spritewidth, (uint)(spriteheight * slpFile.m_Frames.Count), constructorbot.ToArray()); tilesetTextures[tex] = new Texture(img); }
/// <summary> /// Export die enthaltenen SLPs in den gegebenen Ordner. /// Reihenfolge der Exports ist wichtig - bei Änderungen im TechTreeEditor-Plugin gegenprüfen! /// </summary> /// <param name="folder">Der Zielordner.</param> /// <param name="baseId">Die erste freie ID, zu der exportiert werden soll.</param> /// <param name="broadside">Gibt an, ob die Grafiken zusätzlich im Breitseitenmodus exportiert werden sollen.</param> /// <param name="enabledCivSets">Eine Liste mit den zu exportierenden Kultur-Grafiksets.</param> public void Export(string folder, int baseId, bool broadside, List <Civ> enabledCivSets) { // Die aktuell freie ID int currId = baseId; // Basispfad bauen string baseFileName = Path.Combine(folder, Name); // Der XML-Projektdatei-Code string xmlCode = ""; // Hilfsfunktion fürs Exportieren Action <SLPFile, string> exportSlp = (slp, suffix) => { // Exportstruktur anlegen DRSLibrary.DRSFile.ExternalFile extFile = new DRSLibrary.DRSFile.ExternalFile(); // Breitseitenmodus? SLPFile slpE = slp; if (broadside) { // Suffix erweitern suffix += " [B]"; // Neue SLP mit umkopierten Frames erzeugen slp.writeData(); RAMBuffer tmpBuffer = (RAMBuffer)slp.DataBuffer; tmpBuffer.Position = 0; slpE = new SLPFile(tmpBuffer); slpE._frameInformationHeaders.Clear(); slpE._frameInformationData.Clear(); // Drehrichtungen vorne bis links (-> links bis hinten) for (int i = 4; i <= 8; ++i) { // Alle Frames der Drehrichtung kopieren for (int f = i * (int)(slp.FrameCount / 9); f < (i + 1) * (int)(slp.FrameCount / 9); ++f) { // Header kopieren SLPFile.FrameInformationHeader fHead = new SLPFile.FrameInformationHeader(); fHead.AnchorX = slp._frameInformationHeaders[f].AnchorX; fHead.AnchorY = slp._frameInformationHeaders[f].AnchorY; fHead.Width = slp._frameInformationHeaders[f].Width; fHead.Height = slp._frameInformationHeaders[f].Height; fHead.Properties = slp._frameInformationHeaders[f].Properties; slpE._frameInformationHeaders.Add(fHead); // Daten kopieren SLPFile.FrameInformationData fData = new SLPFile.FrameInformationData(); fData.BinaryCommandTable = new List <SLPFile.BinaryCommand>(slp._frameInformationData[f].BinaryCommandTable); fData.BinaryRowEdge = slp._frameInformationData[f].BinaryRowEdge; fData.CommandTable = slp._frameInformationData[f].CommandTable; fData.CommandTableOffsets = new uint[slp._frameInformationData[f].CommandTableOffsets.Length]; fData.RowEdge = slp._frameInformationData[f].RowEdge; slpE._frameInformationData.Add(fData); } } // Drehrichtungen links links hinten bis hinten (-> hinten hinten rechts bis rechts) for (int i = 7; i >= 4; --i) { // Alle Frames der Drehrichtung spiegeln und kopieren for (int f = i * (int)(slp.FrameCount / 9); f < (i + 1) * (int)(slp.FrameCount / 9); ++f) { // Header kopieren SLPFile.FrameInformationHeader fHead = new SLPFile.FrameInformationHeader(); fHead.AnchorX = (int)slp._frameInformationHeaders[f].Width - slp._frameInformationHeaders[f].AnchorX; fHead.AnchorY = slp._frameInformationHeaders[f].AnchorY; fHead.Width = slp._frameInformationHeaders[f].Width; fHead.Height = slp._frameInformationHeaders[f].Height; fHead.Properties = slp._frameInformationHeaders[f].Properties; slpE._frameInformationHeaders.Add(fHead); // Daten spiegeln und kopieren SLPFile.FrameInformationData fData = new SLPFile.FrameInformationData(); fData.BinaryCommandTable = new List <SLPFile.BinaryCommand>(); fData.BinaryRowEdge = new SLPFile.BinaryRowedge[slp._frameInformationData[f].BinaryRowEdge.Length]; for (int bre = 0; bre < fData.BinaryRowEdge.Length; ++bre) { fData.BinaryRowEdge[bre] = new SLPFile.BinaryRowedge(slp._frameInformationData[f].BinaryRowEdge[bre]._right, slp._frameInformationData[f].BinaryRowEdge[bre]._left); } fData.RowEdge = new ushort[fHead.Height, 2]; for (int re = 0; re < fHead.Height; ++re) { fData.RowEdge[re, 0] = slp._frameInformationData[f].RowEdge[re, 1]; fData.RowEdge[re, 1] = slp._frameInformationData[f].RowEdge[re, 0]; } fData.CommandTable = new int[fHead.Height, fHead.Width]; for (int h = 0; h < fHead.Height; ++h) { for (int w = 0; w < fHead.Width; ++w) { fData.CommandTable[h, fHead.Width - w - 1] = slp._frameInformationData[f].CommandTable[h, w]; } } fData.CommandTableOffsets = new uint[slp._frameInformationData[f].CommandTableOffsets.Length]; slpE.CreateBinaryCommandTable(fData, (int)fHead.Width, (int)fHead.Height, slpE._settings); slpE._frameInformationData.Add(fData); } } } // SLP-Daten lesen und zuweisen slpE.writeData(); RAMBuffer slpBuffer = (RAMBuffer)slpE.DataBuffer; slpBuffer.Position = 0; extFile.Data = slpBuffer.ReadByteArray(slpBuffer.Length); // Metadaten festlegen extFile.DRSFile = "graphics"; extFile.FileID = (uint)(currId++); extFile.ResourceType = "slp"; // Exportdatei speichern extFile.ToBinary().Save(Path.Combine(folder, extFile.FileID + ".res")); // XML-Code generieren xmlCode += "<ResFile>" + extFile.FileID + ".res</ResFile>\r\n"; // SLP speichern if (!string.IsNullOrEmpty(suffix)) { slpBuffer.Save(baseFileName + " " + suffix + ".slp"); } else { slpBuffer.Save(baseFileName + ".slp"); } }; // Schatten und Rumpf exportieren if (ShadowSlp != null) { exportSlp(ShadowSlp, "(Schatten)"); } if (BaseSlp != null) { exportSlp(BaseSlp, ""); } // Hilfsfunktion für Segel-Export (Reihenfolge wichtig für ID-Vergabe) Action <Civ> exportCivSails = (civ) => { // Segel exportieren if (Sails[Sail.SailType.MainGo].Used) { exportSlp(Sails[Sail.SailType.MainGo].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.MainGo] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Small1].Used) { exportSlp(Sails[Sail.SailType.Small1].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Small1] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Mid1].Used) { exportSlp(Sails[Sail.SailType.Mid1].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Mid1] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Large1].Used) { exportSlp(Sails[Sail.SailType.Large1].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Large1] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.MainStop].Used) { exportSlp(Sails[Sail.SailType.MainStop].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.MainStop] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Large2].Used) { exportSlp(Sails[Sail.SailType.Large2].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Large2] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Mid2].Used) { exportSlp(Sails[Sail.SailType.Mid2].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Mid2] + ") [" + CivNames[civ] + "]"); } if (Sails[Sail.SailType.Small2].Used) { exportSlp(Sails[Sail.SailType.Small2].SailSlps[civ], "(" + Sail.SailTypeNames[Sail.SailType.Small2] + ") [" + CivNames[civ] + "]"); } }; // Segel kulturweise exportieren foreach (Civ civSet in enabledCivSets) { exportCivSails(civSet); } // XML-Code speichern File.WriteAllText(Path.Combine(folder, "projectdata" + (broadside ? "_b" : "") + ".xml"), xmlCode); // Ggf. noch die Nicht-Breitseiten-Frames exportieren if (broadside) { Export(folder, currId, false, enabledCivSets); } }
/// <summary> /// Updates the currently displayed frames when the projectile frame delay is changed. /// </summary> private void UpdateDisplayedFrames() { // Are any DRS files loaded? Are there drawable frames? if (_drs1 == null && _drs2 == null || _drawnImages.Count == 0) { return; } // Ensure frame delay is in range int frameDelay = CurrentUnitEntry.Value.ProjectileFrameDelay % _currentUnitGraphic.FrameCount; // Generate and assign frames for (short a = 0; a < _drawnImages.Count; ++a) { // Get frame ID int frameId = frameDelay + a * _currentUnitGraphic.FrameCount; // Calculate combined frame dimensions while setting the anchor point to (0, 0) OffsetData frameDimensions = new OffsetData(0, 0, 0, 0); // Store considered SLPs for later drawing // Tuple: frameId, anchorX, anchorY, slpObject // slpObject == null --> redraw main SLP var drawnSlpFrames = new List <Tuple <int, int, int, SLPFile> >(); // Check primary SLP SLPFile primarySlp = null; SLPFile.FrameInformationHeader primarySlpFrameHeader = null; if (_currentUnitGraphic.SLP >= 0 && _slps.ContainsKey((ushort)_currentUnitGraphic.SLP)) { // Get SLP primarySlp = _slps[(ushort)_currentUnitGraphic.SLP]; // Update dimensions primarySlpFrameHeader = primarySlp._frameInformationHeaders[frameId]; frameDimensions.Left = primarySlpFrameHeader.AnchorX; frameDimensions.Top = primarySlpFrameHeader.AnchorY; frameDimensions.Right = (int)primarySlpFrameHeader.Width - primarySlpFrameHeader.AnchorX; frameDimensions.Bottom = (int)primarySlpFrameHeader.Height - primarySlpFrameHeader.AnchorY; // Add SLP to render list // Only if no deltas are present, else the primary graphic should be drawn explicitly if (_renderedDeltas.Count == 0) { drawnSlpFrames.Add(new Tuple <int, int, int, SLPFile>(frameId, primarySlpFrameHeader.AnchorX, primarySlpFrameHeader.AnchorY, primarySlp)); } } // Check deltas foreach (var currDelta in _renderedDeltas) { // Redrawer? if (currDelta.GraphicID == -1 && primarySlp != null) { drawnSlpFrames.Add(new Tuple <int, int, int, SLPFile>(frameId, primarySlpFrameHeader.AnchorX, primarySlpFrameHeader.AnchorY, primarySlp)); } else if (currDelta.GraphicID != -1) { // Get graphic and SLP var currDeltaGraphic = _genieFile.Graphics[currDelta.GraphicID]; SLPFile currDeltaSlp = _slps[(ushort)currDeltaGraphic.SLP]; // Update dimensions int currDeltaFrameId = GetCorrespondingFrameId(frameId, _currentUnitGraphic, currDeltaGraphic); SLPFile.FrameInformationHeader frameHeader = currDeltaSlp._frameInformationHeaders[currDeltaFrameId]; frameDimensions.Left = Math.Max(frameDimensions.Left, frameHeader.AnchorX + currDelta.DirectionX); frameDimensions.Top = Math.Max(frameDimensions.Top, frameHeader.AnchorY + currDelta.DirectionY); frameDimensions.Right = Math.Max(frameDimensions.Right, (int)frameHeader.Width - (frameHeader.AnchorX + currDelta.DirectionX)); frameDimensions.Bottom = Math.Max(frameDimensions.Bottom, (int)frameHeader.Height - (frameHeader.AnchorY + currDelta.DirectionY)); // Add delta SLP to render list drawnSlpFrames.Add(new Tuple <int, int, int, SLPFile>(currDeltaFrameId, frameHeader.AnchorX + currDelta.DirectionX, frameHeader.AnchorY + currDelta.DirectionY, currDeltaSlp)); } } // Render frame if neccessary if (!_precomputedUnitFrames.ContainsKey(frameId)) { // Fall back to empty image if there are no graphics to be drawn if (drawnSlpFrames.Count == 0) { _precomputedUnitFrames[frameId] = new System.Drawing.Bitmap(1, 1).ToImageSource(); } else { // Create bitmap // 'using' environment to free memory correctly, avoiding OutOfMemory exceptions using (System.Drawing.Bitmap currFrame = new System.Drawing.Bitmap(frameDimensions.Left + frameDimensions.Right, frameDimensions.Top + frameDimensions.Bottom)) { // Draw on bitmap using (System.Drawing.Graphics currFrameG = System.Drawing.Graphics.FromImage(currFrame)) { // Get main frame System.Drawing.Bitmap primarySlpFrame = (primarySlpFrameHeader == null ? null : primarySlp.getFrameAsBitmap((uint)frameId, Pal50500, SLPFile.Masks.Graphic, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(100, 100, 100, 100)) ); // Go through render list and render main image and deltas foreach (Tuple <int, int, int, SLPFile> currRenderEntry in drawnSlpFrames) { // Draw main frame? if (currRenderEntry.Item4 == primarySlp) { // Ensure that main frame exists if (primarySlpFrame != null) { currFrameG.DrawImage(primarySlpFrame, frameDimensions.Left - primarySlpFrameHeader.AnchorX, frameDimensions.Top - primarySlpFrameHeader.AnchorY); } } else { // Draw delta frame currFrameG.DrawImage(currRenderEntry.Item4.getFrameAsBitmap((uint)currRenderEntry.Item1, Pal50500, SLPFile.Masks.Graphic, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(100, 100, 100, 100)), frameDimensions.Left - currRenderEntry.Item2, frameDimensions.Top - currRenderEntry.Item3); } } } _precomputedUnitFrames[frameId] = currFrame.ToImageSource(); } } } // Assign to drawn image objects _drawnImages[a].Source = _precomputedUnitFrames[frameId]; _drawnImages[a].Width = _precomputedUnitFrames[frameId].Width; _drawnImages[a].Height = _precomputedUnitFrames[frameId].Height; _anchors[a] = new Point(frameDimensions.Left, frameDimensions.Top); // Frame anchor point // Calculate bounds including the anchor point _maxFrameOffsets.Left = Math.Max(_maxFrameOffsets.Left, frameDimensions.Left); _maxFrameOffsets.Right = Math.Max(_maxFrameOffsets.Right, frameDimensions.Right); _maxFrameOffsets.Top = Math.Max(_maxFrameOffsets.Top, frameDimensions.Top); _maxFrameOffsets.Bottom = Math.Max(_maxFrameOffsets.Bottom, frameDimensions.Bottom); } // Update positions UpdatePositions(); }
/// <summary> /// Updates the render panel when a new unit is loaded. /// </summary> private void UpdateUnitRenderData() { // Are any DRS files loaded? if (_drs1 == null && _drs2 == null || _genieFile == null) { return; } // If no unit is given or the unit does not have projectile data, clear panel if (CurrentUnitEntry.Key < 0 || CurrentUnitEntry.Value?.ProjectileCount == null) { // Clear and abort _renderPanel.Children.Clear(); return; } // Clear lists _renderPanel.Children.Clear(); _renderedDeltas.Clear(); _drawnImages.Clear(); _precomputedUnitFrames.Clear(); _slps.Clear(); _anchors.Clear(); _anchorPointShapes.Clear(); _projectileAreaShapes.Clear(); // Reset frame offsets _maxFrameOffsets = new OffsetData(0, 0, 0, 0); // Find unit data // There must be at least one civ where this unit is defined, else the BalancingFile class would consist only of null members foreach (Civ c in _genieFile.Civs) { if (c.UnitPointers[CurrentUnitEntry.Key] > 0) { // Unit is defined, use data _currentUnitData = c.Units[CurrentUnitEntry.Key]; break; } } // Find graphic if (_currentUnitData.Type50?.AttackGraphic >= 0 && _genieFile.GraphicPointers[_currentUnitData.Type50.AttackGraphic] > 0) { _currentUnitGraphic = _genieFile.Graphics[_currentUnitData.Type50.AttackGraphic]; } else if (_currentUnitData.StandingGraphic1 >= 0 && _genieFile.GraphicPointers[_currentUnitData.StandingGraphic1] > 0) { _currentUnitGraphic = _genieFile.Graphics[_currentUnitData.StandingGraphic1]; } else { // Abort, no graphic available _currentUnitGraphic = null; return; } // Find deltas; use only deltas that have graphic ID -1 or an existing SLP foreach (var currDelta in _currentUnitGraphic.Deltas) { if (currDelta.GraphicID == -1 || (currDelta.GraphicID >= 0 && _genieFile.GraphicPointers[currDelta.GraphicID] > 0 && ((_drs1?.ResourceExists((uint)_genieFile.Graphics[currDelta.GraphicID].SLP) ?? false) || (_drs2?.ResourceExists((uint)_genieFile.Graphics[currDelta.GraphicID].SLP) ?? false)))) { _renderedDeltas.Add(currDelta); } } // Load needed SLPs Action <ushort> loadSlpFromDrs = (slpId) => { // Get SLP from DRS by priority if (_slps.ContainsKey(slpId)) { return; } if (_drs1?.ResourceExists(slpId) ?? false) { _slps[slpId] = new SLPFile(new RAMBuffer(_drs1.GetResourceData(slpId))); } else if (_drs2?.ResourceExists(slpId) ?? false) { _slps[slpId] = new SLPFile(new RAMBuffer(_drs2.GetResourceData(slpId))); } }; if (_currentUnitGraphic.SLP >= 0) { loadSlpFromDrs((ushort)_currentUnitGraphic.SLP); } foreach (var currDelta in _renderedDeltas) { if (currDelta.GraphicID >= 0) { loadSlpFromDrs((ushort)_genieFile.Graphics[currDelta.GraphicID].SLP); } } // Create shape objects depending on angle count (ignore mirrored sides) // Each shape gets an event handler for mouse events, such that it can be dragged around by the user int effectiveAngleCount = (_currentUnitGraphic.MirroringMode > 0 ? _currentUnitGraphic.AngleCount / 2 + 1 : _currentUnitGraphic.AngleCount); for (int a = 0; a < effectiveAngleCount; ++a) { // Create image Image img = new Image { Tag = a }; img.MouseLeftButtonDown += _shape_OnMouseLeftButtonDown; img.MouseLeftButtonUp += _shape_OnMouseLeftButtonUp; _drawnImages.Add(img); _renderPanel.Children.Add(img); // Create anchor point list items _anchors.Add(new Point()); // Create anchor point shape Ellipse anchorEllipse = new Ellipse { Fill = Brushes.Magenta, Width = 3, Height = 3, Tag = a }; anchorEllipse.MouseLeftButtonDown += _shape_OnMouseLeftButtonDown; anchorEllipse.MouseLeftButtonUp += _shape_OnMouseLeftButtonUp; _anchorPointShapes.Add(anchorEllipse); _renderPanel.Children.Add(anchorEllipse); // Create projectile area shape Rectangle projectileRectangle = new Rectangle { Fill = new SolidColorBrush(ProjectileAreaTransparentColor), Width = TileSideLength, Height = TileSideLength, Tag = a }; projectileRectangle.MouseLeftButtonDown += _shape_OnMouseLeftButtonDown; projectileRectangle.MouseLeftButtonUp += _shape_OnMouseLeftButtonUp; projectileRectangle.RenderTransform = new RotateTransform(a * 45, projectileRectangle.Width / 2, projectileRectangle.Height / 2); _projectileAreaShapes.Add(projectileRectangle); _renderPanel.Children.Add(projectileRectangle); } // Initialize user defined offsets while (_userDefinedFrameOffsets.Count < effectiveAngleCount) { _userDefinedFrameOffsets.Add(new Point()); } // Show initial frame UpdateDisplayedFrames(); }
public static void Initialize() { var style = Styles.Titlebar | Styles.Close; size = new Vector2f(Configuration.Width, Configuration.Height); Window = new RenderWindow(new VideoMode(Configuration.Width, Configuration.Height), "Open Empires", style); Window.SetFramerateLimit(Configuration.Framerate); Window.SetVerticalSyncEnabled(Configuration.VSync); Window.Closed += (sender, args) => Window.Close(); Window.Resized += (sender, args) => Resize(new Vector2f(args.Width, args.Height)); /*Window.MouseButtonPressed += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, true, args.X, args.Y)); * Window.MouseButtonReleased += (sender, args) => DispatchEvent(new MouseButtonInputArgs(args.Button, false, args.X, args.Y)); * Window.MouseWheelMoved += (sender, args) => DispatchEvent(new MouseWheelInputArgs(args.Delta, args.X, args.Y)); * Window.MouseMoved += (sender, args) => DispatchEvent(new MouseMoveInputArgs(args.X, args.Y));*/ Window.MouseMoved += new EventHandler <MouseMoveEventArgs>(Window_MouseMoved); Window.MouseWheelMoved += (sender, args) => { /* Mouse wheel zoom implementation where the view will zoom * towards the area the cursor is pointing to */ var mousePos = Mouse.GetPosition(Window); float relX = (float)mousePos.X / Window.Size.X - 0.5f; float relY = (float)mousePos.Y / Window.Size.Y - 0.5f; GameView.Move(new Vector2f { X = relX * GameView.Size.X, Y = relY * GameView.Size.Y }); GameView.Zoom(1 - (args.Delta * 0.1f)); GameView.Move(new Vector2f { X = -relX * GameView.Size.X, Y = -relY * GameView.Size.Y }); }; Window.KeyPressed += (sender, args) => { KeyStates[(int)args.Code] = true; }; Window.KeyReleased += (sender, args) => { KeyStates[(int)args.Code] = false; }; Blendomatic.ReadBlendomatic(new System.IO.FileStream("blendomatic.dat", System.IO.FileMode.Open)); map = new Map(); GameView = new View(DefaultView); GameView.Center = new Vector2f((map.Width / 2) * 96, 0); var blend = Blendomatic.BlendingModes[2]; var tile = blend.Tiles[12]; var img = new Image(97, 49); for (var y = 0; y < img.Size.Y; y++) { for (var x = 0; x < img.Size.X; x++) { img.SetPixel((uint)x, (uint)y, new Color(255, 0, 0, 0)); } } var i = 0; for (var y = 0; y < img.Size.X; y++) { var bytesPerRow = y < 24 ? 1 + (4 * y) : 97 - (4 * (y - 24)); var startX = 48 - (bytesPerRow / 2); for (var x = 0; x < bytesPerRow; x++) { img.SetPixel((uint)(startX + x), (uint)y, new Color(0, 0, 0, tile[i++])); } } var slpFile = new SLPFile(); slpFile.LoadFile("textures/ter15002.slp"); var spritewidth = slpFile.GetFrame(0).m_Width; var spriteheight = slpFile.GetFrame(0).m_Height; var imgg = new Image((uint)spritewidth, (uint)(spriteheight), slpFile.GetFrame(0).GetRGBAArray()); for (var y = 0; y < imgg.Size.Y; y++) { for (var x = 0; x < imgg.Size.X; x++) { var col = imgg.GetPixel((uint)x, (uint)y); col.A = (byte)(Math.Min(255, (128 - img.GetPixel((uint)x, (uint)y).A) * 2)); if (img.GetPixel((uint)x, (uint)y).R == 255) { col.A = 0; } imgg.SetPixel((uint)x, (uint)y, col); } } selected = new Sprite(new Texture(imgg)); /* blend sand to forest now */ var blend2 = Blendomatic.BlendingModes[2]; var tile2 = blend2.Tiles[12]; var img2 = new Image(97, 49); for (var y = 0; y < img2.Size.Y; y++) { for (var x = 0; x < img2.Size.X; x++) { img2.SetPixel((uint)x, (uint)y, new Color(255, 0, 0, 0)); } } var i2 = 0; for (var y = 0; y < img.Size.X; y++) { var bytesPerRow = y < 24 ? 1 + (4 * y) : 97 - (4 * (y - 24)); var startX = 48 - (bytesPerRow / 2); for (var x = 0; x < bytesPerRow; x++) { img2.SetPixel((uint)(startX + x), (uint)y, new Color(0, 0, 0, tile[i2++])); } } var slpFile2 = new SLPFile(); slpFile2.LoadFile("textures/ter15017.slp"); var spritewidth2 = slpFile2.GetFrame(0).m_Width; var spriteheight2 = slpFile2.GetFrame(0).m_Height; var imgg2 = new Image((uint)spritewidth2, (uint)(spriteheight2), slpFile2.GetFrame(0).GetRGBAArray()); for (var y = 0; y < imgg2.Size.Y; y++) { for (var x = 0; x < imgg2.Size.X; x++) { var col = imgg2.GetPixel((uint)x, (uint)y); col.A = (byte)(Math.Min(255, (128 - img.GetPixel((uint)x, (uint)y).A) * 2)); if (img2.GetPixel((uint)x, (uint)y).R == 255) { col.A = 0; } imgg2.SetPixel((uint)x, (uint)y, col); } } selected2 = new Sprite(new Texture(imgg2)); EntManager = new EntityManager(); }