Re-add project files with LICENSE/Readme

This commit is contained in:
David Allen 2022-07-16 09:01:36 -05:00
commit cfc6b7d1b2
85 changed files with 1446 additions and 0 deletions

160
src/Calendar.gd Normal file
View file

@ -0,0 +1,160 @@
extends TextureButton
signal date_selected(date)
enum Month { JAN = 1, FEB = 2, MAR = 3, APR = 4, MAY = 5, JUN = 6, JUL = 7,
AUG = 8, SEP = 9, OCT = 10, NOV = 11, DEC = 12 }
const MONTH_NAME = [
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
]
const MONTH_DAYS = [
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
]
const WEEKDAY_NAME = [
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
]
const MAX_YEAR = 9999
const MIN_YEAR = 1970
onready var popup = $popup
onready var label_month = $popup/form/bg/header/labels/month
onready var label_year = $popup/form/bg/header/labels/year
onready var button_month_prev = $popup/form/bg/header/prev_month
onready var button_month_next = $popup/form/bg/header/next_month
onready var button_year_prev = $popup/form/bg/header/prev_year
onready var button_year_next = $popup/form/bg/header/next_year
onready var days = $popup/form/days
var day = 1
var month = 1
var year = 1970
var weekday = 0
var dst = 0
var is_open = false
func _ready():
# Set to today's date
var date = OS.get_date()
month = date["month"]
year = date["year"]
day = date["day"]
dst = date["dst"]
weekday = date["weekday"]
connect("pressed", self, "_show_popup")
button_month_prev.connect("pressed", self, "_goto_prev_month")
button_month_next.connect("pressed", self, "_goto_next_month")
button_year_prev.connect("pressed", self, "_goto_prev_year")
button_year_next.connect("pressed", self, "_goto_next_year")
popup.connect("popup_hide", self, "set_open", [false])
setup_day_buttons()
func set_open(value):
is_open = value
func _show_popup():
if is_open:
popup.hide()
is_open = false
return
label_month.set_text(MONTH_NAME[month-1])
label_year.set_text(str(year))
popup.set_position(get_global_position()+Vector2(40, 40))
popup.popup()
is_open = true
func set_year(value):
year = value
func _goto_next_month():
if month < 12:
month += 1
weekday = MONTH_DAYS[month-1] % 7
else:
if year >= MAX_YEAR:
return
month = 1
year += 1
label_month.set_text(MONTH_NAME[month-1])
label_year.set_text(str(year))
setup_day_buttons()
func _goto_prev_month():
if month > 1:
month -= 1
weekday = MONTH_DAYS[month-1] % 7
else:
if year <= MIN_YEAR:
return
month = 12
year -= 1
label_month.set_text(MONTH_NAME[month-1])
label_year.set_text(str(year))
setup_day_buttons()
func _goto_next_year():
year = clamp(year+1, MIN_YEAR, MAX_YEAR)
label_year.set_text(str(year))
setup_day_buttons()
func _goto_prev_year():
year = clamp(year-1, MIN_YEAR, MAX_YEAR)
label_year.set_text(str(year))
setup_day_buttons()
func get_weekday(date):
# See ref for details: https://artofmemory.com/blog/how-to-calculate-the-day-of-the-week/
# Only works for Gregorian calendar
var day = date["day"]
var month = date["month"]
var year = date["year"]
var is_leap_year = false
if year % 4 == 0:
is_leap_year = year % 400 == 0 or year % 100 == 0
var yy = int(str(year).right(2)) # get last 2 digits in year
var year_code = fmod((yy + floor(yy / 4)), 7.0)
var month_code = [0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5][month-1]
var century_code = [4, 2, 0, 6, 4, 2, 0][floor(year/100)-17] # -17 because start with 1700
var leap_year_code = -1 if is_leap_year and month < 2 else 0
# print("year code: ", year_code, "\nmonth code: ", month_code, "\ncentury_code: ", century_code, "\nleap code: ", leap_year_code, "\nday: ", day)
return fmod((year_code + month_code + century_code + day + leap_year_code), 7)
func setup_day_buttons():
var days_in_month = MONTH_DAYS[month-1]
var date = {"day": 1, "month": month, "year": year}
var first_weekday_month = get_weekday(date)
# print("weekday for {month}/{day}/{year}: ".format(date), get_weekday(date))
clear_buttons()
var iter = 1
for i in range(first_weekday_month, first_weekday_month+days_in_month):
var button = days.get_child(7+i) # +7 for labels
button.set_text(str(iter))
if button.is_connected("pressed", self, "emit_signal"):
button.disconnect("pressed", self, "emit_signal")
button.connect("pressed", self, "emit_signal", ["date_selected", {"day": iter, "month": month, "year": year}])
if i == day:
button.set_pressed(true)
iter += 1
func clear_buttons():
for i in range(7, days.get_child_count()):
var button = days.get_child(i)
button.set_text("")

