So, this is the code attached to the book model :
func _ready():
# anim
ap = $AnimationPlayer
ap.assigned_animation = "opening_strap"
ap.seek(0,true)
The book model is included in a detail view scene (the book model, a key model, some hotspots, and another animationplayer which will coordinate the key and book animations) :
func_ready():
# dv ap
ap = $AnimationPlayer
ap.connect("animation_finished", self, "on_anim_finished")
book = $book_key
key = $key
key.hide()
#@fixme : pages
hs_drop = $HS_dv_drop_key
hs_click_l = $HS_dv_btn_l
hs_click_r = $HS_dv_btn_r
# disable @start
on_item_invis()
The detail view scene responds to a change in visibility ; if invis, it simply disables all hotspots ; if vis : it checks some variables to see what animation it should display & what hotspots should be active. While trying to understand the problem I've been having, I have commented the animation bits out (to make sure they're not part of the problem).
The book detail view scene is used in the inventory detail view. It, along with some other items are all part of the invent dv scenetree, but they are invisible & inactive by default.
The invent dv visibility is toggled by the magnifier button (if an invent item is selected first) :
func _ready():
setup()
# transform magnify btn press into dv vis toggle
GA.connect("s_toggle_dv_vis", self, "on_toggle_dv_vis")
func setup():
# vpc
vpc.connect("gui_input", self, "on_gui_input")
vpc.mouse_filter = Control.MOUSE_FILTER_STOP
# vp
vp.own_world = true
# raycast
ray.cast_to = Vector3(0,0,-1)
ray.collision_mask = 2
ray.collide_with_areas = true
ray.collide_with_bodies = false
# dv items
for c in items.get_children():
coll_items[c.name.to_lower()] = c
# hack : BUG
# if I don't detach from/re-attach to scenetree, 'openinig-strap anim' never on fr=0
var hack_book_key:Spatial = $ViewportContainer/Viewport/items/book_key
hack_book_key.get_parent().remove_child(hack_book_key)
$ViewportContainer/Viewport/items.add_child(hack_book_key)
# dv nfo : clear all
reset_dv_nfo()
#@start
hide()
func on_toggle_dv_vis(is_vis:bool):
# called when magnify btn is toggled
# the dv can only open/close with decorated btn selected
set_dv_nfo() # dv item and label txt to display
if is_vis:
GA.set_game_mode(GA.GAMEMODE.DV)
vp.gui_disable_input = false
cam.current = true
ray.enabled = true
show()
else:
GA.set_game_mode(GA.GAMEMODE.WORLD)
vp.gui_disable_input = true
cam.current = false
ray.enabled = false
hide()
func set_dv_nfo():
# find correct img/model & txt
var item_id:String = GA.get_selected_invent_item_id()
show_item(item_id)
show_label(item_id)
... I think that's all the relevant code.
Another thing I tried doing, but didn't work, is this :
func show_item(item_id:String):
hide_all_items()
var item:Spatial = coll_items.get(item_id)
### other hack : doesn't work : call animplayer of book model
if item_id.match("book_key"):
item.book.ap.assigned_animation = "opening_strap"
item.book.ap.seek(0,true)
###
if item is DV:
item.enable_hs()
item.show()
Thanks for your time !