diff --git a/AlertInfo.tscn b/AlertInfo.tscn new file mode 100644 index 0000000..afa3b2a --- /dev/null +++ b/AlertInfo.tscn @@ -0,0 +1,189 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://new_dynamicfont.tres" type="DynamicFont" id=1] + +[node name="AlertInfo" type="VBoxContainer"] +margin_right = 717.0 +margin_bottom = 393.0 + +[node name="Intro" type="HBoxContainer" parent="."] +margin_right = 720.0 +margin_bottom = 28.0 +alignment = 1 + +[node name="IntroLabel" type="Label" parent="Intro"] +margin_left = 321.0 +margin_right = 394.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Alert #" +align = 1 + +[node name="AlertNum" type="Label" parent="Intro"] +margin_left = 398.0 +margin_right = 398.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) + +[node name="Headline" type="HBoxContainer" parent="."] +margin_top = 32.0 +margin_right = 720.0 +margin_bottom = 91.0 +alignment = 1 + +[node name="HLabel" type="Label" parent="Headline"] +margin_right = 720.0 +margin_bottom = 59.0 +rect_min_size = Vector2( 720, 15 ) +custom_fonts/font = ExtResource( 1 ) +text = "Flood Watch issued June 22 at 10:51AM EDT until June 22 at 11:00PM EDT by NWS Baltimore MD/Washington DC" +align = 1 +autowrap = true + +[node name="HSeparator3" type="HSeparator" parent="."] +margin_top = 95.0 +margin_right = 720.0 +margin_bottom = 99.0 + +[node name="AlertInfo1" type="HBoxContainer" parent="."] +margin_top = 103.0 +margin_right = 720.0 +margin_bottom = 131.0 +alignment = 1 + +[node name="Label" type="Label" parent="AlertInfo1"] +margin_left = 273.0 +margin_right = 368.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Severity:" +align = 1 + +[node name="A1Status" type="Label" parent="AlertInfo1"] +margin_left = 372.0 +margin_right = 446.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Severe" +align = 1 + +[node name="AlertInfo2" type="HBoxContainer" parent="."] +margin_top = 135.0 +margin_right = 720.0 +margin_bottom = 163.0 +alignment = 1 + +[node name="Label" type="Label" parent="AlertInfo2"] +margin_left = 261.0 +margin_right = 367.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Certainty:" +align = 1 + +[node name="A2Status" type="Label" parent="AlertInfo2"] +margin_left = 371.0 +margin_right = 459.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Possible" +align = 1 + +[node name="AlertInfo3" type="HBoxContainer" parent="."] +margin_top = 167.0 +margin_right = 720.0 +margin_bottom = 195.0 +alignment = 1 + +[node name="Label" type="Label" parent="AlertInfo3"] +margin_left = 275.0 +margin_right = 368.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Urgency:" +align = 1 + +[node name="A3Status" type="Label" parent="AlertInfo3"] +margin_left = 372.0 +margin_right = 445.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Future" +align = 1 + +[node name="AlertInfo4" type="HBoxContainer" parent="."] +margin_top = 199.0 +margin_right = 720.0 +margin_bottom = 227.0 +alignment = 1 + +[node name="Label" type="Label" parent="AlertInfo4"] +margin_left = 257.0 +margin_right = 325.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Event:" +align = 1 + +[node name="A4Status" type="Label" parent="AlertInfo4"] +margin_left = 329.0 +margin_right = 462.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Flood Watch" +align = 1 + +[node name="AlertInfo5" type="HBoxContainer" parent="."] +margin_top = 231.0 +margin_right = 720.0 +margin_bottom = 259.0 +alignment = 1 + +[node name="Label" type="Label" parent="AlertInfo5"] +margin_left = 261.0 +margin_right = 370.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Response:" +align = 1 + +[node name="A5Status" type="Label" parent="AlertInfo5"] +margin_left = 374.0 +margin_right = 459.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 1 ) +text = "Prepare" +align = 1 + +[node name="HSeparator2" type="HSeparator" parent="."] +margin_top = 263.0 +margin_right = 720.0 +margin_bottom = 267.0 + +[node name="Desc" type="Label" parent="."] +margin_top = 271.0 +margin_right = 720.0 +margin_bottom = 1043.0 +custom_fonts/font = ExtResource( 1 ) +text = "* WHAT...Flash flooding caused by excessive rainfall continues to be\\npossible.\\n\\n* WHERE...Portions of DC, Maryland, Virginia and West Virginia,\\nincluding the following areas: in DC, District of Columbia. In\\nMaryland, Carroll, Central and Eastern Allegany, Central and\\nSoutheast Howard, Central and Southeast Montgomery, Frederick MD,\\nNorthern Baltimore, Northwest Howard, Northwest Montgomery, Prince\\nGeorges, Southern Baltimore and Washington. In Virginia,\\nArlington/Falls Church/Alexandria, Clarke, Culpeper, Eastern\\nLoudoun, Fairfax, Frederick VA, Greene, Madison, Northern\\nFauquier, Northern Virginia Blue Ridge, Orange, Page, Prince\\nWilliam/Manassas/Manassas Park, Rappahannock, Rockingham,\\nShenandoah, Southern Fauquier, Spotsylvania, Stafford, Warren and\\nWestern Loudoun. In West Virginia, Berkeley, Eastern Mineral,\\nHampshire, Hardy, Jefferson and Morgan.\\n\\n* WHEN...From 3 PM EDT this afternoon through this evening.\\n\\n* IMPACTS...Excessive runoff may result in flooding of rivers,\\ncreeks, streams, and other low-lying and flood-prone locations.\\n\\n* ADDITIONAL DETAILS...\\n- Widespread showers and thunderstorms are expected later this\\nafternoon into the evening. Given a very warm and moist air\\nmass, these will produce some very heavy rainfall at times.\\nRainfall amounts of 1 to 3 inches are possible within the\\nspan of a couple of hours, with locally higher amounts\\npossible.\\n- http://www.weather.gov/safety/flood" +align = 1 +autowrap = true + +[node name="HSeparator4" type="HSeparator" parent="."] +margin_top = 1047.0 +margin_right = 720.0 +margin_bottom = 1051.0 + +[node name="Ins" type="Label" parent="."] +margin_top = 1055.0 +margin_right = 720.0 +margin_bottom = 1083.0 +custom_fonts/font = ExtResource( 1 ) +text = "Instructions Go Here" +align = 1 +autowrap = true + +[node name="HSeparator5" type="HSeparator" parent="."] +margin_top = 1087.0 +margin_right = 720.0 +margin_bottom = 1091.0 diff --git a/Main.gd b/Main.gd index 3917869..77fd345 100644 --- a/Main.gd +++ b/Main.gd @@ -16,7 +16,13 @@ var CatForecastURL var WeeklyForecastResult var HourlyForecastResult var DetailedForecastNumebr -var CityState = str(city,state) +var CityState +var ZoneURL +var ZoneID +var AlertBase = "https://api.weather.gov/alerts/active/zone/" +var ActiveAlertURL +var Alerts +var AlertCount func _ready(): print("Program Starting") @@ -36,6 +42,8 @@ func _on_Location_request_completed(result, response_code, headers, body): zipCode = json.result.zip lat = json.result.lat long = json.result.lon + #lat = 33.4025 #For Testing. + #long = -84.522 #For Testing fullURL = str(baseURL, lat, ",", long) CityState = str(city," ",state) $GUI/Forecasts/Window/Header/Location.text = String(CityState) @@ -57,15 +65,19 @@ func _on_Forecast_request_completed(result, response_code, headers, body): ForecastURL = GPjson.result.properties.forecast HForecastURL = GPjson.result.properties.forecastHourly CatForecastURL = str(ForecastURL,ImpUnits) + ZoneURL = GPjson.result.properties.county print("Forecast URL:") print(ForecastURL) print("Hourly URL:") print(HForecastURL) print("Full Weekly URL:") print(CatForecastURL) + print("Zone URL:") + print(ZoneURL) print("Getting Weekly Forecast") getHourlyForecast() getWeeklyForecast() + getZoneID() func getHourlyForecast(): $NetworkController/HoulyForecast.request(HForecastURL) @@ -73,6 +85,9 @@ func getHourlyForecast(): func getWeeklyForecast(): $NetworkController/WeeklyForecast.request(CatForecastURL) +func getZoneID(): + $NetworkController/ZoneIDRequest.request(ZoneURL) + func _on_HoulyForecast_request_completed(result, response_code, headers, body): var HourlyForecastJSON = JSON.parse(body.get_string_from_utf8()) HourlyForecastResult = HourlyForecastJSON.result.properties.periods @@ -83,6 +98,85 @@ func _on_WeeklyForecast_request_completed(result, response_code, headers, body): WeeklyForecastResult = WeeklyForecastJSON.result.properties.periods PrintWeeklyResults() +func _on_ZoneIDRequest_request_completed(result, response_code, headers, body): + var ZoneIDRequestResult = JSON.parse(body.get_string_from_utf8()) + ZoneID = ZoneIDRequestResult.result.properties.id + ActiveAlertURL = str(AlertBase,ZoneID) + print("ZoneID:") + print(ZoneID) + print("Active Alerts URL:") + print(ActiveAlertURL) + getAlerts() + +func getAlerts(): + $NetworkController/AlertRequest.request(ActiveAlertURL) + +func _on_AlertRequest_request_completed(result, response_code, headers, body): + var AlertJSON = JSON.parse(body.get_string_from_utf8()) + Alerts = AlertJSON.result.features + AlertHandler() + +func AlertHandler(): + print("Alerts:") + if Alerts == []: + print("No Alerts") + $GUI/Forecasts/Window/NowCast/Alert.visible = false + else: + $GUI/Forecasts/Window/NowCast/Alert.visible = true + print("ALERT!") + AlertCount = Alerts.size() + #AlertCount = 3 #Testing. + print("Alert Count:") + print(AlertCount) + alertProcessing() + +func alertProcessing(): + var i = AlertCount + var Counter = 0 + var AlertNumber = 1 + var scene = ResourceLoader.load("res://AlertInfo.tscn") + var path = get_tree().get_root().get_node("Main/GUI/AlertDisplay/Body/AlertScroll/Target") + print(path) + print(scene) + print(i) + + for number in range(i): + #Make Instance + print("Loop:", Counter) + var NewInstance = scene.instance() + NewInstance.name = "AlertInfo" + String(Counter) + path.add_child(NewInstance) + print("New Instance Name:") + print(NewInstance.name) + NewInstance.get_node("Intro/AlertNum").text = String(AlertNumber) + NewInstance.get_node("Headline/HLabel").text = String(Alerts[Counter].properties.headline) + NewInstance.get_node("AlertInfo1/A1Status").text = String(Alerts[Counter].properties.severity) + NewInstance.get_node("AlertInfo2/A2Status").text = String(Alerts[Counter].properties.certainty) + NewInstance.get_node("AlertInfo3/A3Status").text = String(Alerts[Counter].properties.urgency) + NewInstance.get_node("AlertInfo4/A4Status").text = String(Alerts[Counter].properties.event) + NewInstance.get_node("AlertInfo5/A5Status").text = String(Alerts[Counter].properties.response) + NewInstance.get_node("Desc").text = String(Alerts[Counter].properties.description) + print("Instructions:") + print(Alerts[Counter].properties.instruction) + + if Alerts[Counter].properties.instruction == null: + print("NULL!!!!") + NewInstance.get_node("Ins").text = "No Further Instructions at this Time" + else: + print("Instructions Present") + NewInstance.get_node("Ins").text = String(Alerts[Counter].properties.instruction) + + Counter = Counter + 1 + AlertNumber = AlertNumber + 1 + +func _on_Alert_pressed(): + $GUI/AlertDisplay.visible = true + $GUI/Forecasts.visible = false + +func _on_ForecastReturn_pressed(): + $GUI/AlertDisplay.visible = false + $GUI/Forecasts.visible = true + func PrintHourlyResults(): #NowCast $GUI/Forecasts/Window/NowCast/NowTemp/Temp.text = String(HourlyForecastResult[0].temperature) @@ -99,6 +193,7 @@ func PrintHourlyResults(): func PrintWeeklyResults(): $GUI/Forecasts/Window/WeeklyScroll.get_v_scrollbar().modulate = Color(0, 0, 0, 0) #Hide Scroll Bar + $GUI/AlertDisplay/Body/AlertScroll.get_v_scrollbar().modulate = Color(0, 0, 0, 0) #Hide Scroll Bar $GUI/Forecasts/Window/WeeklyScroll/WeekCast/W0/Date.text = String(WeeklyForecastResult[0].name) $GUI/Forecasts/Window/WeeklyScroll/WeekCast/W0/W0Temp/Temp.text = String(WeeklyForecastResult[0].temperature) $GUI/Forecasts/Window/WeeklyScroll/WeekCast/W0/W0Temp/Unit.text = String(WeeklyForecastResult[0].temperatureUnit) diff --git a/Main.tscn b/Main.tscn index 6658e00..99ebab6 100644 --- a/Main.tscn +++ b/Main.tscn @@ -16,6 +16,10 @@ script = ExtResource( 1 ) [node name="HoulyForecast" type="HTTPRequest" parent="NetworkController"] +[node name="AlertRequest" type="HTTPRequest" parent="NetworkController"] + +[node name="ZoneIDRequest" type="HTTPRequest" parent="NetworkController"] + [node name="GUI" type="CanvasLayer" parent="."] follow_viewport_enable = true @@ -127,9 +131,9 @@ autowrap = true [node name="Alert" type="Button" parent="GUI/Forecasts/Window/NowCast"] visible = false -margin_top = 71.0 -margin_right = 101.0 -margin_bottom = 91.0 +margin_top = 128.0 +margin_right = 200.0 +margin_bottom = 148.0 text = "Weather Alert" [node name="HSeparator2" type="HSeparator" parent="GUI/Forecasts/Window"] @@ -1182,13 +1186,53 @@ margin_bottom = 256.0 visible = false anchor_right = 1.0 anchor_bottom = 1.0 +custom_constants/margin_top = 60 -[node name="ForecastReturn" type="Button" parent="GUI/AlertDisplay"] -visible = false +[node name="Body" type="VBoxContainer" parent="GUI/AlertDisplay"] +margin_top = 60.0 margin_right = 720.0 margin_bottom = 1080.0 +[node name="Header" type="Label" parent="GUI/AlertDisplay/Body"] +margin_right = 722.0 +margin_bottom = 28.0 +custom_fonts/font = ExtResource( 2 ) +text = "Weather Alerts" +align = 1 + +[node name="HSeparator" type="HSeparator" parent="GUI/AlertDisplay/Body"] +margin_top = 32.0 +margin_right = 722.0 +margin_bottom = 36.0 + +[node name="AlertScroll" type="ScrollContainer" parent="GUI/AlertDisplay/Body"] +margin_top = 40.0 +margin_right = 722.0 +margin_bottom = 960.0 +rect_min_size = Vector2( 0, 920 ) +size_flags_vertical = 3 +scroll_horizontal_enabled = false + +[node name="Target" type="VBoxContainer" parent="GUI/AlertDisplay/Body/AlertScroll"] +margin_right = 722.0 +margin_bottom = 960.0 +rect_min_size = Vector2( 710, 960 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="ForecastReturn" type="Button" parent="GUI/AlertDisplay/Body"] +margin_top = 964.0 +margin_right = 722.0 +margin_bottom = 998.0 +rect_min_size = Vector2( 0, 20 ) +custom_fonts/font = ExtResource( 2 ) +text = "Close" + [connection signal="request_completed" from="NetworkController/Location" to="." method="_on_Location_request_completed"] [connection signal="request_completed" from="NetworkController/Forecast" to="." method="_on_Forecast_request_completed"] [connection signal="request_completed" from="NetworkController/WeeklyForecast" to="." method="_on_WeeklyForecast_request_completed"] [connection signal="request_completed" from="NetworkController/HoulyForecast" to="." method="_on_HoulyForecast_request_completed"] +[connection signal="request_completed" from="NetworkController/AlertRequest" to="." method="_on_AlertRequest_request_completed"] +[connection signal="request_completed" from="NetworkController/ZoneIDRequest" to="." method="_on_ZoneIDRequest_request_completed"] +[connection signal="pressed" from="GUI/Forecasts/Window/NowCast/Alert" to="." method="_on_Alert_pressed"] +[connection signal="pressed" from="GUI/AlertDisplay/Body/ForecastReturn" to="." method="_on_ForecastReturn_pressed"] diff --git a/export_presets.cfg b/export_presets.cfg index 283b20b..df02e73 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -7,7 +7,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="../../Exports/Android/MiniWeather.apk" +export_path="../../DevTools/Exports/Android/MiniWeather/MiniWeatherV0.1.5.apk" script_export_mode=1 script_encryption_key=""