diff --git a/studio/story.py b/studio/story.py index 8b15536..2f19b63 100644 --- a/studio/story.py +++ b/studio/story.py @@ -590,4 +590,23 @@ def get_legacy(project_location): return data - +def get_asset_data(win, name, force=False): + + # This function will return a data of about the asset. + + if name not in win.assets or force: + + data = { + "fraction":0.0 + } + + # Now let's get a fraction of the asset + if os.path.exists(win.project+"/ast/"+name+".blend"): + data["fraction"] = 1.0 + else: + check = checklist.get_list(win.project+"/dev/"+name+"/asset.progress") + data["fraction"] = check["fraction"] + + win.assets[name] = data + + return win.assets[name] diff --git a/studio/studio_gtk.py b/studio/studio_gtk.py index 6f27228..70a3151 100644 --- a/studio/studio_gtk.py +++ b/studio/studio_gtk.py @@ -78,6 +78,7 @@ def run(win): win.update = {"versions":{}} win.project = project win.out_dots = {} + win.assets = {} if pm_project.is_legacy(project): diff --git a/studio/studio_nodes.py b/studio/studio_nodes.py index 1b44257..206a2ee 100644 --- a/studio/studio_nodes.py +++ b/studio/studio_nodes.py @@ -14,6 +14,9 @@ import cairo from settings import settings from settings import talk +# Studio +from studio import story + # UI modules from UI import UI_testing from UI import UI_color @@ -27,7 +30,16 @@ def node_dot(layer, win, x, y, direction="in", entry="end"): # This is a very alpha version of the dot thing - UI_color.set(layer, win, "progress_background") + raw_entry = entry + if type(entry) == list: + entry = entry[0]+":"+entry[1] + + + if entry.startswith("scene:") or entry in ["start", "end"]: + UI_color.set(layer, win, "progress_background") + else: + UI_color.set(layer, win, "node_imagefile") + UI_elements.roundrect(layer, win, x, y, @@ -35,14 +47,12 @@ def node_dot(layer, win, x, y, direction="in", entry="end"): 0, 6) - raw_entry = entry - if type(entry) == list: - entry = entry[0]+":"+entry[1] if direction != "in": win.out_dots[entry] = [x+6, y+6] - else: + + elif entry.startswith("scene:") or entry in ["start", "end"]: for arrow in win.story["arrows"]: if raw_entry == arrow[1]: @@ -61,7 +71,29 @@ def node_dot(layer, win, x, y, direction="in", entry="end"): except: pass + + elif entry.startswith("asset:"): + for link in win.story["links"]: + + if link[0] == "file": + link = link[1] + fr = "file:"+link + + if entry[entry.find(":")+1:] in link: + try: + UI_color.set(layer, win, "node_imagefile") + layer.move_to( + win.out_dots[fr][0], + win.out_dots[fr][1] + ) + layer.line_to(x+6, y+6) + layer.stroke() + + except: + pass + + def start_node(outlayer, win, x, y, width, height): # This function will draw a start node in the top left corner of the story @@ -158,166 +190,170 @@ def scene_node(outlayer, win, x, y, width, height, name="Unknown", fraction=0.0) # This function will draw scene nodes. - # Making the layer - surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height)) - layer = cairo.Context(surface) - entry = ['scene', name] - selected = False - if win.url == "story_editor": - - if win.current["LMB"] and entry in win.story["selected"]: - if int(win.current["LMB"][0]) in range(int(x), int(x+width))\ - and int(win.current["LMB"][1]) in range(int(y), int(y+height)): - win.current["tool"] = "grab" - win.story["active"] = entry - - #else: - # win.current["tool"] = "selection" + if int(x) in range(int(0-width), int(win.current["w"]))\ + and int(y) in range(int(0-height), int(win.current["h"])): - if win.current["LMB"] and win.current["tool"] == "selection": - - # If mouse over. But way more complex. Because we might select more then - # 1 scene at ones. - - mx = win.current["mx"] - my = win.current["my"] - pmx = win.current["LMB"][0] - pmy = win.current["LMB"][1] - - intersect = UI_math.rectangle_overlap( - [mx, my, pmx-mx, pmy-my], - [x,y,width, height]) + # Making the layer + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height)) + layer = cairo.Context(surface) + + + + selected = False + if win.url == "story_editor": + + if win.current["LMB"] and entry in win.story["selected"]: + if int(win.current["LMB"][0]) in range(int(x), int(x+width))\ + and int(win.current["LMB"][1]) in range(int(y), int(y+height)): + win.current["tool"] = "grab" + win.story["active"] = entry - # Now let's make a higlight - if intersect: + + if win.current["LMB"] and win.current["tool"] == "selection": + + # If mouse over. But way more complex. Because we might select more then + # 1 scene at ones. + + mx = win.current["mx"] + my = win.current["my"] + pmx = win.current["LMB"][0] + pmy = win.current["LMB"][1] + + intersect = UI_math.rectangle_overlap( + [mx, my, pmx-mx, pmy-my], + [x,y,width, height]) + + # Now let's make a higlight + if intersect: + selected = True + + elif win.previous["LMB"] and win.previous["tool"] == "selection": + + # If you released the mouse while selecting. Then do selecting. I guess. + mx = win.previous["mx"] + my = win.previous["my"] + pmx = win.previous["LMB"][0] + pmy = win.previous["LMB"][1] + + intersect = UI_math.rectangle_overlap( + [mx, my, pmx-mx, pmy-my], + [x,y,width, height]) + + # Now let's make a selection + if intersect: + win.story["selected"].append(entry) + + if win.story["active"] not in win.story["selected"]: + win.story["active"] = entry + + if entry in win.story["selected"]: selected = True - elif win.previous["LMB"] and win.previous["tool"] == "selection": + if selected: - # If you released the mouse while selecting. Then do selecting. I guess. - mx = win.previous["mx"] - my = win.previous["my"] - pmx = win.previous["LMB"][0] - pmy = win.previous["LMB"][1] - intersect = UI_math.rectangle_overlap( - [mx, my, pmx-mx, pmy-my], - [x,y,width, height]) - - # Now let's make a selection - if intersect: - win.story["selected"].append(entry) - - if win.story["active"] not in win.story["selected"]: - win.story["active"] = entry - - if entry in win.story["selected"]: - selected = True - - if selected: - - - if win.current["tool"] == "grab": - try: - if win.current["LMB"]: - x += win.current["mx"] - win.current["LMB"][0] - y += win.current["my"] - win.current["LMB"][1] - - - elif win.previous["LMB"]: - win.story["scenes"][name]["position"][0]\ - += win.previous["mx"] - win.previous["LMB"][0] - win.story["scenes"][name]["position"][1]\ - += win.previous["my"] - win.previous["LMB"][1] - - x += win.previous["mx"] - win.previous["LMB"][0] - y += win.previous["my"] - win.previous["LMB"][1] - - - # In case there is a parent event in the scene. - - if win.story["scenes"][name]["parent"]: + if win.current["tool"] == "grab": + try: + if win.current["LMB"]: + x += win.current["mx"] - win.current["LMB"][0] + y += win.current["my"] - win.current["LMB"][1] - parent = win.story["scenes"][name]["parent"] - win.story["events"][parent]["position"] = [x, y] - win.story["events"][parent]["size"] = [0, 0] - - else: - win.current["tool"] = "selection" - - - except: - raise() + elif win.previous["LMB"]: + win.story["scenes"][name]["position"][0]\ + += win.previous["mx"] - win.previous["LMB"][0] + win.story["scenes"][name]["position"][1]\ + += win.previous["my"] - win.previous["LMB"][1] + + x += win.previous["mx"] - win.previous["LMB"][0] + y += win.previous["my"] - win.previous["LMB"][1] + + + + + else: + win.current["tool"] = "selection" + + # In case there is a parent event in the scene. + + if win.story["scenes"][name]["parent"]: + + + parent = win.story["scenes"][name]["parent"] + win.story["events"][parent]["position"] = [x, y] + win.story["events"][parent]["size"] = [0, 0] + + except: + raise() + + # The selected outline - # The selected outline + UI_color.set(outlayer, win, "progress_background") + + if win.story["active"] == entry: + UI_color.set(outlayer, win, "text_normal") + outlayer.set_line_width(4) + UI_elements.roundrect(outlayer, win, + x, + y, + width, + height, + 10, + fill=False) + outlayer.stroke() + outlayer.set_line_width(2) - UI_color.set(outlayer, win, "progress_background") - - if win.story["active"] == entry: - UI_color.set(outlayer, win, "text_normal") - outlayer.set_line_width(4) - UI_elements.roundrect(outlayer, win, - x, - y, + # Clip + UI_elements.roundrect(layer, win, + 0, + 0, width, height, 10, fill=False) - outlayer.stroke() - outlayer.set_line_width(2) - - # Clip - UI_elements.roundrect(layer, win, - 0, - 0, - width, - height, - 10, - fill=False) - layer.clip() - - # Background - UI_color.set(layer, win, "dark_overdrop") - layer.rectangle(0,0,width, height) - layer.fill() - - # top banner - - UI_color.set(layer, win, "node_blendfile") - layer.rectangle(0,0,width, 20) - layer.fill() - - # Text saying The name of the scene - UI_color.set(layer, win, "text_normal") - layer.set_font_size(15) - layer.move_to(15,15) - layer.show_text(name) - - # Fraction - UI_color.set(layer, win, "progress_background") - UI_elements.roundrect(layer, win, - 10, - height-20, - width-20, - 0, - 5) - - UI_color.set(layer, win, "progress_active") - UI_elements.roundrect(layer, win, - 10, - height-20, - (width-20)*fraction, - 0, - 5) - - - # Outputting the layer - outlayer.set_source_surface(surface, x, y) - outlayer.paint() - + layer.clip() + + # Background + UI_color.set(layer, win, "dark_overdrop") + layer.rectangle(0,0,width, height) + layer.fill() + + # top banner + + UI_color.set(layer, win, "node_blendfile") + layer.rectangle(0,0,width, 20) + layer.fill() + + # Text saying The name of the scene + UI_color.set(layer, win, "text_normal") + layer.set_font_size(15) + layer.move_to(15,15) + layer.show_text(name) + + # Fraction + UI_color.set(layer, win, "progress_background") + UI_elements.roundrect(layer, win, + 10, + height-20, + width-20, + 0, + 5) + + UI_color.set(layer, win, "progress_active") + UI_elements.roundrect(layer, win, + 10, + height-20, + (width-20)*fraction, + 0, + 5) + + + # Outputting the layer + outlayer.set_source_surface(surface, x, y) + outlayer.paint() + # Dots node_dot(outlayer, win, x-5, y+25, entry=entry) @@ -375,102 +411,293 @@ def event_node(outlayer, win, x, y, width, height, name="Unknown"): outlayer.set_source_surface(surface, x, y) outlayer.paint() -def file_node(outlayer, win, x, y, width=150, height=150, name=""): + + +def link_node(outlayer, win, x, y, width=150, height=150, name="", num=0, linktype="file"): # This node will output links to files. - # Making the layer - surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height)) - layer = cairo.Context(surface) + if linktype == "asset": + width += 50 + height += 80 + if int(x) in range(int(0-width), int(win.current["w"]))\ + and int(y) in range(int(0-height), int(win.current["h"])): + + # Making the layer + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height)) + layer = cairo.Context(surface) + + entry = [linktype, num] + + + + + selected = False + if win.url == "story_editor": + + if win.current["LMB"] and entry in win.story["selected"]: + if int(win.current["LMB"][0]) in range(int(x), int(x+width))\ + and int(win.current["LMB"][1]) in range(int(y), int(y+height)): + win.current["tool"] = "grab" + win.story["active"] = entry + + + if win.current["LMB"] and win.current["tool"] == "selection": + + # If mouse over. But way more complex. Because we might select more then + # 1 scene at ones. + + mx = win.current["mx"] + my = win.current["my"] + pmx = win.current["LMB"][0] + pmy = win.current["LMB"][1] + + intersect = UI_math.rectangle_overlap( + [mx, my, pmx-mx, pmy-my], + [x,y,width, height]) + + # Now let's make a higlight + if intersect: + selected = True + + elif win.previous["LMB"] and win.previous["tool"] == "selection": + + # If you released the mouse while selecting. Then do selecting. I guess. + mx = win.previous["mx"] + my = win.previous["my"] + pmx = win.previous["LMB"][0] + pmy = win.previous["LMB"][1] + + intersect = UI_math.rectangle_overlap( + [mx, my, pmx-mx, pmy-my], + [x,y,width, height]) + + # Now let's make a selection + if intersect: + win.story["selected"].append(entry) + + if win.story["active"] not in win.story["selected"]: + win.story["active"] = entry + + if entry in win.story["selected"]: + selected = True + + if selected: + + + if win.current["tool"] == "grab": + try: + if win.current["LMB"]: + x += win.current["mx"] - win.current["LMB"][0] + y += win.current["my"] - win.current["LMB"][1] + + + elif win.previous["LMB"]: + win.story["links"][num][2][0]\ + += win.previous["mx"] - win.previous["LMB"][0] + win.story["links"][num][2][1]\ + += win.previous["my"] - win.previous["LMB"][1] + + x += win.previous["mx"] - win.previous["LMB"][0] + y += win.previous["my"] - win.previous["LMB"][1] + + else: + win.current["tool"] = "selection" + + + except: + raise() + + # The selected outline + + UI_color.set(outlayer, win, "progress_background") + + if win.story["active"] == entry: + UI_color.set(outlayer, win, "text_normal") + outlayer.set_line_width(4) + UI_elements.roundrect(outlayer, win, + x, + y, + width, + height, + 10, + fill=False) + outlayer.stroke() + outlayer.set_line_width(2) + + + + # Clip + UI_elements.roundrect(layer, win, + 0, + 0, + width, + height, + 10, + fill=False) + layer.clip() + + # Background + UI_color.set(layer, win, "dark_overdrop") + layer.rectangle(0,0,width, height) + layer.fill() + + if linktype == "asset": + + assettype = name[:name.rfind("/")].replace("/", "") + + if os.path.exists(win.project+"/dev"+name+"/renders/Preview.png"): + UI_elements.image(layer, win, + win.project+"/dev"+name+"/renders/Preview.png", + 0, 0, width, height) + elif os.path.exists(win.project+"/dev"+name+"/renders/Preview.jpg"): + UI_elements.image(layer, win, + win.project+"/dev"+name+"/renders/Preview.jpg", + 0, 0, width, height) + + else: + UI_elements.image(layer, win, + "settings/themes/"+win.settings["Theme"]+"/icons/"+assettype+".png", + width/2, height/2-20, 40, 40) + + # Here I want to add some buttons for accessing the various folder of + # the asset. And also to link stuff into those folders using nodes. + + # Darkening thing. + UI_color.set(layer, win, "dark_overdrop") + layer.rectangle(0,0,50, height) + layer.fill() + + # Blendfiles + def do(): + print("Blendfiles of "+name) + + UI_elements.roundrect(layer, win, + 5, + 25, + 40, + 40, + 10, + do, + "blender", + talk.text("blend_files_folder"), + url="story_editor", + offset=[x,y]) + + + + # References + def do(): + print("References of "+name) + + UI_elements.roundrect(layer, win, + 5, + 75, + 40, + 40, + 10, + do, + "idea", + talk.text("reference_folder"), + url="story_editor", + offset=[x,y]) + + # Textures + def do(): + print("Textures of "+name) + + UI_elements.roundrect(layer, win, + 5, + 125, + 40, + 40, + 10, + do, + "texture", + talk.text("tex_folder"), + url="story_editor", + offset=[x,y]) + + # Renders + def do(): + print("Renders of "+name) + + UI_elements.roundrect(layer, win, + 5, + 175, + 40, + 40, + 10, + do, + "render", + talk.text("renders_folder"), + url="story_editor", + offset=[x,y]) + + # Fraction + + fraction = story.get_asset_data(win, name)["fraction"] + + UI_color.set(layer, win, "progress_background") + UI_elements.roundrect(layer, win, + 65, + height-20, + width-85, + 0, + 5) + + UI_color.set(layer, win, "progress_active") + UI_elements.roundrect(layer, win, + 65, + height-20, + (width-85)*fraction, + 0, + 5) + + + UI_color.set(layer, win, "node_asset") + + else: + if os.path.exists(win.project+"/"+name): + UI_elements.image(layer, win, + win.project+"/"+name, + 0, 0, width, height) + + else: + UI_elements.image(layer, win, + name, + 0, 0, width, height) + + UI_color.set(layer, win, "node_imagefile") + + # top banner + + + layer.rectangle(0,0,width, 20) + layer.fill() + + # Text saying The name of the event + UI_color.set(layer, win, "text_normal") + layer.set_font_size(15) + layer.move_to(15,15) + layer.show_text(name[name.rfind("/")+1:]) + + # Outputting the layer + outlayer.set_source_surface(surface, x, y) + outlayer.paint() + + if linktype == "asset": + node_dot(outlayer, win, x-6, y+25+14, entry="shit") + node_dot(outlayer, win, x-6, y+75+14, entry=["asset", name+"/reference"]) + node_dot(outlayer, win, x-6, y+125+14, entry=["asset", name+"/tex"]) + node_dot(outlayer, win, x-6, y+175+14, entry=["asset", name+"/renders"]) + else: + node_dot(outlayer, win, x+width-6, y+120, entry=["file", name], direction="out") - # Clip - UI_elements.roundrect(layer, win, - 0, - 0, - width, - height, - 10, - fill=False) - layer.clip() - - # Background - UI_color.set(layer, win, "dark_overdrop") - layer.rectangle(0,0,width, height) - layer.fill() - - if os.path.exists(win.project+"/"+name): - UI_elements.image(layer, win, - win.project+"/"+name, - 0, 0, width, height) - - else: - UI_elements.image(layer, win, - name, - 0, 0, width, height) - - # top banner - - UI_color.set(layer, win, "progress_active") - layer.rectangle(0,0,width, 20) - layer.fill() - - # Text saying The name of the event - UI_color.set(layer, win, "text_normal") - layer.set_font_size(15) - layer.move_to(15,15) - layer.show_text(name) - - # Outputting the layer - outlayer.set_source_surface(surface, x, y) - outlayer.paint() - -def asset_node(outlayer, win, x, y, width=150, height=150, name=""): - - # This node will output links to files. - - # Making the layer - surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height)) - layer = cairo.Context(surface) - - - # Clip - UI_elements.roundrect(layer, win, - 0, - 0, - width, - height, - 10, - fill=False) - layer.clip() - - # Background - UI_color.set(layer, win, "dark_overdrop") - layer.rectangle(0,0,width, height) - layer.fill() - - if os.path.exists(win.project+"/dev"+name+"/renders/Preview.png"): - UI_elements.image(layer, win, - win.project+"/dev"+name+"/renders/Preview.png", - 0, 0, width, height) - else: - UI_elements.image(layer, win, - win.project+"/dev"+name+"/renders/Preview.jpg", - 0, 0, width, height) - - # top banner - - UI_color.set(layer, win, "progress_time") - layer.rectangle(0,0,width, 20) - layer.fill() - - # Text saying The name of the event - UI_color.set(layer, win, "text_normal") - layer.set_font_size(15) - layer.move_to(15,15) - layer.show_text(name) - - # Outputting the layer - outlayer.set_source_surface(surface, x, y) - outlayer.paint() - + else: # If not in the frame + if linktype == "file": + try: + del win.out_dots["file:"+name] + except: + pass diff --git a/studio/studio_storyLayer.py b/studio/studio_storyLayer.py index 9aa74ff..77d2090 100644 --- a/studio/studio_storyLayer.py +++ b/studio/studio_storyLayer.py @@ -481,11 +481,7 @@ def layer(win): ly = link[2][1] + cy - if linktype == "file": - - studio_nodes.file_node(layer, win, lx, ly, name=linkname) - else: - studio_nodes.asset_node(layer, win, lx, ly, name=linkname) + studio_nodes.link_node(layer, win, lx, ly, name=linkname, num=num, linktype=linktype ) # In case there is a selection bug if not win.story["selected"]: