private void BuySpellHandler()
        {
            const int tradeMessageBaseId = 260;
            const int notEnoughGoldId    = 454;
            int       tradePrice         = GetTradePrice();
            int       msgOffset          = 0;

            if (GameManager.Instance.PlayerEntity.GetGoldAmount() < tradePrice)
            {
                DaggerfallUI.MessageBox(notEnoughGoldId);
            }
            else
            {
                if (presentedCost >> 1 <= tradePrice)
                {
                    if (presentedCost - (presentedCost >> 2) <= tradePrice)
                    {
                        msgOffset = 2;
                    }
                    else
                    {
                        msgOffset = 1;
                    }
                }

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(tradeMessageBaseId + msgOffset);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmTrade_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
        }
        void ClickHandler(BaseScreenComponent sender, Vector2 position)
        {
            int offset = (int)position.y * racePickerBitmap.Width + (int)position.x;

            if (offset < 0 || offset >= racePickerBitmap.Data.Length)
            {
                return;
            }

            int id = racePickerBitmap.Data[offset];

            if (raceDict.ContainsKey(id))
            {
                promptLabel.Enabled = false;
                selectedRace        = raceDict[id];

                TextFile.Token[]     textTokens = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(selectedRace.DescriptionID);
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                messageBox.SetTextTokens(textTokens);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                Button noButton = messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                noButton.ClickSound       = DaggerfallUI.Instance.GetAudioClip(SoundClips.ButtonClick);
                messageBox.OnButtonClick += ConfirmRacePopup_OnButtonClick;
                messageBox.OnCancel      += ConfirmRacePopup_OnCancel;
                uiManager.PushWindow(messageBox);

                DaggerfallAudioSource source = DaggerfallUI.Instance.GetComponent <DaggerfallAudioSource>();
                source.PlayOneShot((uint)selectedRace.ClipID);
            }
        }
Exemple #3
0
        protected void ScamMessageBox_OnGotUserInput(DaggerfallInputMessageBox sender, string input)
        {
            int playerIntell = player.Stats.LiveIntelligence;

            if (LimitedGoldShops.LimitedGoldShops.ShopBuildingData.TryGetValue(currentBuildingID, out sd))
            {
                investedFlag = sd.InvestedIn;
                shopAttitude = sd.ShopAttitude;
            }

            bool result = int.TryParse(input, out investOffer);

            if (!result || investOffer < 500)
            {
                tokens = LGSTextTokenHolder.ShopTextTokensMean(25);
                DaggerfallUI.MessageBox(tokens);
                return;
            }

            DaggerfallMessageBox scamConfimBox = new DaggerfallMessageBox(uiManager, this);

            tokens = LGSTextTokenHolder.ShopTextTokensMean(3);
            scamConfimBox.SetTextTokens(tokens);
            scamConfimBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            scamConfimBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            scamConfimBox.OnButtonClick += ConfirmGettingScammed_OnButtonClick;
            uiManager.PushWindow(scamConfimBox);
        }
        void DaggerfallClassSelectWindow_OnItemPicked(int index, string className)
        {
            if (index == classList.Count) // "Custom" option selected
            {
                selectedClass      = null;
                selectedClassIndex = -1;
                CloseWindow();
            }
            else
            {
                selectedClass      = classList[index];
                selectedClassIndex = index;

                TextFile.Token[]     textTokens = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(startClassDescriptionID + index);
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                messageBox.SetTextTokens(textTokens);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                Button noButton = messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                noButton.ClickSound       = DaggerfallUI.Instance.GetAudioClip(SoundClips.ButtonClick);
                messageBox.OnButtonClick += ConfirmClassPopup_OnButtonClick;
                uiManager.PushWindow(messageBox);

                AudioClip clip = DaggerfallUnity.Instance.SoundReader.GetAudioClip(SoundClips.SelectClassDrums);
                DaggerfallUI.Instance.AudioSource.PlayOneShot(clip, DaggerfallUnity.Settings.SoundVolume);
            }
        }
        void TrainingService()
        {
            CloseWindow();
            // Check enough time has passed since last trained
            DaggerfallDateTime now = DaggerfallUnity.Instance.WorldTime.Now;

            if ((now.ToClassicDaggerfallTime() - playerEntity.TimeOfLastSkillTraining) < 720)
            {
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(TrainingToSoonId);
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
                messageBox.SetTextTokens(tokens);
                messageBox.ClickAnywhereToClose = true;
                messageBox.Show();
            }
            else
            {   // Offer training price
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(TrainingOfferId);
                messageBox.SetTextTokens(tokens, guild);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmTraining_OnButtonClick;
                messageBox.Show();
            }
        }
 private void JoinButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
 {
     CloseWindow();
     guild = guildManager.JoinGuild(guildGroup, buildingFactionId);
     if (guild == null)
     {
         DaggerfallUI.MessageBox("Joining guild " + guildGroup + " not implemented.");
     }
     else if (!guild.IsMember())
     {
         DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
         if (guild.IsEligibleToJoin(playerEntity))
         {
             messageBox.SetTextTokens(guild.TokensEligible(playerEntity), guild);
             messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
             messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
             messageBox.OnButtonClick += ConfirmJoinGuild_OnButtonClick;
         }
         else
         {
             messageBox.SetTextTokens(guild.TokensIneligible(playerEntity), guild);
             messageBox.ClickAnywhereToClose = true;
         }
         messageBox.Show();
     }
 }
Exemple #7
0
        private void InputMessageBox_OnGotUserInput(DaggerfallInputMessageBox sender, string input)
        {
            daysToRent = 0;
            bool result = int.TryParse(input, out daysToRent);

            if (!result || daysToRent < 1)
            {
                return;
            }

            int daysAlreadyRented = 0;

            if (rentedRoom != null)
            {
                daysAlreadyRented = (int)((rentedRoom.expiryTime - DaggerfallUnity.Instance.WorldTime.Now.ToSeconds()) / DaggerfallDateTime.SecondsPerDay);
            }

            if (daysToRent + daysAlreadyRented > 350)
            {
                DaggerfallUI.MessageBox(tooManyDaysFutureId);
            }
            else
            {
                int cost = FormulaHelper.CalculateRoomCost(daysToRent);
                tradePrice = FormulaHelper.CalculateTradePrice(cost, buildingData.quality, false);

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(offerPriceId);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmRenting_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
        }
        void EditOrDeleteSlot(int slot)
        {
            const int howToAlterSpell = 1708;

            // Do nothing if slot not set
            if (string.IsNullOrEmpty(effectEntries[slot].Key))
            {
                return;
            }

            // Offer to edit or delete effect
            editOrDeleteSlot = slot;
            DaggerfallMessageBox mb = new DaggerfallMessageBox(uiManager, this);

            mb.SetTextTokens(howToAlterSpell);
            Button editButton = mb.AddButton(DaggerfallMessageBox.MessageBoxButtons.Edit);

            editButton.OnMouseClick += EditButton_OnMouseClick;
            Button deleteButton = mb.AddButton(DaggerfallMessageBox.MessageBoxButtons.Delete);

            deleteButton.OnMouseClick += DeleteButton_OnMouseClick;
            mb.OnButtonClick          += EditOrDeleteSpell_OnButtonClick;
            mb.OnCancel += EditOrDeleteSpell_OnCancel;
            mb.Show();
        }
Exemple #9
0
        private DaggerfallMessageBox CreateDialogBox(string[] dialogText)
        {
            DaggerfallMessageBox dialogBox = new DaggerfallMessageBox(uiManager, this);

            dialogBox.SetText(dialogText);
            dialogBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            dialogBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            return(dialogBox);
        }
Exemple #10
0
        void CureDiseaseService()
        {
            CloseWindow();
            int numberOfDiseases = 0;

            if (playerEntity.Disease.IsDiseased())
            {
                numberOfDiseases++; // TODO: Support multiple diseases
            }
            if (playerEntity.TimeToBecomeVampireOrWerebeast != 0)
            {
                numberOfDiseases++;
            }

            if (numberOfDiseases > 0)
            {
                // Get base cost
                int baseCost = 250 * numberOfDiseases;

                // Apply rank-based discount if this is an Arkay temple
                baseCost = guild.ReducedCureCost(baseCost);

                // Apply temple quality and regional price modifiers
                int costBeforeBargaining = FormulaHelper.CalculateCost(baseCost, buildingDiscoveryData.quality);

                // Apply bargaining to get final price
                curingCost = FormulaHelper.CalculateTradePrice(costBeforeBargaining, buildingDiscoveryData.quality, false);

                // Index correct message
                const int tradeMessageBaseId = 260;
                int       msgOffset          = 0;
                if (costBeforeBargaining >> 1 <= curingCost)
                {
                    if (costBeforeBargaining - (costBeforeBargaining >> 2) <= curingCost)
                    {
                        msgOffset = 2;
                    }
                    else
                    {
                        msgOffset = 1;
                    }
                }
                // Offer curing at the calculated price.
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(tradeMessageBaseId + msgOffset);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmCuring_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
            else
            {   // Not diseased
                DaggerfallUI.MessageBox(30);
            }
        }
        protected void DaedraSummoningService(int npcFactionId)
        {
            PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;

            if (!playerEntity.FactionData.GetFactionData(npcFactionId, out summonerFactionData))
            {
                DaggerfallUnity.LogMessage("Error no faction data for NPC FactionId: " + npcFactionId);
                return;
            }
            // Select appropriate Daedra for summoning attempt.
            int dayOfYear = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.DayOfYear;

            if (summonerFactionData.id == (int)FactionFile.FactionIDs.The_Glenmoril_Witches)
            {   // Always Hircine at Glenmoril witches (reversed from classic: this is intentional)
                daedraToSummon = daedraData[0];
            }
            else if ((FactionFile.FactionTypes)summonerFactionData.type == FactionFile.FactionTypes.WitchesCoven)
            {   // Witches covens summon a random Daedra each day.
                int daedraIndex = playerEntity.DaedraSummonIndex;
                if (playerEntity.DaedraSummonDay != dayOfYear || daedraIndex == 0)
                {
                    playerEntity.DaedraSummonIndex = daedraIndex = Random.Range(1, daedraData.Length);
                    playerEntity.DaedraSummonDay   = dayOfYear;
                }
                daedraToSummon = daedraData[daedraIndex];
            }
            else
            {   // Is this a summoning day?
                foreach (DaedraData dd in daedraData)
                {
                    if (dd.dayOfYear == dayOfYear)
                    {
                        daedraToSummon = dd;
                        break;
                    }
                }
            }
            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);

            if (daedraToSummon.factionId == 0)
            {   // Display not summoning day message.
                TextFile.Token[] tokens = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(SummonNotToday);
                messageBox.SetTextTokens(tokens, this);
                messageBox.ClickAnywhereToClose = false;
            }
            else
            {   // Ask player if they really want to risk the summoning.
                messageBox.SetTextTokens(SummonAreYouSure, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmSummon_OnButtonClick;
            }
            messageBox.Show();
        }
Exemple #12
0
        private void GuiltyNotGuilty_OnButtonClick(DaggerfallMessageBox sender, DaggerfallMessageBox.MessageBoxButtons messageBoxButton)
        {
            sender.CloseWindow();
            if (messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Guilty)
            {
                if (punishmentType != 0)
                {
                    if (punishmentType == 1)
                    {
                        state = 5;
                    }
                    else
                    {
                        fine         >>= 1;
                        daysInPrison >>= 1;
                        playerEntity.DeductGoldAmount(fine);

                        // Classic gives a legal reputation raise here, probably a bug since it means you get a separate raise
                        // for paying the fine and for serving prison time.
                        if (daysInPrison > 0)
                        {
                            state = 3;
                        }
                        else
                        {
                            // Give the reputation raise here if no prison time will be served.
                            playerEntity.RaiseReputationForDoingSentence();
                            repositionPlayer = true;
                            // Oversight in classic: Does not refill vital signs when releasing in this case, so player is left with 1 health.
                            playerEntity.FillVitalSigns();
                            ReleaseFromPrison();
                        }
                    }
                }
                else
                {
                    state = 4;
                }
            }
            else // Pleading not guilty
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 127);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextHowConvince));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Debate);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Lie);
                messageBox.OnButtonClick += DebateLie_OnButtonClick;
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.AllowCancel = false;
                uiManager.PushWindow(messageBox);
            }
            Update();
        }
