/// <summary> /// 發生於活動物件集合變更 /// </summary> protected virtual void OnGameObjectsChanged(ObjectCollection oldValue, ObjectCollection newValue) { if (oldValue != null) { oldValue.BindingUnlock(); } if (newValue != null) { newValue.Binding(this, true); } if (GameObjectsChanged != null) { GameObjectsChanged(this, oldValue, newValue); } }
/// <summary> /// 綁定物件到集合(集合內綁定,除此之外勿使用此函數) /// </summary> /// <param name="collection">集合</param> /// <param name="bindingLock">綁定後是否鎖定綁定功能</param> public void Binding(ObjectCollection collection, bool bindingLock = false) { if (_Container == collection) { return; } if (BindingLock) { throw new Exception("物件已被鎖定無法綁定"); } if (collection != null && !collection.Contains(this)) { throw new Exception("物件不在集合中"); } Container = collection; Scene = null; BindingLock = bindingLock; OnBindingChanged(); }
public ObjectUISceneChoice(int x, int y, int width, int height) : base(x, y, width, height, new DrawBrush(Color.White, ShapeType.Rectangle)) { BackObjects = new ObjectCollection(); var ScenesItems = GlobalScenes.Scenes.GetItems(); int group1Idx = 0; int group1Cot = ScenesItems.Count; _UIScenes = new ObjectUISceneInfo[group1Cot]; _UIScenesLocation = new PointF[group1Cot]; foreach (ISceneInfo sceneInfo in ScenesItems) { _UIScenes[group1Idx] = new ObjectUISceneInfo(DirectionType.TopLeft, 0, 0, new MoveStraight(this, 1, 3000, 1, 100, 1F)); _UIScenes[group1Idx].MoveObject.Target.Anchor = DirectionType.TopLeft; _UIScenes[group1Idx].MoveObject.Anchor = DirectionType.TopLeft; _UIScenes[group1Idx].Layout.Depend.Anchor = DirectionType.TopLeft; _UIScenes[group1Idx].Layout.Depend.SetObject(this); _UIScenes[group1Idx].BindingScene = sceneInfo; _UIScenes[group1Idx].SceneChoice += (s, i, l) => { OnSceneChoice(i, l); }; _UIScenes[group1Idx].HightScoreClick += (s, i) => { OnSceneHightScoreClick(sceneInfo); }; UIObjects.Add(_UIScenes[group1Idx]); group1Idx++; } if (group1Cot > 0) { int maxH = (int)((width - _PaddingX * 2 + _ItemPaddingX) / (_UIScenes[0].Layout.RectWidth + _ItemPaddingX)); // 橫向最多項目數 int cotX = group1Cot > maxH ? maxH : group1Cot; // 橫向數量 int cotY = (group1Cot - 1) / maxH + 1; // 縱向數量 float baseX = (width - (_UIScenes[0].Layout.RectWidth * cotX) - (_ItemPaddingX * (cotX - 1))) / 2; float baseY = _PaddingY + (height - (_UIScenes[0].Layout.RectWidth * cotY) - (_ItemPaddingY * (cotY - 1))) / 2; baseY = Math.Max(_ItemMinY, baseY); float originX = baseX; for (int i = 0; i < _UIScenes.Length; i++) { _UIScenesLocation[i] = new PointF(baseX, baseY); _UIScenes[i].Layout.X = baseX; _UIScenes[i].Layout.Y = baseY + height; _UIScenes[i].MoveObject.Target.SetOffsetByXY(baseX, baseY + height); if (i > 0 && i - 1 % cotX == 0) { baseX = originX; baseY += _UIScenes[0].Layout.RectHeight + _ItemPaddingY; } else { baseX += _UIScenes[i].Layout.RectWidth + _ItemPaddingX; } } } _DrawGroup1 = new DrawUIText(Color.DarkSlateBlue, Color.White, Color.AliceBlue, Color.DarkSlateBlue, 2, 12, "生存100秒", new Font("標楷體", 18, FontStyle.Bold), GlobalFormat.BottomCenter); _DrawGroup1.DrawObjectInside = new DrawSceneTypeA(Color.LightSteelBlue); _UIGroup1 = new ObjectUI(DirectionType.Center, -200, height / 2, 200, 200, _DrawGroup1, new MoveStraight(this, 1, 3000, 1, 100, 1F)); _UIGroup1.Propertys.Add(new PropertyShadow(3, 4)); _UIGroup1.Layout.Depend.Anchor = DirectionType.TopLeft; _UIGroup1.Layout.Depend.SetObject(this); _UIGroup1.GetFocus += (s, e) => { _DrawGroup1.Colors.SetColor("Back", Color.FromArgb(255, 255, 220)); _DrawGroup1.DrawObjectInside.Colors.SetColor("Player", Color.Black); _DrawGroup1.DrawObjectInside.Colors.SetColor("Ememy", Color.Red); }; _UIGroup1.LostFocus += (s, e) => { _DrawGroup1.Colors.SetColor("Back", Color.AliceBlue); _DrawGroup1.DrawObjectInside.Colors.SetColor("Player", Color.LightSteelBlue); _DrawGroup1.DrawObjectInside.Colors.SetColor("Ememy", Color.LightSteelBlue); }; _UIGroup1.Click += (s, e) => { Mode = 1; }; _DrawGroup2 = new DrawUIText(Color.DarkSlateBlue, Color.White, Color.WhiteSmoke, Color.DarkSlateBlue, 2, 12, "", new Font("標楷體", 18), GlobalFormat.BottomCenter); _UIGroup2 = new ObjectUI(DirectionType.Center, width + 200, height / 2, 200, 200, _DrawGroup2, new MoveStraight(this, 1, 3000, 1, 100, 1F)); _UIGroup2.Propertys.Add(new PropertyShadow(-3, 4)); _UIGroup2.Layout.Depend.Anchor = DirectionType.TopLeft; _UIGroup2.Layout.Depend.SetObject(this); _CommandBack = new ObjectUI(20, 20, 80, 40, new DrawUIText(Color.Black, Color.Gray, Color.FromArgb(255, 255, 255, 220), Color.Black, 1, 8, "返回", new Font("微軟正黑體", 18), GlobalFormat.MiddleCenter)); _CommandBack.Propertys.Add(new PropertyShadow(5, 4) { RFix = 0F, GFix = 0F, BFix = 0F }); _CommandBack.Layout.Depend.Anchor = DirectionType.TopLeft; _CommandBack.Layout.Depend.SetObject(this); _CommandBack.Visible = false; _CommandBack.Click += (s, e) => { Mode = 0; }; UIObjects.Add(_CommandBack); UIObjects.Add(_UIGroup1); UIObjects.Add(_UIGroup2); Mode = 0; }
/// <summary> /// 使用預設定位點(左上)建立不可移動介面物件 /// </summary> /// <param name="x">物件左上位置X</param> /// <param name="y">物件左上位置Y</param> /// <param name="width">物件寬度</param> /// <param name="height">物件高度</param> /// <param name="drawObject">繪製物件</param> /// <param name="moveObject">移動物件</param> public ObjectUIPanel(int x, int y, int width, int height, DrawBase drawObject) : this(DirectionType.TopLeft, x, y, width, height, drawObject) { UIObjects = new ObjectCollection(); }
/// <summary> /// 使用指定的定位點建立不可移動介面物件 /// </summary> /// <param name="anchor">定位點位置X</param> /// <param name="x">物件左上位置X</param> /// <param name="y">物件左上位置Y</param> /// <param name="width">物件寬度</param> /// <param name="height">物件高度</param> /// <param name="drawObject">繪製物件</param> public ObjectUIPanel(DirectionType anchor, int x, int y, int width, int height, DrawBase drawObject) : base(anchor, x, y, width, height, drawObject) { UIObjects = new ObjectCollection(SceneNull.Value); }
/// <summary> /// 使用指定的定位點和移動物件建立介面物件 /// </summary> /// <param name="x">物件左上位置X</param> /// <param name="y">物件左上位置Y</param> /// <param name="width">物件寬度</param> /// <param name="height">物件高度</param> /// <param name="drawObject">繪製物件</param> /// <param name="moveObject">移動物件</param> public ObjectUIPanel(DirectionType anchor, int x, int y, int width, int height, DrawBase drawObject, MoveBase moveObject) : base(anchor, x, y, width, height, drawObject, moveObject) { UIObjects = new ObjectCollection(); }