477 lines
12 KiB
Python
477 lines
12 KiB
Python
|
# THIS FILE IS A PART OF VCStudio
|
||
|
# PYTHON 3
|
||
|
|
||
|
import os
|
||
|
import datetime
|
||
|
|
||
|
# GTK module ( Graphical interface
|
||
|
import gi
|
||
|
gi.require_version('Gtk', '3.0')
|
||
|
from gi.repository import Gtk
|
||
|
import cairo
|
||
|
|
||
|
# Own modules
|
||
|
from settings import settings
|
||
|
from settings import talk
|
||
|
|
||
|
# UI modules
|
||
|
from UI import UI_testing
|
||
|
from UI import UI_color
|
||
|
from UI import UI_elements
|
||
|
from UI import UI_math
|
||
|
|
||
|
def node_dot(layer, win, x, y, direction="in", entry="end"):
|
||
|
|
||
|
# This function will draw a dot to which various nodes are connected. And
|
||
|
# from which connections going off.
|
||
|
|
||
|
# This is a very alpha version of the dot thing
|
||
|
|
||
|
UI_color.set(layer, win, "progress_background")
|
||
|
UI_elements.roundrect(layer, win,
|
||
|
x,
|
||
|
y,
|
||
|
0,
|
||
|
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:
|
||
|
for arrow in win.story["arrows"]:
|
||
|
if raw_entry == arrow[1]:
|
||
|
|
||
|
fr = arrow[0]
|
||
|
if type(fr) == list:
|
||
|
fr = fr[0]+":"+fr[1]
|
||
|
|
||
|
try:
|
||
|
UI_color.set(layer, win, "progress_background")
|
||
|
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
|
||
|
# editor. This is where the story begins.
|
||
|
|
||
|
# 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()
|
||
|
|
||
|
# top banner
|
||
|
|
||
|
UI_color.set(layer, win, "node_badfile")
|
||
|
layer.rectangle(0,0,width, 20)
|
||
|
layer.fill()
|
||
|
|
||
|
# Text saying START
|
||
|
UI_color.set(layer, win, "text_normal")
|
||
|
layer.set_font_size(15)
|
||
|
layer.move_to(width/2-len(talk.text("Start"))*9/2,15)
|
||
|
layer.show_text(talk.text("Start"))
|
||
|
|
||
|
|
||
|
|
||
|
# Outputting the layer
|
||
|
outlayer.set_source_surface(surface, x, y)
|
||
|
outlayer.paint()
|
||
|
|
||
|
# Dot
|
||
|
node_dot(outlayer, win, x+width-7, y+height-12, direction="out", entry="start")
|
||
|
|
||
|
|
||
|
def end_node(outlayer, win, x, y, width, height):
|
||
|
|
||
|
# This function will draw a end node in the bottom right corner of the story
|
||
|
# editor. This is where the story ends.
|
||
|
|
||
|
# 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()
|
||
|
|
||
|
# top banner
|
||
|
|
||
|
UI_color.set(layer, win, "node_badfile")
|
||
|
layer.rectangle(0,0,width, 20)
|
||
|
layer.fill()
|
||
|
|
||
|
# Text saying END
|
||
|
UI_color.set(layer, win, "text_normal")
|
||
|
layer.set_font_size(15)
|
||
|
layer.move_to(width/2-len(talk.text("End"))*9/2,15)
|
||
|
layer.show_text(talk.text("End"))
|
||
|
|
||
|
# Outputting the layer
|
||
|
outlayer.set_source_surface(surface, x, y)
|
||
|
outlayer.paint()
|
||
|
|
||
|
# Dot
|
||
|
node_dot(outlayer, win, x-2, y+height-12)
|
||
|
|
||
|
|
||
|
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 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["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"]:
|
||
|
|
||
|
|
||
|
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()
|
||
|
|
||
|
# 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()
|
||
|
|
||
|
# 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)
|
||
|
node_dot(outlayer, win, x+width-7, y+25, direction="out",entry=entry)
|
||
|
|
||
|
def event_node(outlayer, win, x, y, width, height, name="Unknown"):
|
||
|
|
||
|
# This function draws events.
|
||
|
|
||
|
x = x - 20
|
||
|
y = y - 20
|
||
|
width = width + 40
|
||
|
height = height + 40
|
||
|
|
||
|
entry = ['event', name]
|
||
|
|
||
|
|
||
|
# Making sure the size is alright
|
||
|
if width < 100:
|
||
|
width = 100
|
||
|
if height < 100:
|
||
|
height = 100
|
||
|
|
||
|
# 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()
|
||
|
|
||
|
|
||
|
|
||
|
# 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 file_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+"/"+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()
|
||
|
|