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

1
.import/.gdignore Normal file
View file

@ -0,0 +1 @@

View file

@ -0,0 +1,3 @@
source_md5="2de721d625eab5711f405ede4febd65d"
dest_md5="0a1f0682e85c566130c686b20645c6c4"

View file

@ -0,0 +1,3 @@
source_md5="2de721d625eab5711f405ede4febd65d"
dest_md5="0a1f0682e85c566130c686b20645c6c4"

View file

@ -0,0 +1,3 @@
source_md5="2d5d656d0211f39365bf70cfb211c07b"
dest_md5="8db4f4a77eedbd49c55fec9a07d0c609"

View file

@ -0,0 +1,3 @@
source_md5="2d5d656d0211f39365bf70cfb211c07b"
dest_md5="8db4f4a77eedbd49c55fec9a07d0c609"

View file

@ -0,0 +1,3 @@
source_md5="46ee73135106dc54fb583a046a8442bf"
dest_md5="cef9934fa8508382309d137fbc659919"

View file

@ -0,0 +1,3 @@
source_md5="46ee73135106dc54fb583a046a8442bf"
dest_md5="cef9934fa8508382309d137fbc659919"

View file

@ -0,0 +1,3 @@
source_md5="d1180bd0d190c3867126406d218f42b6"
dest_md5="51b6598fbcd3194d5a75b0bfc651a2a0"

View file

@ -0,0 +1,3 @@
source_md5="d1180bd0d190c3867126406d218f42b6"
dest_md5="51b6598fbcd3194d5a75b0bfc651a2a0"

View file

@ -0,0 +1,3 @@
source_md5="84a0ecae90fd489efc76e3cc8784a832"
dest_md5="da8238fc36c973cdee950cac023f756c"

View file

@ -0,0 +1,3 @@
source_md5="84a0ecae90fd489efc76e3cc8784a832"
dest_md5="da8238fc36c973cdee950cac023f756c"

View file

@ -0,0 +1,3 @@
source_md5="adf1db510488227bf21e83fcc664c2e4"
dest_md5="085317847a577293accd137e86600821"

View file

@ -0,0 +1,3 @@
source_md5="adf1db510488227bf21e83fcc664c2e4"
dest_md5="085317847a577293accd137e86600821"

View file

@ -0,0 +1,3 @@
source_md5="a01042dbc0036dc0c89b053d6bd5ad64"
dest_md5="5a2a270868576941d1078e051e9feff7"

View file

@ -0,0 +1,3 @@
source_md5="a01042dbc0036dc0c89b053d6bd5ad64"
dest_md5="5a2a270868576941d1078e051e9feff7"

View file

@ -0,0 +1,3 @@
source_md5="ce84ab9d92ac720a98ab936d19864283"
dest_md5="a5843bea3f6f521f69f48b5e6d26fbdb"

View file

@ -0,0 +1,3 @@
source_md5="ce84ab9d92ac720a98ab936d19864283"
dest_md5="a5843bea3f6f521f69f48b5e6d26fbdb"

View file

@ -0,0 +1,3 @@
source_md5="35ec506acd39131b7f77d40dd85806f3"
dest_md5="bfdc9aca38e56388de14b01f9352f48e"

View file

@ -0,0 +1,3 @@
source_md5="35ec506acd39131b7f77d40dd85806f3"
dest_md5="bfdc9aca38e56388de14b01f9352f48e"

View file

@ -0,0 +1,3 @@
source_md5="4fac229ce7f651b732a5a1e39fac97c3"
dest_md5="d9fea4e4f788ecee6cca2d826d807f69"

View file

@ -0,0 +1,3 @@
source_md5="7b299c9d6e3ccef5c3ae8e19cce06770"
dest_md5="d6bf7005fe96fe5cc52158a318eb3564"

View file

@ -0,0 +1,3 @@
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
dest_md5="26ea799ea0a3da9e753b3ebe822e0570"

Binary file not shown.

View file

@ -0,0 +1,3 @@
source_md5="a94b86e2de6b4616b4730799041ea34f"
dest_md5="0f2affa46f46a4645982cf7d33f930f6"

Binary file not shown.

View file

@ -0,0 +1,3 @@
source_md5="deeebc374373527df61bb94de9a4f719"
dest_md5="ed4807339cc84d269500be36a8f9a9cb"

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License (MIT)
Copyright (c) 2022 David J. Allen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

