private void button_OK_Click(object sender, EventArgs e) { if (element != null) { //element.setName(textBox_mapName.Text.Trim()); //element.setTileSize((short)numericUpDown_TileW.Value, (short)numericUpDown_TileH.Value); //element.setMapSize((short)numericUpDown_MapW.Value, (short)numericUpDown_MapH.Value); //element.setColor(this.panel_MapColor.BackColor.ToArgb()); //if (comboBox_mapType.SelectedText.Equals("正视地图")) //{ // element.setMapType(MapElement.TYPE_COMMON); //} //else if(comboBox_mapType.SelectedText.Equals("斜45度")) //{ // element.setMapType(MapElement.TYPE_45); //} byte newValue = (byte)numericUpDown_FlagInf.Value; TilePhysicsElement sameValueElem = manager.getElemWithValue(newValue); if (sameValueElem != null && !sameValueElem.Equals(element)) { MessageBox.Show("存在相同标记的物理单元!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } element.setValue(newValue, this.panel_MapColor.BackColor.ToArgb()); } this.Close(); }
public static TilePhysicsElement createElement(TilePhysicsManager managerT) { manager = managerT; element = new TilePhysicsElement(manager); SmallDialog_NewTile_Physics dialog = new SmallDialog_NewTile_Physics("新建物理单元"); dialog.ShowDialog(); return element; }
public TilePhysicsElement clone() { TilePhysicsElement newInstance = new TilePhysicsElement(tilePhysicsManager); newInstance.flagInf = flagInf; newInstance.color = color; return(newInstance); }
public void combine(TilePhysicsManager src_Manager, ArrayList mapsID) { for (int i = 0; i < src_Manager.getElementCount(); i++) { TilePhysicsElement srcTile = src_Manager.getElement(i); //检查是否被源关卡所用到 bool usingBySrc = false; for (int j = 0; j < mapsID.Count; j++) { MapElement map = src_Manager.mapsManager.getElement((int)mapsID[j]); if (map.getTileUsedTime(srcTile) > 0) { usingBySrc = true; break; } } if (!usingBySrc) { continue; } //进入合并 TilePhysicsElement newTile = null; for (int j = 0; j < getElementCount(); j++) { TilePhysicsElement localTile = getElement(j); if (localTile.equlasTo(srcTile)) { newTile = localTile; break; } } if (newTile == null) { newTile = srcTile.clone(this); } if (!PhyTilesList.Contains(newTile)) { this.addElement(newTile); } //转移引用 for (int k = 0; k < src_Manager.mapsManager.getElementCount(); k++) { MapElement map = src_Manager.mapsManager.getElement(k); for (int x = 0; x < map.getMapW(); x++) { for (int y = 0; y < map.getMapH(); y++) { MapTileElement mapTile = map.getTile(x, y); if (mapTile.tile_physic != null && mapTile.tile_physic.Equals(srcTile)) { mapTile.tile_physic = newTile; } } } } } }
public static TilePhysicsElement createElement(TilePhysicsManager managerT) { manager = managerT; element = new TilePhysicsElement(manager); SmallDialog_NewTile_Physics dialog = new SmallDialog_NewTile_Physics("新建物理单元"); dialog.ShowDialog(); return(element); }
public void WriteObject(System.IO.Stream s) { short len = (short)PhyTilesList.Count; IOUtil.writeShort(s, len); for (short i = 0; i < len; i++) { TilePhysicsElement clipElem = (TilePhysicsElement)PhyTilesList[i]; clipElem.WriteObject(s); } }
public TilePhysicsManager cloneForExport(MapsManager mapsManagerT) { TilePhysicsManager newInstance = new TilePhysicsManager(mapsManagerT); for (int i = 0; i < getElementCount(); i++) { TilePhysicsElement elementI = getElement(i); newInstance.addElement(elementI.clone(newInstance)); } return(newInstance); }
//串行化输入与输出=================================================================== #region SerializeAble Members public void ReadObject(System.IO.Stream s) { PhyTilesList.Clear(); short len = IOUtil.readShort(s); for (short i = 0; i < len; i++) { TilePhysicsElement clipElem = new TilePhysicsElement(this); clipElem.ReadObject(s); addElement(clipElem); } }
//是否存在指定数值的单元 public bool isValueExist(int value) { for (int i = 0; i < this.getElementCount(); i++) { TilePhysicsElement element = (TilePhysicsElement)PhyTilesList[i]; if (element != null && element.getFlagInf() == value) { return(true); } } return(false); }
//返回指定参数值的单元 public TilePhysicsElement getElemWithValue(byte value) { for (int i = 0; i < this.getElementCount(); i++) { TilePhysicsElement element = (TilePhysicsElement)PhyTilesList[i]; if (element != null && element.getFlagInf() == value) { return(element); } } return(null); }
//加入新单元 public bool addElement(TilePhysicsElement element) { if (PhyTilesList.Count >= short.MaxValue) { MessageBox.Show("操作被取消,超过最大数量:" + short.MaxValue, "警告:", MessageBoxButtons.OK); return(false); } else { PhyTilesList.Add(element); return(true); } }
//设置地图单元 public static void configElement(TilePhysicsElement elementT) { if (elementT == null) { Console.WriteLine("error in configElement"); return; } manager = elementT.tilePhysicsManager; element = elementT; SmallDialog_NewTile_Physics dialog = new SmallDialog_NewTile_Physics("设置物理单元属性"); dialog.numericUpDown_FlagInf.Value = element.getFlagInf(); dialog.panel_MapColor.BackColor = GraphicsUtil.getColor(element.getColor()); dialog.ShowDialog(); }
//根据单元返回索引 public int getElementIndx(TilePhysicsElement element) { return PhyTilesList.IndexOf(element); }
public bool equlasTo(TilePhysicsElement element) { return element != null && element.flagInf == flagInf; }
public TilePhysicsElement clone() { TilePhysicsElement newInstance = new TilePhysicsElement(tilePhysicsManager); newInstance.flagInf = flagInf; newInstance.color = color; return newInstance; }
public bool equlasTo(TilePhysicsElement element) { return(element != null && element.flagInf == flagInf); }
//加入新单元 public bool addElement(TilePhysicsElement element) { if (PhyTilesList.Count >= short.MaxValue) { MessageBox.Show("操作被取消,超过最大数量:" + short.MaxValue, "警告:", MessageBoxButtons.OK); return false; } else { PhyTilesList.Add(element); return true; } }
//设置焦点物理单元 public void setFocusTile_Phy(int index) { TilePhysicsElement elemn = mapsManager.tilePhysicsManager.getElement(index); //if (elemn != null) //{ currentTile_Phy = elemn; //} }
//根据单元返回索引 public int getElementIndx(TilePhysicsElement element) { return(PhyTilesList.IndexOf(element)); }
//执行操作与访问=================================================================== //返回切片ID public int getElementID(TilePhysicsElement element) { int index = PhyTilesList.IndexOf(element); return(index); }
//自动添加地图物理方格 private void button_AutoGen_Click(object sender, EventArgs e) { //if (mapsManager.tilePhysicsManager.getElementCount() != 0) //{ // MessageBox.Show("已存在物理方格,不能自动添加", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} int color=0xFF; short checkValue = 1; for (int i = 0; i < this.numericUpDown_autoGen_Phy.Value; i++) { TilePhysicsElement element = new TilePhysicsElement(mapsManager.tilePhysicsManager); while (mapsManager.tilePhysicsManager.isValueExist(checkValue)) { checkValue++; } element.setValue(checkValue, color); color += ((0x22 * (1 + i / 36)) << 16) + ((0x22 * (1 + (i % 36) / 6)) << 8) + ((0x22 * (1 + (i % 6)))); if (!mapsManager.tilePhysicsManager.addElement(element)) { break; } } updateContainer_Physics(); }
//执行操作与访问=================================================================== //返回切片ID public int getElementID(TilePhysicsElement element) { int index = PhyTilesList.IndexOf(element); return index; }