/* MOUSE MOVE HANDLER */ /* HANDLERS */ /* PARAMETERS HANDELING */ public void SetParameters(UInt16 tw, UInt16 th, UInt16 mw, UInt16 mh, UInt16 bt, Image tb, TileContainer tc, ArrayList mo, ObjectContainer oc) { if (tb == null || tc == null || parametersSet) throw (new Exception("Parameters error!")); if (tb.Width % tw != 0 || tb.Height % th != 0) { throw (new Exception("Parsing bitmap error!")); } tileWidth = tw; tileHeight = th; mapWidth = mw; mapHeight = mh; mapOffsets = new UInt16[mapWidth * mapHeight]; for (int i = 0; i < mapOffsets.Length; i++) mapOffsets[i] = (UInt16)((((i / mapWidth) % bt) * bt) + ((i % mapWidth) % bt)); mapObjects.Clear(); this.AutoScrollMinSize = new Size(tileWidth * mapWidth, tileHeight * mapHeight); tileBitmap = tb; tileContainer = tc; objectTypes = mo; objectContainer = oc; parametersSet = true; selectedTileId = 0; pointerHintX = 0; pointerHintY = 0; IsSaved = false; this.Invalidate(); }
public void SetParametersFromFile(FileStream fileStream, Image tb, TileContainer tc, ArrayList mo, ObjectContainer oc) { if (fileStream == null || tb == null || tc == null || parametersSet) throw (new Exception("Parameters error!")); tileBitmap = tb; tileContainer = tc; objectTypes = mo; objectContainer = oc; try { UInt16 count = 0; try { count = Utils.readUint16LittleEndian(fileStream); } catch (Exception) { count = 0; } startCoordinates.Clear(); for (int i = 0; i < count; i++) startCoordinates.Add(new Coord(Utils.readUint16LittleEndian(fileStream), Utils.readUint16LittleEndian(fileStream))); tileWidth = Utils.readUint16LittleEndian(fileStream); tileHeight = Utils.readUint16LittleEndian(fileStream); mapWidth = Utils.readUint16LittleEndian(fileStream); mapHeight = Utils.readUint16LittleEndian(fileStream); mapOffsets = new UInt16[mapWidth * mapHeight]; for (int i = 0; i < mapOffsets.Length; i++) mapOffsets[i] = Utils.readUint16LittleEndian(fileStream); try { count = Utils.readUint16LittleEndian(fileStream); } catch (Exception) { count = 0; } mapObjects.Clear(); for (int i = 0; i < count; i++) { UInt16 id = Utils.readUint16LittleEndian(fileStream); int insertIndex = 0; while (insertIndex < mapObjects.Count && ((ObjectType)objectTypes[(((ObjectInstance)mapObjects[insertIndex]).Id)]).height <= ((ObjectType)objectTypes[id]).height) insertIndex++; mapObjects.Insert(insertIndex, new ObjectInstance(id, Utils.readUint16LittleEndian(fileStream), Utils.readUint16LittleEndian(fileStream))); } } catch (Exception) { throw (new Exception("Error reading file!")); } this.AutoScrollMinSize = new Size(tileWidth * mapWidth, tileHeight * mapHeight); parametersSet = true; selectedTileId = 0; pointerHintX = 0; pointerHintY = 0; IsSaved = true; }
public void ResetParameters() { if (!parametersSet) return; tileWidth = 0; tileHeight = 0; mapWidth = 0; mapHeight = 0; mapOffsets = null; mapObjects.Clear(); startCoordinates.Clear(); tileBitmap = null; tileContainer = null; objectTypes = null; objectContainer = null; this.AutoScrollPosition = new Point(0, 0); parametersSet = false; }