Commit 9b2ba8c3 authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Added MiniSentrySDK.

Better error handling in general especially in GetData and Trade dialog.
Updated Cake file to number the DLL files in the order they need to load.
parent dc28d48d
......@@ -59,15 +59,14 @@ namespace Glitterworld_Prime
}
floatMenuOptions = new List<FloatMenuOption>();
var tradeship = mapComponent.GetTradeShip();
var communicable = (ICommunicable) tradeship; // Cast trader as ICommunicable;
var tradeShip = mapComponent.GetTradeShip();
var communicable = (ICommunicable) tradeShip; // Cast trader as ICommunicable;
Action action = delegate
{
if (!Building_PrimeUplink.HasUplink(myPawn.Map))
{
Messages.Message("GWPNeedUplink".Translate(), this,
MessageTypeDefOf.RejectInput);
Messages.Message("GWPNeedUplink".Translate(), this, MessageTypeDefOf.RejectInput);
return;
}
......@@ -86,7 +85,12 @@ namespace Glitterworld_Prime
#if DEBUG
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption("Dump Thing data", DumpThingData.DumpData, MenuOptionPriority.InitiateSocial, null,
new FloatMenuOption("Dump Thing data", DumpThingData.DumpData, MenuOptionPriority.Low, null,
null, 0f,
null, null), myPawn, this, "ReservedBy"));
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption("Throw an error!", Utilities.SendTestException, MenuOptionPriority.High, null,
null, 0f,
null, null), myPawn, this, "ReservedBy"));
#endif
......@@ -94,6 +98,9 @@ namespace Glitterworld_Prime
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
Action reactivateAction = delegate { Find.WindowStack.Add(new DialogPrimeReactivate()); };
{
Find.WindowStack.Add(new DialogPrimeReactivate());
}
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption("Reactivate", reactivateAction, MenuOptionPriority.InitiateSocial, null, null, 0f,
......@@ -101,17 +108,17 @@ namespace Glitterworld_Prime
}
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption(tradeship.TraderName, action, MenuOptionPriority.InitiateSocial, null, null, 0f,
new FloatMenuOption(tradeShip.TraderName, action, MenuOptionPriority.InitiateSocial, null, null, 0f,
null, null), myPawn, this, "ReservedBy"));
return floatMenuOptions;
}
public override void SpawnSetup(Map map, bool respawningAfterLoad)
{
base.SpawnSetup(map, respawningAfterLoad);
}
// public override void SpawnSetup(Map map, bool respawningAfterLoad)
// {
// base.SpawnSetup(map, respawningAfterLoad);
// }
#endregion
}
......
......@@ -24,7 +24,7 @@ namespace Glitterworld_Prime
private readonly GlitterWorld_MapComponent _mapComponent;
private readonly Pawn _player;
private readonly bool _shouldClose = false;
private bool _shouldClose = false;
private readonly ITrader _trader;
private Stopwatch _apiStopwatch;
......@@ -78,73 +78,84 @@ namespace Glitterworld_Prime
public override void DoWindowContents(Rect inRect)
{
GUI.color = Color.white;
if (_shouldClose)
try
{
Close();
return;
}
Text.Font = GameFont.Small;
GUI.color = Color.white;
switch (_status)
{
case DownloadStatus.Incomplete:
if (_previousStatus != DownloadStatus.Incomplete)
{
_previousStatus = DownloadStatus.Incomplete;
_downloadMessage = "GWPSendingThingList".Translate();
}
break;
case DownloadStatus.DoneSendingSupportedThings:
if (_previousStatus != DownloadStatus.DoneSendingSupportedThings)
{
// Now send the mods
_previousStatus = DownloadStatus.DoneSendingSupportedThings;
_downloadMessage = "GWPSendingModList".Translate();
_apiStopwatch = new Stopwatch();
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
GlitterWorldApi.PutModListAsync(_mapComponent, PutModListComplete_Callback);
}
break;
case DownloadStatus.DoneSendingMods:
if (_previousStatus != DownloadStatus.DoneSendingMods)
{
// Download Goods from Server
_previousStatus = DownloadStatus.DoneSendingMods;
_downloadMessage = "GWPGetMarketData".Translate();
_apiStopwatch = new Stopwatch();
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
GlitterWorldApi.GetServerGoodsAsync(_mapComponent, DownloadThingsComplete_Callback);
}
break;
case DownloadStatus.Complete:
// Mark that we've sent all the metadata, so not to do it again.
_mapComponent.HasSentThingListYet = true;
// We're done, close and go to the trade screen.
var dt = new DialogPrimeTrade(_player, _trader);
Find.WindowStack.Add(dt);
if (_shouldClose)
{
Close();
break;
return;
}
case DownloadStatus.Failed:
Messages.Message("GWPCantGetMarketData".Translate(), MessageTypeDefOf.NegativeEvent);
Close();
break;
Text.Font = GameFont.Small;
default:
throw new ArgumentOutOfRangeException();
switch (_status)
{
case DownloadStatus.Incomplete:
if (_previousStatus != DownloadStatus.Incomplete)
{
_previousStatus = DownloadStatus.Incomplete;
_downloadMessage = "GWPSendingThingList".Translate();
}
break;
case DownloadStatus.DoneSendingSupportedThings:
if (_previousStatus != DownloadStatus.DoneSendingSupportedThings)
{
// Now send the mods
_previousStatus = DownloadStatus.DoneSendingSupportedThings;
_downloadMessage = "GWPSendingModList".Translate();
_apiStopwatch = new Stopwatch();
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
GlitterWorldApi.PutModListAsync(_mapComponent, PutModListComplete_Callback);
}
break;
case DownloadStatus.DoneSendingMods:
if (_previousStatus != DownloadStatus.DoneSendingMods)
{
// Download Goods from Server
_previousStatus = DownloadStatus.DoneSendingMods;
_downloadMessage = "GWPGetMarketData".Translate();
_apiStopwatch = new Stopwatch();
LogWriter.WriteMessage("Starting request to server");
_apiStopwatch.Start();
GlitterWorldApi.GetServerGoodsAsync(_mapComponent, DownloadThingsComplete_Callback);
}
break;
case DownloadStatus.Complete:
// Mark that we've sent all the metadata, so not to do it again.
_mapComponent.HasSentThingListYet = true;
// We're done, close and go to the trade screen.
var dt = new DialogPrimeTrade(_player, _trader);
Find.WindowStack.Add(dt);
Close();
break;
case DownloadStatus.Failed:
Messages.Message("GWPCantGetMarketData".Translate(), MessageTypeDefOf.NegativeEvent);
Close();
break;
default:
throw new ArgumentOutOfRangeException();
}
}
catch (Exception exception)
{
Utilities.CaptureError(exception);
Close();
_shouldClose = true;
return;
}
var textWidth = Text.CalcSize(_downloadMessage);
......
......@@ -24,15 +24,9 @@ namespace Glitterworld_Prime
this.closeOnClickedOutside = true;
}
protected virtual int MaxCodeLength
{
get { return 8; }
}
protected virtual int MaxCodeLength => 8;
public override Vector2 InitialSize
{
get { return new Vector2(280f, 175f); }
}
public override Vector2 InitialSize => new Vector2(280f, 175f);
public override void DoWindowContents(Rect inRect)
{
......
......@@ -38,18 +38,25 @@ namespace Glitterworld_Prime
public DialogPrimeTrade(Pawn playerNegotiator, ITrader trader) : base(playerNegotiator, trader)
{
TradeSession.SetupWith(trader, playerNegotiator, false);
closeOnCancel = true;
forcePause = true;
absorbInputAroundWindow = true;
soundAppear = SoundDefOf.CommsWindow_Open;
soundClose = SoundDefOf.CommsWindow_Close;
if (!(trader is Pawn)) soundAmbient = SoundDefOf.RadioComms_Ambience;
_sorter1 = TransferableSorterDefOf.Category;
_sorter2 = TransferableSorterDefOf.MarketValue;
// This has been set to food to reduce lag when the Window opens.
_filter = ThingCategoryDefOf.Foods;
try
{
TradeSession.SetupWith(trader, playerNegotiator, false);
closeOnCancel = true;
forcePause = true;
absorbInputAroundWindow = true;
soundAppear = SoundDefOf.CommsWindow_Open;
soundClose = SoundDefOf.CommsWindow_Close;
if (!(trader is Pawn)) soundAmbient = SoundDefOf.RadioComms_Ambience;
_sorter1 = TransferableSorterDefOf.Category;
_sorter2 = TransferableSorterDefOf.MarketValue;
// This has been set to food to reduce lag when the Window opens.
_filter = ThingCategoryDefOf.Foods;
}
catch (Exception exception)
{
Utilities.CaptureError(exception);
}
}
#endregion
......@@ -75,180 +82,188 @@ namespace Glitterworld_Prime
public override void DoWindowContents(Rect inRect)
{
TradeSession.deal.UpdateCurrencyCount();
// This code draws the two sort button and assigns the callback for the dropdown menus when they've been clicked.
DoTransferableSorters(
delegate(TransferableSorterDef x)
{
_sorter1 = x;
CacheTradeables();
}, delegate(TransferableSorterDef x)
{
_sorter2 = x;
CacheTradeables();
}, delegate(ThingCategoryDef x)
{
_filter = x;
CacheTradeables();
});
// Define width of trade window
var num = inRect.width - 590f;
// Define the Header rectangle
var rect = new Rect(num, 0f, inRect.width - num, TopAreaHeight);
GUI.BeginGroup(rect);
try
{
TradeSession.deal.UpdateCurrencyCount();
Text.Font = GameFont.Medium;
Text.Anchor = TextAnchor.UpperLeft;
// This code draws the two sort button and assigns the callback for the dropdown menus when they've been clicked.
DoTransferableSorters(
delegate(TransferableSorterDef x)
{
_sorter1 = x;
CacheTradeables();
}, delegate(TransferableSorterDef x)
{
_sorter2 = x;
CacheTradeables();
}, delegate(ThingCategoryDef x)
{
_filter = x;
CacheTradeables();
});
// Draw trader name
var rect3 = new Rect(rect.width / 2f, 0f, rect.width / 2f, rect.height);
Text.Anchor = TextAnchor.UpperRight;
var text = TradeSession.trader.TraderName;
if (Text.CalcSize(text).x > rect3.width)
{
Text.Font = GameFont.Small;
text = text.Truncate(rect3.width, null);
}
// Define width of trade window
var num = inRect.width - 590f;
Widgets.Label(rect3, text);
// Define the Header rectangle
var rect = new Rect(num, 0f, inRect.width - num, TopAreaHeight);
GUI.BeginGroup(rect);
// Negotiator
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.UpperLeft;
var rect4 = new Rect(0f, 27f, rect.width / 2f, rect.height / 2f);
Widgets.Label(rect4, "Negotiator".Translate() + ": " + TradeSession.playerNegotiator.LabelShort);
Text.Font = GameFont.Medium;
Text.Anchor = TextAnchor.UpperLeft;
// Trader description
Text.Anchor = TextAnchor.UpperRight;
var rect5 = new Rect(rect.width / 2f, 27f, rect.width / 2f, rect.height / 2f);
Widgets.Label(rect5, TradeSession.trader.TraderKind.LabelCap);
// Draw trader name
var rect3 = new Rect(rect.width / 2f, 0f, rect.width / 2f, rect.height);
Text.Anchor = TextAnchor.UpperRight;
var text = TradeSession.trader.TraderName;
if (Text.CalcSize(text).x > rect3.width)
{
Text.Font = GameFont.Small;
text = text.Truncate(rect3.width, null);
}
// Trade hints / explanation
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = new Color(1f, 1f, 1f, 0.6f);
Text.Font = GameFont.Tiny;
var rect6 = new Rect(rect.width / 2f - 100f - 30f, 0f, 200f, rect.height);
Text.Anchor = TextAnchor.LowerCenter;
Widgets.Label(rect6, "PositiveBuysNegativeSells".Translate());
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = Color.white;
GUI.EndGroup();
Widgets.Label(rect3, text);
// Draw currency row
var num2 = 0f;
if (_cachedCurrencyTradeable != null)
{
var num3 = inRect.width - 16f;
var rect8 = new Rect(0f, TopAreaHeight, num3, 30f);
TradeUI.DrawTradeableRow(rect8, _cachedCurrencyTradeable, 1);
GUI.color = Color.gray;
Widgets.DrawLineHorizontal(0f, TopAreaHeight + 30f - 1f, num3);
// Negotiator
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.UpperLeft;
var rect4 = new Rect(0f, 27f, rect.width / 2f, rect.height / 2f);
Widgets.Label(rect4, "Negotiator".Translate() + ": " + TradeSession.playerNegotiator.LabelShort);
// Trader description
Text.Anchor = TextAnchor.UpperRight;
var rect5 = new Rect(rect.width / 2f, 27f, rect.width / 2f, rect.height / 2f);
Widgets.Label(rect5, TradeSession.trader.TraderKind.LabelCap);
// Trade hints / explanation
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = new Color(1f, 1f, 1f, 0.6f);
Text.Font = GameFont.Tiny;
var rect6 = new Rect(rect.width / 2f - 100f - 30f, 0f, 200f, rect.height);
Text.Anchor = TextAnchor.LowerCenter;
Widgets.Label(rect6, "PositiveBuysNegativeSells".Translate());
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = Color.white;
num2 = 30f;
}
GUI.EndGroup();
// Define the tradeable subwindow.
var mainRect = new Rect(0f, TopAreaHeight + num2, inRect.width,
inRect.height - TopAreaHeight - 38f - num2 - 20f);
// Draw currency row
var num2 = 0f;
if (_cachedCurrencyTradeable != null)
{
var num3 = inRect.width - 16f;
var rect8 = new Rect(0f, TopAreaHeight, num3, 30f);
TradeUI.DrawTradeableRow(rect8, _cachedCurrencyTradeable, 1);
GUI.color = Color.gray;
Widgets.DrawLineHorizontal(0f, TopAreaHeight + 30f - 1f, num3);
GUI.color = Color.white;
num2 = 30f;
}
// Draw the tradables
FillMainRect(mainRect);
// Define the tradeable subwindow.
var mainRect = new Rect(0f, TopAreaHeight + num2, inRect.width,
inRect.height - TopAreaHeight - 38f - num2 - 20f);
// Draw, Reset, Accept and Cancel buttons
var rect9 = new Rect(inRect.width / 2f - AcceptButtonSize.x / 2f, inRect.height - 55f, AcceptButtonSize.x,
AcceptButtonSize.y);
if (Widgets.ButtonText(rect9, "AcceptButton".Translate(), true, false, true))
{
Action action = () =>
// Draw the tradables
FillMainRect(mainRect);
// Draw, Reset, Accept and Cancel buttons
var rect9 = new Rect(inRect.width / 2f - AcceptButtonSize.x / 2f, inRect.height - 55f,
AcceptButtonSize.x,
AcceptButtonSize.y);
if (Widgets.ButtonText(rect9, "AcceptButton".Translate(), true, false, true))
{
Log.Message("GWP Starting order build", true);
Action action = () =>
{
Log.Message("GWP Starting order build", true);
bool flag;
var tracker = Utilities.GetMapComponent(TradeSession.playerNegotiator.Map).OrderTracker;
var tracker = Utilities.GetMapComponent(TradeSession.playerNegotiator.Map).OrderTracker;
if (!TradeSession.deal.TryExecute(out flag))
{
Log.Message("Error at TradeSession.deal.TryExecute() or Colony couldn't afford it", true);
return;
}
bool flag;
if (!TradeSession.deal.TryExecute(out flag))
{
Log.Message("Error at TradeSession.deal.TryExecute() or Colony couldn't afford it", true);
return;
}
if (flag)
{
var orderSuccess = tracker.TryPlaceOrder((TraderPrime) TradeSession.trader);
if (flag)
{
var orderSuccess = tracker.TryPlaceOrder((TraderPrime) TradeSession.trader);
// Were we able to place the order?
if (orderSuccess)
{
// Yes, Plav a sound and record the trade deal for the pawn.
SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(null);
var pawn = TradeSession.trader as Pawn;
if (pawn != null)
TaleRecorder.RecordTale(TaleDefOf.TradedWith, TradeSession.playerNegotiator, pawn);
}
// If not then the refund was already issued and the error displayed.
// Close the dialog.
Close(false);
}
else
{
LogWriter.WriteErrorMessage(
"Error processing order, RimWorld couldn't complete the trade.");
}
// Were we able to place the order?
if (orderSuccess)
Event.current.Use();
Close();
};
if (TradeSession.deal.DoesTraderHaveEnoughSilver())
{
var amt = TradeSession.deal.SilverTradeable.CountToTransferToSource;
if (amt > 0 && amt < 1)
{
// Yes, Plav a sound and record the trade deal for the pawn.
SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(null);
var pawn = TradeSession.trader as Pawn;
if (pawn != null)
TaleRecorder.RecordTale(TaleDefOf.TradedWith, TradeSession.playerNegotiator, pawn);
SoundDefOf.ClickReject.PlayOneShotOnCamera(null);
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("GWPGiveItAway".Translate(),
action, false, null));
}
// If not then the refund was already issued and the error displayed.
// Close the dialog.
Close(false);
action();
}
else
{
LogWriter.WriteErrorMessage(
"Error processing order, RimWorld couldn't complete the trade.");
}
Event.current.Use();
Close();
};
if (TradeSession.deal.DoesTraderHaveEnoughSilver())
{
var amt = TradeSession.deal.SilverTradeable.CountToTransferToSource;
if (amt > 0 && amt < 1)
{
FlashSilver();
SoundDefOf.ClickReject.PlayOneShotOnCamera(null);
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("GWPGiveItAway".Translate(),
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmTraderShortFunds".Translate(),
action, false, null));
}
action();
Event.current.Use();
}
var rect10 = new Rect(rect9.x - 10f - OtherBottomButtonSize.x, rect9.y, OtherBottomButtonSize.x,
OtherBottomButtonSize.y);
if (Widgets.ButtonText(rect10, "ResetButton".Translate(), true, false, true))
{
SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
TradeSession.deal.Reset();
Utilities.SetTradablesPrice();
CacheTradeables();
Event.current.Use();
}
else
var rect11 = new Rect(rect9.xMax + 10f, rect9.y, OtherBottomButtonSize.x, OtherBottomButtonSize.y);
if (Widgets.ButtonText(rect11, "CancelButton".Translate(), true, false, true))
{
FlashSilver();
SoundDefOf.ClickReject.PlayOneShotOnCamera(null);
Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmTraderShortFunds".Translate(),
action, false, null));
Close(true);
Event.current.Use();
}
Event.current.Use();
}
if (_filterOnlyColonyItems == _filterSettingLastFrame) return;
var rect10 = new Rect(rect9.x - 10f - OtherBottomButtonSize.x, rect9.y, OtherBottomButtonSize.x,
OtherBottomButtonSize.y);
if (Widgets.ButtonText(rect10, "ResetButton".Translate(), true, false, true))
{
SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
TradeSession.deal.Reset();
Utilities.SetTradablesPrice();
_filterSettingLastFrame = _filterOnlyColonyItems;
CacheTradeables();
Event.current.Use();
}
var rect11 = new Rect(rect9.xMax + 10f, rect9.y, OtherBottomButtonSize.x, OtherBottomButtonSize.y);
if (Widgets.ButtonText(rect11, "CancelButton".Translate(), true, false, true))
catch (Exception e)
{
Utilities.CaptureError(e);