Add files via upload

This commit is contained in:
Bluzume 2021-09-24 17:08:17 +12:00 committed by GitHub
parent 4323c7e74c
commit 9f1f97712e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 387 additions and 17 deletions

View File

@ -82,22 +82,23 @@ namespace SilicaTilesEditor
// newItem
//
this.newItem.Name = "newItem";
this.newItem.Size = new System.Drawing.Size(121, 22);
this.newItem.Size = new System.Drawing.Size(180, 22);
this.newItem.Text = "New File";
this.newItem.Click += new System.EventHandler(this.newItem_Click);
//
// loadItem
//
this.loadItem.Name = "loadItem";
this.loadItem.Size = new System.Drawing.Size(121, 22);
this.loadItem.Size = new System.Drawing.Size(180, 22);
this.loadItem.Text = "Load File";
this.loadItem.Click += new System.EventHandler(this.loadItem_Click);
//
// saveItem
//
this.saveItem.Name = "saveItem";
this.saveItem.Size = new System.Drawing.Size(121, 22);
this.saveItem.Size = new System.Drawing.Size(180, 22);
this.saveItem.Text = "Save File";
this.saveItem.Click += new System.EventHandler(this.saveItem_Click);
//
// layerMenu
//

View File

@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SilicaTilesEditor
@ -19,7 +12,18 @@ namespace SilicaTilesEditor
private void newItem_Click(object sender, EventArgs e)
{
this.Enabled = false;
NewMapForm mapForm = new NewMapForm();
DialogResult res = mapForm.ShowDialog();
this.Enabled = true;
if (res == DialogResult.OK)
{
MessageBox.Show("Map Created", "Map Creation", MessageBoxButtons.OK, MessageBoxIcon.Information);
tileList.UpdateScroll();
tileSelector.CalculateScroll();
tileSelector.Invalidate();
}
}
private void loadItem_Click(object sender, EventArgs e)
@ -32,7 +36,8 @@ namespace SilicaTilesEditor
Map.OpenMap(loadFileDg.FileName);
tileList.UpdateScroll();
tileList.Invalidate();
tileSelector.CalculateScroll();
tileSelector.Invalidate();
}
}
private void MainForm_Load(object sender, EventArgs e)
@ -43,6 +48,7 @@ namespace SilicaTilesEditor
layout.ColumnStyles[0].Width = (32*7) + SystemInformation.VerticalScrollBarWidth;
tileset0.Checked = true;
tileList.ExtOverlay = 0;
tileList.UpdateScroll();
tileSelector.CalculateScroll();
tileSelector.Invalidate();
}
@ -154,5 +160,17 @@ namespace SilicaTilesEditor
}
private void saveItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDg = new SaveFileDialog();
saveFileDg.Filter = "Map Data Files|*.MAP";
saveFileDg.Title = "Select Map File";
saveFileDg.FileName = Map.LoadedMap;
if (saveFileDg.ShowDialog() == DialogResult.OK)
{
Map.SaveMap(saveFileDg.FileName);
MessageBox.Show("File saved successfully.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

View File

@ -52,6 +52,43 @@ namespace SilicaTilesEditor
return 1;
}
public static void SaveMap(string MapFile)
{
byte[] worldMap = new byte[8 + (Width * Height) * 2];
byte[] WidthInt = BitConverter.GetBytes(Width);
byte[] HeightInt = BitConverter.GetBytes(Height);
Array.ConstrainedCopy(WidthInt, 0, worldMap, 0, 4);
Array.ConstrainedCopy(HeightInt, 0, worldMap, 4, 4);
int ii = 8;
for (int i = 0; i < MapData.Length; i++)
{
worldMap[ii] = oMapData[i];
worldMap[ii + 1] = MapData[i];
ii += 2;
}
LoadedMap = MapFile;
MapLoaded = true;
File.WriteAllBytes(MapFile, worldMap);
}
public static void CreateMap(int width, int height)
{
Width = width;
Height = height;
MapData = new byte[width * height];
oMapData = new byte[width * height];
for (int i = 0; i < MapData.Length; i++)
{
oMapData[i] = 1;
MapData[i] = 1;
}
LoadedMap = "NEW.MAP";
MapLoaded = true;
}
public static void OpenMap(string MapFile)
{
byte[] worldMap = File.ReadAllBytes(MapFile);
@ -70,8 +107,6 @@ namespace SilicaTilesEditor
ii += 2;
}
worldMap = null;
LoadedMap = MapFile;
MapLoaded = true;
}

136
SilicaTilesEditor/NewMapForm.Designer.cs generated Normal file
View File

