Little bug at Caesar Questlog.

Hello guys. Im needing your help again, but this is a little bug we're talking about.
Im using Caesar Questlog script, which is is made of 2 scripts. Im posting them right now for people to see below:
Problem is this: If im about to add a new quest with the command:

Questlog.add("<icon=scroll> Solving my problem",
"Help Nebukadnezar II solving his problem
<br><image=questimage1><down=8><space=20>
<br>Place: Hbgames.org
<br>Reward: Much love
")

everything works fine. But when Im about to add a new quest, the Icon of the second quest stacks with the first one. What I mean is this: I have prepared a picture. Look exactly. If I have one quests, it looks fine. But when another quest is added, the icons stacks with the first one, wich it shouldnt be. I hope you understood me.
Image

  1. #///////////////////////HTML-Rendering-Engine/////////////////////////////////
  2. #~~~~~~~~~~~~~~~~by Caesar~~~~~~~~~~~~~~~~~~~
  3. #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  4. class Bitmap
  5. def draw_shadow_text(x, y, width, height, str, align=0)
  6. color = font.color.dup
  7. font.color = Color.new(192, 192, 192, 156)
  8. draw_text(x+2, y+2, width, height, str, align)
  9. font.color = color
  10. draw_text(x, y, width, height, str, align)
  11. end
  12. #----------------
  13. def draw_html(x, y, width, height, str)
  14. # remember string and font variables
  15. str = str.dup
  16. color = font.color.dup
  17. bold = font.bold
  18. italic = font.italic
  19. size = font.size
  20. name = font.name.dup
  21. #::::::::::
  22. shadow = false
  23. underlined = false
  24. opacity = 255
  25. str.gsub!(/<if=([0-9]+)>(.+?)<else>(.+?)<\/if>/) {$game_switches[$1.to_i] ? $2 : $3}
  26. str.gsub!(/<var=([0-9]+)>/) {$game_variables[$1.to_i].to_s}
  27. str.gsub!(/<eval={(.+?)}>/) {eval $1}
  28. str.gsub!(/<style=([A-Za-z0-9_-]+)>(.+?)<\/style>/) {
  29. STYLES.has_key?($1) ? STYLES[$1].sub("|", $2) : ""
  30. } if defined?(STYLES)
  31. str.gsub!(/<br>/) {"\n"}
  32. str.gsub!(/\\\\/) {"\00"}
  33. str.gsub!(/<b>/) {"\01"}
  34. str.gsub!(/<\/b>/) {"\02"}
  35. str.gsub!(/<i>/) {"\03"}
  36. str.gsub!(/<\/i>/) {"\04"}
  37. str.gsub!(/<color=(#?[0-9a-z_]+)>/) {"\05[#{$1}]"}
  38. str.gsub!(/<\/color>/) {"\06"}
  39. str.gsub!(/<shadow>/) {"\16"}
  40. str.gsub!(/<\/shadow>/) {"\17"}
  41. str.gsub!(/<small>/) {"\20"}
  42. str.gsub!(/<\/small>/) {"\21"}
  43. str.gsub!(/<big>/) {"\23"}
  44. str.gsub!(/<\/big>/) {"\21"}
  45. str.gsub!(/<size=([0-9]+)>/) {"\24[#{$1}]"}
  46. str.gsub!(/<\/size>/) {"\21"}
  47. str.gsub!(/<font=([A-Za-z0-9\s]+)>/) {"\25[#{$1}]"}
  48. str.gsub!(/<\/font>/) {"\26"}
  49. str.gsub!(/<u>/) {"\27"}
  50. str.gsub!(/<\/u>/) {"\30"}
  51. str.gsub!(/<icon=([_A-Za-z0-9-]+)>/) {"\11[#{$1}]"}
  52. str.gsub!(/<image=([_A-Za-z0-9-]+)>/) {"\31[#{$1}]"}
  53. str.gsub!(/<down=([0-9]+)>/) {"\22[#{$1}]"}
  54. str.gsub!(/<space=([0-9]+)>/) {"\100[#{$1}]"}
  55. str.gsub!(/<line>/) {"\07"}
  56. ix = 0
  57. iy = 0
  58. while ((c = str.slice!(/./m)) != nil)
  59. if c == "\00" # \\
  60. c = "\\"
  61. end
  62. if c == "\01" # <b>
  63. font.bold = true
  64. end
  65. if c == "\02" #</b>
  66. font.bold = bold
  67. end
  68. if c == "\03" # <i>
  69. font.italic = true
  70. end
  71. if c == "\04" # </i>
  72. font.italic = false
  73. end
  74. if c == "\05" # <color=xxx>
  75. str.sub!(/\[(#?[0-9a-z_]+)\]/, "")
  76. if $1[0] == 35
  77. col = Color.decode($1)
  78. elsif $1.to_i != 0
  79. col = Window_Base.text_color($1.to_i)
  80. else
  81. col = Color.get($1)
  82. end
  83. font.color = col
  84. end
  85. if c == "\06" # </color>
  86. font.color = color
  87. end
  88. if c == "\16" # <shadow>
  89. shadow = true
  90. end
  91. if c == "\17" # </shadow>
  92. shadow = false
  93. end
  94. if c == "\20" # <small>
  95. font.size -= 5 if font.size > 10
  96. end
  97. if c == "\21" # </small> </big> </size>
  98. font.size = size
  99. end
  100. if c == "\23" # <big>
  101. font.size += 5 if font.size < 92
  102. end
  103. if c == "\24" # <size=xx>
  104. str.sub!(/\[([0-9]+)\]/, "")
  105. newsize = $1.to_i
  106. font.size = newsize if newsize > 5 and newsize < 97
  107. end
  108. if c == "\25" # <font=xxx>
  109. str.sub!(/\[([A-Za-z0-9\s]+)\]/, "")
  110. font.name = $1 if Font.exist?($1)
  111. end
  112. if c == "\26" # </font>
  113. font.name = name
  114. end
  115. if c == "\27" # <u>
  116. underlined = true
  117. end
  118. if c == "\30" # </u>
  119. underlined = false
  120. end
  121. if c == "\11" #<icon=xxx>
  122. str.sub!(/\[([_A-Za-z0-9-]+)\]/, "")
  123. icon = RPG::Cache.icon($1)
  124. blt(ix + 8, iy + LINE_HEIGHT/2 - 12, icon, Rect.new(0, 0, 24, 24))
  125. ix += 24
  126. end
  127. if c == "\31" # <image=xxx>
  128. str.sub!(/\[([_A-Za-z0-9-]+)\]/, "")
  129. image = RPG::Cache.picture($1)
  130. iy += LINE_HEIGHT
  131. blt((width-image.rect.width)/2, iy, image, image.rect)
  132. iy += image.rect.height
  133. ix = 0
  134. end
  135. if c == "\22" # <down=xxx>
  136. str.sub!(/\[([0-9]+)\]/, "")
  137. iy += $1.to_i
  138. ix = 0
  139. end
  140. if c == "\100" # <space=xxx>
  141. str.sub!(/\[([0-9]+)\]/, "")
  142. ix += $1.to_i
  143. c = ""
  144. end
  145. if c == "\07" # <line>
  146. iy += LINE_HEIGHT + 3
  147. fill_rect(16, iy, width-32, 2, font.color)
  148. fill_rect(16, iy, width-32, 2, Color.new(192, 192, 192, 156)) if shadow
  149. iy += 5
  150. ix = 0
  151. end
  152. if c == "\n"
  153. iy += LINE_HEIGHT
  154. ix = 0
  155. end
  156. #:::::::::
  157. if shadow
  158. draw_shadow_text(x+ix+4, y+iy, 40, font.size, c)
  159. else
  160. draw_text(x+ix+4, y+iy, 40, font.size, c)
  161. end
  162. w = text_size(c).width
  163. if underlined
  164. fill_rect(x+ix+4, y+iy+text_size("T").height+3, w, 2, font.color)
  165. end
  166. ix += w
  167. end
  168. #::::::::::
  169. #reset font variables
  170. font.color = color
  171. font.bold = bold
  172. font.italic = italic
  173. font.size = size
  174. font.name = name
  175. #return height of the bitmap
  176. return iy + LINE_HEIGHT
  177. end
  178. end
  179. #==============
  180. class Color
  181. def Color.get(s)
  182. eval "Color.#{s}" rescue Color.white
  183. end
  184. #------------
  185. def Color.decode(hex)
  186. return Color.decode(hex[1..hex.length]) if hex[0] == 35
  187. hex.downcase!
  188. red = hex[0..1].hex
  189. green = hex[2..3].hex
  190. blue = hex[4..5].hex
  191. alpha = hex.length == 8 ? hex[6..7].hex : 255
  192. return Color.new(red, green, blue, alpha)
  193. end
  194. #------------
  195. def Color.normal_color
  196. return Color.new(255, 255, 255, 255)
  197. end
  198. #-----------
  199. def Color.disabled_color
  200. return Color.new(255, 255, 255, 128)
  201. end
  202. #-----------
  203. def Color.system_color
  204. return Color.new(192, 224, 255, 255)
  205. end
  206. #-----------
  207. def Color.crisis_color
  208. return Color.new(255, 255, 64, 255)
  209. end
  210. #-----------
  211. def Color.knockout_color
  212. return Color.new(255, 64, 0)
  213. end
  214. #------------
  215. def Color.white(alpha=255)
  216. return Color.new(255, 255, 255, alpha)
  217. end
  218. #-----------
  219. def Color.black(alpha=255)
  220. return Color.new(0, 0, 0, alpha)
  221. end
  222. #----------
  223. def Color.red(alpha=255)
  224. return Color.new(255, 0, 0, alpha)
  225. end
  226. #----------
  227. def Color.green(alpha=255)
  228. return Color.new(0, 255, 0, alpha)
  229. end
  230. #---------
  231. def Color.blue(alpha=255)
  232. return Color.new(0, 0, 255, alpha)
  233. end
  234. #----------
  235. def Color.yellow(alpha=255)
  236. return Color.new(255, 255, 0, alpha)
  237. end
  238. #----------
  239. def Color.cyan(alpha=255)
  240. return Color.new(0, 255, 255, alpha)
  241. end
  242. #----------
  243. def Color.magenta(alpha=255)
  244. return Color.new(255, 255, 0, alpha)
  245. end
  246. #----------
  247. def Color.light_gray(alpha=255)
  248. return Color.new(192, 192, 192, alpha)
  249. end
  250. #-----------
  251. def Color.gray(alpha=255)
  252. return Color.new(128, 128, 128, alpha)
  253. end
  254. #-----------
  255. def Color.dark_gray(alpha=255)
  256. return Color.new(64, 64, 64, alpha)
  257. end
  258. #-----------
  259. def Color.pink(alpha=255)
  260. return Color.new(255, 175, 175, alpha)
  261. end
  262. #-----------
  263. def Color.orange(alpha=255)
  264. return Color.new(255, 200, 0, alpha)
  265. end
  266. end
  267. #=====================
  268. class Window_Base < Window
  269. # redefine text colors for static context
  270. def self.text_color(n)
  271. case n
  272. when 0
  273. return Color.new(255, 255, 255, 255)
  274. when 1
  275. return Color.new(128, 128, 255, 255)
  276. when 2
  277. return Color.new(255, 128, 128, 255)
  278. when 3
  279. return Color.new(128, 255, 128, 255)
  280. when 4
  281. return Color.new(128, 255, 255, 255)
  282. when 5
  283. return Color.new(255, 128, 255, 255)
  284. when 6
  285. return Color.new(255, 255, 128, 255)
  286. when 7
  287. return Color.new(192, 192, 192, 255)
  288. else
  289. return Color.white
  290. end
  291. end
  292. end
Expand to see the code.



  1. #//////////////////////////////////Questlog 3.0/////////////////////////////////
  2. #~~~~~~~~~~~~~~~~~~by Caesar~~~~~~~~~~~~~~~~~
  3. #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  4. #===================Parameter==================
  5. # Wenn true, werden neue Quests oben eingefügt, ansonsten unten
  6. INSERT_AT_TOP = true
  7. # Zeilenhöhe in der Questbeschreibung
  8. LINE_HEIGHT = 24
  9. # Windowskin der Questlog-Fenster (nil = default)
  10. WINDOWSKIN = nil
  11. # "Überschrift" des Questlogs
  12. HEADER_TEXT = "Questlog"
  13. # Geschwindigkeit beim Scrollen (Pixel / Frame)
  14. SCROLL_SPEED = 7
  15. # Styles für die Beschreibungen der Quests
  16. STYLES = {
  17. "h1" => "<size=45><font=Cambria><b>|</b></font></size><down=40>",
  18. "h2" => "<big><b><font=Cambria>|</font></b></big><down=32>",
  19. "disabled" => "<color=disabled_color>|</color>",
  20. "highlight" => "<color=#eeee32>|</color>",
  21. "system" => "<color=system_color>|</color>"
  22. }
  23. # Dieser Process wird ausgeführt, sobald das Questlog geschlossen wird;
  24. # (Default: Spieler kommt wieder auf die Map)
  25. ON_CLOSE = Proc.new {$scene = Scene_Map.new}
  26. #============================================
  27. class Scene_Questlog
  28. def main
  29. @window_header = Window_Help.new
  30. @window_header.x = 65
  31. @window_header.y = 28
  32. @window_header.z = 500
  33. @window_header.width = 510
  34. @window_header.windowskin = RPG::Cache.windowskin(WINDOWSKIN) unless
  35. WINDOWSKIN.nil?
  36. @window_header.contents = Bitmap.new(478, 32)
  37. @window_header.contents.font.size = 30
  38. @window_header.contents.draw_text(0, 0, 510, 32, HEADER_TEXT, 1)
  39. @window_titles = Window_Questlog_Titles.new
  40. @window_titles.windowskin = RPG::Cache.windowskin(WINDOWSKIN) unless
  41. WINDOWSKIN.nil?
  42. @window_description = Window_Questlog_Description.new(
  43. $game_system.questlog.quests.map{|q| q.description})
  44. @window_description.windowskin = RPG::Cache.windowskin(WINDOWSKIN) unless
  45. WINDOWSKIN.nil?
  46. @index = @window_titles.index
  47. spriteset = Spriteset_Map.new
  48. Graphics.transition
  49. loop do
  50. Graphics.update
  51. Input.update
  52. update
  53. if $scene != self
  54. break
  55. end
  56. end
  57. Graphics.freeze
  58. @window_header.dispose
  59. @window_titles.dispose
  60. @window_description.dispose
  61. spriteset.dispose
  62. end
  63. #----------------
  64. def update
  65. @window_titles.update
  66. if Input.trigger?(Input::B)
  67. $game_system.se_play($data_system.cancel_se)
  68. ON_CLOSE.call
  69. return
  70. end
  71. if Input.press?(Input::R)
  72. @window_description.scroll_down
  73. elsif Input.press?(Input::L)
  74. @window_description.scroll_up
  75. end
  76. if @index != @window_titles.index
  77. @window_description.index = @index = @window_titles.index
  78. end
  79. end
  80. end
  81. #=============
  82. class Quest
  83. attr_reader :title
  84. attr_reader :description
  85. def initialize(title, description)
  86. @title = title
  87. @description = description
  88. end
  89. end
  90. #============
  91. class Questlog
  92. attr_reader :quests
  93. def initialize
  94. @quests = []
  95. end
  96. #-----------
  97. def add(quest, description="")
  98. return add(Quest.new(quest, description)) unless quest.is_a?(Quest)
  99. i = index(quest.title)
  100. return @quests[i] = quest if i != nil
  101. if INSERT_AT_TOP
  102. # insert quest at top of the list
  103. @quests.unshift(quest)
  104. else
  105. # insert quest at bottom of the list
  106. @quests.push(quest)
  107. end
  108. end
  109. #-----------
  110. def remove(title)
  111. @quests.delete_if{ |quest| quest.title == title}
  112. end
  113. #-----------
  114. def count
  115. return @quests.length
  116. end
  117. #------------
  118. def index(title)
  119. for i in [email hidden]-1
  120. return i if @quests[i].title == title
  121. end
  122. return nil
  123. end
  124. #------------
  125. def Questlog.add(title, description="")
  126. $game_system.questlog.add(title, description)
  127. end
  128. #------------
  129. def Questlog.remove(title)
  130. $game_system.questlog.remove(title)
  131. end
  132. end
  133. #=============
  134. class Window_Questlog_Description < Window_Base
  135. attr_reader :index
  136. #------------------
  137. def initialize(descriptions)
  138. super(275, 92, 300, 360)
  139. @descriptions = descriptions
  140. @cache = Array.new(descriptions.size)
  141. self.contents = Bitmap.new(width-32, height-32)
  142. self.index = 0
  143. self.z = 500
  144. end
  145. #-----------
  146. def index=(index)
  147. return if index == @index or @descriptions.empty?
  148. @index = index
  149. self.oy = 0
  150. # bitmaps are only rendered once and than cached to reach more efficiency
  151. if @cache[index].nil?
  152. buffer = Bitmap.new(width-32, 2000)
  153. docheight = buffer.draw_html(0, 0, 270, 2000, @descriptions[index])
  154. @cache[index] = self.contents = Bitmap.new(width-32, docheight)
  155. self.contents.blt(0, 0, buffer, Rect.new(0, 0, self.width-32, docheight))
  156. else
  157. self.contents = @cache[index]
  158. end
  159. end
  160. #-----------
  161. def scroll_down
  162. self.oy += SCROLL_SPEED if self.height + self.oy - 32 < self.contents.height
  163. end
  164. #------------
  165. def scroll_up
  166. self.oy -= SCROLL_SPEED
  167. self.oy = 0 if self.oy < 0
  168. end
  169. end
  170. #=============
  171. class Window_Questlog_Titles < Window_Base
  172. attr_reader :index
  173. def initialize
  174. super(65, 92, 210, 360)
  175. self.z = 500
  176. @item_max = $game_system.questlog.count
  177. self.contents = Bitmap.new(width-32, @item_max > 0 ? @item_max*32 : 32)
  178. @index = 0
  179. refresh
  180. end
  181. #-------------
  182. def index=(index)
  183. @index = index
  184. update_cursor_rect
  185. end
  186. #-------------
  187. def top_row=(row)
  188. if row < 0
  189. row = 0
  190. end
  191. if row > @item_max - 1
  192. row = @item_max - 1
  193. end
  194. self.oy = row * 32
  195. end
  196. #-------------
  197. def page_row_max
  198. return (self.height - 32) / 32
  199. end
  200. #-------------
  201. def page_item_max
  202. return page_row_max * @column_max
  203. end
  204. #-------------
  205. def update_cursor_rect
  206. if @index < 0
  207. self.cursor_rect.empty
  208. return
  209. end
  210. row = @index
  211. top_row = self.oy / 32
  212. if row < top_row
  213. self.top_row = row
  214. end
  215. if row > top_row + (self.page_row_max - 1)
  216. self.top_row = row - (self.page_row_max - 1)
  217. end
  218. self.cursor_rect.set(0, @index * 32 - self.oy, self.width - 32, 32)
  219. end
  220. #-------------
  221. def refresh
  222. self.contents.clear
  223. for i in 0...$game_system.questlog.count
  224. quest = $game_system.questlog.quests[i]
  225. y = i*32
  226. self.contents.draw_html(4, y, 150, 32, quest.title)
  227. end
  228. end
  229. #------------
  230. def update
  231. super
  232. if self.active and @item_max > 0 and @index >= 0
  233. if Input.repeat?(Input::DOWN) and
  234. (Input.trigger?(Input::DOWN) or @index < @item_max - 1)
  235. $game_system.se_play($data_system.cursor_se)
  236. @index = (@index + 1) % @item_max
  237. end
  238. if Input.repeat?(Input::UP) and
  239. (Input.trigger?(Input::UP) or @index > 0)
  240. $game_system.se_play($data_system.cursor_se)
  241. @index = (@index - 1 + @item_max) % @item_max
  242. end
  243. end
  244. update_cursor_rect
  245. end
  246. end
  247. #===========
  248. class Scene_Map
  249. def call_questlog
  250. $game_temp.questlog_calling = false
  251. $game_player.straighten
  252. $scene = Scene_Questlog.new
  253. end
  254. end
  255. #===========
  256. class Game_System
  257. attr_accessor :questlog
  258. alias questlog_init initialize
  259. def initialize
  260. questlog_init
  261. @questlog = Questlog.new
  262. end
  263. end
  264. #===========
  265. class Game_Temp
  266. attr_accessor :questlog_calling
  267. alias questlog_init initialize
  268. def initialize
  269. questlog_init
  270. @questlog_calling = false
  271. end
  272. end
  273. #========================
  274. class Scene_Load < Scene_File
  275. # if a game that does not yet contain the questlog is loaded
  276. # a new (empty) questlog instance is created
  277. alias questlog_read_save_data read_save_data
  278. def read_save_data(file)
  279. questlog_read_save_data(file)
  280. $game_system.questlog = Questlog.new if $game_system.questlog.nil?
  281. end
  282. end
Expand to see the code.
Image
The top highlighted line in green is the original (without the #)
Change it to the bottom line. The +4 is what the item menu uses to center the icon in the cursor box.

As you can see in your screenshot the line hugs the top of the cursor.
You might also consider +4 to the text line's positioning so its comfortably in the center of the rectangle.
Image

But this all depends on your Font & Text size, if you plan on changing it.
The shadow text line is above it, but I think you can ignore it. At the top of the script, Shadow is set to FALSE. If you change it to TRUE it adds a offset duplicate text as a shadow to all the text, which is dumb to leave it as all-or-none.
I changed this line at 124 blt(ix + 8, iy + LINE_HEIGHT/2 - 12, icon, Rect.new(0, 0, 24, 24))
with this one:
blt(ix + 8, y + 4 , icon, Rect.new(0, 0, 24, 24))

And at 161 I replaced this:
draw_text(x+ix+4, y+iy, 40, font.size, c)
with this:
draw_text(x+ix+4, y+iy+4, 40, font.size, c)

It worked. Thank you very much. You have helpt me yet again.
As I see your work in the forum, you know both scripting and pixeling, you are indeed very talented.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=79009