128 lines
3.8 KiB
GDScript
128 lines
3.8 KiB
GDScript
extends VBoxContainer
|
|
|
|
const TimeSlot = preload("res://scenes/board/time_slot.tscn")
|
|
const ReservationScene = preload("res://scenes/board/reservation.tscn")
|
|
|
|
const WorkingDayStart = 8
|
|
const WorkingDayEnd = 20
|
|
|
|
const MinimalMinutesToShowTitle = 30
|
|
const MinimalMinutesForBigSize = 60
|
|
|
|
@onready var _main: Main = get_tree().get_current_scene()
|
|
@onready var _timeline = $Panel/Timeline
|
|
@onready var _reservations = $Panel/Reservations
|
|
@onready var _date = $TopBar/DateButton
|
|
|
|
func _process(delta):
|
|
_process_hour_size()
|
|
_process_date()
|
|
|
|
func _process_hour_size():
|
|
var hour_size = get_viewport_rect().size.y/15
|
|
|
|
for time_slot in _timeline.get_children():
|
|
time_slot.set_height(hour_size)
|
|
|
|
func _process_date():
|
|
var date = Time.get_date_dict_from_system()
|
|
_date.text = "%02d.%02d.%04d" % [date.day, date.month, date.year]
|
|
|
|
func _ready():
|
|
_remove_time_slots()
|
|
_remove_reservations()
|
|
|
|
_fill_with_slots()
|
|
_update_schedule()
|
|
|
|
func _remove_time_slots():
|
|
for time_slot in _timeline.get_children():
|
|
time_slot.queue_free()
|
|
|
|
func _fill_with_slots():
|
|
for hour in range(WorkingDayStart, WorkingDayEnd):
|
|
var slot = TimeSlot.instantiate()
|
|
_timeline.add_child(slot)
|
|
slot.set_time(hour)
|
|
|
|
func _remove_reservations():
|
|
for reservation in _reservations.get_children():
|
|
reservation.queue_free()
|
|
|
|
func _update_schedule():
|
|
if not _main.is_node_ready():
|
|
await _main.ready
|
|
|
|
var repo = _main.get_reservation_repo()
|
|
|
|
for reservation in repo.list_reservations():
|
|
var start_time_hours = reservation.start_time.hours
|
|
var start_time_minutes = reservation.start_time.minutes
|
|
var start_time = (start_time_hours - WorkingDayStart)*60 + start_time_minutes
|
|
|
|
var finish_time_hours = reservation.finish_time.hours
|
|
var finish_time_minutes = reservation.finish_time.minutes
|
|
var finish_time = (finish_time_hours - WorkingDayStart)*60 + finish_time_minutes
|
|
|
|
var reservation_time = finish_time - start_time
|
|
|
|
_compose_reservation(start_time, reservation_time, \
|
|
reservation.title, reservation.color, reservation.id)
|
|
|
|
func _compose_reservation(start_time, duration_time, title, color, id):
|
|
if duration_time < MinimalMinutesToShowTitle:
|
|
title = ""
|
|
|
|
var reservation = ReservationScene.instantiate()
|
|
_reservations.add_child(reservation)
|
|
reservation.set_start_time(start_time)
|
|
reservation.set_duration_time(duration_time)
|
|
reservation.set_title(title)
|
|
reservation.set_color(color)
|
|
reservation.set_id(id)
|
|
|
|
if duration_time < MinimalMinutesForBigSize:
|
|
reservation.set_font(reservation.Fonts.MEDIUM)
|
|
|
|
func _input(event):
|
|
if not _main.get_current_page() == Main.Pages.Board:
|
|
return
|
|
|
|
if event is InputEventScreenTouch or (event is InputEventMouseButton and event.pressed):
|
|
if _clicked_on_timeline(event.position):
|
|
await get_tree().create_timer(0.01, false).timeout
|
|
|
|
if _main.get_current_page() == Main.Pages.Board:
|
|
var time = _get_time_by_position(event.position)
|
|
var creation_page = _main.load_page(Main.Pages.ReservationCreation)
|
|
creation_page.set_start_time(time)
|
|
|
|
func _get_time_by_position(position):
|
|
var hour_size = get_viewport_rect().size.y / 15
|
|
var hours_with_minutes_in_float = \
|
|
(position.y - _timeline.global_position.y) / hour_size + WorkingDayStart
|
|
var hours = floor(hours_with_minutes_in_float)
|
|
var minutes = (hours_with_minutes_in_float - hours) * 60
|
|
var minutes_normalized = floor(minutes/30)*30
|
|
|
|
return {"hours": hours, "minutes": minutes_normalized}
|
|
|
|
func _clicked_on_timeline(pos: Vector2):
|
|
var timeline_position = _timeline.global_position
|
|
return (
|
|
pos.x > timeline_position.x and
|
|
pos.x < _timeline.size.x + timeline_position.x
|
|
) and (
|
|
pos.y > timeline_position.y and
|
|
pos.y < _timeline.size.y + timeline_position.y
|
|
)
|
|
|
|
func _on_room_button_pressed():
|
|
print("emit change room signal")
|
|
|
|
func _on_date_button_pressed():
|
|
print("emit change date signal")
|
|
|
|
func update():
|
|
_ready()
|