32
README.md Normal file
View file

@ -0,0 +1,32 @@
# Godot Calendar
A simple calendar with VERY basic functionality to select day, month, and year.
![screenshot](assets/screenshots/ss1.png)
## How to Use
Simply clone the repository and add the scene to your project. The calendar only has a single signal that returns the date (day, month, and year) as a dictionary.
```gdscript
onready var calendar = $Calendar
func _ready():
calendar.connect("date_selected", self, "print_date")
func print_date(date):
print("date selected: ", date)
print("weekday: ", calendar.get_weekday(date))
```
## TODO
- [ ] Better define popup/hide behavior.
- [ ] Add dates for before and after current month.
- [ ] Add method to get daylight savings for selected date.
- [ ] Make more customizable??

BIN
assets/screenshots/ss1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_32x32_01.png-79cbd90f22f1ab244008a919061d4f65.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_32x32_01.png"
dest_files=[ "res://.import/btn_32x32_01.png-79cbd90f22f1ab244008a919061d4f65.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_32x32_02.png-2f6195ca0f07c65d93abd1f340cd6564.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_32x32_02.png"
dest_files=[ "res://.import/btn_32x32_02.png-2f6195ca0f07c65d93abd1f340cd6564.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_32x32_03.png-ff2921f7e03c63bfbb2e1c953da931f8.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_32x32_03.png"
dest_files=[ "res://.import/btn_32x32_03.png-ff2921f7e03c63bfbb2e1c953da931f8.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_32x32_04.png-2ea1b94f4c4d8ccd184c302908f79a0a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_32x32_04.png"
dest_files=[ "res://.import/btn_32x32_04.png-2ea1b94f4c4d8ccd184c302908f79a0a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_64x64_01.png-4a5dcdc4ebc9d73c2165462f317264fa.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_64x64_01.png"
dest_files=[ "res://.import/btn_64x64_01.png-4a5dcdc4ebc9d73c2165462f317264fa.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_64x64_02.png-05ad88b8d82e22a24c3fc59bc660150b.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_64x64_02.png"
dest_files=[ "res://.import/btn_64x64_02.png-05ad88b8d82e22a24c3fc59bc660150b.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_64x64_03.png-23b73d910e5721506fac33d7618a1ddc.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_64x64_03.png"
dest_files=[ "res://.import/btn_64x64_03.png-23b73d910e5721506fac33d7618a1ddc.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_64x64_04.png-f782924dc1ddc3abfe90c985d62cc139.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_64x64_04.png"
dest_files=[ "res://.import/btn_64x64_04.png-f782924dc1ddc3abfe90c985d62cc139.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/btn_64x64_05.png-c8d3cdf69700363c7fe7e6983113e024.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/btn_64x64_05.png"
dest_files=[ "res://.import/btn_64x64_05.png-c8d3cdf69700363c7fe7e6983113e024.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/fastBackwards.png-23e3b875391285f6e1867ad4307c8e31.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/fastBackwards.png"
dest_files=[ "res://.import/fastBackwards.png-23e3b875391285f6e1867ad4307c8e31.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/fastForward.png-5dc9dc1dd0f314414d0e8358c405e79f.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/fastForward.png"
dest_files=[ "res://.import/fastForward.png-5dc9dc1dd0f314414d0e8358c405e79f.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
assets/textures/left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/left.png-bd97b939cfc653e64b2698a809562f8d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/left.png"
dest_files=[ "res://.import/left.png-bd97b939cfc653e64b2698a809562f8d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -0,0 +1,6 @@
All of these images are taken from 100% royalty free sites,
and have afterwards been edited.
Although you might want to add your own calendar button image.
Have fun!

BIN
assets/textures/right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/right.png-e73bbacd62879aa4c672f3bc1e84ca8e.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/right.png"
dest_files=[ "res://.import/right.png-e73bbacd62879aa4c672f3bc1e84ca8e.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

7
default_env.tres Normal file
View file

@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

35
icon.png.import Normal file
View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

23
project.godot Normal file
View file

@ -0,0 +1,23 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
[application]
config/name="Calendar"
run/main_scene="res://src/Calendar.tscn"
config/icon="res://icon.png"
[physics]
common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"

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]