/// <summary> /// 初始化预置 /// </summary> private void InitPrefab() { pcPrefab.Controls.Clear(); //加载预置Box for (int i = 0; i < PrefabList.Instance.CurPrefabList.Count; i++) { BoxItem boxItem = PrefabList.Instance.CurPrefabList[i]; PrefabItemUI prefabItem = new PrefabItemUI(boxItem); if (object.ReferenceEquals(this.showMapUI.DesignBoxItem, boxItem)) { prefabItem.IsSelected = true; } prefabItem.Click += new EventHandler(prefabItem_Click); pcPrefab.Controls.Add(prefabItem); prefabItem.Location = new Point(prefabItem.Width * i, 0); } //"删除"功能Box BoxItem boxDeleteItem = new BoxItem("Delete"); PrefabItemUI prefabDeleteItem = new PrefabItemUI(boxDeleteItem); prefabDeleteItem.Click += new EventHandler(prefabItem_Click); pcPrefab.Controls.Add(prefabDeleteItem); prefabDeleteItem.Location = new Point(PrefabList.Instance.CurPrefabList.Count * prefabDeleteItem.Width, 0); //"添加"功能Box BoxItem boxAddItem = new BoxItem("Add"); PrefabItemUI prefabAddItem = new PrefabItemUI(boxAddItem); prefabAddItem.Click += new EventHandler(prefabAddItem_Click); pcPrefab.Controls.Add(prefabAddItem); prefabAddItem.Location = new Point((PrefabList.Instance.CurPrefabList.Count + 1) * prefabAddItem.Width, 0); }
/// <summary> /// 预置Box点击,设置选中状态、当前设计Box、属性显示 /// </summary> private void prefabItem_Click(object sender, EventArgs e) { PrefabItemUI prefabItem = sender as PrefabItemUI; if (prefabItem == null) { return; } foreach (Control c in pcPrefab.Controls) { if (c is PrefabItemUI) { ((PrefabItemUI)c).IsSelected = false; } } prefabItem.IsSelected = true; //设置选中(红边框) showMapUI.DesignBoxItem = prefabItem.BoxItem; //设置当前设计Box biPropEdit.BoxItem = prefabItem.BoxItem; //属性显示 }
void timer_Tick(object sender, EventArgs e) { //转换方向 if (curDirectionCount >= turnDirectionCount) { curDir = RndDirection.NewRndDirection; curDirectionCount = 0; } //方向图片显示 foreach (Control c in pcPrefab.Controls) { PrefabItemUI prefabItemUI = c as PrefabItemUI; if (prefabItemUI == null) { continue; } prefabItemUI.ShowDirection = curDir; prefabItemUI.ShowIndex = directCountDict[curDir]; } //当前方向计次增加 directCountDict[curDir]++; curDirectionCount++; }