580
src/Calendar.tscn Normal file
View file

@ -0,0 +1,580 @@
[gd_scene load_steps=12 format=2]
[ext_resource path="res://src/Calendar.gd" type="Script" id=1]
[ext_resource path="res://assets/textures/btn_32x32_04.png" type="Texture" id=2]
[ext_resource path="res://assets/textures/btn_32x32_03.png" type="Texture" id=3]
[ext_resource path="res://src/calendar_days.tres" type="ButtonGroup" id=4]
[ext_resource path="res://assets/textures/right.png" type="Texture" id=5]
[ext_resource path="res://assets/textures/left.png" type="Texture" id=6]
[ext_resource path="res://assets/textures/fastBackwards.png" type="Texture" id=7]
[ext_resource path="res://assets/textures/fastForward.png" type="Texture" id=8]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.819608, 0.8, 0.8, 1 )
border_width_left = 4
border_width_top = 4
border_width_right = 4
border_width_bottom = 4
border_color = Color( 0.376471, 0.376471, 0.376471, 0.784314 )
border_blend = true
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
expand_margin_left = 16.0
expand_margin_right = 16.0
expand_margin_top = 16.0
expand_margin_bottom = 16.0
shadow_color = Color( 0, 0, 0, 0.235294 )
shadow_size = 16
[sub_resource type="StyleBoxFlat" id=3]
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_blend = true
corner_radius_top_left = 4
corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4
shadow_color = Color( 0, 0, 0, 0.352941 )
shadow_size = 6
[sub_resource type="StyleBoxEmpty" id=2]
[node name="Calendar" type="TextureButton"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -1024.0
margin_bottom = -600.0
rect_min_size = Vector2( 32, 32 )
texture_normal = ExtResource( 3 )
texture_pressed = ExtResource( 2 )
script = ExtResource( 1 )
[node name="popup" type="PopupPanel" parent="."]
visible = true
margin_left = 43.0
margin_top = 43.0
margin_right = 354.0
margin_bottom = 341.0
rect_min_size = Vector2( 350, 325 )
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/panel = SubResource( 1 )
[node name="form" type="VBoxContainer" parent="popup"]
margin_left = 4.0
margin_top = 4.0
margin_right = 350.0
margin_bottom = 321.0
[node name="bg" type="PanelContainer" parent="popup/form"]
self_modulate = Color( 0.54902, 0.54902, 0.54902, 0.431373 )
margin_right = 346.0
margin_bottom = 16.0
custom_styles/panel = SubResource( 3 )
[node name="header" type="HBoxContainer" parent="popup/form/bg"]
margin_left = 1.0
margin_top = 1.0
margin_right = 345.0
margin_bottom = 15.0
[node name="prev_year" type="TextureButton" parent="popup/form/bg/header"]
modulate = Color( 0, 0, 0, 1 )
margin_right = 32.0
margin_bottom = 14.0
rect_min_size = Vector2( 32, 0 )
texture_normal = ExtResource( 7 )
expand = true
[node name="prev_month" type="TextureButton" parent="popup/form/bg/header"]
modulate = Color( 0, 0, 0, 1 )
margin_left = 36.0
margin_right = 68.0
margin_bottom = 14.0
rect_min_size = Vector2( 32, 0 )
texture_normal = ExtResource( 6 )
expand = true
[node name="labels" type="HBoxContainer" parent="popup/form/bg/header"]
margin_left = 72.0
margin_right = 272.0
margin_bottom = 14.0
rect_min_size = Vector2( 200, 0 )
alignment = 1
[node name="month" type="Label" parent="popup/form/bg/header/labels"]
margin_left = 59.0
margin_right = 104.0
margin_bottom = 14.0
text = "January"
align = 2
valign = 1
max_lines_visible = 1
[node name="year" type="Label" parent="popup/form/bg/header/labels"]
margin_left = 108.0
margin_right = 140.0
margin_bottom = 14.0
size_flags_horizontal = 4
size_flags_vertical = 5
custom_styles/normal = SubResource( 2 )
text = "2022"
valign = 1
max_lines_visible = 1
[node name="next_month" type="TextureButton" parent="popup/form/bg/header"]
modulate = Color( 0, 0, 0, 1 )
margin_left = 276.0
margin_right = 308.0
margin_bottom = 14.0
rect_min_size = Vector2( 32, 0 )
texture_normal = ExtResource( 5 )
expand = true
[node name="next_year" type="TextureButton" parent="popup/form/bg/header"]
modulate = Color( 0, 0, 0, 1 )
margin_left = 312.0
margin_right = 344.0
margin_bottom = 14.0
rect_min_size = Vector2( 32, 0 )
texture_normal = ExtResource( 8 )
expand = true
[node name="spacer" type="Control" parent="popup/form"]
margin_top = 20.0
margin_right = 346.0
margin_bottom = 35.0
rect_min_size = Vector2( 0, 15 )
[node name="days" type="GridContainer" parent="popup/form"]
margin_top = 39.0
margin_right = 346.0
margin_bottom = 197.0
size_flags_horizontal = 3
columns = 7
[node name="sunday" type="Label" parent="popup/form/days"]
margin_right = 46.0
margin_bottom = 14.0
text = "Sun"
align = 1
[node name="monday" type="Label" parent="popup/form/days"]
margin_left = 50.0
margin_right = 96.0
margin_bottom = 14.0
text = "Mon"
align = 1
[node name="tuesday" type="Label" parent="popup/form/days"]
margin_left = 100.0
margin_right = 146.0
margin_bottom = 14.0
text = "Tue"
align = 1
[node name="wednesday" type="Label" parent="popup/form/days"]
margin_left = 150.0
margin_right = 196.0
margin_bottom = 14.0
text = "Wed"
align = 1
[node name="thursday" type="Label" parent="popup/form/days"]
margin_left = 200.0
margin_right = 246.0
margin_bottom = 14.0
text = "Thu"
align = 1
[node name="friday" type="Label" parent="popup/form/days"]
margin_left = 250.0
margin_right = 296.0
margin_bottom = 14.0
text = "Fri"
align = 1
[node name="saturday" type="Label" parent="popup/form/days"]
margin_left = 300.0
margin_right = 346.0
margin_bottom = 14.0
text = "Sat"
align = 1
[node name="0" type="Button" parent="popup/form/days"]
margin_top = 18.0
margin_right = 46.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="1" type="Button" parent="popup/form/days"]
margin_left = 50.0
margin_top = 18.0
margin_right = 96.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="2" type="Button" parent="popup/form/days"]
margin_left = 100.0
margin_top = 18.0
margin_right = 146.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="3" type="Button" parent="popup/form/days"]
margin_left = 150.0
margin_top = 18.0
margin_right = 196.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="4" type="Button" parent="popup/form/days"]
margin_left = 200.0
margin_top = 18.0
margin_right = 246.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="5" type="Button" parent="popup/form/days"]
margin_left = 250.0
margin_top = 18.0
margin_right = 296.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="6" type="Button" parent="popup/form/days"]
margin_left = 300.0
margin_top = 18.0
margin_right = 346.0
margin_bottom = 38.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="7" type="Button" parent="popup/form/days"]
margin_top = 42.0
margin_right = 46.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="8" type="Button" parent="popup/form/days"]
margin_left = 50.0
margin_top = 42.0
margin_right = 96.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="9" type="Button" parent="popup/form/days"]
margin_left = 100.0
margin_top = 42.0
margin_right = 146.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="10" type="Button" parent="popup/form/days"]
margin_left = 150.0
margin_top = 42.0
margin_right = 196.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="11" type="Button" parent="popup/form/days"]
margin_left = 200.0
margin_top = 42.0
margin_right = 246.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="12" type="Button" parent="popup/form/days"]
margin_left = 250.0
margin_top = 42.0
margin_right = 296.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="13" type="Button" parent="popup/form/days"]
margin_left = 300.0
margin_top = 42.0
margin_right = 346.0
margin_bottom = 62.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="14" type="Button" parent="popup/form/days"]
margin_top = 66.0
margin_right = 46.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="15" type="Button" parent="popup/form/days"]
margin_left = 50.0
margin_top = 66.0
margin_right = 96.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="16" type="Button" parent="popup/form/days"]
margin_left = 100.0
margin_top = 66.0
margin_right = 146.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="17" type="Button" parent="popup/form/days"]
margin_left = 150.0
margin_top = 66.0
margin_right = 196.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="18" type="Button" parent="popup/form/days"]
margin_left = 200.0
margin_top = 66.0
margin_right = 246.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="19" type="Button" parent="popup/form/days"]
margin_left = 250.0
margin_top = 66.0
margin_right = 296.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="20" type="Button" parent="popup/form/days"]
margin_left = 300.0
margin_top = 66.0
margin_right = 346.0
margin_bottom = 86.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="21" type="Button" parent="popup/form/days"]
margin_top = 90.0
margin_right = 46.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="22" type="Button" parent="popup/form/days"]
margin_left = 50.0
margin_top = 90.0
margin_right = 96.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="23" type="Button" parent="popup/form/days"]
margin_left = 100.0
margin_top = 90.0
margin_right = 146.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="24" type="Button" parent="popup/form/days"]
margin_left = 150.0
margin_top = 90.0
margin_right = 196.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="25" type="Button" parent="popup/form/days"]
margin_left = 200.0
margin_top = 90.0
margin_right = 246.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="26" type="Button" parent="popup/form/days"]
margin_left = 250.0
margin_top = 90.0
margin_right = 296.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="27" type="Button" parent="popup/form/days"]
margin_left = 300.0
margin_top = 90.0
margin_right = 346.0
margin_bottom = 110.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="28" type="Button" parent="popup/form/days"]
margin_top = 114.0
margin_right = 46.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="29" type="Button" parent="popup/form/days"]
margin_left = 50.0
margin_top = 114.0
margin_right = 96.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="30" type="Button" parent="popup/form/days"]
margin_left = 100.0
margin_top = 114.0
margin_right = 146.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="31" type="Button" parent="popup/form/days"]
margin_left = 150.0
margin_top = 114.0
margin_right = 196.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="32" type="Button" parent="popup/form/days"]
margin_left = 200.0
margin_top = 114.0
margin_right = 246.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="33" type="Button" parent="popup/form/days"]
margin_left = 250.0
margin_top = 114.0
margin_right = 296.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="34" type="Button" parent="popup/form/days"]
margin_left = 300.0
margin_top = 114.0
margin_right = 346.0
margin_bottom = 134.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="35" type="Button" parent="popup/form/days"]
margin_top = 138.0
margin_right = 46.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="36" type="Button" parent="popup/form/days"]
margin_left = 50.0
margin_top = 138.0
margin_right = 96.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="37" type="Button" parent="popup/form/days"]
margin_left = 100.0
margin_top = 138.0
margin_right = 146.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="38" type="Button" parent="popup/form/days"]
margin_left = 150.0
margin_top = 138.0
margin_right = 196.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="39" type="Button" parent="popup/form/days"]
margin_left = 200.0
margin_top = 138.0
margin_right = 246.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="40" type="Button" parent="popup/form/days"]
margin_left = 250.0
margin_top = 138.0
margin_right = 296.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="41" type="Button" parent="popup/form/days"]
margin_left = 300.0
margin_top = 138.0
margin_right = 346.0
margin_bottom = 158.0
size_flags_horizontal = 3
toggle_mode = true
group = ExtResource( 4 )
[node name="Tween" type="Tween" parent="."]

