Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##### thought bubble producer
- init python:
- ### constants
- _sqrt2 = 1.4142
- _oneeightyoverpi = 57.2958
- _split_4_lines = 900
- _split_3_lines = 600
- _split_2_lines = 300
- _text_boundary = 5
- _line_width = 8
- _flag_distance = 50
- _flag_thickness = 20
- _side_boundary = 20
- _bottom_boundary = 50
- ### images
- _blackoutline = "assets/ui/bubbles/blackcircle.png"
- _whiteinside = "assets/ui/bubbles/whitecircle.png"
- _flagoutline = "assets/ui/bubbles/blackarrow.png"
- _flaginside = "assets/ui/bubbles/whitearrow.png"
- screen SpeechBubble(who,what):
- python:
- import math
- if '\n' not in what: # not manually split into lines
- t = renpy.render(Text(what),5000,50,0,0)
- w = t.get_size()[0]
- if w > _split_4_lines:
- n2 = int(len(what)/2)
- n2a = len(what)-n2
- while what[n2] != ' ' and what[n2a] != ' ':
- n2 -= 1
- n2a += 1
- if what[n2] != ' ':
- n2 = n2a
- n1 = int(n2/2)
- n3 = len(what)-int(n2/2)
- while what[n1] != ' ':
- n1 -= 1
- while what[n3] != ' ':
- n3 += 1
- what = what[:n1]+'\n'+what[n1+1:n2]+'\n'+what[n2+1:n3]+'\n'+what[n3+1:]
- elif w > _split_3_lines:
- n1 = int(len(what)/3)
- n2 = len(what)-n1
- while what[n1] != ' ':
- n1 -= 1
- while what[n2] != ' ':
- n2 += 1
- what = what[:n1]+'\n'+what[n1+1:n2]+'\n'+what[n2+1:]
- elif w > _split_2_lines:
- n1 = int(len(what)/2)
- n2 = len(what)-n1
- while what[n1] != ' ' and what[n2] != ' ':
- n1 -= 1
- n2 += 1
- if what[n2] == ' ':
- n1 = n2
- what = what[:n1]+'\n'+what[n1+1:]
- what_text = Text(what,color="#000",text_align=0.5)
- t = renpy.render(what_text,1280,720,0,0)
- tx,ty = t.get_size()
- A = int(float(tx)/_sqrt2)+_text_boundary
- B = int(float(ty)/_sqrt2)+_text_boundary
- if who == Protagonist:
- xcenter = 640
- ycenter = 720-ty-_bottom_boundary
- point_at = (640,720)
- elif MtCharacterList.has_key(who):
- who = MtCharacterList[who]
- img = who.image
- if img:
- box = renpy.get_image_bounds(img)
- else:
- box = None
- if box:
- charx = box[0]+int(box[2]/2)
- chary = box[1]+box[3]
- point_at = (charx,chary-who.height)
- ycenter = 600-ty-_bottom_boundary
- if charx > 600 and charx < 680: # mid-screen
- xcenter = renpy.random.choice(
- [ box[0]-int(tx/2),
- box[0]+box[2]+int(tx/2) ] )
- elif charx <= 600: # on the left
- xcenter = box[0]+box[2]+int(tx/2)
- else:
- xcenter = box[0]-int(tx/2)
- else: # character not on screen
- xcenter = 500
- ycenter = 650-ty-_bottom_boundary
- point_at = (0,720)
- else: # random character
- xcenter = 200+renpy.random.randint(0,300)
- ycenter = 240+renpy.random.randint(0,600)
- point_at = (xcenter+renpy.random.randint(-10,10),0)
- if xcenter-A < _side_boundary: # too far left
- xcenter = A +_side_boundary
- if xcenter+A > 1280-_side_boundary: # too far right
- xcenter = -A+1280-_side_boundary
- # calculate flag angle and size
- angle = math.atan2(point_at[1]-ycenter,point_at[0]-xcenter)
- #angle = st
- d=A*B/math.sqrt((A**2)*math.sin(angle)**2+(B**2)*math.cos(angle)**2)
- ## start of actual drawing
- add _blackoutline: # black outer ellipse
- size (A*2+_line_width,B*2+_line_width)
- align (xcenter,ycenter)
- add _flagoutline: # black outside of flag
- size (d+_flag_distance+_flag_thickness,d+_flag_distance+_flag_thickness)
- rotate angle
- align (xcenter,ycenter)
- add _whiteinside: # white inner ellipse
- size (A*2,B*2)
- align (xcenter,ycenter)
- add _flaginside: # white inside of flag
- size (d+_flag_distance,d+_flag_distance)
- rotate angle
- align (xcenter,ycenter)
- text what:
- id "what"
- color '#FFF'
- align (int(xcenter),int(ycenter))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement