Image loader, datetime
This commit is contained in:
+88
-13
@@ -1,14 +1,27 @@
|
||||
extends Control
|
||||
|
||||
@export var stage_pages: Array[Container]
|
||||
@export var item_pages: Array[Control]
|
||||
@export var stage_page_scroller: ScrollContainer
|
||||
|
||||
const ITEM_BUTTON = preload("uid://d3xjfxwe3w16v")
|
||||
|
||||
const PAGE_COUNT = 5
|
||||
const PAGE_WIDTH = 1080
|
||||
const DRAG_TOLERANCE = 360
|
||||
const SWIPE_DURATION: float = 2
|
||||
const SWIPE_DELAY = 2000 # msec
|
||||
|
||||
@onready var g_entity_descriptions: Array = [
|
||||
$StageRows/PageScroller/HBoxContainer/ForcePage/Description,
|
||||
$StageRows/PageScroller/HBoxContainer/ResourcePage/Description,
|
||||
$StageRows/PageScroller/HBoxContainer/StarPage/Description,
|
||||
$StageRows/PageScroller/HBoxContainer/StructurePage/Description,
|
||||
$StageRows/PageScroller/HBoxContainer/LifePage/Description
|
||||
]
|
||||
|
||||
@onready var g_top_menu: TopMenu = $StageRows/TopMenu
|
||||
|
||||
|
||||
var g_tween: Tween = null
|
||||
var g_dragged_start: Vector2 = Vector2.ZERO
|
||||
var g_scroll_start: int = 0
|
||||
@@ -23,19 +36,64 @@ var g_counters: Dictionary[String, Counter] = {
|
||||
"swipe": Counter.new(),
|
||||
}
|
||||
|
||||
var ActiveEntities: Dictionary = {}
|
||||
|
||||
func _ready() -> void:
|
||||
var owniverse = Owniverse.new()
|
||||
|
||||
|
||||
func entity_activated(entity: OwniverseEntity) -> void:
|
||||
_control_page(entity)
|
||||
_set_description(entity)
|
||||
|
||||
func _set_description(entity: OwniverseEntity) -> void:
|
||||
var description: String = "[b]" \
|
||||
+ Global.get_localized_item_description(entity.entity_name, "label") \
|
||||
+ "[/b]" \
|
||||
+ "\n" \
|
||||
+ Global.get_localized_item_description(entity.entity_name, "description")
|
||||
var desc_page = clamp(entity.entity_page, 0, 4)
|
||||
g_entity_descriptions[desc_page].text = description
|
||||
pass
|
||||
|
||||
func _control_page(entity: OwniverseEntity) -> void:
|
||||
if !ActiveEntities.has(entity.entity_page):
|
||||
ActiveEntities[entity.entity_page] = null
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
pass
|
||||
#page_scroller.scroll_horizontal = 3240
|
||||
|
||||
var current_entity:OwniverseEntity = ActiveEntities[entity.entity_page]
|
||||
if current_entity == entity:
|
||||
return
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var actions = _check_counters(delta)
|
||||
_do_actions(actions)
|
||||
ActiveEntities[entity.entity_page] = entity
|
||||
|
||||
if current_entity != null and current_entity.entity_page == entity.entity_page:
|
||||
current_entity.set_selection(false)
|
||||
|
||||
entity.set_selection(true)
|
||||
|
||||
# subpages
|
||||
if entity.sub_page != -1:
|
||||
item_pages[entity.sub_page].visible = true
|
||||
|
||||
if current_entity == null \
|
||||
or current_entity.sub_page == -1 \
|
||||
or current_entity.sub_page == entity.sub_page:
|
||||
return
|
||||
item_pages[current_entity.sub_page].visible = false
|
||||
|
||||
|
||||
func _init_entities() -> bool:
|
||||
for e_id in Global.Entities:
|
||||
var entity_properties: Dictionary = Global.Entities[e_id]
|
||||
var entity: OwniverseEntity = ITEM_BUTTON.instantiate()
|
||||
if !entity_properties.has("page"):
|
||||
printerr("Entity `", e_id, "` has no `page` key.")
|
||||
return false
|
||||
var page: int = int(entity_properties.page)
|
||||
item_pages[page].add_child(entity)
|
||||
entity.init_button(entity_properties)
|
||||
entity.entity_activated.connect(entity_activated)
|
||||
|
||||
return false
|
||||
|
||||
|
||||
func _check_counters(delta: float) -> Array:
|
||||
@@ -59,16 +117,14 @@ func _do_actions(actions: Array) -> void:
|
||||
"swipe":
|
||||
_swipe_to_nearest_page()
|
||||
|
||||
func button_pressed() -> void:
|
||||
print(name)
|
||||
|
||||
#region Swipe
|
||||
|
||||
|
||||
func _swipe_to_nearest_page() -> void:
|
||||
if stage_page_scroller.scroll_horizontal % PAGE_WIDTH == 0: return
|
||||
|
||||
var new_page: int = round(1.0 * stage_page_scroller.scroll_horizontal / PAGE_WIDTH)
|
||||
#print(stage_page_scroller.scroll_horizontal, " | ", 1.0 * stage_page_scroller.scroll_horizontal / PAGE_WIDTH, " | ", new_page)
|
||||
|
||||
if g_tween != null:
|
||||
if g_tween.is_running():
|
||||
@@ -92,3 +148,22 @@ func _input(event: InputEvent) -> void:
|
||||
g_counters.swipe.value = 0
|
||||
elif event is InputEventScreenTouch:
|
||||
pass
|
||||
#endregion
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_init_entities()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# Update date
|
||||
var dt: float = owniverse.add_time_delta(delta)
|
||||
if owniverse.g_speed > 1:
|
||||
dt = round(dt)
|
||||
else:
|
||||
dt = snapped(dt, 0.1)
|
||||
|
||||
g_top_menu.set_datetime(str(dt))
|
||||
|
||||
|
||||
var actions = _check_counters(delta)
|
||||
_do_actions(actions)
|
||||
|
||||
Reference in New Issue
Block a user