54
src/Date.gd Normal file
View file

@ -0,0 +1,54 @@
# Supported Date Formats:
# DD : Two digit day of month
# MM : Two digit month
# YY : Two digit year
# YYYY : Four digit year
func date(date_format = "DD-MM-YY") -> String:
if("DD".is_subsequence_of(date_format)):
date_format = date_format.replace("DD", str(day()).pad_zeros(2))
if("MM".is_subsequence_of(date_format)):
date_format = date_format.replace("MM", str(month()).pad_zeros(2))
if("YYYY".is_subsequence_of(date_format)):
date_format = date_format.replace("YYYY", str(year()))
elif("YY".is_subsequence_of(date_format)):
date_format = date_format.replace("YY", str(year()).substr(2,3))
return date_format
enum Month { JAN = 1, FEB = 2, MAR = 3, APR = 4, MAY = 5, JUN = 6, JUL = 7,
AUG = 8, SEP = 9, OCT = 10, NOV = 11, DEC = 12 }
const MONTH_NAME = [
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec" ]
const WEEKDAY_NAME = [
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" ]
func get_days_in_month(month : int, year : int) -> int:
var number_of_days : int
if(month == Month.APR || month == Month.JUN || month == Month.SEP
|| month == Month.NOV):
number_of_days = 30
elif(month == Month.FEB):
var is_leap_year = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
if(is_leap_year):
number_of_days = 29
else:
number_of_days = 28
else:
number_of_days = 31
return number_of_days
func get_weekday(day : int, month : int, year : int) -> int:
var t : Array = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
if(month < 3):
year -= 1
return (year + year/4 - year/100 + year/400 + t[month - 1] + day) % 7

3
src/calendar_days.tres Normal file
View file

@ -0,0 +1,3 @@
[gd_resource type="ButtonGroup" format=2]
[resource]