From 9161c5d2d22ad4212005b3c4382c42b21d16d8f8 Mon Sep 17 00:00:00 2001 From: numidium Date: Sun, 24 Sep 2023 15:20:19 -0400 Subject: [PATCH 1/2] Synchronize char creation wizard screens Addresses a bug described here: https://forums.dfworkshop.net/viewtopic.php?p=66200 The skill bonus screen de-synchronizes with the summary screen when the user goes back and forth in the character creation wizard. My fix was to ensure either window is synced to the character document whenever they are pushed. I also made it so that changes made on the summary page are propagated backward in the wizard as far as makes sense. Skills bonuses will still be wiped if the user creates a new biography since that alters them. --- .../Game/UserInterface/SkillsRollout.cs | 5 +-- .../CreateCharAddBonusSkills.cs | 36 +++++++++++-------- .../CreateCharAddBonusStats.cs | 2 +- .../CreateCharFaceSelect.cs | 3 +- .../UserInterfaceWindows/CreateCharSummary.cs | 7 ++++ .../DaggerfallStartNewGameWizard.cs | 32 ++++++++++------- 6 files changed, 54 insertions(+), 31 deletions(-) diff --git a/Assets/Scripts/Game/UserInterface/SkillsRollout.cs b/Assets/Scripts/Game/UserInterface/SkillsRollout.cs index c11be8665f..396a5b9784 100644 --- a/Assets/Scripts/Game/UserInterface/SkillsRollout.cs +++ b/Assets/Scripts/Game/UserInterface/SkillsRollout.cs @@ -146,7 +146,7 @@ public void Reroll() UpdateSkillValueLabels(); } - public void SetClassSkills(DFCareer dfClass) + public void SetClassSkills(DFCareer dfClass, bool doReroll = true) { // Set primary, major, minor skills from class template primarySkills[0] = dfClass.PrimarySkill1; @@ -163,7 +163,8 @@ public void SetClassSkills(DFCareer dfClass) minorSkills[5] = dfClass.MinorSkill6; UpdateSkillLabels(); - Reroll(); + if (doReroll) + Reroll(); } #endregion diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusSkills.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusSkills.cs index b4ff6f76a8..dcd340e248 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusSkills.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusSkills.cs @@ -33,15 +33,8 @@ public class CreateCharAddBonusSkills : DaggerfallPopupWindow const int strYouMustDistributeYourBonusPoints = 14; Texture2D nativeTexture; - DFCareer dfClass; SkillsRollout skillsRollout; - public DFCareer DFClass - { - get { return dfClass; } - set { SetClass(value); } - } - public DaggerfallSkills StartingSkills { get { return skillsRollout.StartingSkills; } @@ -63,6 +56,23 @@ public CreateCharAddBonusSkills(IUserInterfaceManager uiManager) { } + public void SetCharacterDocument(CharacterDocument characterDocument, bool isRestored) + { + Setup(); + if (isRestored) // Restore points previously set by user. + { + skillsRollout.SetClassSkills(characterDocument.career, false); + skillsRollout.StartingSkills = characterDocument.startingSkills; + skillsRollout.WorkingSkills = characterDocument.workingSkills; + skillsRollout.SkillBonuses = BiogFile.GetSkillEffects(characterDocument.biographyEffects); + } + else + { + skillsRollout.SetClassSkills(characterDocument.career); + skillsRollout.SkillBonuses = BiogFile.GetSkillEffects(characterDocument.biographyEffects); + } + } + protected override void Setup() { if (IsSetup) @@ -98,17 +108,13 @@ public override void Draw() base.Draw(); } - #region Private Methods - - void SetClass(DFCareer dfClass) + public void SetBonusSkillPoints(int primary, int major, int minor) { - Setup(); - this.dfClass = dfClass; - skillsRollout.SetClassSkills(dfClass); + skillsRollout.PrimarySkillBonusPoints = primary; + skillsRollout.MajorSkillBonusPoints = major; + skillsRollout.MinorSkillBonusPoints = minor; } - #endregion - #region Event Handlers void OkButton_OnMouseClick(BaseScreenComponent sender, Vector2 position) diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusStats.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusStats.cs index 3d31921531..c71b001177 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusStats.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharAddBonusStats.cs @@ -1,4 +1,4 @@ -// Project: Daggerfall Unity +// Project: Daggerfall Unity // Copyright: Copyright (C) 2009-2022 Daggerfall Workshop // Web Site: http://www.dfworkshop.net // License: MIT License (http://www.opensource.org/licenses/mit-license.php) diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharFaceSelect.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharFaceSelect.cs index 5574d12316..28e23eea90 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharFaceSelect.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharFaceSelect.cs @@ -1,4 +1,4 @@ -// Project: Daggerfall Unity +// Project: Daggerfall Unity // Copyright: Copyright (C) 2009-2022 Daggerfall Workshop // Web Site: http://www.dfworkshop.net // License: MIT License (http://www.opensource.org/licenses/mit-license.php) @@ -64,6 +64,7 @@ protected override void Setup() public void SetFaceTextures(RaceTemplate raceTemplate, Genders raceGender) { + facePicker.FaceIndex = 0; facePicker.SetFaceTextures(raceTemplate, raceGender); } diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSummary.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSummary.cs index 9f2bb1b04e..599fa745f3 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSummary.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSummary.cs @@ -46,6 +46,13 @@ public CharacterDocument CharacterDocument set { SetCharacterSheet(value); } } + public DaggerfallSkills StartingSkills => skillsRollout.StartingSkills; + public DaggerfallSkills WorkingSkills => skillsRollout.WorkingSkills; + public DaggerfallStats StartingStats => statsRollout.StartingStats; + public DaggerfallStats WorkingStats => statsRollout.WorkingStats; + public Tuple BonusSkillPoints => new Tuple(skillsRollout.PrimarySkillBonusPoints, skillsRollout.MajorSkillBonusPoints, skillsRollout.MinorSkillBonusPoints); + public int FaceIndex => facePicker.FaceIndex; + public CreateCharSummary(IUserInterfaceManager uiManager) : base(uiManager) { diff --git a/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs b/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs index d40c9c4c4f..d25849437c 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs @@ -53,6 +53,8 @@ public class StartNewGameWizard : DaggerfallBaseWindow CreateCharReflexSelect createCharReflexSelectWindow; CreateCharSummary createCharSummaryWindow; + bool skillsNeedReroll; + WizardStages WizardStage { get { return wizardStage; } @@ -179,6 +181,7 @@ void SetChooseBioWindow() createCharChooseBioWindow.OnClose += CreateCharChooseBioWindow_OnClose; wizardStage = WizardStages.SelectBiographyMethod; + skillsNeedReroll = true; uiManager.PushWindow(createCharChooseBioWindow); } @@ -248,16 +251,9 @@ void SetAddBonusSkillsWindow() { createCharAddBonusSkillsWindow = new CreateCharAddBonusSkills(uiManager); createCharAddBonusSkillsWindow.OnClose += AddBonusSkillsWindow_OnClose; - createCharAddBonusSkillsWindow.DFClass = characterDocument.career; - createCharAddBonusSkillsWindow.SkillBonuses = BiogFile.GetSkillEffects(characterDocument.biographyEffects); - } - - // Update class if player changes class selection - if (createCharAddBonusSkillsWindow.DFClass != characterDocument.career) - { - createCharAddBonusSkillsWindow.DFClass = characterDocument.career; } + createCharAddBonusSkillsWindow.SetCharacterDocument(characterDocument, !skillsNeedReroll); wizardStage = WizardStages.AddBonusSkills; uiManager.PushWindow(createCharAddBonusSkillsWindow); } @@ -514,8 +510,8 @@ void AddBonusStatsWindow_OnClose() { if (!createCharAddBonusStatsWindow.Cancelled) { - characterDocument.startingStats = createCharAddBonusStatsWindow.StartingStats; - characterDocument.workingStats = createCharAddBonusStatsWindow.WorkingStats; + characterDocument.startingStats.Copy(createCharAddBonusStatsWindow.StartingStats); + characterDocument.workingStats.Copy(createCharAddBonusStatsWindow.WorkingStats); SetAddBonusSkillsWindow(); } else @@ -528,12 +524,16 @@ void AddBonusSkillsWindow_OnClose() { if (!createCharAddBonusSkillsWindow.Cancelled) { - characterDocument.startingSkills = createCharAddBonusSkillsWindow.StartingSkills; - characterDocument.workingSkills = createCharAddBonusSkillsWindow.WorkingSkills; + characterDocument.startingSkills.Copy(createCharAddBonusSkillsWindow.StartingSkills); + characterDocument.workingSkills.Copy(createCharAddBonusSkillsWindow.WorkingSkills); SetSelectReflexesWindow(); + skillsNeedReroll = false; } else { + // Copy current stats to bonus stats window. + createCharAddBonusStatsWindow.StartingStats.Copy(characterDocument.startingStats); + createCharAddBonusStatsWindow.WorkingStats.Copy(characterDocument.workingStats); SetAddBonusStatsWindow(); } } @@ -565,6 +565,14 @@ void SummaryWindow_OnClose() } else { + // Copy skill and stat changes back to previous screens. + characterDocument.startingSkills.Copy(createCharSummaryWindow.StartingSkills); + characterDocument.workingSkills.Copy(createCharSummaryWindow.WorkingSkills); + characterDocument.startingStats.Copy(createCharSummaryWindow.StartingStats); + characterDocument.workingStats.Copy(createCharSummaryWindow.WorkingStats); + var bonusSkillPoints = createCharSummaryWindow.BonusSkillPoints; + createCharAddBonusSkillsWindow.SetBonusSkillPoints(bonusSkillPoints.Item1, bonusSkillPoints.Item2, bonusSkillPoints.Item3); + characterDocument.faceIndex = createCharSummaryWindow.FaceIndex; SetSelectReflexesWindow(); } } From 16d13582d79670a69e53aa79cf21371f15095731 Mon Sep 17 00:00:00 2001 From: numidium Date: Sun, 21 Jan 2024 17:49:30 -0500 Subject: [PATCH 2/2] Keep old method for compatibility --- Assets/Scripts/Game/UserInterface/SkillsRollout.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Assets/Scripts/Game/UserInterface/SkillsRollout.cs b/Assets/Scripts/Game/UserInterface/SkillsRollout.cs index ce23f8e065..fe57ae5f82 100644 --- a/Assets/Scripts/Game/UserInterface/SkillsRollout.cs +++ b/Assets/Scripts/Game/UserInterface/SkillsRollout.cs @@ -146,6 +146,11 @@ public void Reroll() UpdateSkillValueLabels(); } + public void SetClassSkills(DFCareer dfClass) + { + SetClassSkills(dfClass, true); + } + public void SetClassSkills(DFCareer dfClass, bool doReroll = true) { // Set primary, major, minor skills from class template