public static SwapControlsHandler GetHandlerForPawn(Pawn pawn)
        {
            if (SimpleSidearms.saveData == null)
            {
                throw new Exception("Cannot get handler- saveData not loaded");
            }
            var pawnId = pawn.thingIDNumber;
            SwapControlsHandler handler;

            if (!SimpleSidearms.saveData.handlers.TryGetValue(pawnId, out handler))
            {
                handler = new SwapControlsHandler(pawn);
                SimpleSidearms.saveData.handlers.Add(pawnId, handler);
            }
            return(handler);
        }
Exemple #2
0
        private bool DrawLocklock(SwapControlsHandler handler, Rect rect)
        {
            Texture2D lockTex;

            if (handler.autoLockOnManualSwap)
            {
                lockTex = TextureResources.autolockOn;
                TooltipHandler.TipRegion(rect, "WeaponSwitchAutolockOn".Translate());
            }
            else
            {
                lockTex = TextureResources.autolockOff;
                TooltipHandler.TipRegion(rect, "WeaponSwitchAutolockOff".Translate());
            }
            MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverCommand);

            if (Mouse.IsOver(rect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsAdvanced, OpportunityType.GoodToKnow);
                GUI.color = iconMouseOverColor;
            }
            else
            {
                GUI.color = iconBaseColor;
            }

            GUI.DrawTexture(rect, lockTex);
            GUI.color = Color.white;

            if (Widgets.ButtonInvisible(rect, true))
            {
                handler.autoLockOnManualSwap = !handler.autoLockOnManualSwap;
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvanced, KnowledgeAmount.SpecificInteraction);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        private bool DrawLocklock(SwapControlsHandler handler, Rect rect)
        {
            Texture2D lockTex;

            if (handler.autoLockOnManualSwap)
            {
                lockTex = TextureResources.autolockOn;
                TooltipHandler.TipRegion(rect, "WeaponSwitchAutolockOn".Translate());
            }
            else
            {
                lockTex = TextureResources.autolockOff;
                TooltipHandler.TipRegion(rect, "WeaponSwitchAutolockOff".Translate());
            }
            MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverCommand);

            if (Mouse.IsOver(rect))
            {
                GUI.color = iconMouseOverColor;
            }
            else
            {
                GUI.color = iconBaseColor;
            }

            GUI.DrawTexture(rect, lockTex);
            GUI.color = Color.white;

            if (Widgets.ButtonInvisible(rect, true))
            {
                handler.autoLockOnManualSwap = !handler.autoLockOnManualSwap;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        private bool DrawLock(SwapControlsHandler handler, Rect rect)
        {
            Texture2D lockTex;

            if (handler.currentWeaponLocked)
            {
                lockTex = TextureResources.lockClosed;
                TooltipHandler.TipRegion(rect, "LockedWeaponSwitch".Translate());
            }
            else
            {
                lockTex = TextureResources.lockOpen;
                TooltipHandler.TipRegion(rect, "UnlockedWeaponSwitch".Translate());
            }
            MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverCommand);

            if (Mouse.IsOver(rect))
            {
                GUI.color = iconMouseOverColor;
            }
            else
            {
                GUI.color = iconBaseColor;
            }

            GUI.DrawTexture(rect, lockTex);
            GUI.color = Color.white;

            if (Widgets.ButtonInvisible(rect, true))
            {
                handler.currentWeaponLocked = !handler.currentWeaponLocked;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        private void iconClickAction(int buttonID)
        {
            if (interactedWeapon != null)
            {
                Thing toSwapTo;
                if (interactedRanged)
                {
                    if (buttonID == 0)
                    {
                        toSwapTo = interactedWeapon;

                        if (GoldfishModule.GetGoldfishForPawn(parent) != null && toSwapTo.def.defName.Equals(GoldfishModule.GetGoldfishForPawn(parent).primary))
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsPrimary, KnowledgeAmount.Total);
                        }

                        WeaponAssingment.weaponSwapSpecific(parent, toSwapTo, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
                        SwapControlsHandler handler = SwapControlsHandler.GetHandlerForPawn(parent);
                        if (handler.autoLockOnManualSwap)
                        {
                            handler.currentWeaponLocked = true;
                        }

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.dropSidearm(parent, interactedWeapon);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
                else
                {
                    if (buttonID == 0)
                    {
                        toSwapTo = interactedWeapon;

                        if (GoldfishModule.GetGoldfishForPawn(parent) != null && toSwapTo.def.defName.Equals(GoldfishModule.GetGoldfishForPawn(parent).primary))
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsPrimary, KnowledgeAmount.Total);
                        }

                        WeaponAssingment.weaponSwapSpecific(parent, toSwapTo, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.dropSidearm(parent, interactedWeapon);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
            }
            else if (interactedWeaponMemory != null)
            {
                if (interactedRanged)
                {
                    if (buttonID == 0)
                    {
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.forgetSidearmMemory(parent, interactedWeaponMemory);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsMissing, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
                else
                {
                    if (buttonID == 0)
                    {
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.forgetSidearmMemory(parent, interactedWeaponMemory);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsMissing, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
            }
            else if (interactedUnarmed == true)
            {
                if (buttonID == 0)
                {
                    WeaponAssingment.weaponSwapSpecific(parent, null, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                }
            }
        }
Exemple #6
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft)
        {
            var gizmoRect = new Rect(topLeft.x, topLeft.y, Width, MinGizmoSize);

            if (Mouse.IsOver(gizmoRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsBasic, OpportunityType.Important);
            }

            var contentRect = gizmoRect.ContractedBy(ContentPadding);

            Widgets.DrawWindowBackground(gizmoRect);

            var globalInteracted = false;

            interactedWeapon       = null;
            interactedWeaponMemory = null;
            interactedRanged       = false;
            interactedUnarmed      = false;

            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(parent);
            //if (pawnMemory == null)
            //    return new GizmoResult(GizmoState.Clear);

            int i = 0;

            for (i = 0; i < rangedWeapons.Count; i++)
            {
                var  iconOffset = new Vector2((IconSize * i) + IconGap * (i - 1) + LockPanelWidth, 0);
                bool interacted = DrawIconForWeapon(pawnMemory, rangedWeapons[i], contentRect, iconOffset);
                if (interacted)
                {
                    interactedWeapon = rangedWeapons[i];
                }
                if (interacted)
                {
                    interactedRanged = true;
                }
                globalInteracted |= interacted;
            }

            int j = 0;

            if (pawnMemory != null)
            {
                foreach (ThingDef def in rangedWeaponMemories)
                {
                    if (!parent.hasWeaponSomewhere(def))
                    {
                        var  iconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + LockPanelWidth, 0);
                        bool interacted = DrawIconForWeaponMemory(pawnMemory, def, contentRect, iconOffset);
                        if (interacted)
                        {
                            interactedWeaponMemory = def;
                        }
                        if (interacted)
                        {
                            interactedRanged = true;
                        }
                        globalInteracted |= interacted;
                        j++;
                    }
                }
            }

            for (i = 0; i < meleeWeapons.Count; i++)
            {
                var  iconOffset = new Vector2((IconSize * i) + IconGap * (i - 1) + LockPanelWidth, IconSize + IconGap);
                bool interacted = DrawIconForWeapon(pawnMemory, meleeWeapons[i], contentRect, iconOffset);
                if (interacted)
                {
                    interactedWeapon = meleeWeapons[i];
                }
                if (interacted)
                {
                    interactedRanged = false;
                }
                globalInteracted |= interacted;
            }

            j = 0;
            if (pawnMemory != null)
            {
                foreach (ThingDef def in meleeWeaponMemories)
                {
                    if (!parent.hasWeaponSomewhere(def))
                    {
                        var  iconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + LockPanelWidth, IconSize + IconGap);
                        bool interacted = DrawIconForWeaponMemory(pawnMemory, def, contentRect, iconOffset);
                        if (interacted)
                        {
                            interactedWeaponMemory = def;
                        }
                        if (interacted)
                        {
                            interactedRanged = false;
                        }
                        globalInteracted |= interacted;
                        j++;
                    }
                }
            }

            var unarmedIconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + LockPanelWidth, IconSize + IconGap);

            interactedUnarmed = DrawIconForUnarmed(parent, contentRect, unarmedIconOffset);
            globalInteracted |= interactedUnarmed;

            Rect locksPanel = new Rect(gizmoRect.x + ContentPadding, gizmoRect.y, LockPanelWidth - ContentPadding, MinGizmoSize);
            //locksPanel = locksPanel.ContractedBy(LockPanelPadding);

            SwapControlsHandler handler = SwapControlsHandler.GetHandlerForPawn(parent);

            Rect lockPanel     = new Rect(locksPanel.x, locksPanel.y + (locksPanel.height / 2f) - locksPanel.width - LockIconsOffset, locksPanel.width, locksPanel.width);
            Rect locklockPanel = new Rect(locksPanel.x, locksPanel.y + (locksPanel.height / 2f) + LockIconsOffset, locksPanel.width, locksPanel.width);

            DrawLock(handler, lockPanel);
            UIHighlighter.HighlightOpportunity(lockPanel, "SidearmListButton");
            DrawLocklock(handler, locklockPanel);
            UIHighlighter.HighlightOpportunity(locklockPanel, "SidearmListButton");

            UIHighlighter.HighlightOpportunity(gizmoRect, "SidearmList");

            DrawGizmoLabel(defaultLabel, gizmoRect);
            return(globalInteracted ? new GizmoResult(GizmoState.Interacted, Event.current) : new GizmoResult(GizmoState.Clear));
        }
Exemple #7
0
 private void iconClickAction(int buttonID)
 {
     if (interactedWeapon != null)
     {
         Thing toSwapTo;
         if (interactedRanged)
         {
             if (buttonID == 0)
             {
                 toSwapTo = interactedWeapon;
                 WeaponAssingment.weaponSwapSpecific(parent, toSwapTo, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
                 SwapControlsHandler handler = SwapControlsHandler.GetHandlerForPawn(parent);
                 if (handler.autoLockOnManualSwap)
                 {
                     handler.currentWeaponLocked = true;
                 }
             }
             else if (buttonID == 1)
             {
                 WeaponAssingment.dropSidearm(parent, interactedWeapon);
             }
         }
         else
         {
             if (buttonID == 0)
             {
                 toSwapTo = interactedWeapon;
                 WeaponAssingment.weaponSwapSpecific(parent, toSwapTo, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
             }
             else if (buttonID == 1)
             {
                 WeaponAssingment.dropSidearm(parent, interactedWeapon);
             }
         }
     }
     else if (interactedWeaponMemory != null)
     {
         if (interactedRanged)
         {
             if (buttonID == 0)
             {
             }
             else if (buttonID == 1)
             {
                 WeaponAssingment.forgetSidearmMemory(parent, interactedWeaponMemory);
             }
         }
         else
         {
             if (buttonID == 0)
             {
             }
             else if (buttonID == 1)
             {
                 WeaponAssingment.forgetSidearmMemory(parent, interactedWeaponMemory);
             }
         }
     }
     else if (interactedUnarmed == true)
     {
         if (buttonID == 0)
         {
             WeaponAssingment.weaponSwapSpecific(parent, null, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
         }
     }
 }