Exemple #13
0
 private void HealedButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
 {
     if (DaggerfallUnity.Settings.IllegalRestWarning && GameManager.Instance.PlayerGPS.IsPlayerInTown(true, true))
     {
         DaggerfallMessageBox mb = DaggerfallUI.MessageBox(TextManager.Instance.GetText("DaggerfallUI", "illegalRestWarning"));
         mb.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
         mb.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
         mb.OnButtonClick += ConfirmIllegalRestUntilHealed_OnButtonClick;
     }
     else
     {
         DoRestUntilHealed(false);
     }
 }
Exemple #14
0
 private void WhileButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
 {
     DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick);
     if (DaggerfallUnity.Settings.IllegalRestWarning && GameManager.Instance.PlayerGPS.IsPlayerInTown(true, true))
     {
         DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick);
         DaggerfallMessageBox mb = DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("illegalRestWarning"));
         mb.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
         mb.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
         mb.OnButtonClick += ConfirmIllegalRestForAWhile_OnButtonClick;
     }
     else
     {
         DoRestForAWhile(false);
     }
 }
Exemple #15
0
        private void DeleteSaveButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
        {
            // Must have a save selected
            if (savesList.SelectedIndex < 0)
            {
                return;
            }

            // Confirmation
            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);

            messageBox.SetText(new string[] { HardStrings.confirmDeleteSave, "" });
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Delete);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Cancel);
            messageBox.OnButtonClick += ConfirmDelete_OnButtonClick;
            uiManager.PushWindow(messageBox);
        }
        protected virtual void InputMessageBox_OnGotUserInput(DaggerfallInputMessageBox sender, string input)
        {
            daysToRent = 0;
            bool result = int.TryParse(input, out daysToRent);

            if (!result || daysToRent < 1)
            {
                return;
            }

            int daysAlreadyRented = 0;

            if (rentedRoom != null)
            {
                daysAlreadyRented = (int)((rentedRoom.expiryTime - DaggerfallUnity.Instance.WorldTime.Now.ToSeconds()) / DaggerfallDateTime.SecondsPerDay);
                if (daysAlreadyRented < 0)
                {
                    daysAlreadyRented = 0;
                }
            }

            if (daysToRent + daysAlreadyRented > 350)
            {
                DaggerfallUI.MessageBox(tooManyDaysFutureId);
            }
            else if (GameManager.Instance.GuildManager.GetGuild(FactionFile.GuildGroups.KnightlyOrder).FreeTavernRooms())
            {
                DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("roomFreeForKnightSuchAsYou"));
                RentRoom();
            }
            else
            {
                int cost = FormulaHelper.CalculateRoomCost(daysToRent);
                tradePrice = FormulaHelper.CalculateTradePrice(cost, buildingData.quality, false);

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(offerPriceId);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmRenting_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
        }
Exemple #17
0
        void DaggerfallClassSelectWindow_OnItemPicked(int index)
        {
            selectedClass = classList[index];

            TextFile.Token[]     textTokens = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(startClassDescriptionID + index);
            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);

            messageBox.SetTextTokens(textTokens);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            Button noButton = messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);

            noButton.ClickSound       = DaggerfallUI.Instance.GetAudioClip(SoundClips.ButtonClick);
            messageBox.OnButtonClick += ConfirmClassPopup_OnButtonClick;
            uiManager.PushWindow(messageBox);

            AudioClip clip = DaggerfallUnity.Instance.SoundReader.GetAudioClip(SoundClips.SelectClassDrums);

            DaggerfallUI.Instance.AudioSource.PlayOneShot(clip);
        }
        private void SaveLoadEventHandler(BaseScreenComponent sender, Vector2 position)
        {
            if (mode == Modes.SaveGame)
            {
                // Must have a save name
                if (saveNameTextBox.Text.Length == 0)
                {
                    DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("youMustEnterASaveName"));
                    return;
                }

                // Get save key and confirm if already exists
                int key = GameManager.Instance.SaveLoadManager.FindSaveFolderByNames(currentPlayerName, saveNameTextBox.Text);
                if (key != -1)
                {
                    DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                    messageBox.SetText(new string[] { TextManager.Instance.GetLocalizedText("confirmOverwriteSave"), "" });
                    messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                    messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                    messageBox.OnButtonClick += ConfirmOverwrite_OnButtonClick;
                    uiManager.PushWindow(messageBox);
                }
                else
                {
                    SaveGame();
                }
            }
            else if (mode == Modes.LoadGame)
            {
                // Must have a save name
                if (saveNameTextBox.Text.Length == 0)
                {
                    DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("youMustSelectASaveName"));
                    return;
                }

                GameManager.Instance.SaveLoadManager.PromptLoadGame(currentPlayerName, saveNameTextBox.Text, () =>
                {
                    loadingLabel.Text = TextManager.Instance.GetLocalizedText("loading");
                    loading           = true;
                });
            }
        }
        public void BeginButtonOnClickHandler(BaseScreenComponent sender, Vector2 position)
        {
            Refresh();

            // Warns player if they have a disease
            if (GameManager.Instance.PlayerEffectManager.DiseaseCount > 0 || GameManager.Instance.PlayerEffectManager.PoisonCount > 0)
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(1010);
                messageBox.SetTextTokens(tokens);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmTravelPopupDiseasedButtonClick;
                uiManager.PushWindow(messageBox);
            }
            else
            {
                CallFastTravelGoldCheck();
            }
        }
Exemple #20
0
        private void SaveOptionsAndContinue()
        {
            DaggerfallUnity.Settings.ShowOptionsAtStart = alwayShowOptions.IsChecked;
            DaggerfallUnity.Settings.VSync = vsync.IsChecked;
            DaggerfallUnity.Settings.SwapHealthAndFatigueColors = swapHealthAndFatigue.IsChecked;
            DaggerfallUnity.Settings.InvertMouseVertical        = invertMouseVertical.IsChecked;
            DaggerfallUnity.Settings.MouseLookSmoothing         = mouseSmoothing.IsChecked;
            DaggerfallUnity.Settings.Handedness       = GetHandedness(leftHandWeapons.IsChecked);
            DaggerfallUnity.Settings.PlayerNudity     = playerNudity.IsChecked;
            DaggerfallUnity.Settings.ClickToAttack    = clickToAttack.IsChecked;
            DaggerfallUnity.Settings.EnableController = enableController.IsChecked;
            DaggerfallUnity.Settings.SaveSettings();

            if (ModManager.Instance)
            {
                foreach (Mod mod in ModManager.Instance.Mods.Where(x => x.Enabled))
                {
                    bool?isGameVersionSatisfied = mod.IsGameVersionSatisfied();
                    if (isGameVersionSatisfied == false)
                    {
                        var messageBox = new DaggerfallMessageBox(uiManager, this, true);
                        messageBox.SetText(GetText("incompatibleMods"));
                        messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                        messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No, true);
                        messageBox.OnButtonClick += (_, messageBoxButton) =>
                        {
                            moveNextStage = messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Yes;
                            messageBox.CloseWindow();
                        };
                        uiManager.PushWindow(messageBox);
                        return;
                    }
                    else if (isGameVersionSatisfied == null)
                    {
                        Debug.LogWarningFormat("Unknown format for property \"DFUnity_Version\" of mod {0}. Please use x.y.z version of minimum compatible game build.", mod.Title);
                    }
                }
            }

            moveNextStage = true;
        }
