Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. ##### thought bubble producer
  2.  
  3. init python:
  4.  
  5. ### constants
  6.  
  7. _sqrt2 = 1.4142
  8. _oneeightyoverpi = 57.2958
  9.  
  10. _split_4_lines = 900
  11. _split_3_lines = 600
  12. _split_2_lines = 300
  13.  
  14. _text_boundary = 5
  15. _line_width = 8
  16. _flag_distance = 50
  17. _flag_thickness = 20
  18. _side_boundary = 20
  19. _bottom_boundary = 50
  20.  
  21.  
  22. ### images
  23.  
  24. _blackoutline = "assets/ui/bubbles/blackcircle.png"
  25. _whiteinside = "assets/ui/bubbles/whitecircle.png"
  26. _flagoutline = "assets/ui/bubbles/blackarrow.png"
  27. _flaginside = "assets/ui/bubbles/whitearrow.png"
  28.  
  29.  
  30.  
  31.  
  32.  
  33. screen SpeechBubble(who,what):
  34.  
  35. python:
  36. import math
  37.  
  38. if '\n' not in what: # not manually split into lines
  39.  
  40. t = renpy.render(Text(what),5000,50,0,0)
  41. w = t.get_size()[0]
  42.  
  43. if w > _split_4_lines:
  44.  
  45. n2 = int(len(what)/2)
  46. n2a = len(what)-n2
  47. while what[n2] != ' ' and what[n2a] != ' ':
  48. n2 -= 1
  49. n2a += 1
  50. if what[n2] != ' ':
  51. n2 = n2a
  52. n1 = int(n2/2)
  53. n3 = len(what)-int(n2/2)
  54. while what[n1] != ' ':
  55. n1 -= 1
  56. while what[n3] != ' ':
  57. n3 += 1
  58. what = what[:n1]+'\n'+what[n1+1:n2]+'\n'+what[n2+1:n3]+'\n'+what[n3+1:]
  59.  
  60. elif w > _split_3_lines:
  61.  
  62. n1 = int(len(what)/3)
  63. n2 = len(what)-n1
  64. while what[n1] != ' ':
  65. n1 -= 1
  66. while what[n2] != ' ':
  67. n2 += 1
  68. what = what[:n1]+'\n'+what[n1+1:n2]+'\n'+what[n2+1:]
  69.  
  70. elif w > _split_2_lines:
  71.  
  72. n1 = int(len(what)/2)
  73. n2 = len(what)-n1
  74. while what[n1] != ' ' and what[n2] != ' ':
  75. n1 -= 1
  76. n2 += 1
  77. if what[n2] == ' ':
  78. n1 = n2
  79. what = what[:n1]+'\n'+what[n1+1:]
  80.  
  81. what_text = Text(what,color="#000",text_align=0.5)
  82.  
  83. t = renpy.render(what_text,1280,720,0,0)
  84.  
  85. tx,ty = t.get_size()
  86. A = int(float(tx)/_sqrt2)+_text_boundary
  87. B = int(float(ty)/_sqrt2)+_text_boundary
  88.  
  89. if who == Protagonist:
  90. xcenter = 640
  91. ycenter = 720-ty-_bottom_boundary
  92. point_at = (640,720)
  93.  
  94. elif MtCharacterList.has_key(who):
  95. who = MtCharacterList[who]
  96. img = who.image
  97. if img:
  98. box = renpy.get_image_bounds(img)
  99. else:
  100. box = None
  101. if box:
  102. charx = box[0]+int(box[2]/2)
  103. chary = box[1]+box[3]
  104. point_at = (charx,chary-who.height)
  105. ycenter = 600-ty-_bottom_boundary
  106. if charx > 600 and charx < 680: # mid-screen
  107. xcenter = renpy.random.choice(
  108. [ box[0]-int(tx/2),
  109. box[0]+box[2]+int(tx/2) ] )
  110. elif charx <= 600: # on the left
  111. xcenter = box[0]+box[2]+int(tx/2)
  112. else:
  113. xcenter = box[0]-int(tx/2)
  114.  
  115. else: # character not on screen
  116. xcenter = 500
  117. ycenter = 650-ty-_bottom_boundary
  118. point_at = (0,720)
  119.  
  120. else: # random character
  121. xcenter = 200+renpy.random.randint(0,300)
  122. ycenter = 240+renpy.random.randint(0,600)
  123. point_at = (xcenter+renpy.random.randint(-10,10),0)
  124.  
  125. if xcenter-A < _side_boundary: # too far left
  126. xcenter = A +_side_boundary
  127. if xcenter+A > 1280-_side_boundary: # too far right
  128. xcenter = -A+1280-_side_boundary
  129.  
  130. # calculate flag angle and size
  131. angle = math.atan2(point_at[1]-ycenter,point_at[0]-xcenter)
  132. #angle = st
  133. d=A*B/math.sqrt((A**2)*math.sin(angle)**2+(B**2)*math.cos(angle)**2)
  134.  
  135. ## start of actual drawing
  136.  
  137. add _blackoutline: # black outer ellipse
  138. size (A*2+_line_width,B*2+_line_width)
  139. align (xcenter,ycenter)
  140.  
  141. add _flagoutline: # black outside of flag
  142. size (d+_flag_distance+_flag_thickness,d+_flag_distance+_flag_thickness)
  143. rotate angle
  144. align (xcenter,ycenter)
  145.  
  146. add _whiteinside: # white inner ellipse
  147. size (A*2,B*2)
  148. align (xcenter,ycenter)
  149.  
  150. add _flaginside: # white inside of flag
  151. size (d+_flag_distance,d+_flag_distance)
  152. rotate angle
  153. align (xcenter,ycenter)
  154.  
  155. text what:
  156. id "what"
  157. color '#FFF'
  158. align (int(xcenter),int(ycenter))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement