public string GetTravelMode()
        {
            if (TravelMode == TravelModeType.Default)
            {
                return(string.Empty);
            }

            return(TravelMode.ToString().ToLower());
        }
Example #2
0
        public Directions GetDirections(Coordinate origin, Coordinate destination, TravelMode travelMode = TravelMode.Driving)
        {
            if (!CoordinateValidator.Validate(origin.Latitude, origin.Longitude))
            {
                throw new ArgumentException("Invalid origin coordinate supplied.");
            }

            if (!CoordinateValidator.Validate(destination.Latitude, destination.Longitude))
            {
                throw new ArgumentException("Invalid destination coordinate supplied.");
            }

            return(GetDirections(XDocument.Load(String.Format(ApiDirections,
                                                              String.Format("{0},{1}", origin.Latitude, origin.Longitude),
                                                              String.Format("{0},{1}", destination.Latitude, destination.Longitude),
                                                              travelMode.ToString().ToLower()))));
        }
        public String GenerateRequest()
        {
            String toReturn = header;

            toReturn = toReturn + travelMode.ToString() + "?";
            if (wayPoints != null && wayPoints.Count != 0)
            {
                int wpCount = 0;

                foreach (String wp in wayPoints)
                {
                    if (wpCount == 0)
                    {
                        toReturn = toReturn + "wp." + wpCount + "=" + wp;
                    }
                    else
                    {
                        toReturn = append(toReturn, "wp." + wpCount + "=" + wp);
                    }
                    wpCount++;
                }
            }

            if (avoid.Count != 0)
            {
                using (IEnumerator <ToAvoid> value = avoid.GetEnumerator())
                {
                    value.MoveNext();
                    toReturn = append(toReturn, "avoid=" + value.Current.ToString());
                    while (value.MoveNext())
                    {
                        toReturn = append(toReturn, "," + value.Current.ToString());
                    }
                }
            }

            toReturn = (distanceBeforeFirstTurn != null) ? append(toReturn, "dbft=" + distanceBeforeFirstTurn) : toReturn;
            toReturn = (heading != null) ? append(toReturn, "hd=" + heading) : toReturn;
            toReturn = append(toReturn, "optimize=" + optimize.ToString());
            toReturn = append(toReturn, "key=" + bingMapsKey);

            return(toReturn);
        }
Example #4
0
        // TODO
        ///// <summary>
        ///// Array of intermediate waypoints. Directions will be calculated from the origin to the destination by way of each waypoint in this array. Optional.
        ///// </summary>
        ///// <value>The waypoints.</value>
        //public DirectionsWaypoint[] Waypoints { get; set; }


        /// <summary>
        /// When overridden in a derived class, registers the <see cref="T:System.Web.UI.ScriptDescriptor"/> objects for the control.
        /// </summary>
        /// <param name="targetControl">The server control to which the extender is associated.</param>
        /// <returns>
        /// An enumeration of <see cref="T:System.Web.UI.ScriptDescriptor"/> objects.
        /// </returns>
        protected override IEnumerable <ScriptDescriptor> GetScriptDescriptors(Control targetControl)
        {
            var descriptor = new ScriptBehaviorDescriptor("Velyo.Google.Maps.DirectionsBehavior", targetControl.ClientID);

            // properties
            descriptor.AddProperty("name", UniqueID);

            // directions servise properties
            if (AvoidHighways.HasValue)
            {
                descriptor.AddProperty("avoidHighways", AvoidHighways.Value);
            }
            if (AvoidTolls.HasValue)
            {
                descriptor.AddProperty("avoidTolls", AvoidTolls.Value);
            }
            if (_destination != null)
            {
                descriptor.AddProperty("destination", _destination.Value);
            }
            if (OptimizeWaypoints.HasValue)
            {
                descriptor.AddProperty("optimizeWaypoints", OptimizeWaypoints.Value);
            }
            if (_origin != null)
            {
                descriptor.AddProperty("origin", _origin.Value);
            }
            if (ProvideRouteAlternatives.HasValue)
            {
                descriptor.AddProperty("provideRouteAlternatives", ProvideRouteAlternatives.Value);
            }
            if (Region != null)
            {
                descriptor.AddProperty("region", Region);
            }
            descriptor.AddProperty("travelMode", TravelMode.ToString());
            if (UnitSystem.HasValue)
            {
                descriptor.AddProperty("unitSystem", UnitSystem.Value);
            }
            //descriptor.AddProperty("waypoints", this.waypoints);

            // directions renderer properties
            descriptor.AddProperty("draggable", Draggable);
            descriptor.AddProperty("hideRouteList", HideRouteList);
            if (_markerOptions != null)
            {
                descriptor.AddProperty("markerOptions", _markerOptions.ToScriptData());
            }
            if (PanelID != null)
            {
                descriptor.AddProperty("panelId", PanelID);
            }
            if (_polylineOptions != null)
            {
                descriptor.AddProperty("polylineOptions", _polylineOptions.ToScriptData());
            }
            descriptor.AddProperty("preserveViewport", PreserveViewport);
            descriptor.AddProperty("routeIndex", RouteIndex);
            if (SuppressBicyclingLayer.HasValue)
            {
                descriptor.AddProperty("suppressBicyclingLayer", SuppressBicyclingLayer.Value);
            }
            if (SuppressInfoWindows.HasValue)
            {
                descriptor.AddProperty("suppressInfoWindows", SuppressInfoWindows.Value);
            }
            if (SuppressMarkers.HasValue)
            {
                descriptor.AddProperty("suppressMarkers", SuppressMarkers.Value);
            }
            if (SuppressPolylines.HasValue)
            {
                descriptor.AddProperty("suppressPolylines", SuppressPolylines.Value);
            }

            // events
            if (Changed != null)
            {
                descriptor.AddEvent("changed", "Velyo.Google.Maps.Directions.DirectionsBehavior.raiseServerChanged");
            }
            else if (OnClientChanged != null)
            {
                descriptor.AddEvent("changed", OnClientChanged);
            }

            yield return(descriptor);
        }
 public string BuildTravelMode(TravelMode travelMode)
 {
     return($"mode={travelMode.ToString().ToLower()}");
 }
Example #6
0
        protected override QueryStringParametersList GetQueryStringParameters()
        {
            if (string.IsNullOrWhiteSpace(Origin))
            {
                throw new ArgumentException("Must specify an Origin");
            }
            if (string.IsNullOrWhiteSpace(Destination))
            {
                throw new ArgumentException("Must specify a Destination");
            }
            if (!Enum.IsDefined(typeof(AvoidWay), Avoid))
            {
                throw new ArgumentException("Invalid enumeration value for 'Avoid'");
            }
            if (!Enum.IsDefined(typeof(TravelMode), TravelMode))
            {
                throw new ArgumentException("Invalid enumeration value for 'TravelMode'");
            }

            if (TravelMode == TravelMode.Transit && (DepartureTime == default(DateTime) && ArrivalTime == default(DateTime)))
            {
                throw new ArgumentException("You must set either DepatureTime or ArrivalTime when TravelMode = Transit");
            }

            var parameters = base.GetQueryStringParameters();

            parameters.Add("origin", Origin);
            parameters.Add("destination", Destination);
            parameters.Add("mode", TravelMode.ToString().ToLower());

            if (Alternatives)
            {
                parameters.Add("alternatives", "true");
            }

            if (Avoid != AvoidWay.Nothing)
            {
                parameters.Add("avoid", Avoid.ToString().ToLower());
            }

            if (!string.IsNullOrWhiteSpace(Language))
            {
                parameters.Add("language", Language);
            }

            if (!string.IsNullOrWhiteSpace(Region))
            {
                parameters.Add("region", Region);
            }

            if (Waypoints != null && Waypoints.Any())
            {
                IEnumerable <string> waypoints;

                if (OptimizeWaypoints)
                {
                    const string optimizeWaypoints = "optimize:true";

                    waypoints = new string[] { optimizeWaypoints }.Concat(Waypoints);
                }
                else
                {
                    waypoints = Waypoints;
                }

                parameters.Add("waypoints", string.Join("|", waypoints));
            }

            if (ArrivalTime != default(DateTime))
            {
                parameters.Add("arrival_time", UnixTimeConverter.DateTimeToUnixTimestamp(ArrivalTime).ToString(CultureInfo.InvariantCulture));
            }

            if (DepartureTime != default(DateTime))
            {
                parameters.Add("departure_time", UnixTimeConverter.DateTimeToUnixTimestamp(DepartureTime).ToString(CultureInfo.InvariantCulture));
            }

            return(parameters);
        }
Example #7
0
        public override void DoWindowContents(Rect inRect)
        {
            float CurrentY = 0f;

            //Title
            Text.Font = GameFont.Medium;
            string  Title     = objective.def.LabelCap;
            Vector2 TitleSize = Text.CalcSize(Title);
            Rect    TitleRect = new Rect(new Vector2(0f, CurrentY), TitleSize);

            Widgets.Label(TitleRect, Title);
            Text.Font = GameFont.Small;
            CurrentY += TitleRect.height;

            Rect MainInfoBody = new Rect(0f, CurrentY, inRect.width, inRect.height - CurrentY);

            Widgets.DrawMenuSection(MainInfoBody);
            Rect MainInfoSub = MainInfoBody.ContractedBy(5f);

            CurrentY = 0f;
            GUI.BeginGroup(MainInfoSub);

            float tenth  = MainInfoSub.width * 0.1f;
            float middle = tenth * 5f;
            //Objective Type - State - Work - Time
            string  TypeLabel     = "OType_SMO".Translate() + ": " + (objective.def.type.ToString() + "_Label").Translate();
            Vector2 TypeLabelSize = Text.CalcSize(TypeLabel);
            Rect    TypeLabelRect = new Rect(new Vector2(5f, CurrentY), TypeLabelSize);

            string  StateLabel     = "OState_SMO".Translate() + ": " + (objective.CurrentState.ToString() + "_SMO").Translate();
            Vector2 StateLabelSize = Text.CalcSize(StateLabel);
            Rect    StateLabelRect = new Rect(new Vector2(middle, CurrentY), StateLabelSize);

            CurrentY += StateLabelRect.height + 5f;

            bool    workExists     = objective.def.workAmount > 0;
            string  WorkAmount     = "WorkAmount_SMO".Translate() + ": " + (workExists ? Math.Round(objective.GetWorkDone, 0) + "/" + objective.def.workAmount : "N/A");
            Vector2 WorkAmountSize = Text.CalcSize(WorkAmount);
            string  TimerLabel     = "Timer_SMO".Translate() + ": " + StoryUtils.GetTimerText(objective.GetTimer, objective.CurrentState);
            Vector2 TimerLabelSize = Text.CalcSize(TimerLabel);
            Rect    WorkAmountRect = new Rect(new Vector2(5f, CurrentY), WorkAmountSize);
            Rect    TimerLabelRect = new Rect(new Vector2(middle, CurrentY), TimerLabelSize);

            CurrentY += WorkAmountRect.height;

            Rect TSWTRect = new Rect(0f, TypeLabelRect.yMin, MainInfoSub.width, TypeLabelRect.height + WorkAmountRect.height + 5f);

            Widgets.DrawBoxSolid(TSWTRect, new ColorInt(33, 33, 33).ToColor);
            Widgets.Label(TypeLabelRect, TypeLabel);
            Widgets.Label(StateLabelRect, StateLabel);
            Widgets.Label(WorkAmountRect, WorkAmount);
            Widgets.Label(TimerLabelRect, TimerLabel);
            AddGap(MainInfoSub, ref CurrentY);

            //TravelSettings
            TravelSettings travelSettings = objective.def.travelSettings;
            float          width          = MainInfoSub.width - 10f;

            if (travelSettings != null)
            {
                TravelMode    mode            = travelSettings.mode;
                string        ModeLabel       = (mode.ToString() + "Travel_SMO").Translate();
                float         ModeLabelHeight = Text.CalcHeight(ModeLabel, width);
                Rect          ModeLabelRect   = new Rect(5f, CurrentY, width, ModeLabelHeight);
                Rect          BoxRect         = new Rect();
                List <string> factions        = new List <string>();
                List <string> factionCounts   = new List <string>();

                if (!travelSettings.factionSettings.factions.NullOrEmpty())
                {
                    foreach (FactionDef def in travelSettings.factionSettings.factions)
                    {
                        string label = def.LabelCap;
                        factions.Add(label);
                    }
                    foreach (FactionDef def in travelSettings.factionSettings.factions)
                    {
                        string label = def.LabelCap;
                        factionCounts.Add(label + ": " + objective.travelTracker.CountFor(def) + "/" + travelSettings.factionSettings.Value(mode));
                    }
                }

                if (mode == TravelMode.Reach || mode == TravelMode.Explore)
                {
                    float height = 4f * 25f;
                    BoxRect = new Rect(0f, CurrentY, MainInfoSub.width, height);
                    Widgets.DrawBoxSolid(BoxRect, new ColorInt(33, 33, 33).ToColor);
                    CurrentY += ModeLabelHeight + 5f;
                    var listing = new Listing_Standard(GameFont.Small);
                    listing.Begin(new Rect(5f, CurrentY, MainInfoSub.width - 10f, height));
                    listing.ColumnWidth = (MainInfoSub.width - 10f) * 0.5f;
                    //left side
                    string Distance = "TravelDistance_SMO".Translate(travelSettings.minDistance);
                    listing.Label(Distance, Text.CalcHeight(Distance, listing.ColumnWidth));
                    string Biome = "TileBiome_SMO".Translate() + ": " + (travelSettings.tileSettings.biome?.LabelCap ?? "N/A");
                    listing.Label(Biome, Text.CalcHeight(Biome, listing.ColumnWidth));
                    string River = "TileA_SMO".Translate() + " " + (travelSettings.tileSettings.river?.label ?? "N/A");
                    listing.Label(River, Text.CalcHeight(River, listing.ColumnWidth));
                    //right side
                    listing.NewColumn();
                    string Destination = "TravelDestination_SMO".Translate() + ": " + (travelSettings.destination?.label ?? "N/A");
                    listing.Label(Destination, Text.CalcHeight(Destination, listing.ColumnWidth));
                    string Road = "TileA_SMO".Translate() + " " + travelSettings.tileSettings.road?.label;
                    listing.Label(Road, Text.CalcHeight(Road, listing.ColumnWidth));
                    string Hilliness = "Tile_SMO".Translate() + " " + (travelSettings.tileSettings.hilliness.HasValue ? travelSettings.tileSettings.hilliness.Value.GetLabel() : "N/A");
                    listing.Label(Hilliness, Text.CalcHeight(Hilliness, listing.ColumnWidth));
                    listing.End();
                    CurrentY += (height - 23f);
                    Widgets.Label(ModeLabelRect, ModeLabel);
                }
                else if (mode == TravelMode.Trade)
                {
                    CurrentY += ModeLabelHeight;
                    Rect   ValueLabelRect = new Rect();
                    string ValueLabel     = "";
                    int    silver         = travelSettings.minSilver;
                    if (silver != 0)
                    {
                        ValueLabel = silver > 0 ? "TradeBuy_SMO".Translate(silver) : "TradeSell_SMO".Translate(-silver);
                        Vector2 ValueLabelSize = Text.CalcSize(ValueLabel);
                        ValueLabelRect = new Rect(new Vector2(5f, CurrentY), ValueLabelSize);
                        CurrentY      += ValueLabelSize.y;
                    }
                    BoxRect = new Rect(0f, ModeLabelRect.yMin, MainInfoSub.width, ModeLabelHeight + ValueLabelRect.height);
                    Widgets.DrawBoxSolid(BoxRect, new ColorInt(33, 33, 33).ToColor);
                    Widgets.Label(ModeLabelRect, ModeLabel);
                    Widgets.Label(ValueLabelRect, ValueLabel);
                    TryMakeTextList(MainInfoSub, ref CurrentY, "", factionCounts, false);
                }
                else
                {
                    TryMakeTextList(MainInfoSub, ref CurrentY, ModeLabel, factionCounts, false);
                }
                AddGap(MainInfoSub, ref CurrentY);
            }
            //ThingSettings
            ThingSettings thingSettings = objective.def.targetSettings?.thingSettings;

            if (thingSettings != null)
            {
                string ThingSettingLabel       = ResolveThingSettings();
                float  ThingSettingLabelHeight = Text.CalcHeight(ThingSettingLabel, width);
                Rect   ThingSettingLabelRect   = new Rect(5f, CurrentY, width, ThingSettingLabelHeight);
                CurrentY += ThingSettingLabelRect.height;

                string  stuff          = thingSettings.stuff?.LabelCap ?? "AnyStuff_SMO".Translate();
                string  StuffLabel     = "ThingSettingsStuff_SMO".Translate(stuff);
                Vector2 StuffLabelSize = Text.CalcSize(StuffLabel);
                Rect    StuffLabelRect = new Rect(new Vector2(5f, CurrentY), StuffLabelSize);

                string  qual             = thingSettings.minQuality?.GetLabel() ?? "Any_SMO".Translate();
                string  QualityLabel     = "ThingSettingsQuality_SMO".Translate(qual);
                Vector2 QualityLabelSize = Text.CalcSize(QualityLabel);
                Rect    QualityLabelRect = new Rect(new Vector2(middle, CurrentY), QualityLabelSize);
                CurrentY += QualityLabelRect.height;

                int     num          = objective.thingTracker?.GetThingCount >= thingSettings.minAmount ? thingSettings.minAmount : objective.thingTracker.GetThingCount;
                string  NumLabel     = "MapCheckCount_SMO".Translate(num + "/" + thingSettings.minAmount);
                Vector2 NumLabelSize = Text.CalcSize(NumLabel);
                Rect    NumLabelRect = new Rect(new Vector2(5f, CurrentY), NumLabelSize);
                CurrentY += NumLabelRect.height;

                Rect TSRect = new Rect(0f, ThingSettingLabelRect.yMin, width + 10f, ThingSettingLabelHeight + QualityLabelSize.y + NumLabelSize.y);
                Widgets.DrawBoxSolid(TSRect, new ColorInt(33, 33, 33).ToColor);
                Widgets.Label(ThingSettingLabelRect, ThingSettingLabel);
                Widgets.Label(StuffLabelRect, StuffLabel);
                Widgets.Label(QualityLabelRect, QualityLabel);
                Widgets.Label(NumLabelRect, NumLabel);

                AddGap(MainInfoSub, ref CurrentY);
            }

            //PawnSettings
            PawnSettings pawnSettings = objective.def.targetSettings?.pawnSettings;

            if (pawnSettings != null)
            {
                bool   humanlike          = pawnSettings.def?.race.Humanlike ?? false;
                string PawnDefLabel       = ResolvePawnSettings();
                float  PawnDefLabelHeight = Text.CalcHeight(PawnDefLabel, width);
                Rect   PawnDefLabelRect   = new Rect(5f, CurrentY, width, PawnDefLabelHeight);
                CurrentY += PawnDefLabelHeight;

                string  PawnKindDefLabel     = "PawnSettingsKind_SMO".Translate(pawnSettings.kindDef?.LabelCap ?? "N/A");
                Vector2 PawnKindDefLabelSize = Text.CalcSize(PawnKindDefLabel);
                Rect    PawnKindDefLabelRect = new Rect(new Vector2(5f, CurrentY), PawnKindDefLabelSize);

                string  FactionLabel     = "PawnSettingsFaction_SMO".Translate(pawnSettings.factionDef?.LabelCap ?? "N/A");
                Vector2 FactionLabelSize = Text.CalcSize(FactionLabel);
                Rect    FactionLabelRect = new Rect(new Vector2(middle, CurrentY), FactionLabelSize);
                CurrentY += PawnKindDefLabelSize.y;

                string  GenderLabel     = "PawnSettingsGender_SMO".Translate(pawnSettings.gender?.GetLabel(!humanlike) ?? "N/A");
                Vector2 GenderLabelSize = Text.CalcSize(GenderLabel);
                Rect    GenderLabelRect = new Rect(new Vector2(5f, CurrentY), GenderLabelSize);

                int     num          = objective.thingTracker?.GetPawnCount >= pawnSettings.minAmount ? pawnSettings.minAmount : objective.thingTracker.GetPawnCount;
                string  NumLabel     = "MapCheckCount_SMO".Translate(num + "/" + pawnSettings.minAmount);
                Vector2 NumLabelSize = Text.CalcSize(NumLabel);
                Rect    NumLabelRect = new Rect(new Vector2(middle, CurrentY), NumLabelSize);
                CurrentY += GenderLabelSize.y;

                Rect PawnSettingRect = new Rect(0f, PawnDefLabelRect.yMin, width + 10f, PawnDefLabelHeight + PawnKindDefLabelSize.y + GenderLabelSize.y);
                Widgets.DrawBoxSolid(PawnSettingRect, new ColorInt(33, 33, 33).ToColor);
                Widgets.Label(PawnDefLabelRect, PawnDefLabel);
                Widgets.Label(PawnKindDefLabelRect, PawnKindDefLabel);
                Widgets.Label(FactionLabelRect, FactionLabel);
                Widgets.Label(GenderLabelRect, GenderLabel);
                Widgets.Label(NumLabelRect, NumLabel);

                AddGap(MainInfoSub, ref CurrentY);
            }

            //Stations
            if (NeedsStation)
            {
                List <string> stations = new List <string>();
                foreach (ThingValue tv in objective.def.targetSettings?.targets)
                {
                    stations.Add(tv.ThingDef.LabelCap);
                }
                TryMakeTextList(MainInfoSub, ref CurrentY, "Stations_SMO".Translate(objective.def.BestPotentialStation.LabelCap), stations, true);
            }
            if (!objective.def.skillRequirements.NullOrEmpty())
            {
                List <string> skills = new List <string>();
                foreach (SkillRequirement sr in objective.def.skillRequirements)
                {
                    skills.Add(sr.Summary);
                }
                TryMakeTextList(MainInfoSub, ref CurrentY, "SkillRequirementsInfo_SMO".Translate(), skills, true);
            }

            float RestHeight     = MainInfoBody.ContractedBy(5f).height - CurrentY;
            float ContainerSplit = NeedsStation ? RestHeight * 0.5f : RestHeight / 3f;

            //Targets
            if (objective.def.targetSettings != null && objective.def.targetSettings.targets.Count > 0 && !NeedsStation)
            {
                float  TotalHeight     = objective.def.targetSettings.targets.Count * 34f;
                float  ContainerHeight = TotalHeight > ContainerSplit ? ContainerSplit : TotalHeight;
                Rect   ContainerRect   = new Rect(0f, CurrentY, MainInfoSub.width, ContainerHeight);
                string TargetDesc      = ResolveTargetText();
                if (!TargetDesc.NullOrEmpty())
                {
                    float TargetDescHeight = Text.CalcHeight(TargetDesc, MainInfoSub.width - 5f);
                    Rect  BoxRect          = new Rect(0f, CurrentY, MainInfoSub.width, TargetDescHeight + 10f);
                    Rect  TargetDescRect   = BoxRect.ContractedBy(5f);
                    ContainerRect.y += BoxRect.height + 5f;
                    CurrentY        += BoxRect.height + 5f;
                    if (TotalHeight > ContainerSplit)
                    {
                        ContainerRect.height -= BoxRect.height + 5f;
                    }
                    Widgets.DrawBoxSolid(BoxRect, new ColorInt(33, 33, 33).ToColor);
                    Widgets.Label(TargetDescRect, TargetDesc);
                }
                StoryUtils.DrawMenuSectionColor(ContainerRect, 1, new ColorInt(40, 40, 40), StoryMats.defaultBorder);
                GUI.BeginGroup(ContainerRect.ContractedBy(1));
                Widgets.BeginScrollView(new Rect(0f, 0f, ContainerRect.width, ContainerRect.height), ref TargetPos, new Rect(0f, 0f, ContainerRect.width, TotalHeight), false);
                float             CurY    = 5f;
                List <ThingValue> targets = objective.def.targetSettings.targets;
                for (int i = 0; i < targets.Count; i++)
                {
                    ThingValue   thingValue = targets[i];
                    ThingTracker tracker    = objective.thingTracker;
                    if (i % 2 == 0)
                    {
                        GUI.color = new Color(1f, 1f, 1f, 0.5f);
                        Widgets.DrawHighlight(new Rect(0f, CurY - 5f, ContainerRect.width, 34f));
                        GUI.color = Color.white;
                    }
                    string    label    = tracker.WorksWithPawns ? thingValue.PawnKindDef.LabelCap : thingValue.ThingDef.LabelCap;
                    WidgetRow itemRow  = new WidgetRow(5f, CurY);
                    WidgetRow infoRect = new WidgetRow(ContainerRect.width * 0.5f, CurY);
                    itemRow.Gap(10f);
                    GUI.color = ResolveColor(thingValue);
                    if ((thingValue.IsPawnKindDef && !thingValue.ThingDef.race.Humanlike) || thingValue.ThingDef != null)
                    {
                        if (thingValue.ThingDef.uiIcon != BaseContent.BadTex)
                        {
                            itemRow.Icon(thingValue.ThingDef.uiIcon);
                        }
                    }
                    GUI.color = Color.white;
                    itemRow.Label(label);
                    if (tracker.TargetsDone.TryGetValue(thingValue, out int value))
                    {
                        infoRect.Label(value.ToString() + "/" + thingValue.value);
                    }
                    CurY += 34f;
                }
                CurrentY += ContainerRect.height;
                Widgets.EndScrollView();
                GUI.EndGroup();
            }

            //Rewards
            float RewardContainerHeight     = ContainerSplit - 46f;
            List <IncidentProperties> props = new List <IncidentProperties>(objective.def.incidentsOnCompletion);

            if (objective.def.result != null)
            {
                props.Add(objective.def.result);
            }
            if (!props.NullOrEmpty())
            {
                if (props.Any(p => p.type == IncidentType.Reward))
                {
                    if (!props.NullOrEmpty() && props.Any(p => !p?.spawnSettings?.spawnList.NullOrEmpty() ?? false))
                    {
                        float TotalHeight          = props.Sum(s => s.spawnSettings.spawnList.Count) * 34f;
                        float height               = TotalHeight > ContainerSplit ? ContainerSplit : TotalHeight;
                        Rect  CompletedRewardsRect = new Rect(0f, CurrentY, MainInfoSub.width, height);
                        CurrentY += CompletedRewardsRect.height;
                        DrawRewardContainer(CompletedRewardsRect, "CompletedRewards_SMO".Translate(), ref RewardCompletedPos, props);
                    }
                }
                props = objective.def.incidentsOnFail;
                if (props.Any(p => p.type == IncidentType.Reward))
                {
                    if (!props.NullOrEmpty() && props.Any(p => !p?.spawnSettings?.spawnList.NullOrEmpty() ?? false))
                    {
                        float total             = props.Sum(s => s.spawnSettings.spawnList.Count) * 34f;
                        float height            = total > ContainerSplit ? ContainerSplit : total;
                        Rect  FailedRewardsRect = new Rect(0f, CurrentY, MainInfoSub.width, height);
                        CurrentY += FailedRewardsRect.height;
                        DrawRewardContainer(FailedRewardsRect, "FailedRewards_SMO".Translate(), ref RewardFailedPos, props);
                    }
                }
            }
            GUI.EndGroup();
        }
