From 13df131d6d3365212b263fd018ed8c24a226b54b Mon Sep 17 00:00:00 2001 From: numidium Date: Sun, 5 Aug 2018 01:45:40 -0400 Subject: [PATCH] Add error dialogs and finalize data persistence --- .../CreateCharCustomClass.cs | 67 +++++++++-- .../CreateCharReputationWindow.cs | 107 +++++++++--------- .../CreateCharSpecialAdvantageWindow.cs | 6 +- .../DaggerfallStartNewGameWizard.cs | 16 ++- 4 files changed, 124 insertions(+), 72 deletions(-) diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharCustomClass.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharCustomClass.cs index 0bd29692dd..52239f3481 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharCustomClass.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharCustomClass.cs @@ -34,6 +34,9 @@ public class CreateCharCustomClass : DaggerfallPopupWindow const int maxHpPerLevel = 30; const int minHpPerLevel = 4; const int defaultHpPerLevel = 8; + const int strNameYourClass = 301; + const int strSetSkills = 300; + const int strDistributeStats = 302; Texture2D nativeTexture; Texture2D nativeDaggerTexture; @@ -60,6 +63,7 @@ public class CreateCharCustomClass : DaggerfallPopupWindow CreateCharReputationWindow createCharReputationWindow; CreateCharSpecialAdvantageWindow createCharSpecialAdvantageWindow; + CreateCharSpecialAdvantageWindow createCharSpecialDisadvantageWindow; DaggerfallListPickerWindow skillPicker; #endregion @@ -311,28 +315,57 @@ public void specialAdvantageButton_OnMouseClick(BaseScreenComponent sender, Vect public void specialDisadvantageButton_OnMouseClick(BaseScreenComponent sender, Vector2 pos) { - createCharSpecialAdvantageWindow = new CreateCharSpecialAdvantageWindow(uiManager, disadvantages, createdClass, this, true); - uiManager.PushWindow(createCharSpecialAdvantageWindow); + createCharSpecialDisadvantageWindow = new CreateCharSpecialAdvantageWindow(uiManager, disadvantages, createdClass, this, true); + uiManager.PushWindow(createCharSpecialDisadvantageWindow); } void ReputationButton_OnMouseClick(BaseScreenComponent sender, Vector2 position) { createCharReputationWindow = new CreateCharReputationWindow(uiManager, this); - createCharReputationWindow.OnClose += CreateCharReputationWindow_OnClose; uiManager.PushWindow(createCharReputationWindow); } - void CreateCharReputationWindow_OnClose() - { - merchantsRep = createCharReputationWindow.MerchantsRep; - peasantsRep = createCharReputationWindow.PeasantsRep; - scholarsRep = createCharReputationWindow.ScholarsRep; - nobilityRep = createCharReputationWindow.NobilityRep; - underworldRep = createCharReputationWindow.UnderworldRep; - } - void ExitButton_OnMouseClick(BaseScreenComponent sender, Vector2 position) { + DaggerfallMessageBox messageBox; + + // Is the class name set? + if (nameTextBox.Text.Length == 0) + { + messageBox = new DaggerfallMessageBox(uiManager, this); + messageBox.SetTextTokens(strNameYourClass); + messageBox.ClickAnywhereToClose = true; + messageBox.Show(); + return; + } + + // Are all skills set? + for (int i = 0; i < skillLabels.Length; i++) + { + if (skillLabels [i].Text == string.Empty) + { + messageBox = new DaggerfallMessageBox(uiManager, this); + messageBox.SetTextTokens(strSetSkills); + messageBox.ClickAnywhereToClose = true; + messageBox.Show(); + return; + } + } + + // Are all attribute points distributed? + if (statsRollout.BonusPool > 0) + { + messageBox = new DaggerfallMessageBox(uiManager, this); + messageBox.SetTextTokens(strDistributeStats); + messageBox.ClickAnywhereToClose = true; + messageBox.Show(); + } + + // Set advantages/disadvantages + createCharSpecialAdvantageWindow.InitializeCareerData(); + createCharSpecialAdvantageWindow.ParseCareerData(); + createCharSpecialDisadvantageWindow.ParseCareerData(); + CloseWindow(); } @@ -391,26 +424,31 @@ public int DisadvantageAdjust public short MerchantsRep { get { return merchantsRep; } + set { merchantsRep = value; } } public short PeasantsRep { get { return peasantsRep; } + set { peasantsRep = value; } } public short ScholarsRep { get { return scholarsRep; } + set { scholarsRep = value; } } public short NobilityRep { get { return nobilityRep; } + set { nobilityRep = value; } } public short UnderworldRep { get { return underworldRep; } + set { underworldRep = value; } } public DFCareer CreatedClass @@ -423,6 +461,11 @@ public string ClassName get { return nameTextBox.Text; } } + public StatsRollout Stats + { + get { return statsRollout; } + } + #endregion } } \ No newline at end of file diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharReputationWindow.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharReputationWindow.cs index d4b5c75904..3fa94763f9 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharReputationWindow.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharReputationWindow.cs @@ -35,6 +35,7 @@ public class CreateCharReputationWindow : DaggerfallPopupWindow const float barBottomY = 128f; const float barMiddleY = 76f; const float barLength = 50f; + const int strBalanceMustEqualZero = 303; Color greenBarColor = new Color(.388f, .549f, .223f); Color redBarColor = new Color(.580f, .031f, 0f); @@ -42,12 +43,8 @@ public class CreateCharReputationWindow : DaggerfallPopupWindow Texture2D nativeTexture; DaggerfallFont font; Panel repPanel = new Panel(); - short merchantsRep = 0; - short peasantsRep = 0; - short scholarsRep = 0; - short nobilityRep = 0; - short underworldRep = 0; short pointsToDistribute = 0; + CreateCharCustomClass prevWindow; #region UI Rects @@ -101,6 +98,8 @@ protected override void Setup() base.Setup(); + prevWindow = (CreateCharCustomClass)this.PreviousWindow; + // Load native texture nativeTexture = DaggerfallUI.GetTextureFromImg(nativeImgName); if (!nativeTexture) @@ -121,25 +120,23 @@ protected override void Setup() exitButton.OnMouseClick += ExitButton_OnMouseClick; // Setup adjustable bars - SetupRepBars(merchantsGreenPanel, merchantsRedPanel, new Vector2(3f, 75f), new Vector2(3f, 77f)); - SetupRepBars(peasantsGreenPanel, peasantsRedPanel, new Vector2(36f, 75f), new Vector2(36f, 77f)); - SetupRepBars(scholarsGreenPanel, scholarsRedPanel, new Vector2(69f, 75f), new Vector2(69f, 77f)); - SetupRepBars(nobilityGreenPanel, nobilityRedPanel, new Vector2(102f, 75f), new Vector2(102f, 77f)); - SetupRepBars(underworldGreenPanel, underworldRedPanel, new Vector2(135f, 75f), new Vector2(135f, 77f)); + SetupRepBars(merchantsGreenPanel, merchantsRedPanel, new Vector2(3f, 75f), new Vector2(3f, 77f), prevWindow.MerchantsRep); + SetupRepBars(peasantsGreenPanel, peasantsRedPanel, new Vector2(36f, 75f), new Vector2(36f, 77f), prevWindow.PeasantsRep); + SetupRepBars(scholarsGreenPanel, scholarsRedPanel, new Vector2(69f, 75f), new Vector2(69f, 77f), prevWindow.ScholarsRep); + SetupRepBars(nobilityGreenPanel, nobilityRedPanel, new Vector2(102f, 75f), new Vector2(102f, 77f), prevWindow.NobilityRep); + SetupRepBars(underworldGreenPanel, underworldRedPanel, new Vector2(135f, 75f), new Vector2(135f, 77f), prevWindow.UnderworldRep); // Setup text labels - merchantsPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(18f, 143f), merchantsRep.ToString(), repPanel); - peasantsPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(50f, 143f), peasantsRep.ToString(), repPanel); - scholarsPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(82f, 143f), scholarsRep.ToString(), repPanel); - nobilityPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(114f, 143f), nobilityRep.ToString(), repPanel); - underworldPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(146f, 143f), nobilityRep.ToString(), repPanel); + merchantsPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(18f, 143f), prevWindow.MerchantsRep.ToString(), repPanel); + peasantsPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(50f, 143f), prevWindow.PeasantsRep.ToString(), repPanel); + scholarsPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(82f, 143f), prevWindow.ScholarsRep.ToString(), repPanel); + nobilityPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(114f, 143f), prevWindow.NobilityRep.ToString(), repPanel); + underworldPtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(146f, 143f), prevWindow.UnderworldRep.ToString(), repPanel); distributePtsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(64f, 173f), pointsToDistribute.ToString(), repPanel); IsSetup = true; } - - #endregion public override void Update() @@ -160,37 +157,48 @@ void RepPanel_OnMouseClick(BaseScreenComponent sender, Vector2 position) { if (position.x >= 134f) // Underworld { - UpdateRep(position, underworldGreenPanel, underworldRedPanel, underworldPtsLabel, out underworldRep); + prevWindow.UnderworldRep = UpdateRep(position, underworldGreenPanel, underworldRedPanel, underworldPtsLabel); } else if (position.x >= 101f) // Nobility { - UpdateRep(position, nobilityGreenPanel, nobilityRedPanel, nobilityPtsLabel, out nobilityRep); + prevWindow.NobilityRep = UpdateRep(position, nobilityGreenPanel, nobilityRedPanel, nobilityPtsLabel); } else if (position.x >= 68f) // Scholars { - UpdateRep(position, scholarsGreenPanel, scholarsRedPanel, scholarsPtsLabel, out scholarsRep); + prevWindow.ScholarsRep = UpdateRep(position, scholarsGreenPanel, scholarsRedPanel, scholarsPtsLabel); } else if (position.x >= 35f) // Peasants { - UpdateRep(position, peasantsGreenPanel, peasantsRedPanel, peasantsPtsLabel, out peasantsRep); + prevWindow.PeasantsRep = UpdateRep(position, peasantsGreenPanel, peasantsRedPanel, peasantsPtsLabel); } else // Merchants { - UpdateRep(position, merchantsGreenPanel, merchantsRedPanel, merchantsPtsLabel, out merchantsRep); + prevWindow.MerchantsRep = UpdateRep(position, merchantsGreenPanel, merchantsRedPanel, merchantsPtsLabel); } + UpdatePointsToDistribute(); } } void ExitButton_OnMouseClick(BaseScreenComponent sender, Vector2 pos) { - CloseWindow(); + if (pointsToDistribute != 0) + { + DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this); + messageBox.SetTextTokens(strBalanceMustEqualZero); + messageBox.ClickAnywhereToClose = true; + messageBox.Show(); + } + else + { + CloseWindow(); + } } #endregion #region Helper methods - void SetupRepBars(Panel greenBar, Panel redBar, Vector2 greenBarPos, Vector2 redBarPos) + void SetupRepBars(Panel greenBar, Panel redBar, Vector2 greenBarPos, Vector2 redBarPos, short val) { // Positive rep greenBar.Position = greenBarPos; @@ -203,6 +211,21 @@ void SetupRepBars(Panel greenBar, Panel redBar, Vector2 greenBarPos, Vector2 red redBar.BackgroundColor = redBarColor; redBar.Size = repBarSize; repPanel.Components.Add(redBar); + + // Initialize value + if (val > 0) + { + greenBar.Enabled = true; + redBar.Enabled = false; + greenBar.Position = new Vector2(greenBar.Position.x, barMiddleY - (float)val * 5f); + greenBar.Size = new Vector2(greenBar.Size.x, barMiddleY - greenBar.Position.y); + } + if (val < 0) + { + redBar.Enabled = true; + greenBar.Enabled = false; + redBar.Size = new Vector2(redBar.Size.x, (float)val * -5f); + } } int RoundNearestBarHeight(int number) @@ -223,11 +246,12 @@ int RoundNearestBarHeight(int number) return ret > maxHeight ? maxHeight : ret; // don't go over the top or bottom } - void UpdateRep(Vector2 mousePos, Panel greenBar, Panel redBar, TextLabel label, out short repVal) + short UpdateRep(Vector2 mousePos, Panel greenBar, Panel redBar, TextLabel label) { float clickedHeight = ((float)Math.Abs(barMiddleY - mousePos.y) / barLength) * barLength; int nearestHeight = RoundNearestBarHeight((int)clickedHeight); int sign = 1; // positive or negative + short repVal; if (mousePos.y < barMiddleY) { @@ -248,38 +272,13 @@ void UpdateRep(Vector2 mousePos, Panel greenBar, Panel redBar, TextLabel label, repVal = (short)(sign * nearestHeight / 5); label.Text = repVal.ToString(); - // Update "Points to Distribute" - pointsToDistribute = (short)(-merchantsRep - peasantsRep - scholarsRep - nobilityRep - underworldRep); - distributePtsLabel.Text = pointsToDistribute.ToString(); + return repVal; } - #endregion - - #region Properties - - public short MerchantsRep + void UpdatePointsToDistribute() { - get { return merchantsRep; } - } - - public short PeasantsRep - { - get { return peasantsRep; } - } - - public short ScholarsRep - { - get { return scholarsRep; } - } - - public short NobilityRep - { - get { return nobilityRep; } - } - - public short UnderworldRep - { - get { return underworldRep; } + pointsToDistribute = (short)(-prevWindow.MerchantsRep - prevWindow.PeasantsRep - prevWindow.ScholarsRep - prevWindow.NobilityRep - prevWindow.UnderworldRep); + distributePtsLabel.Text = pointsToDistribute.ToString(); } #endregion diff --git a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSpecialAdvantageWindow.cs b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSpecialAdvantageWindow.cs index ae751a1727..ee79f087d2 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSpecialAdvantageWindow.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/CreateCharSpecialAdvantageWindow.cs @@ -421,8 +421,6 @@ void AdvantageLabel_OnMouseClick(BaseScreenComponent sender, Vector2 pos) void ExitButton_OnMouseClick(BaseScreenComponent sender, Vector2 pos) { CloseWindow(); - InitializeCareerData(); // clean data before parsing - ParseCareerData(); // transfer data from window to career object } #endregion @@ -802,7 +800,7 @@ void SetDamage(string secondary) } } - void InitializeCareerData() + public void InitializeCareerData() { advantageData.Paralysis = DFCareer.Tolerance.Normal; advantageData.Magic = DFCareer.Tolerance.Normal; @@ -848,7 +846,7 @@ void InitializeCareerData() advantageData.DamageFromHolyPlaces = false; } - void ParseCareerData() + public void ParseCareerData() { foreach (SpecialAdvDis advDis in advDisList) { diff --git a/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs b/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs index f65474faae..9dda75d775 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallStartNewGameWizard.cs @@ -301,13 +301,25 @@ void ClassSelectWindow_OnClose() void CreateCharCustomClassWindow_OnClose() { + characterDocument.career = createCharCustomClassWindow.CreatedClass; + characterDocument.career.Name = createCharCustomClassWindow.ClassName; + + // Set reputation adjustments characterDocument.reputationMerchants = createCharCustomClassWindow.MerchantsRep; characterDocument.reputationCommoners = createCharCustomClassWindow.PeasantsRep; characterDocument.reputationScholars = createCharCustomClassWindow.ScholarsRep; characterDocument.reputationNobility = createCharCustomClassWindow.NobilityRep; characterDocument.reputationUnderworld = createCharCustomClassWindow.UnderworldRep; - characterDocument.career = createCharCustomClassWindow.CreatedClass; - characterDocument.career.Name = createCharCustomClassWindow.ClassName; + + // Set attributes + characterDocument.career.Strength = createCharCustomClassWindow.Stats.WorkingStats.LiveStrength; + characterDocument.career.Intelligence = createCharCustomClassWindow.Stats.WorkingStats.LiveIntelligence; + characterDocument.career.Willpower = createCharCustomClassWindow.Stats.WorkingStats.LiveWillpower; + characterDocument.career.Agility = createCharCustomClassWindow.Stats.WorkingStats.LiveAgility; + characterDocument.career.Endurance = createCharCustomClassWindow.Stats.WorkingStats.LiveEndurance; + characterDocument.career.Personality = createCharCustomClassWindow.Stats.WorkingStats.LivePersonality; + characterDocument.career.Speed = createCharCustomClassWindow.Stats.WorkingStats.LiveSpeed; + characterDocument.career.Luck = createCharCustomClassWindow.Stats.WorkingStats.LiveLuck; SetNameSelectWindow(); }