Exemple #21
0
        private void SaveLoadEventHandler(BaseScreenComponent sender, Vector2 position)
        {
            if (mode == Modes.SaveGame)
            {
                // Must have a save name
                if (saveNameTextBox.Text.Length == 0)
                {
                    DaggerfallUI.MessageBox(HardStrings.youMustEnterASaveName);
                    return;
                }

                // Get save key and confirm if already exists
                int key = GameManager.Instance.SaveLoadManager.FindSaveFolderByNames(currentPlayerName, saveNameTextBox.Text);
                if (key != -1)
                {
                    DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                    messageBox.SetText(HardStrings.confirmOverwriteSave, "");
                    messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                    messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                    messageBox.OnButtonClick += ConfirmOverwrite_OnButtonClick;
                    uiManager.PushWindow(messageBox);
                }
                else
                {
                    SaveGame();
                }
            }
            else if (mode == Modes.LoadGame)
            {
                // Must have a save name
                if (saveNameTextBox.Text.Length == 0)
                {
                    DaggerfallUI.MessageBox(HardStrings.youMustSelectASaveName);
                    return;
                }

                LoadGame();
            }
        }
        private void BuyButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
        {
            DaggerfallUI.Instance.PlayOneShot(SoundClips.ButtonClick);
            const int tradeMessageBaseId = 260;
            const int notEnoughGoldId    = 454;
            int       tradePrice         = GetTradePrice();
            int       msgOffset          = 0;

            if (!GameManager.Instance.PlayerEntity.Items.Contains(Items.ItemGroups.MiscItems, (int)Items.MiscItems.Spellbook))
            {
                DaggerfallUI.MessageBox(noSpellBook);
            }
            else if (GameManager.Instance.PlayerEntity.GetGoldAmount() < tradePrice)
            {
                DaggerfallUI.MessageBox(notEnoughGoldId);
            }
            else
            {
                if (presentedCost >> 1 <= tradePrice)
                {
                    if (presentedCost - (presentedCost >> 2) <= tradePrice)
                    {
                        msgOffset = 2;
                    }
                    else
                    {
                        msgOffset = 1;
                    }
                }

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(tradeMessageBaseId + msgOffset);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmTrade_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
        }
Exemple #23
0
        void ShowTradePopup()
        {
            const int tradeMessageBaseId = 260;
            const int notEnoughGoldId    = 454;
            int       msgOffset          = 0;
            int       tradePrice         = GetTradePrice();

            if (windowMode != WindowModes.Sell && windowMode != WindowModes.SellMagic && PlayerEntity.GetGoldAmount() < tradePrice)
            {
                DaggerfallUI.MessageBox(notEnoughGoldId);
            }
            else
            {
                if (cost >> 1 <= tradePrice)
                {
                    if (cost - (cost >> 2) <= tradePrice)
                    {
                        msgOffset = 2;
                    }
                    else
                    {
                        msgOffset = 1;
                    }
                }
                if (windowMode == WindowModes.Sell || windowMode == WindowModes.SellMagic)
                {
                    msgOffset += 3;
                }

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(tradeMessageBaseId + msgOffset);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmTrade_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
        }
Exemple #24
0
        protected virtual DaggerfallMessageBox CreateDialogBox(string entryStr, string baseKey)
        {
            string heading     = TextManager.Instance.GetLocalizedText(baseKey + "Head");
            string action      = TextManager.Instance.GetLocalizedText(baseKey);
            string explanation = TextManager.Instance.GetLocalizedText(baseKey + "2");

            TextFile.Token[] tokens = new TextFile.Token[] {
                TextFile.CreateTextToken(heading), TextFile.CreateFormatToken(TextFile.Formatting.JustifyCenter), TextFile.NewLineToken,
                TextFile.CreateTextToken(action), TextFile.NewLineToken, TextFile.NewLineToken,
                new TextFile.Token()
                {
                    text = entryStr, formatting = TextFile.Formatting.TextHighlight
                }, TextFile.CreateFormatToken(TextFile.Formatting.JustifyCenter), TextFile.NewLineToken,
                TextFile.CreateTextToken(explanation), TextFile.CreateFormatToken(TextFile.Formatting.EndOfRecord)
            };

            DaggerfallMessageBox dialogBox = new DaggerfallMessageBox(uiManager, this);

            dialogBox.SetHighlightColor(Color.white);
            dialogBox.SetTextTokens(tokens);
            dialogBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            dialogBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            return(dialogBox);
        }
        void CureDiseaseService()
        {
            CloseWindow();
            int numberOfDiseases = GameManager.Instance.PlayerEffectManager.DiseaseCount;

            if (playerEntity.TimeToBecomeVampireOrWerebeast != 0)
            {
                numberOfDiseases++;
            }

            // Check holidays for free / cheaper curing
            uint minutes   = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime();
            int  holidayId = FormulaHelper.GetHolidayId(minutes, GameManager.Instance.PlayerGPS.CurrentRegionIndex);

            if (numberOfDiseases > 0 &&
                (holidayId == (int)DFLocation.Holidays.South_Winds_Prayer ||
                 holidayId == (int)DFLocation.Holidays.First_Harvest ||
                 holidayId == (int)DFLocation.Holidays.Second_Harvest))
            {
                GameManager.Instance.PlayerEffectManager.CureAllDiseases();
                playerEntity.TimeToBecomeVampireOrWerebeast = 0;
                DaggerfallUI.MessageBox(TextManager.Instance.GetText(textDatabase, "freeHolidayCuring"));
            }
            else if (numberOfDiseases > 0)
            {
                // Get base cost
                int baseCost = 250 * numberOfDiseases;

                // Apply rank-based discount if this is an Arkay temple
                baseCost = guild.ReducedCureCost(baseCost);

                // Apply temple quality and regional price modifiers
                int costBeforeBargaining = FormulaHelper.CalculateCost(baseCost, buildingDiscoveryData.quality);

                // Halve the price on North Winds Prayer holiday
                if (holidayId == (int)DFLocation.Holidays.North_Winds_Festival)
                {
                    costBeforeBargaining /= 2;
                }

                // Apply bargaining to get final price
                curingCost = FormulaHelper.CalculateTradePrice(costBeforeBargaining, buildingDiscoveryData.quality, false);

                // Index correct message
                const int tradeMessageBaseId = 260;
                int       msgOffset          = 0;
                if (costBeforeBargaining >> 1 <= curingCost)
                {
                    if (costBeforeBargaining - (costBeforeBargaining >> 2) <= curingCost)
                    {
                        msgOffset = 2;
                    }
                    else
                    {
                        msgOffset = 1;
                    }
                }
                // Offer curing at the calculated price.
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, uiManager.TopWindow);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(tradeMessageBaseId + msgOffset);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmCuring_OnButtonClick;
                messageBox.Show();
            }
            else
            {   // Not diseased
                DaggerfallUI.MessageBox(30);
            }
        }
Exemple #26
0
        protected void InvestMessageBox_OnGotUserInput(DaggerfallInputMessageBox sender, string input)
        {
            int playerIntell = player.Stats.LiveIntelligence;

            if (LimitedGoldShops.LimitedGoldShops.ShopBuildingData.TryGetValue(currentBuildingID, out sd))
            {
                investedFlag = sd.InvestedIn;
                shopAttitude = sd.ShopAttitude;
            }

            bool result = int.TryParse(input, out investOffer);

            if (!result || investOffer < 500)
            {
                tokens = LGSTextTokenHolder.ShopTextTokensNeutral(5);
                DaggerfallUI.MessageBox(tokens);
                return;
            }

            DaggerfallMessageBox investConfimBox = new DaggerfallMessageBox(uiManager, this);

            if (buildQual <= 3) // 01 - 03
            {
                if (shopAttitude == 0)
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensNice(11, investOffer);
                }
                else
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensMean(14, investOffer);
                }
            }
            else if (buildQual <= 7) // 04 - 07
            {
                if (shopAttitude == 0)
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensNice(3, investOffer);
                }
                else
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensMean(10, investOffer);
                }
            }
            else if (buildQual <= 17) // 08 - 17
            {
                if (shopAttitude == 0)
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensNice(15, investOffer);
                }
                else
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensMean(18, investOffer);
                }
            }
            else                      // 18 - 20
            {
                if (shopAttitude == 0)
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensNice(19, investOffer);
                }
                else
                {
                    tokens = LGSTextTokenHolder.ShopTextTokensMean(22, investOffer);
                }
            }
            if (investedFlag)
            {
                if (buildQual <= 3) // 01 - 03
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(13, investOffer);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(16, investOffer);
                    }
                }
                else if (buildQual <= 7) // 04 - 07
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(9, investOffer);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(12, investOffer);
                    }
                }
                else if (buildQual <= 17) // 08 - 17
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(17, investOffer);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(20, investOffer);
                    }
                }
                else                      // 18 - 20
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(21, investOffer);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(24, investOffer);
                    }
                }
            }
            investConfimBox.SetTextTokens(tokens);
            investConfimBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            investConfimBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            investConfimBox.OnButtonClick += ConfirmInvestment_OnButtonClick;
            uiManager.PushWindow(investConfimBox);
        }
        protected override void ShowTradePopup()
        {
            const int tradeMessageBaseId = 260;
            const int notEnoughGoldId    = 454;
            int       msgOffset          = 0;
            int       tradePrice         = GetTradePrice();

            int currentBuildingID = GameManager.Instance.PlayerEnterExit.BuildingDiscoveryData.buildingKey;
            int goldSupply        = 0;
            int shopAttitude      = 0; // For now, 0 = Nice Attitude and 1 = Bad Attitude.

            LimitedGoldShops.ShopData sd;
            if (LimitedGoldShops.LimitedGoldShops.ShopBuildingData.TryGetValue(currentBuildingID, out sd))
            {
                goldSupply   = sd.CurrentGoldSupply;
                shopAttitude = sd.ShopAttitude;
            }

            if (WindowMode == WindowModes.Sell && goldSupply <= 0)
            {
                int buildQual           = GameManager.Instance.PlayerEnterExit.BuildingDiscoveryData.quality;
                TextFile.Token[] tokens = LGSTextTokenHolder.ShopTextTokensNice(4);
                if (buildQual <= 3)        // 01 - 03
                {
                    if (shopAttitude == 0) // Possibly could add the "shop type" to the save-data as well, and use that to determine some other things.
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(5);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(4);
                    }
                }
                else if (buildQual <= 7) // 04 - 07
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(6);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(5);
                    }
                }
                else if (buildQual <= 13) // 08 - 13
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(4);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(6);
                    }
                }
                else if (buildQual <= 17) // 14 - 17
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(7);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(7);
                    }
                }
                else                      // 18 - 20
                {
                    if (shopAttitude == 0)
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensNice(8);
                    }
                    else
                    {
                        tokens = LGSTextTokenHolder.ShopTextTokensMean(8);
                    }
                }

                DaggerfallMessageBox noGoldShop = new DaggerfallMessageBox(DaggerfallUI.UIManager, this);
                noGoldShop.SetTextTokens(tokens, this);
                noGoldShop.ClickAnywhereToClose = true;
                uiManager.PushWindow(noGoldShop);
            }
            else if (WindowMode == WindowModes.Sell && goldSupply < tradePrice)
            {
                TextFile.Token[] tokens = DaggerfallUnity.Instance.TextProvider.CreateTokens(
                    TextFile.Formatting.JustifyCenter,
                    "I can't afford your offer.",
                    "Would you be willing to settle",
                    "for the " + goldSupply.ToString() + " gold that I have left?");

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmPoorTrade_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
            else if (WindowMode != WindowModes.Sell && WindowMode != WindowModes.SellMagic && PlayerEntity.GetGoldAmount() < tradePrice)
            {
                DaggerfallUI.MessageBox(notEnoughGoldId);
            }
            else
            {
                if (cost >> 1 <= tradePrice)
                {
                    if (cost - (cost >> 2) <= tradePrice)
                    {
                        msgOffset = 2;
                    }
                    else
                    {
                        msgOffset = 1;
                    }
                }
                if (WindowMode == WindowModes.Sell || WindowMode == WindowModes.SellMagic)
                {
                    msgOffset += 3;
                }

                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                TextFile.Token[]     tokens     = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(tradeMessageBaseId + msgOffset);
                messageBox.SetTextTokens(tokens, this);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                messageBox.OnButtonClick += ConfirmTrade_OnButtonClick;
                uiManager.PushWindow(messageBox);
            }
        }
Exemple #28
0
        public override void Update()
        {
            base.Update();

            if (state == 0) // Starting
            {
                regionIndex = GameManager.Instance.PlayerGPS.CurrentRegionIndex;

                int crimeType = (int)playerEntity.CrimeCommitted - 1;
                int legalRep  = playerEntity.RegionData[regionIndex].LegalRep;

                // Get whether punishment is normal (fine/prison) or a severe punishment (banishment/execution)
                int threshold1 = 0;
                int threshold2 = 0;

                if (legalRep < 0)
                {
                    threshold1 = -legalRep;
                    if (threshold1 > 75)
                    {
                        threshold1 = 75;
                    }
                    threshold2 = -legalRep / 2;
                    if (threshold2 > 75)
                    {
                        threshold2 = 75;
                    }
                }
                if (UnityEngine.Random.Range(1, 101) > threshold2 &&
                    UnityEngine.Random.Range(1, 101) > threshold1)
                {
                    punishmentType = 2; // fine/prison
                }
                else
                {
                    punishmentType = 0; // banishment or execution
                }
                // Calculate penalty amount
                int penaltyAmount = 0;

                if (legalRep >= 0)
                {
                    penaltyAmount = PenaltyPerLegalRepPoint[crimeType] * legalRep
                                    + BasePenaltyAmounts[crimeType];
                }
                else
                {
                    penaltyAmount = BasePenaltyAmounts[crimeType]
                                    - PenaltyPerLegalRepPoint[crimeType] * legalRep;
                }

                if (penaltyAmount > MaximumPenaltyAmounts[crimeType])
                {
                    penaltyAmount = MaximumPenaltyAmounts[crimeType];
                }
                else if (penaltyAmount < MinimumPenaltyAmounts[crimeType])
                {
                    penaltyAmount = MinimumPenaltyAmounts[crimeType];
                }

                penaltyAmount /= 40;

                // Calculate days of prison and fine
                daysInPrison = 0;
                fine         = 0;

                for (int i = 0; i < penaltyAmount; i++)
                {
                    if ((DFRandom.rand() & 1) != 0)
                    {
                        fine += 40;
                    }
                    else
                    {
                        daysInPrison += 3;
                    }
                }

                // If player can't pay fine, limit fine and add to prison sentence
                int playerGold = playerEntity.GetGoldAmount();
                if (playerGold < fine)
                {
                    daysInPrison += (fine - playerGold) / 40;
                    fine          = playerGold;
                }

                DaggerfallMessageBox messageBox;
                if (crimeType == 4 || crimeType == 3)  // Assault or murder
                {
                    // If player is a member of the Dark Brotherhood, they may be rescued for a violent crime
                    Guilds.Guild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Dark_Brotherhood);
                    if (guild.IsMember())
                    {
                        if (guild.Rank >= UnityEngine.Random.Range(0, 20))
                        {
                            messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                            messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextDB));
                            messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                            messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                            messageBox.ClickAnywhereToClose          = true;
                            uiManager.PushWindow(messageBox);
                            playerEntity.FillVitalSigns();
                            playerEntity.RaiseReputationForDoingSentence();
                            state = 100;
                            return;
                        }
                    }
                }
                if (crimeType <= 2 || crimeType == 11) // Attempted breaking and entering, trespassing, breaking and entering, pickpocketing
                {
                    // If player is a member of the Thieves Guild, they may be rescued for a thieving crime
                    Guilds.Guild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Thieves_Guild);
                    if (guild.IsMember())
                    {
                        if (guild.Rank >= UnityEngine.Random.Range(0, 20))
                        {
                            messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                            messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextTG));
                            messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                            messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                            messageBox.ClickAnywhereToClose          = true;
                            uiManager.PushWindow(messageBox);
                            playerEntity.FillVitalSigns();
                            playerEntity.RaiseReputationForDoingSentence();
                            state = 100;
                            return;
                        }
                    }
                }

                messageBox = new DaggerfallMessageBox(uiManager, this, false, 105);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextStart));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Guilty);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.NotGuilty);
                messageBox.OnButtonClick += GuiltyNotGuilty_OnButtonClick;
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                uiManager.PushWindow(messageBox);
                state = 1;       // Done with initial message
            }
            else if (state == 2) // Found guilty
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextFoundGuilty));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.ClickAnywhereToClose          = true;
                uiManager.PushWindow(messageBox);
                state = 3;
            }
            else if (state == 3) // Serve prison sentence
            {
                PositionPlayerAtLocationEntrance();
                ServeTime(daysInPrison);
                playerEntity.RaiseReputationForDoingSentence();
                state = 100;
            }
            else if (state == 4) // Banished
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextBanished));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.ClickAnywhereToClose          = true;
                uiManager.PushWindow(messageBox);
                playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 1;
                PositionPlayerAtLocationEntrance();
                state = 100;
            }
            // Note: Seems like an execution sentence can't be given in classic. It can't be given here, either.
            else if (state == 5) // Execution
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextExecuted));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.ClickAnywhereToClose          = true;
                uiManager.PushWindow(messageBox);
                playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 2;
                state = 6;
            }
            else if (state == 6) // Reposition player at entrance
            {
                PositionPlayerAtLocationEntrance();
                state = 100;
            }
            else if (state == 100) // Done
            {
                ReleaseFromJail();
            }
        }
        public override void Update()
        {
            base.Update();

            // Close immediately if no crime assigned to player
            if (playerEntity.CrimeCommitted == Entity.PlayerEntity.Crimes.None)
            {
                CloseWindow();
                return;
            }

            if (state == 0) // Starting
            {
                regionIndex = GameManager.Instance.PlayerGPS.CurrentRegionIndex;

                int crimeType = (int)playerEntity.CrimeCommitted - 1;
                int legalRep  = playerEntity.RegionData[regionIndex].LegalRep;

                // Get whether punishment is normal (fine/prison) or a severe punishment (banishment/execution)
                int threshold1 = 0;
                int threshold2 = 0;

                if (legalRep < 0)
                {
                    threshold1 = -legalRep;
                    if (threshold1 > 75)
                    {
                        threshold1 = 75;
                    }
                    threshold2 = -legalRep / 2;
                    if (threshold2 > 75)
                    {
                        threshold2 = 75;
                    }
                }
                if (Dice100.FailedRoll(threshold2) &&
                    Dice100.FailedRoll(threshold1))
                {
                    punishmentType = 2; // fine/prison
                }
                else
                {
                    punishmentType = 0; // banishment or execution
                }
                // Calculate penalty amount
                int penaltyAmount = 0;

                if (legalRep >= 0)
                {
                    penaltyAmount = PenaltyPerLegalRepPoint[crimeType] * legalRep + BasePenaltyAmounts[crimeType];
                }
                else
                {
                    penaltyAmount = BasePenaltyAmounts[crimeType] - PenaltyPerLegalRepPoint[crimeType] * legalRep;
                }

                if (penaltyAmount > MaximumPenaltyAmounts[crimeType])
                {
                    penaltyAmount = MaximumPenaltyAmounts[crimeType];
                }
                else if (penaltyAmount < MinimumPenaltyAmounts[crimeType])
                {
                    penaltyAmount = MinimumPenaltyAmounts[crimeType];
                }

                penaltyAmount /= 40;

                // Calculate days of prison and fine
                daysInPrison = 0;
                fine         = 0;

                for (int i = 0; i < penaltyAmount; i++)
                {
                    if ((DFRandom.rand() & 1) != 0)
                    {
                        fine += 40;
                    }
                    else
                    {
                        daysInPrison += 3;
                    }
                }

                // If player can't pay fine, limit fine and add to prison sentence
                int playerGold = playerEntity.GetGoldAmount();
                if (playerGold < fine)
                {
                    daysInPrison += (fine - playerGold) / 40;
                    fine          = playerGold;
                }

                DaggerfallMessageBox messageBox;
                if (crimeType == 4 || crimeType == 3) // Assault or murder
                {
                    // If player is a member of the Dark Brotherhood, they may be rescued for a violent crime
                    Guilds.IGuild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Dark_Brotherhood);
                    if (guild.IsMember())
                    {
                        if (guild.Rank >= UnityEngine.Random.Range(0, 20))
                        {
                            messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                            messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextDB));
                            messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                            messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                            messageBox.ClickAnywhereToClose          = true;
                            uiManager.PushWindow(messageBox);
                            playerEntity.FillVitalSigns();
                            playerEntity.RaiseReputationForDoingSentence();
                            state = 100;
                            return;
                        }
                    }
                }
                if (crimeType <= 2 || crimeType == 11) // Attempted breaking and entering, trespassing, breaking and entering, pickpocketing
                {
                    // If player is a member of the Thieves Guild, they may be rescued for a thieving crime
                    Guilds.IGuild guild = GameManager.Instance.GuildManager.GetGuild((int)FactionFile.FactionIDs.The_Thieves_Guild);
                    if (guild.IsMember())
                    {
                        if (guild.Rank >= UnityEngine.Random.Range(0, 20))
                        {
                            messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                            messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextTG));
                            messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                            messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                            messageBox.ClickAnywhereToClose          = true;
                            messageBox.AllowCancel = false;
                            uiManager.PushWindow(messageBox);
                            playerEntity.FillVitalSigns();
                            playerEntity.RaiseReputationForDoingSentence();
                            state = 100;
                            return;
                        }
                    }
                }

                messageBox = new DaggerfallMessageBox(uiManager, this, false, 105);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextStart));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Guilty);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.NotGuilty);
                messageBox.OnButtonClick += GuiltyNotGuilty_OnButtonClick;
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.AllowCancel = false;
                uiManager.PushWindow(messageBox);
                state = 1;       // Done with initial message
            }
            else if (state == 2) // Found guilty
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextFoundGuilty));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.ClickAnywhereToClose          = true;
                messageBox.AllowCancel = false;
                uiManager.PushWindow(messageBox);

                if (daysInPrison > 0)
                {
                    state = 3;
                }
                else
                {
                    // Give the reputation raise here if no prison time will be served.
                    playerEntity.RaiseReputationForDoingSentence();
                    repositionPlayer = true;
                    playerEntity.FillVitalSigns();
                    ReleaseFromPrison();
                    state = 100;
                }
            }
            else if (state == 3) // Serve prison sentence
            {
                playerEntity.InPrison = true;
                SwitchToPrisonScreen();
                daysInPrisonLeft = daysInPrison;
                playerEntity.RaiseReputationForDoingSentence();
                repositionPlayer = true;
                state            = 100;
            }
            else if (state == 4) // Banished
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextBanished));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.ClickAnywhereToClose          = true;
                messageBox.AllowCancel = false;
                uiManager.PushWindow(messageBox);
                playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 1;
                repositionPlayer = true;

                // Refill player vitals after banishment, otherwise player left with 1HP outside city gates
                playerEntity.FillVitalSigns();
                state = 100;
            }
            // Note: Seems like an execution sentence can't be given in classic. It can't be given here, either.
            else if (state == 5) // Execution
            {
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this, false, 149);
                messageBox.SetTextTokens(DaggerfallUnity.Instance.TextProvider.GetRSCTokens(courtTextExecuted));
                messageBox.ScreenDimColor = new Color32(0, 0, 0, 0);
                messageBox.ParentPanel.VerticalAlignment = VerticalAlignment.Bottom;
                messageBox.ClickAnywhereToClose          = true;
                messageBox.AllowCancel = false;
                uiManager.PushWindow(messageBox);
                playerEntity.RegionData[regionIndex].SeverePunishmentFlags |= 2;
                state = 6;
            }
            else if (state == 6) // Reposition player at entrance
            {
                repositionPlayer = true;
                state            = 100;
            }
            else if (state == 100) // Done
            {
                if (playerEntity.InPrison)
                {
                    if (Input.GetKey(exitKey)) // Speed up prison day countdown. Not in classic.
                    {
                        prisonUpdateInterval = 0.001f;
                    }
                    else
                    {
                        prisonUpdateInterval = 0.3f;
                    }

                    if (prisonUpdateTimer == 0)
                    {
                        prisonUpdateTimer = Time.realtimeSinceStartup;
                    }

                    if (Time.realtimeSinceStartup < prisonUpdateTimer + prisonUpdateInterval)
                    {
                        return;
                    }
                    else
                    {
                        prisonUpdateTimer = Time.realtimeSinceStartup;
                        UpdatePrisonScreen();
                    }
                }
                else
                {
                    ReleaseFromPrison();
                }
            }
        }
        private void DeleteSaveButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
        {
            // Must have a save selected
            if (savesList.SelectedIndex < 0)
                return;

            // Confirmation
            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
            messageBox.SetText(HardStrings.confirmDeleteSave, "");
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Delete);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Cancel);
            messageBox.OnButtonClick += ConfirmDelete_OnButtonClick;
            uiManager.PushWindow(messageBox);
        }
        private void SaveLoadEventHandler(BaseScreenComponent sender, Vector2 position)
        {
            if (mode == Modes.SaveGame)
            {
                // Must have a save name
                if (saveNameTextBox.Text.Length == 0)
                {
                    DaggerfallUI.MessageBox(HardStrings.youMustEnterASaveName);
                    return;
                }

                // Get save key and confirm if already exists
                int key = GameManager.Instance.SaveLoadManager.FindSaveFolderByNames(currentPlayerName, saveNameTextBox.Text);
                if (key != -1)
                {
                    DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                    messageBox.SetText(HardStrings.confirmOverwriteSave, "");
                    messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                    messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                    messageBox.OnButtonClick += ConfirmOverwrite_OnButtonClick;
                    uiManager.PushWindow(messageBox);
                }
                else
                {
                    SaveGame();
                }
            }
            else if (mode == Modes.LoadGame)
            {
                // Must have a save name
                if (saveNameTextBox.Text.Length == 0)
                {
                    DaggerfallUI.MessageBox(HardStrings.youMustSelectASaveName);
                    return;
                }

                LoadGame();
            }
        }
        void ClickHandler(BaseScreenComponent sender, Vector2 position)
        {
            int offset = (int)position.y * racePickerBitmap.Width + (int)position.x;
            if (offset < 0 || offset >= racePickerBitmap.Data.Length)
                return;

            int id = racePickerBitmap.Data[offset];
            if (raceDict.ContainsKey(id))
            {
                promptLabel.Enabled = false;
                selectedRace = raceDict[id];

                TextFile.Token[] textTokens = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(selectedRace.DescriptionID);
                DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
                messageBox.SetTextTokens(textTokens);
                messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
                Button noButton = messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
                noButton.ClickSound = DaggerfallUI.Instance.GetAudioClip(SoundClips.ButtonClick);
                messageBox.OnButtonClick += ConfirmRacePopup_OnButtonClick;
                messageBox.OnCancel += ConfirmRacePopup_OnCancel;
                uiManager.PushWindow(messageBox);

                AudioClip clip = DaggerfallUnity.Instance.SoundReader.GetAudioClip((uint)selectedRace.ClipID);
                DaggerfallUI.Instance.AudioSource.PlayOneShot(clip);
            }
        }
        void CreateConfirmationPopUp()
        {
            if (!locationSelected)
                return;

            TextFile.Token[] textTokens = new TextFile.Token[2];
            //int index = currentRegion.MapIdLookup[locationSummary.MapIndex];
            textTokens[0].text = string.Format("Travel to  {0} : {1} ?", currentDFRegion.Name, currentDFRegion.MapNames[locationSummary.MapIndex]);
            textTokens[0].formatting = TextFile.Formatting.Text;
            textTokens[1].text = null;
            textTokens[1].formatting = TextFile.Formatting.NewLine;

            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
            messageBox.SetTextTokens(textTokens);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            messageBox.OnButtonClick += ConfirmTravelPopupButtonClick;
            uiManager.PushWindow(messageBox);
        }
        void DaggerfallClassSelectWindow_OnItemPicked(int index, string className)
        {
            selectedClass = classList[index];

            TextFile.Token[] textTokens = DaggerfallUnity.Instance.TextProvider.GetRSCTokens(startClassDescriptionID + index);
            DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
            messageBox.SetTextTokens(textTokens);
            messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.Yes);
            Button noButton = messageBox.AddButton(DaggerfallMessageBox.MessageBoxButtons.No);
            noButton.ClickSound = DaggerfallUI.Instance.GetAudioClip(SoundClips.ButtonClick);
            messageBox.OnButtonClick += ConfirmClassPopup_OnButtonClick;
            uiManager.PushWindow(messageBox);

            AudioClip clip = DaggerfallUnity.Instance.SoundReader.GetAudioClip(SoundClips.SelectClassDrums);
            DaggerfallUI.Instance.AudioSource.PlayOneShot(clip);
        }