Example #8
0
 public Directions GetDirections(string originAddress, Coordinate destination, TravelMode travelMode = TravelMode.Driving)
 {
     return GetDirections(XDocument.Load(String.Format(ApiDirections, originAddress, String.Format("{0},{1}", destination.Latitude, destination.Longitude), travelMode.ToString().ToLower())));
 }
Example #9
0
 public Directions GetDirections(string originAddress, string destinationAddress, TravelMode travelMode = TravelMode.Driving)
 {
     return GetDirections(XDocument.Load(String.Format(ApiDirections, originAddress, destinationAddress, travelMode.ToString().ToLower())));
 }
Example #10
0
        public Directions GetDirections(Coordinate origin, Coordinate destination, TravelMode travelMode = TravelMode.Driving)
        {
            if (!CoordinateValidator.Validate(origin.Latitude, origin.Longitude))
                throw new ArgumentException("Invalid origin coordinate supplied.");

            if (!CoordinateValidator.Validate(destination.Latitude, destination.Longitude))
                throw new ArgumentException("Invalid destination coordinate supplied.");

            return GetDirections(XDocument.Load(String.Format(ApiDirections,
                        String.Format("{0},{1}", origin.Latitude, origin.Longitude),
                        String.Format("{0},{1}", destination.Latitude, destination.Longitude),
                        travelMode.ToString().ToLower())));
        }
        public TravelTime GetTravelTime(Location origin, Location destination, TravelMode mode)
        {
            string originString = StringForm(origin);
            string destinationString = StringForm(destination);
            var request = new DirectionsRequest()
            {
                ApiKey = apiKey,
                Origin = originString,
                Destination = destinationString,
                TravelMode = mode,
                DepartureTime = DateTime.Now,
            };

            var response = GoogleMapsApi.GoogleMaps.Directions.Query(request);

            var route = response.Routes.FirstOrDefault();
            if (route != null)
            {
                // For routes that contain no waypoints, the route will consist of a single "leg".
                var leg = route.Legs.FirstOrDefault();
                if (leg != null)
                {
                    // Get the origin and destination's lat/long if not yet known.
                    origin.Latitude = origin.Latitude ?? leg.StartLocation.Latitude.ToString();
                    origin.Longitude = origin.Longitude ?? leg.StartLocation.Longitude.ToString();

                    destination.Latitude = destination.Latitude ?? leg.EndLocation.Latitude.ToString();
                    destination.Longitude = destination.Longitude ?? leg.EndLocation.Longitude.ToString();

                    var transitStep = leg.Steps.FirstOrDefault(a => a.TransitDetails != null);

                    TimeSpan duration = leg.Duration.Value;
                    TravelTime time = new TravelTime
                     {
                         Mode = mode.ToString(),
                         Days = duration.Days,
                         Hours = duration.Hours,
                         Minutes = duration.Minutes,
                         Seconds = duration.Seconds,
                         TransitDepartureTime = transitStep == null ? null : transitStep.TransitDetails.DepartureTime.Text,
                         TransitDepartureStop = transitStep == null ? null : transitStep.TransitDetails.DepartureStop.Name,
                         TransitArrivalTime = transitStep == null ? null : transitStep.TransitDetails.ArrivalTime.Text,
                         TransitArrivalStop = transitStep == null ? null : transitStep.TransitDetails.ArrivalStop.Name,
                         TransitRoute = transitStep == null ? null : transitStep.TransitDetails.Lines.ShortName,
                         TransitRouteDescription = transitStep == null ? null : transitStep.TransitDetails.Lines.Name
                     };
                    return time;
                }
            }
            return null;
        }