@ -0,0 +1,136 @@

namespace SilicaTilesEditor
{
partial class NewMapForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.heightUpDown = new System.Windows.Forms.NumericUpDown();
this.widthUpDown = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.createMap = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.heightUpDown)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.widthUpDown)).BeginInit();
this.SuspendLayout();
//
// heightUpDown
//
this.heightUpDown.Location = new System.Drawing.Point(57, 68);
this.heightUpDown.Maximum = new decimal(new int[] {
2147483647,
0,
0,
0});
this.heightUpDown.Name = "heightUpDown";
this.heightUpDown.Size = new System.Drawing.Size(140, 20);
this.heightUpDown.TabIndex = 0;
//
// widthUpDown
//
this.widthUpDown.Location = new System.Drawing.Point(57, 44);
this.widthUpDown.Maximum = new decimal(new int[] {
2147483647,
0,
0,
0});
this.widthUpDown.Name = "widthUpDown";
this.widthUpDown.Size = new System.Drawing.Size(140, 20);
this.widthUpDown.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 46);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Width:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(10, 70);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Height:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(10, 19);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(85, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Create new Map";
//
// createMap
//
this.createMap.Location = new System.Drawing.Point(16, 101);
this.createMap.Name = "createMap";
this.createMap.Size = new System.Drawing.Size(181, 23);
this.createMap.TabIndex = 5;
this.createMap.Text = "Create Map";
this.createMap.UseVisualStyleBackColor = true;
this.createMap.Click += new System.EventHandler(this.createMap_Click);
//
// NewMapForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(212, 136);
this.Controls.Add(this.createMap);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.widthUpDown);
this.Controls.Add(this.heightUpDown);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "NewMapForm";
this.ShowInTaskbar = false;
this.Text = "New Map";
((System.ComponentModel.ISupportInitialize)(this.heightUpDown)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.widthUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.NumericUpDown heightUpDown;
private System.Windows.Forms.NumericUpDown widthUpDown;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button createMap;
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Windows.Forms;
namespace SilicaTilesEditor
{
public partial class NewMapForm : Form
{
public NewMapForm()
{
InitializeComponent();
this.DialogResult = DialogResult.Cancel;
}
private void createMap_Click(object sender, EventArgs e)
{
Map.CreateMap(Convert.ToInt32(widthUpDown.Value), Convert.ToInt32(heightUpDown.Value));
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{286BE9D8-B723-43A5-A9BA-6769D4FD36DB}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<RootNamespace>SilicaTilesEditor</RootNamespace>
<AssemblyName>SilicaTilesEditor</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
@ -57,6 +57,12 @@
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Map.cs" />
<Compile Include="NewMapForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="NewMapForm.Designer.cs">
<DependentUpon>NewMapForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TileMapEditorControl.cs">
@ -69,6 +75,9 @@
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="NewMapForm.resx">
<DependentUpon>NewMapForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@ -32,6 +32,12 @@ namespace SilicaTilesEditor
selectedTileX = Convert.ToInt32(Math.Floor((float)HorizontalScroll.Value / 32.0)) + SelTileX;
selectedTileY = Convert.ToInt32(Math.Floor((float)VerticalScroll.Value / 32.0)) + SelTileY;
if (selectedTileX > Map.Width)
selectedTileX = Map.Width;
if (selectedTileY > Map.Height)
selectedTileX = Map.Height;
if (!(oldSelTileX == SelTileX && oldSelTileY == SelTileY))
{

View File

@ -35,13 +35,35 @@ namespace SilicaTilesEditor
SelectedTileid = ((SelTileY * maxX) + SelTileX) + 1;
bool change = false;
if(SelectedTileid > 0xFF)
{
SelectedTileid = 0xFF;
SelTileX = (SelectedTileid % maxX) -1;
SelTileY = SelectedTileid / maxX;
change = true;
}
if(!Program.form.tileList.DisplayOverlay)
{
if(SelectedTileid > Tileset.TerrainList.Length)
{
SelectedTileid = Tileset.TerrainList.Length;
change = true;
}
}
else
{
if (SelectedTileid > Tileset.JoinedTileset.Length)
{
SelectedTileid = Tileset.JoinedTileset.Length;
change = true;
}
}
if (change)
{
SelTileX = (SelectedTileid % maxX) - 1;
SelTileY = SelectedTileid / maxX;
}
if (!(oldSelTileX == SelTileX && oldSelTileY == SelTileY))
{
Program.form.selTileId.Text = "Seleted Tile ID: " + SelectedTileid;