/// <summary> Main mod function. </summary> /// <param name="helper">The helper. </param> public override void Entry(IModHelper helper) { RWeatherIcon = new Rectangle(); WeatherOpt = helper.ReadConfig <WeatherConfig>(); Dice = new MersenneTwister(); DebugOutput = new StringBuilder(); OurMoon = new SDVMoon(WeatherOpt, Dice); OurIcons = new Sprites.Icons(Helper.Content); CropList = new List <Vector2>(); Conditions = new WeatherConditions(OurIcons, Dice, Helper.Translation, Monitor, WeatherOpt); StaminaMngr = new StaminaDrain(WeatherOpt, Helper.Translation, Monitor); SeedsForDialogue = new int[] { Dice.Next(), Dice.Next() }; DescriptionEngine = new Descriptions(Helper.Translation, Dice, WeatherOpt, Monitor); queuedMsg = null; Vector2 snowPos = Vector2.Zero; TicksOutside = 0; TicksTotal = 0; ExpireTime = 0; if (WeatherOpt.Verbose) { Monitor.Log($"Loading climate type: {WeatherOpt.ClimateType} from file", LogLevel.Trace); } string path = Path.Combine("data", "weather", WeatherOpt.ClimateType + ".json"); GameClimate = helper.ReadJsonFile <FerngillClimate>(path); if (GameClimate is null) { this.Monitor.Log($"The required '{path}' file is missing. Try reinstalling the mod to fix that.", LogLevel.Error); this.Monitor.Log("This mod will now disable itself.", LogLevel.Error); this.Disabled = true; } if (!Disabled) { //subscribe to events TimeEvents.AfterDayStarted += HandleNewDay; SaveEvents.BeforeSave += OnEndOfDay; TimeEvents.TimeOfDayChanged += TenMinuteUpdate; MenuEvents.MenuChanged += MenuEvents_MenuChanged; GameEvents.UpdateTick += CheckForChanges; SaveEvents.AfterReturnToTitle += ResetMod; SaveEvents.AfterLoad += SaveEvents_AfterLoad; GraphicsEvents.OnPostRenderGuiEvent += DrawOverMenus; GraphicsEvents.OnPreRenderHudEvent += DrawPreHudObjects; GraphicsEvents.OnPostRenderHudEvent += DrawObjects; LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged; ControlEvents.KeyPressed += (sender, e) => this.ReceiveKeyPress(e.KeyPressed, this.WeatherOpt.Keyboard); MenuEvents.MenuClosed += (sender, e) => this.ReceiveMenuClosed(e.PriorMenu); //console commands helper.ConsoleCommands .Add("weather_settommorow", helper.Translation.Get("console-text.desc_tmrweather"), TomorrowWeatherChangeFromConsole) .Add("weather_changeweather", helper.Translation.Get("console-text.desc_setweather"), WeatherChangeFromConsole) .Add("world_solareclipse", "Starts the solar eclipse.", SolarEclipseEvent_CommandFired); } }
/// <summary> /// This function returns the lunar phase for an arbitary day. /// </summary> /// <param name="Today">The day you are examining for.</param> /// <returns></returns> public static MoonPhase GetLunarPhaseForDay(SDate Today) { //divide it by the cycle. int currentCycle = (int)Math.Floor(Today.DaysSinceStart / (double)cycleLength); int currentDay = GetDayOfCycle(Today); return(SDVMoon.GetLunarPhase(currentDay)); }
/********* ** Public methods *********/ /**** ** Constructors ****/ /// <summary>Construct an instance.</summary> /// <param name="monitor">Encapsulates logging and monitoring.</param> public WeatherMenu(IMonitor monitor, IReflectionHelper reflectionHelper, Sprites.Icons Icon, ITranslationHelper Helper, WeatherConditions weat, SDVMoon Termina, WeatherConfig ModCon, string text) { // save data this.MenuText = text; this.Monitor = monitor; this.Reflection = reflectionHelper; this.Helper = Helper; this.CurrentWeather = weat; this.IconSheet = Icon; this.OurMoon = Termina; this.OurConfig = ModCon; // update layout this.UpdateLayout(); }
public MoonPhase GetLunarPhase() { //divide it by the cycle. int currentCycle = (int)Math.Floor(SDate.Now().DaysSinceStart / (double)cycleLength); int currentDay = GetDayOfCycle(SDate.Now()); MoonPhase ret = SDVMoon.GetLunarPhase(currentDay); if (ret == MoonPhase.FullMoon) { if (Dice.NextDoublePositive() <= ModConfig.BadMoonRising) { return(MoonPhase.BloodMoon); } } return(ret); }
/// <summary>Render the UI.</summary> /// <param name="spriteBatch">The sprite batch being drawn.</param> public override void draw(SpriteBatch spriteBatch) { // disable when game is using immediate sprite sorting if (!this.ValidatedDrawMode) { IReflectedField <SpriteSortMode> sortModeField = this.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "spriteSortMode", required: false) // XNA ?? this.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "_sortMode"); // MonoGame if (sortModeField.GetValue() == SpriteSortMode.Immediate) { this.Monitor.Log("Aborted the weather draw because the game's current rendering mode isn't compatible with the mod's UI. This only happens in rare cases (e.g. the Stardew Valley Fair).", LogLevel.Warn); this.exitThisMenu(playSound: false); return; } this.ValidatedDrawMode = true; } // calculate dimensions int x = this.xPositionOnScreen; int y = this.yPositionOnScreen; const int gutter = 15; float leftOffset = gutter; float topOffset = gutter; float contentWidth = this.width - gutter * 2; float contentHeight = this.height - gutter * 2; //int tableBorderWidth = 1; // get font SpriteFont font = Game1.smallFont; float lineHeight = font.MeasureString("ABC").Y; //at this point I'm going to manually put this in as I don't need in many places, // and I kinda want to have this where I can understand what it's for float spaceWidth = DrawHelper.GetSpaceWidth(font); // draw background // (This uses a separate sprite batch because it needs to be drawn before the // foreground batch, and we can't use the foreground batch because the background is // outside the clipping area.) //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null); spriteBatch.DrawSprite(Sprites.Letter.Sheet, Sprites.Letter.Sprite, x, y, scale: width / (float)Sprites.Letter.Sprite.Width); //spriteBatch.End(); // begin draw // draw weather icon spriteBatch.Draw(IconSheet.WeatherSource, new Vector2(x + leftOffset, y + topOffset), IconSheet.GetWeatherSprite(CurrentWeather.GetCurrentConditions()), Color.White); leftOffset += 72; string weatherString = ""; // draw text as sent from outside the menu float wrapWidth = this.width - leftOffset - gutter; { Vector2 textSize = spriteBatch.DrawTextBlock(font, MenuText, new Vector2(x + leftOffset, y + topOffset), wrapWidth); topOffset += textSize.Y; topOffset += lineHeight; } //draw moon info spriteBatch.Draw(IconSheet.MoonSource, new Vector2(x + 15, y + topOffset), IconSheet.GetMoonSprite(OurMoon.CurrentPhase), Color.White); weatherString = Helper.Get("moon-desc.desc_moonphase", new { moonPhase = SDVMoon.DescribeMoonPhase(OurMoon.CurrentPhase, Helper) }); Vector2 moonText = spriteBatch.DrawTextBlock(font, weatherString, new Vector2(x + leftOffset, y + topOffset), wrapWidth); topOffset += lineHeight; //stop moon from being cut off. this.drawMouse(Game1.spriteBatch); }
private int GetDayOfCycle() { return(SDVMoon.GetDayOfCycle(SDate.Now())); }
private void DrawOverMenus(object sender, EventArgs e) { //revised this so it properly draws over the canon moon. :v if (Game1.showingEndOfNightStuff && Game1.activeClickableMenu is ShippingMenu menu && !Game1.wasRainingYesterday) { Game1.spriteBatch.Draw(OurIcons.MoonSource, new Vector2((float)(Game1.viewport.Width - 80 * Game1.pixelZoom), (float)Game1.pixelZoom), OurIcons.GetNightMoonSprite(SDVMoon.GetLunarPhaseForDay(SDate.Now().AddDays(-1))), Color.LightBlue, 0.0f, Vector2.Zero, (float)Game1.pixelZoom * 1.5f, SpriteEffects.None, 1f); } }
internal string GenerateTVForecast(WeatherConditions Current, SDVMoon Moon) { //assemble params var talkParams = new Dictionary <string, string> { { "location", GetRandomLocation() }, { "descWeather", GetWeather(Current, Game1.currentSeason) }, { "festival", SDVUtilities.GetFestivalName(SDate.Now()) }, { "festivalTomorrow", SDVUtilities.GetFestivalName(SDate.Now().AddDays(1)) }, { "fogTime", Current.GetFogTime().ToString() }, { "todayHigh", GetTemperatureString(Current.TodayHigh) }, { "todayLow", GetTemperatureString(Current.TodayLow) }, { "tomorrowWeather", GetWeather(Game1.weatherForTomorrow, Game1.currentSeason, true) }, { "tomorrowHigh", GetTemperatureString(Current.TomorrowHigh) }, { "tomorrowLow", GetTemperatureString(Current.TomorrowLow) }, { "condWarning", GetCondWarning(Current) }, { "condString", GetCondWarning(Current) }, { "eveningFog", GetEveningFog(Current) } }; //select the weather string for the TV. SDVTimePeriods CurrentPeriod = SDVTime.CurrentTimePeriod; //get the current time period int nRandom = OurDice.Next(2); //first, check for special conditions -fog, festival, wedding if (Current.HasWeather(CurrentWeather.Fog)) { return(Helper.Get($"weat-loc.fog.{nRandom}", talkParams)); } //festival today else if (Current.HasWeather(CurrentWeather.Festival)) { return(Helper.Get("weat-fesToday.0", talkParams)); } //festival tomorrow else if (SDVUtilities.GetFestivalName(SDate.Now().AddDays(1)) != "") { return(Helper.Get("weat-fesTomorrow.0", talkParams)); } //wedding today else if (Current.HasWeather(CurrentWeather.Wedding)) { return(Helper.Get("weat-wedToday.0", talkParams)); } //wedding tomrrow else if (Game1.countdownToWedding == 1) { talkParams["tomrrowWeather"] = Helper.Get($"weat-{Game1.currentSeason}.sunny.{nRandom}"); return(Helper.Get("weat-wedTomorrow.0", talkParams)); } if (OurDice.NextDoublePositive() > .45) { if (CurrentPeriod == SDVTimePeriods.Morning) { return(Helper.Get($"weat-morn.{nRandom}", talkParams)); } else if (CurrentPeriod == SDVTimePeriods.Afternoon) { return(Helper.Get($"weat-afternoon.{nRandom}", talkParams)); } else if (CurrentPeriod == SDVTimePeriods.Evening) { return(Helper.Get($"weat-evening.{nRandom}", talkParams)); } else if (CurrentPeriod == SDVTimePeriods.Night) { return(Helper.Get($"weat-night.{nRandom}", talkParams)); } else if (CurrentPeriod == SDVTimePeriods.Midnight) { return(Helper.Get($"weat-midnight.{nRandom}", talkParams)); } else if (CurrentPeriod == SDVTimePeriods.LateNight) { return(Helper.Get($"weat-latenight.{nRandom}", talkParams)); } } else { //ye olde generic! return(Helper.Get($"weat-loc.{nRandom}", talkParams)); } return(""); }
internal string GenerateMenuPopup(WeatherConditions Current, SDVMoon Moon) { string text = ""; if (SDate.Now().Season == "spring" && SDate.Now().Day == 1) { text = Helper.Get("weather-menu.openingS1D1", new { descDay = Helper.Get($"date{UpperSeason(SDate.Now().Season)}{SDate.Now().Day}") }) + Environment.NewLine + Environment.NewLine; } else if (SDate.Now().Season == "winter" && SDate.Now().Day == 28) { text = Helper.Get("weather-menu.openingS4D28", new { descDay = Helper.Get($"date{UpperSeason(SDate.Now().Season)}{SDate.Now().Day}") }) + Environment.NewLine + Environment.NewLine; } else { text = Helper.Get("weather-menu.opening", new { descDay = Helper.Get($"date{UpperSeason(SDate.Now().Season)}{SDate.Now().Day}") }) + Environment.NewLine + Environment.NewLine; } if (Current.ContainsCondition(CurrentWeather.Heatwave)) { text += Helper.Get("weather-menu.condition.heatwave") + Environment.NewLine; } if (Current.ContainsCondition(CurrentWeather.Frost)) { text += Helper.Get("weather-menu.condition.frost") + Environment.NewLine; } ISDVWeather CurrentFog = Current.GetWeatherMatchingType("Fog").First(); string fogString = ""; // If the fog is visible, we don't need to display fog information. However, if it's in the morning, // and we know evening fog is likely, we should display the message it's expected // That said, if it's not, we need to pull the fog information down, assuming it's been reset. This checks that the fog end // time is *before* now. To avoid nested trinary statements.. if (SDVTime.CurrentTime < CurrentFog.WeatherExpirationTime && Current.GenerateEveningFog && CurrentFog.WeatherBeginTime < new SDVTime(1200)) { fogString = Helper.Get("weather-menu.expectedFog"); } if (CurrentFog.WeatherBeginTime > SDVTime.CurrentTime && Current.GenerateEveningFog) { fogString = Helper.Get("weather-menu.fogFuture", new { fogTime = CurrentFog.WeatherBeginTime.ToString(), endFog = CurrentFog.WeatherExpirationTime.ToString() }); } //Current Conditions. text += Helper.Get("weather-menu.current", new { todayCondition = Current.HasWeather(CurrentWeather.Fog) ? Helper.Get("weather-menu.fog", new { condition = GetBasicWeather(Current, Game1.currentSeason), fogTime = CurrentFog.IsWeatherVisible ? CurrentFog.WeatherExpirationTime.ToString() : "" }) : GetBasicWeather(Current, Game1.currentSeason), todayHigh = GetTemperatureString(Current.TodayHigh), todayLow = GetTemperatureString(Current.TodayLow), fogString = fogString }) + Environment.NewLine; //Tomorrow weather text += Helper.Get("weather-menu.tomorrow", new { tomorrowCondition = GetBasicWeather(Game1.weatherForTomorrow, Game1.currentSeason), tomorrowLow = GetTemperatureString(Current.TomorrowLow), tomorrowHigh = GetTemperatureString(Current.TomorrowHigh) }) + Environment.NewLine; return(text); }