Commit 8af1bd65 authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Merge branch 'develop' into 'master'

Update master

See merge request GWP/Release!7
parents 340b660e 46683dae
......@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using Glitterworld_Prime.Tools;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.AI;
......@@ -58,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;
}
......@@ -85,25 +85,38 @@ 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
// Are they holding down shift?
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
Action reactivateAction = delegate { Find.WindowStack.Add(new DialogPrimeReactivate()); };
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption("Reactivate", reactivateAction, MenuOptionPriority.InitiateSocial, null, null, 0f,
null, null), myPawn, this, "ReservedBy"));
}
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
}
}
\ No newline at end of file
}
......@@ -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);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using UnityEngine;
using Verse;
namespace Glitterworld_Prime
{
public class DialogPrimeReactivate : Window
{
protected string code;
private bool focusedRenameField;
public DialogPrimeReactivate()
{
this.forcePause = true;
this.doCloseX = true;
this.absorbInputAroundWindow = true;
this.closeOnAccept = false;
this.closeOnClickedOutside = true;
}
protected virtual int MaxCodeLength => 8;
public override Vector2 InitialSize => new Vector2(280f, 175f);
public override void DoWindowContents(Rect inRect)
{
Text.Font = GameFont.Small;
bool flag = false;
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
{
flag = true;
Event.current.Use();
}
GUI.SetNextControlName("CodeField");
string str = Widgets.TextField(new Rect(0.0f, 15f, inRect.width, 35f), this.code);
if (str.Length < (this.MaxCodeLength+1))
this.code = str;
if (!this.focusedRenameField)
{
UI.FocusControl("CodeField", (Window) this);
this.focusedRenameField = true;
}
if (!Widgets.ButtonText(
new Rect(15f, (float) ((double) inRect.height - 35.0 - 15.0), (float) ((double) inRect.width - 15.0 - 15.0),
35f), "OK", true, false, true) && !flag)
return;
AcceptanceReport acceptanceReport = this.CodeIsValid(this.code);
if (!acceptanceReport.Accepted)
{
Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.RejectInput, false);
}
else
{
TryActivate(this.code);
Find.WindowStack.TryRemove((Window) this, true);
}
}
private AcceptanceReport CodeIsValid(string code)
{
if (code.Length != MaxCodeLength)
return new AcceptanceReport("GWPActivateIncorrect".Translate());
return (AcceptanceReport) true;
}
private static void TryActivate(string code)
{
// API Call to reactivate
GlitterWorldApi.ReactivateUserAccount(code);
}
}
}
......@@ -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.