protected virtual void HandleMouseOver() { if (!IsUnderMouse) { DrawBoxUnderMouse = null; return; } DrawBoxUnderMouse = null; foreach (DrawBox child in DrawBoxList) { if (DialoguesAreHidden && dialogues.Contains(child)) { continue; } if (child.CheckMouseOver()) { if (DrawBoxUnderMouse == null) { DrawBoxUnderMouse = child; } else if (DrawBoxList.IndexOf(child) > DrawBoxList.IndexOf(DrawBoxUnderMouse)) { DrawBoxUnderMouse = child; } } } }
public void RequestRemoval(DrawBox box) { if (!removeQue.Contains(box)) { removeQue.Add(box); } }
/// <summary> /// Removes the drawbox in the slot of the provided handler. /// </summary> /// <param name="handler"></param> protected void RemoveDrawBoxInSlot(SlotHandler handler) { DrawBox drawBox = Slots[handler].DrawBox; if (drawBox.Container != this) { Debug.AddExceptionInClass(this.GetType(), "RemoveDrawBoxFromSlot", "DrawBox does not have correct container."); return; } if (!drawBox.IsClosed) { drawBox.Close(); } drawBox.Container = null; drawBox.Handler = null; Slots[handler].DrawBox = null; drawBoxList.Remove(drawBox); DrawBoxHasBeenRemoved(drawBox, handler); UpdateSize(); }
protected override void DrawBoxHasBeenRemoved(DrawBox box, SlotHandler handler) { RemoveSlot(handler); if (DrawBoxRemoved != null) { DrawBoxRemoved(this, box); } }
public void AddDrawBox(DrawBox drawBox) { PutDrawBoxInSlot(drawBox, AddNewSlot()); if (DrawBoxAdded != null) { DrawBoxAdded(this, drawBox); } }
//TODO: make point GetChildDrawBoundary, something that doesnt affect size. protected ViewRect GenerateChildBoundaries(DrawBox drawBox, int newWidth, int newHeight) { if (drawBox.Container != this) { Debug.AddExceptionInClass(this.GetType(), "GenerateChildBoundaries", "Tried to get boundaries for point drawbox with point different container"); return(ViewRect.Empty); } return(GenerateSlotBoundaries(drawBox.Handler)); }
/// <summary> /// Draws the window. /// </summary> /// <param name="gameTime"></param> /// <param name="viewRect"></param> public override void Draw(GameTime gameTime, ViewRect viewRect) { if (IsClosed || !IsInitialized || !Activated) { return; } if (!Hidden) { ViewRect windowRect = viewRect.AddGet(new ViewRect(RealX, RealY, Width, Height)); windowRect.Add(GetDefaultBoundaries()); IRender render = GraphicsManager.GetRender(); render.SetViewRect(windowRect); Project(gameTime, RealX, RealY, render); if (!DialoguesAreHidden && DarkenWhenDialogueExists && GetCurrentDialogue() != null) { DrawBox currentDialogue = GetCurrentDialogue(); foreach (DrawBox d in DrawBoxList) { if (currentDialogue != d) { d.Draw(gameTime, viewRect); } } var r = GraphicsManager.GetRender(); r.Begin(); r.Clear(DarkeningMask); r.End(); currentDialogue.Draw(gameTime, viewRect); } else { foreach (DrawBox d in DrawBoxList) { if (DialoguesAreHidden && dialogues.Contains(d)) { continue; } d.Draw(gameTime, viewRect); } } foreach (var f in drawDelegates) { f(gameTime, viewRect); } drawDelegates.Clear(); } }
/// <summary> /// Tells the drawbox to put the provided child-drawbox in the back of the drawing and update que. /// </summary> /// <param name="drawBox"></param> public void PutChildInBack(DrawBox drawBox) { if (!DrawBoxList.Contains(drawBox)) { Debug.AddExceptionInClass(this.GetType(), "ContainerBox.PutChildInBack", "The DrawBox instance is not one of the alignWith-objects."); return; } drawBoxList.Remove(drawBox); drawBoxList.Insert(0, drawBox); }
/// <summary> /// Removes the specified drawbox from its slot. /// </summary> /// <param name="box"></param> protected void RemoveDrawBoxFromSlot(DrawBox box) { var slotList = (from s in Slots.Values where s.DrawBox == box select s); if (slotList.Count() != 0) { RemoveDrawBoxInSlot(slotList.First().Handler); } else { Debug.AddExceptionInClass(this.GetType(), "RemoveDrawBoxFromSlot", "Tried to remove non-existing drawbox."); } }
/// <summary> /// Inserts the drawbox to the slot with the provided handler. /// </summary> /// <param name="box">The box to insert into the slot.</param> /// <param name="handler">The handler of the slot.</param> protected void PutDrawBoxInSlot(DrawBox box, SlotHandler handler) { if (box == this) { Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add this to itself."); return; } if (handler.DrawBox != null) { Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox to an occupied slot."); return; } if (DrawBoxList.Contains(box)) { Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox instance twice to the same container"); return; } if (box.Container != null) { Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox instance that already has point container."); return; } if (!box.IsInitialized) { Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Can't add point DrawBox that is not initialized."); return; } if (!Slots.ContainsKey(handler)) { Debug.AddExceptionInClass(this.GetType(), "PutDrawBoxInSlot", "Tried to put drawbox in non-existing slot."); return; } Slots[handler].DrawBox = box; drawBoxList.Add(box); box.Parent = Parent; box.Container = this; box.Handler = handler; UpdateSize(); box.ReloadAlignment(); box.AddedToContainer(); DrawBoxHasBeenAdded(box, handler); }
public override void Update(GameTime gameTime) { SetChildParameters(); base.Update(gameTime); if (IsClosed || !IsInitialized || !Activated) { return; } HandleFocus(); HandleMouseOver(); while (dialogues.Count != 0 && dialogues.Last().IsClosed) { dialogues.RemoveAt(dialogues.Count - 1); } if (!DialoguesAreHidden && dialogues.Count != 0) { var dialog = dialogues.Last(); if (dialog != DrawBoxWithFocus) { DrawBoxWithFocus = null; } if (dialog != DrawBoxUnderMouse) { DrawBoxUnderMouse = null; } } if (removeQue.Count != 0) { foreach (DrawBox d in removeQue) { RemoveDrawBoxFromSlot(d); } removeQue.Clear(); } foreach (DrawBox d in new List <DrawBox>(drawBoxList)) { if (DialoguesAreHidden && dialogues.Contains(d)) { continue; } d.Update(gameTime); } }
public static void HorizontallyAlignWith(DrawBox box, DrawBox alignWith, HorizontalAlign align) { switch (align) { case HorizontalAlign.Top: box.Y = alignWith.Y; break; case HorizontalAlign.Center: box.Y = alignWith.Y + (alignWith.Height / 2) - (box.Height / 2); break; case HorizontalAlign.Bottom: box.Y = alignWith.Y + alignWith.Height - box.Height; break; } }
public static void VerticallyAlignWith(DrawBox box, DrawBox alignWith, VerticalAlign align) { switch (align) { case VerticalAlign.Left: box.X = alignWith.X; break; case VerticalAlign.Center: box.X = alignWith.X + (alignWith.Width / 2) - (box.Width / 2); break; case VerticalAlign.Right: box.X = alignWith.X + alignWith.Width - box.Width; break; } }
public override void Draw(GameTime gameTime, ViewRect viewRect) { base.Draw(gameTime, viewRect); if (!IsInitialized || !Activated || Hidden) { return; } viewRect.Add(Boundaries); viewRect.Add(GetMasterBoundaries()); if (!DialoguesAreHidden && DarkenWhenDialogueExists && GetCurrentDialogue() != null) { DrawBox currentDialogue = GetCurrentDialogue(); foreach (DrawBox d in DrawBoxList) { if (currentDialogue != d) { d.Draw(gameTime, viewRect); } } var render = GraphicsManager.GetRender(); render.Begin(); render.Clear(DarkeningMask); render.End(); currentDialogue.Draw(gameTime, viewRect); } else { foreach (DrawBox d in DrawBoxList) { if (DialoguesAreHidden && dialogues.Contains(d)) { continue; } d.Draw(gameTime, viewRect); } } }
protected virtual void HandleFocus() { if (DrawBoxWithFocus != null && DrawBoxWithFocus.Suspended) { DrawBoxWithFocus = null; } if (!HasFocus) { DrawBoxWithFocus = null; return; } DrawBox oldDrawBoxWithFocus = DrawBoxWithFocus; DrawBoxWithFocus = null; foreach (DrawBox d in DrawBoxList) { if (DialoguesAreHidden && dialogues.Contains(d)) { continue; } if (d.CheckFocus()) { if (DrawBoxWithFocus == null) { DrawBoxWithFocus = d; } else if (DrawBoxList.IndexOf(d) > DrawBoxList.IndexOf(DrawBoxWithFocus)) { DrawBoxWithFocus = d; } } } if (DrawBoxWithFocus == null) { DrawBoxWithFocus = oldDrawBoxWithFocus; } }
public static void FromSide(DrawBox box, int distance, Side edge) { ViewRect bounds = box.Boundaries; switch (edge) { case Side.Top: box.Y = distance; break; case Side.Bottom: box.Y = bounds.Height - box.Height - distance; break; case Side.Left: box.X = distance; break; case Side.Right: box.X = bounds.Width - box.Width - distance; break; } }
/// <summary> /// Queries the slotbox whether the child-drawbox is the drawbox with focus. /// </summary> /// <param name="box"></param> /// <returns></returns> public bool TestDrawBoxWithFocus(DrawBox box) { return(DrawBoxWithFocus == box); }
public static void ToHorizontalCenter(DrawBox box) { box.X = (box.Boundaries.Width / 2) - box.Width / 2; }
public static void ToVerticalCenter(DrawBox box) { box.Y = (box.Boundaries.Height / 2) - box.Height / 2; }
protected Origin GenerateChildOrigin(DrawBox box) { return(GenerateChildOrigin(box.Handler)); }
/// <summary> /// Queries the slotbox whether the child-drawbox is inside the slotbox. /// </summary> /// <param name="box"></param> /// <returns></returns> public bool TestIsDrawBoxInContainer(DrawBox box) { return(DrawBoxList.Contains(box)); }
public static void ToTheBottomSideOf(DrawBox box, DrawBox alignWith, int margin, VerticalAlign align) { VerticallyAlignWith(box, alignWith, align); box.Y = alignWith.Y + alignWith.Height + margin; }
public static void ToTheRightSideOf(DrawBox box, DrawBox alignWith, int margin, HorizontalAlign align) { HorizontallyAlignWith(box, alignWith, align); box.X = alignWith.X + alignWith.Width + margin; }
protected ViewRect GenerateChildBoundaries(DrawBox drawBox) { return(GenerateChildBoundaries(drawBox, Width, Height)); }
public static void ToTheTopSideOf(DrawBox box, DrawBox alignWith, int margin, VerticalAlign align) { VerticallyAlignWith(box, alignWith, align); box.Y = alignWith.Y - box.Height - margin; }
/// <summary> /// Is called whenever a drawbox has been removed. /// </summary> /// <param name="box"></param> /// <param name="handler"></param> protected virtual void DrawBoxHasBeenRemoved(DrawBox box, SlotHandler handler) { }
public void PutDialogOnStack(DrawBox drawBox) { dialogues.Add(drawBox); }
/// <summary> /// Queries the slotbox whether the child-drawbox is the last to draw. /// </summary> /// <param name="child"></param> /// <returns></returns> public bool IsChildLastToDraw(DrawBox child) { return(child == DrawBoxList.Last()); }
/// <summary> /// Queries the slotbox whether the child-drawbox is the drawbox under the mouse. /// </summary> /// <param name="box"></param> /// <returns></returns> public bool TestDrawBoxUnderMouse(DrawBox box) { return(DrawBoxUnderMouse == box); }
public void RemoveDialogFromStack(DrawBox drawBox) { dialogues.Remove(drawBox); }