Advertisement
zamphire

Untitled

Jun 17th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. module HUDWidgets
  2. #----------
  3. class WidgetBase < Sprite
  4. def initialize(name, x, y, z)
  5. super()
  6. @name = name
  7. self.x, self.y, self.z = x, y, z
  8. end
  9. def z=(v)
  10. super(v + 60)
  11. end
  12. def z
  13. return super() - 60
  14. end
  15. end
  16. #----------
  17. class TextWidget < WidgetBase
  18. def initialize(name, x, y, z, param, text, id, fname, fsize, fbold, fitalic, fshadow, fcolor, foutline, foutline_color, tw, th, fix_from)
  19. super(name, x, y, z)
  20. #-----
  21. @fsize = fsize
  22. @fix_from = fix_from
  23. @initial_width = nil
  24. #-----
  25. @font = Font.new(fname, fsize)
  26. @font.bold = fbold
  27. @font.italic = fitalic
  28. @font.shadow = fshadow
  29. @font.outline = foutline
  30. @font.out_color = foutline_color
  31. @fbmp = Bitmap.new(1, 1)
  32. @fbmp.font = @font
  33. #-----
  34. @param, @text, @id = param, text, id
  35. @tw, @th = tw, th
  36. #-----
  37. r = @fbmp.text_size('Text')
  38. @font.size *= (@tw.to_f / r.width)
  39. #-----
  40. @fbmp.font = @font
  41. #-----
  42. self.oy = (((r.height * (@tw.to_f / r.width)) * (1.0 - (r.width / @tw.to_f))) * 0.5).ceil
  43. #-----
  44. update
  45. end
  46. def update
  47. actor = $game_party.leader
  48. case @param
  49. when 0 # Text
  50. str = @text
  51. else
  52. return
  53. end
  54. #-----
  55. self.bitmap.dispose if self.bitmap and not self.bitmap.disposed?
  56. return if str.empty?
  57. #-----
  58. r = @fbmp.text_size(str)
  59. bmp = self.bitmap = Bitmap.new(r.width + 32, r.height)
  60. bmp.font = @font
  61. bmp.draw_text(bmp.rect, str, 0)
  62. #-----
  63. @initial_width ||= self.width
  64. #-----
  65. case @fix_from
  66. when 0
  67. self.ox = 0
  68. when 1
  69. self.ox = (self.width - @initial_width) / 2
  70. when 2
  71. self.ox = self.width - @initial_width
  72. end
  73. end
  74. end
  75. end
  76. class Scene_Map < Scene_Base
  77. #----------
  78. alias :hud_alias_start :start
  79. alias :hud_alias_update :update
  80. alias :hud_alias_p_term :terminate
  81. #----------
  82. def start
  83. hud_alias_start
  84. start_hud
  85. end
  86. #-----
  87. def start_hud
  88. @actor_info_cache, @var_info_cache, @hud_widgets = {}, {}, {}
  89. @hud_widgets[1] = HUDWidgets::TextWidget.new('Text', 14, 382, 0, 0, 'Put your text here', 0, 'Arial', 24, false, false, false, Color.new(255, 255, 255, 255), false, Color.new(0, 0, 0, 255), 59, 24,0)
  90. update_hud
  91. end
  92. #----------
  93. def update
  94. hud_alias_update
  95. update_hud
  96. end
  97. #-----
  98. def update_hud
  99. actor = $game_party.leader
  100. end
  101. #----------
  102. def terminate
  103. hud_alias_p_term
  104. hud_dispose
  105. end
  106. #-----
  107. def hud_dispose
  108. @hud_widgets.each_value {|hw| hw.dispose }
  109. end
  110. #----------
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement