Skip to content

Commit

Permalink
Add error dialogs and finalize data persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
numidium committed Aug 5, 2018
1 parent 0f6c345 commit 13df131
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 72 deletions.
67 changes: 55 additions & 12 deletions Assets/Scripts/Game/UserInterfaceWindows/CreateCharCustomClass.cs
Expand Up @@ -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;
Expand All @@ -60,6 +63,7 @@ public class CreateCharCustomClass : DaggerfallPopupWindow

CreateCharReputationWindow createCharReputationWindow;
CreateCharSpecialAdvantageWindow createCharSpecialAdvantageWindow;
CreateCharSpecialAdvantageWindow createCharSpecialDisadvantageWindow;
DaggerfallListPickerWindow skillPicker;

#endregion
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand All @@ -423,6 +461,11 @@ public string ClassName
get { return nameTextBox.Text; }
}

public StatsRollout Stats
{
get { return statsRollout; }
}

#endregion
}
}
107 changes: 53 additions & 54 deletions Assets/Scripts/Game/UserInterfaceWindows/CreateCharReputationWindow.cs
Expand Up @@ -35,19 +35,16 @@ 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);
Vector2 repBarSize = new Vector2(5f, 0f);
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

Expand Down Expand Up @@ -101,6 +98,8 @@ protected override void Setup()

base.Setup();

prevWindow = (CreateCharCustomClass)this.PreviousWindow;

// Load native texture
nativeTexture = DaggerfallUI.GetTextureFromImg(nativeImgName);
if (!nativeTexture)
Expand All @@ -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()
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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)
{
Expand All @@ -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
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -802,7 +800,7 @@ void SetDamage(string secondary)
}
}

void InitializeCareerData()
public void InitializeCareerData()
{
advantageData.Paralysis = DFCareer.Tolerance.Normal;
advantageData.Magic = DFCareer.Tolerance.Normal;
Expand Down Expand Up @@ -848,7 +846,7 @@ void InitializeCareerData()
advantageData.DamageFromHolyPlaces = false;
}

void ParseCareerData()
public void ParseCareerData()
{
foreach (SpecialAdvDis advDis in advDisList)
{
Expand Down
Expand Up @@ -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();
}
Expand Down

0 comments on commit 13df131

Please sign in to comment.