Exemple #1
0
        ////////////////

        private void UpdateInteractionsForEditModeDrag_If(bool isEditMode, bool mouseLeft)
        {
            if (this.IsInteractingWithControls)
            {
                return;
            }
            if (this.IsDragLocked())
            {
                return;
            }

            //

            HUDElement currDrag = HUDElementsLibAPI.GetDraggingElement();

            if (currDrag == null || currDrag == this)
            {
                bool isInteracting = mouseLeft && isEditMode;

                if (isInteracting)
                {
                    if (this.IsDraggingSinceLastTick || this.IsMouseHoveringEditableBox)
                    {
                        this.ApplyDrag();
                    }
                }
                else
                {
                    this.DesiredDragPosition = null;
                }
            }
        }
        ////////////////

        internal void PreUpdateForInteractions()
        {
            foreach (HUDElement elem in this.Elements.Values)
            {
                if (elem.UpdateEditModeInteractionsWithinEntireUI())
                {
                    break;
                }
            }

            if (!HUDElementsLibAPI.IsEditModeActive())
            {
                bool hasInteracted = false;

                foreach (HUDElement elem in this.Elements.Values)
                {
                    hasInteracted = this.UpdateInteractionsWithinEntireUI_If(elem);

                    if (hasInteracted)
                    {
                        break;
                    }
                }

                if (!hasInteracted)
                {
                    this.ClearInteractionsIfAny();
                }
            }
        }
        ////////////////

        public static void AddWidget(HUDElement element)                //string layerName = "Vanilla: Mouse Text"
        {
            var mymod = ModContent.GetInstance <HUDElementsLibMod>();

            mymod.HUDManager?.LoadHUDElement(element);

            mymod.MyUI?.Append(element);
            mymod.MyUI?.Recalculate();

            HUDElementsLibAPI.MessageAboutHUD_If();
        }
Exemple #4
0
        ////////////////

        private bool UpdateEditModeInteractions_If()
        {
            if (!this.IsEnabled())
            {
                return(false);
            }

            bool mouseLeft  = PlayerInput.Triggers.Current.MouseLeft;
            bool isEditMode = HUDElementsLibAPI.IsEditModeActive();

            this.UpdateInteractionsForEditModeControls_If(isEditMode, mouseLeft);
            this.UpdateInteractionsForEditModeDrag_If(isEditMode, mouseLeft);

            return(true);
        }
Exemple #5
0
        ////////////////

        private void DrawOverlays_If(SpriteBatch sb)
        {
            bool isHoverCollision    = false;
            bool isHoverAnchorRight  = false;
            bool isHoverAnchorBottom = false;
            bool isHoverReset        = false;

            //if( Main.playerInventory ) {
            //bool mode = Main.keyState.IsKeyDown( Keys.LeftAlt )
            //	|| Main.keyState.IsKeyDown( Keys.RightAlt );
            bool editMode = HUDElementsLibAPI.IsEditModeActive();

            if (editMode)
            {
                this.DrawEditModeTitle(sb);
                this.DrawEditModeBoxes(sb);
                this.DrawEditModeControls_If(
                    sb,
                    out isHoverCollision,
                    out isHoverReset,
                    out isHoverAnchorRight,
                    out isHoverAnchorBottom
                    );
            }

            //

            (string text, int duration)hoverInfo = this.GetHoverText(
                editMode,
                isHoverCollision,
                isHoverReset,
                isHoverAnchorRight,
                isHoverAnchorBottom
                );

            if (!string.IsNullOrEmpty(hoverInfo.text))
            {
                this.DrawHoverText_If(sb, hoverInfo.text, hoverInfo.duration);
            }
            else
            {
                this.ClearHoverText();
            }
        }
Exemple #6
0
        internal bool UpdateEditModeInteractionsWithinEntireUI()
        {
            //Rectangle area = this.GetHUDComputedArea( false );	<- Incorrect rectangle when game or ui zooms
            //this.IsMouseHovering_Custom = area.Contains( Main.MouseScreen.ToPoint() );

            //bool isInteracting = Main.playerInventory && Main.mouseLeft && this.IsMouseHovering_Custom;
            bool isInteracting = Main.mouseLeft &&
                                 this.IsMouseHoveringEditableBox &&
                                 HUDElementsLibAPI.IsEditModeActive();

            if (isInteracting)
            {
                Main.LocalPlayer.mouseInterface = true;                 // Locks control for this element
                //if( Main.LocalPlayer.mouseInterface ) {
                //	Main.NewText( "HUD_Elem_PreUpdForInt 1" );
                //}
            }

            return(isInteracting);
        }