Example #12
0
 public Directions GetDirections(string originAddress, Coordinate destination, TravelMode travelMode = TravelMode.Driving)
 {
     return(GetDirections(XDocument.Load(String.Format(ApiDirections, originAddress, String.Format("{0},{1}", destination.Latitude, destination.Longitude), travelMode.ToString().ToLower()))));
 }
Example #13
0
 public Directions GetDirections(string originAddress, string destinationAddress, TravelMode travelMode = TravelMode.Driving)
 {
     return(GetDirections(XDocument.Load(String.Format(ApiDirections, originAddress, destinationAddress, travelMode.ToString().ToLower()))));
 }
Example #14
0
        public async Task <RouteInformation> GetRouteInformationAsync(string location, string destination,
                                                                      TravelMode travelMode, int arrivalTimeEpoch)
        {
            //setup the call params
            var callParams = $"?key={_apiKey}&origin={location}&destination={destination}&mode={travelMode.ToString().ToLower()}";

            if (travelMode == TravelMode.Transit)
            {
                callParams += $"&arrival_time={arrivalTimeEpoch.ToString()}";
            }

            //call the maps api
            var apiReq = await _client.GetAsync(callParams);

            //return the results
            var res = new RouteInformation()
            {
                Success = apiReq.IsSuccessStatusCode
            };

            if (res.Success)
            {
                var jo = JObject.Parse(await apiReq.Content.ReadAsStringAsync());

                //check route was actually created
                if (!jo["routes"].HasValues)
                {
                    res.Success = false;
                    return(res);
                }

                var joRoute = jo["routes"][0]["legs"][0];

                //get duration and distance
                res.TravelDistance = joRoute["distance"]["value"].ToObject <int>();
                res.TravelDuration = joRoute["duration"]["value"].ToObject <int>();

                if (travelMode == TravelMode.Transit)
                {
                    //calculate departure time based on route information
                    res.ArrivalTime   = joRoute["arrival_time"]["value"].ToObject <int>();
                    res.DepartureTime = joRoute["departure_time"]["value"].ToObject <int>();
                }
                else
                {
                    //calculate departure time based on arrival time
                    res.ArrivalTime   = arrivalTimeEpoch;
                    res.DepartureTime = arrivalTimeEpoch - res.TravelDuration;
                }
            }

            return(res);
        }