Exemple #7
0
        ////////////////

        private void UpdateInteractionsForEditModeControls_If(bool isEditMode, bool mouseLeft)
        {
            if (this.IsInteractingWithControls)
            {
                bool isInteracting = mouseLeft && isEditMode;                   //&& this.IsMouseHovering_Custom;

                this.IsInteractingWithControls   = isInteracting;
                Main.LocalPlayer.mouseInterface |= isInteracting;                       // Repeatably locks control for this element, if needed
//if( Main.LocalPlayer.mouseInterface ) {
//	Main.NewText( "HUD_UpdIntForCtrlIf 1" );
//}

                return;                 // Only the first tick of interaction matters
            }

            //

            if (!isEditMode)
            {
                return;
            }
            if (!mouseLeft)
            {
                return;
            }
            if (!this.IsMouseHoveringEditableBox)
            {
                return;
            }
            if (HUDElementsLibAPI.GetDraggingElement() != null)
            {
                return;
            }

            //

            Point     mouse = Main.MouseScreen.ToPoint();
            Rectangle area  = this.GetHUDComputedArea(false);

            Rectangle toggler = HUDElement.GetCollisionTogglerArea(area);
            Rectangle reset   = HUDElement.GetResetButtonArea(area);
            Rectangle anchorR = HUDElement.GetRightAnchorButtonArea(area);
            Rectangle anchorB = HUDElement.GetBottomAnchorButtonArea(area);
            bool      pressed = false;

            if (toggler.Contains(mouse) && this.IsCollisionToggleable())
            {
                pressed = this.ApplyCollisionsToggleControlPress_If();
            }
            else if (reset.Contains(mouse) && !this.IsDragLocked())
            {
                pressed = true;
                this.ResetPositionToDefault();
            }
            else if (this.IsAnchorsToggleable())
            {
                if (anchorR.Contains(mouse))
                {
                    pressed = this.ApplyRightAnchorToggleControlPress_If();
                }
                else if (anchorB.Contains(mouse))
                {
                    pressed = this.ApplyBottomAnchorToggleControlPress_If();
                }
            }

            this.IsInteractingWithControls   = pressed;
            Main.LocalPlayer.mouseInterface |= pressed;
//if( Main.LocalPlayer.mouseInterface ) {
//	Main.NewText( "HUD_UpdIntForCtrlIf 2" );
//}
        }
        ////////////////

        /*public override void UpdateUI( GameTime gameTime ) {
         *      //bool mouseLeft = PlayerInput.Triggers.Current.MouseLeft;
         *      //bool isAlt = Main.keyState.IsKeyDown( Keys.LeftAlt ) || Main.keyState.IsKeyDown( Keys.RightAlt );
         *      //this.Logger.Info( "lclick:"+mouseLeft+" ("+Main.mouseLeft+"), alt:"+isAlt+", gameTime:"+gameTime.ElapsedGameTime.Ticks );
         *      //this.MyUI?.Update( gameTime );
         *
         *      foreach( HUDElement elem in this.HUDManager.Elements.Values ) {
         *              if( elem.IsDragging ) {
         * //this.Logger.Info( "drag " + gameTime.ElapsedGameTime.Ticks+", thread: "+Thread.CurrentThread.ManagedThreadId);
         *                      Main.LocalPlayer.mouseInterface = true;		<- This fails because UpdateUI runs before inputs are processed
         *                      break;
         *              }
         *      }
         * }*/


        ////////////////

        public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers)
        {
            if (Main.gameMenu)
            {
                return;
            }

            //

            GameInterfaceDrawMethod widgetsUI = delegate {
                if (Main.gameMenu)
                {
                    return(true);
                }

/*if( this.MyUI != null ) {
 * List<UIElement> elems;
 * ModLibsCore.Libraries.DotNET.Reflection.ReflectionLibraries.Get(
 *      this.MyUI,
 *      "Elements",
 *      out elems
 * );
 * ModLibsCore.Libraries.Debug.DebugLibraries.Print(
 *      "interface",
 *      string.Join(", ", elems
 *              .Where( e=>e.GetType()!=typeof(VanillaHUDElement) )
 *              .Select( e=>((HUDElement)e).Name )
 *      )
 * );
 * }*/
                this.MyUI?.Update(Main._drawInterfaceGameTime);                    //:blobshrug:
                this.MyUI?.Draw(Main.spriteBatch);

                return(true);
            };

            int mouseTextIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text"));

            if (mouseTextIdx >= 0)
            {
                var invOverLayer = new LegacyGameInterfaceLayer(
                    name: "HUDElementsLib: Widgets",
                    drawMethod: widgetsUI,
                    scaleType: InterfaceScaleType.UI
                    );
                layers.Insert(mouseTextIdx, invOverLayer);
            }

            //

            int cursorIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Cursor"));

            if (cursorIdx >= 0)
            {
                foreach (HUDElement elem in this.HUDManager.Elements.Values)
                {
                    if (elem.ConsumesCursor())
                    {
                        layers.RemoveAt(cursorIdx);

                        break;
                    }
                }
            }

            //

            if (HUDElementsLibAPI.IsEditModeActive())
            {
                this.DisableHUDInterfaceLayersForEditMode(layers);
            }
        }