Advertisement
TechSkylander1518

Mr. Gela's Portraits for v19.0

Jul 19th, 2021 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 30.60 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. #===============================================================================
  4. class Scene_Map
  5.   def updatemini
  6.     oldmws=$game_temp.message_window_showing
  7.     oldvis=false
  8.     $game_temp.message_window_showing=true
  9.     loop do
  10.       $game_map.update
  11.       $game_player.update
  12.       $game_system.update
  13.       if $game_screen
  14.         $game_screen.update
  15.       else
  16.         $game_map.screen.update
  17.       end
  18.       break unless $game_temp.player_transferring
  19.       transfer_player
  20.       break if $game_temp.transition_processing
  21.     end
  22.     $game_temp.message_window_showing=oldmws
  23.     @spriteset.update if @spriteset
  24.     @message_window.update if @message_window
  25.   end
  26. end
  27.  
  28.  
  29.  
  30. class Scene_Battle
  31.   def updatemini
  32.     if self.respond_to?("update_basic")
  33.       update_basic(true)
  34.       update_info_viewport                  # Update information viewport
  35.     else
  36.       oldmws=$game_temp.message_window_showing
  37.       $game_temp.message_window_showing=true
  38.       # Update system (timer) and screen
  39.       $game_system.update
  40.       if $game_screen
  41.         $game_screen.update
  42.       else
  43.         $game_map.screen.update
  44.       end
  45.       # If timer has reached 0
  46.       if $game_system.timer_working && $game_system.timer == 0
  47.         # Abort battle
  48.         $game_temp.battle_abort = true
  49.       end
  50.       # Update windows
  51.       @help_window.update if @help_window
  52.       @party_command_window.update if @party_command_window
  53.       @actor_command_window.update if @actor_command_window
  54.       @status_window.update if @status_window
  55.       $game_temp.message_window_showing=oldmws
  56.       @message_window.update if @message_window
  57.       # Update sprite set
  58.       @spriteset.update if @spriteset
  59.     end
  60.   end
  61. end
  62.  
  63.  
  64.  
  65. def pbMapInterpreter
  66.   if $game_map.respond_to?("interpreter")
  67.     return $game_map.interpreter
  68.   elsif $game_system
  69.     return $game_system.map_interpreter
  70.   end
  71.   return nil
  72. end
  73.  
  74. def pbMapInterpreterRunning?
  75.   interp = pbMapInterpreter
  76.   return interp && interp.running?
  77. end
  78.  
  79. def pbRefreshSceneMap
  80.   if $scene && $scene.is_a?(Scene_Map)
  81.     if $scene.respond_to?("miniupdate")
  82.       $scene.miniupdate
  83.     else
  84.       $scene.updatemini
  85.     end
  86.   elsif $scene && $scene.is_a?(Scene_Battle)
  87.     $scene.updatemini
  88.   end
  89. end
  90.  
  91. def pbUpdateSceneMap
  92.   if $scene && $scene.is_a?(Scene_Map) && !pbIsFaded?
  93.     if $scene.respond_to?("miniupdate")
  94.       $scene.miniupdate
  95.     else
  96.       $scene.updatemini
  97.     end
  98.   elsif $scene && $scene.is_a?(Scene_Battle)
  99.     $scene.updatemini
  100.   end
  101. end
  102.  
  103. #===============================================================================
  104. #
  105. #===============================================================================
  106. def pbEventCommentInput(*args)
  107.   parameters = []
  108.   list = *args[0].list   # Event or event page
  109.   elements = *args[1]    # Number of elements
  110.   trigger = *args[2]     # Trigger
  111.   return nil if list == nil
  112.   return nil unless list.is_a?(Array)
  113.   for item in list
  114.     next unless item.code == 108 || item.code == 408
  115.     if item.parameters[0] == trigger
  116.       start = list.index(item) + 1
  117.       finish = start + elements
  118.       for id in start...finish
  119.         next if !list[id]
  120.         parameters.push(list[id].parameters[0])
  121.       end
  122.       return parameters
  123.     end
  124.   end
  125.   return nil
  126. end
  127.  
  128. def pbCurrentEventCommentInput(elements,trigger)
  129.   return nil if !pbMapInterpreterRunning?
  130.   event = pbMapInterpreter.get_character(0)
  131.   return nil if !event
  132.   return pbEventCommentInput(event,elements,trigger)
  133. end
  134.  
  135.  
  136.  
  137. #===============================================================================
  138. #
  139. #===============================================================================
  140. class ChooseNumberParams
  141.   def initialize
  142.     @maxDigits=0
  143.     @minNumber=0
  144.     @maxNumber=0
  145.     @skin=nil
  146.     @messageSkin=nil
  147.     @negativesAllowed=false
  148.     @initialNumber=0
  149.     @cancelNumber=nil
  150.   end
  151.  
  152.   def setMessageSkin(value)
  153.     @messageSkin=value
  154.   end
  155.  
  156.   def messageSkin   # Set the full path for the message's window skin
  157.     @messageSkin
  158.   end
  159.  
  160.   def setSkin(value)
  161.     @skin=value
  162.   end
  163.  
  164.   def skin
  165.     @skin
  166.   end
  167.  
  168.   def setNegativesAllowed(value)
  169.     @negativeAllowed=value
  170.   end
  171.  
  172.   def negativesAllowed
  173.     @negativeAllowed ? true : false
  174.   end
  175.  
  176.   def setRange(minNumber,maxNumber)
  177.     maxNumber=minNumber if minNumber>maxNumber
  178.     @maxDigits=0
  179.     @minNumber=minNumber
  180.     @maxNumber=maxNumber
  181.   end
  182.  
  183.   def setDefaultValue(number)
  184.     @initialNumber=number
  185.     @cancelNumber=nil
  186.   end
  187.  
  188.   def setInitialValue(number)
  189.     @initialNumber=number
  190.   end
  191.  
  192.   def setCancelValue(number)
  193.     @cancelNumber=number
  194.   end
  195.  
  196.   def initialNumber
  197.     return clamp(@initialNumber,self.minNumber,self.maxNumber)
  198.   end
  199.  
  200.   def cancelNumber
  201.     return @cancelNumber || self.initialNumber
  202.   end
  203.  
  204.   def minNumber
  205.     ret=0
  206.     if @maxDigits>0
  207.       ret=-((10**@maxDigits)-1)
  208.     else
  209.       ret=@minNumber
  210.     end
  211.     ret=0 if !@negativeAllowed && ret<0
  212.     return ret
  213.   end
  214.  
  215.   def maxNumber
  216.     ret=0
  217.     if @maxDigits>0
  218.       ret=((10**@maxDigits)-1)
  219.     else
  220.       ret=@maxNumber
  221.     end
  222.     ret=0 if !@negativeAllowed && ret<0
  223.     return ret
  224.   end
  225.  
  226.   def setMaxDigits(value)
  227.     @maxDigits=[1,value].max
  228.   end
  229.  
  230.   def maxDigits
  231.     if @maxDigits>0
  232.       return @maxDigits
  233.     else
  234.       return [numDigits(self.minNumber),numDigits(self.maxNumber)].max
  235.     end
  236.   end
  237.  
  238.   private
  239.  
  240.   def clamp(v,mn,mx)
  241.     return v<mn ? mn : (v>mx ? mx : v)
  242.   end
  243.  
  244.   def numDigits(number)
  245.     ans = 1
  246.     number=number.abs
  247.     while number >= 10
  248.       ans+=1
  249.       number/=10
  250.     end
  251.     return ans
  252.   end
  253. end
  254.  
  255.  
  256.  
  257. def pbChooseNumber(msgwindow,params)
  258.   return 0 if !params
  259.   ret=0
  260.   maximum=params.maxNumber
  261.   minimum=params.minNumber
  262.   defaultNumber=params.initialNumber
  263.   cancelNumber=params.cancelNumber
  264.   cmdwindow=Window_InputNumberPokemon.new(params.maxDigits)
  265.   cmdwindow.z=99999
  266.   cmdwindow.visible=true
  267.   cmdwindow.setSkin(params.skin) if params.skin
  268.   cmdwindow.sign=params.negativesAllowed # must be set before number
  269.   cmdwindow.number=defaultNumber
  270.   pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  271.   loop do
  272.     Graphics.update
  273.     Input.update
  274.     pbUpdateSceneMap
  275.     cmdwindow.update
  276.     msgwindow.update if msgwindow
  277.     yield if block_given?
  278.     if Input.trigger?(Input::USE)
  279.       ret=cmdwindow.number
  280.       if ret>maximum
  281.         pbPlayBuzzerSE()
  282.       elsif ret<minimum
  283.         pbPlayBuzzerSE()
  284.       else
  285.         pbPlayDecisionSE()
  286.         break
  287.       end
  288.     elsif Input.trigger?(Input::BACK)
  289.       pbPlayCancelSE()
  290.       ret=cancelNumber
  291.       break
  292.     end
  293.   end
  294.   cmdwindow.dispose
  295.   Input.update
  296.   return ret
  297. end
  298.  
  299.  
  300.  
  301. #===============================================================================
  302. #
  303. #===============================================================================
  304. class FaceWindowVX < SpriteWindow_Base
  305.   def initialize(face)
  306.     super(0,0,128,128)
  307.     faceinfo=face.split(",")
  308.     facefile=pbResolveBitmap("Graphics/Faces/"+faceinfo[0])
  309.     facefile=pbResolveBitmap("Graphics/Pictures/"+faceinfo[0]) if !facefile
  310.     self.contents.dispose if self.contents
  311.     @faceIndex=faceinfo[1].to_i
  312.     @facebitmaptmp=AnimatedBitmap.new(facefile)
  313.     @facebitmap=BitmapWrapper.new(96,96)
  314.     @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  315.        (@faceIndex % 4) * 96,
  316.        (@faceIndex / 4) * 96, 96, 96
  317.     ))
  318.     self.contents=@facebitmap
  319.   end
  320.  
  321.   def update
  322.     super
  323.     if @facebitmaptmp.totalFrames>1
  324.       @facebitmaptmp.update
  325.       @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  326.          (@faceIndex % 4) * 96,
  327.          (@faceIndex / 4) * 96, 96, 96
  328.       ))
  329.     end
  330.   end
  331.  
  332.   def dispose
  333.     @facebitmaptmp.dispose
  334.     @facebitmap.dispose if @facebitmap
  335.     super
  336.   end
  337. end
  338.  
  339.  
  340.  
  341. #===============================================================================
  342. #
  343. #===============================================================================
  344. def pbGetBasicMapNameFromId(id)
  345.   begin
  346.     map = pbLoadMapInfos
  347.     return "" if !map
  348.     return map[id].name
  349.   rescue
  350.     return ""
  351.   end
  352. end
  353.  
  354. def pbGetMapNameFromId(id)
  355.   map=pbGetBasicMapNameFromId(id)
  356.   map.gsub!(/\\PN/,$Trainer.name) if $Trainer
  357.   return map
  358. end
  359.  
  360. def pbCsvField!(str)
  361.   ret=""
  362.   str.sub!(/\A\s*/,"")
  363.   if str[0,1]=="\""
  364.     str[0,1]=""
  365.     escaped=false
  366.     fieldbytes=0
  367.     str.scan(/./) do |s|
  368.       fieldbytes+=s.length
  369.       break if s=="\"" && !escaped
  370.       if s=="\\" && !escaped
  371.         escaped=true
  372.       else
  373.         ret+=s
  374.         escaped=false
  375.       end
  376.     end
  377.     str[0,fieldbytes]=""
  378.     if !str[/\A\s*,/] && !str[/\A\s*$/]
  379.       raise _INTL("Invalid quoted field (in: {1})",ret)
  380.     end
  381.     str[0,str.length]=$~.post_match
  382.   else
  383.     if str[/,/]
  384.       str[0,str.length]=$~.post_match
  385.       ret=$~.pre_match
  386.     else
  387.       ret=str.clone
  388.       str[0,str.length]=""
  389.     end
  390.     ret.gsub!(/\s+$/,"")
  391.   end
  392.   return ret
  393. end
  394.  
  395. def pbCsvPosInt!(str)
  396.   ret=pbCsvField!(str)
  397.   if !ret[/\A\d+$/]
  398.     raise _INTL("Field {1} is not a positive integer",ret)
  399.   end
  400.   return ret.to_i
  401. end
  402.  
  403.  
  404.  
  405. #===============================================================================
  406. # Money and coins windows
  407. #===============================================================================
  408. def pbGetGoldString
  409.   moneyString=""
  410.   begin
  411.     moneyString=_INTL("${1}",$Trainer.money.to_s_formatted)
  412.   rescue
  413.     if $data_system.respond_to?("words")
  414.       moneyString=_INTL("{1} {2}",$game_party.gold,$data_system.words.gold)
  415.     else
  416.       moneyString=_INTL("{1} {2}",$game_party.gold,Vocab.gold)
  417.     end
  418.   end
  419.   return moneyString
  420. end
  421.  
  422. def pbDisplayGoldWindow(msgwindow)
  423.   moneyString=pbGetGoldString()
  424.   goldwindow=Window_AdvancedTextPokemon.new(_INTL("Money:\n<ar>{1}</ar>",moneyString))
  425.   goldwindow.setSkin("Graphics/Windowskins/goldskin")
  426.   goldwindow.resizeToFit(goldwindow.text,Graphics.width)
  427.   goldwindow.width=160 if goldwindow.width<=160
  428.   if msgwindow.y==0
  429.     goldwindow.y=Graphics.height-goldwindow.height
  430.   else
  431.     goldwindow.y=0
  432.   end
  433.   goldwindow.viewport=msgwindow.viewport
  434.   goldwindow.z=msgwindow.z
  435.   return goldwindow
  436. end
  437.  
  438. def pbDisplayCoinsWindow(msgwindow,goldwindow)
  439.   coinString=($Trainer) ? $Trainer.coins.to_s_formatted : "0"
  440.   coinwindow=Window_AdvancedTextPokemon.new(_INTL("Coins:\n<ar>{1}</ar>",coinString))
  441.   coinwindow.setSkin("Graphics/Windowskins/goldskin")
  442.   coinwindow.resizeToFit(coinwindow.text,Graphics.width)
  443.   coinwindow.width=160 if coinwindow.width<=160
  444.   if msgwindow.y==0
  445.     coinwindow.y=(goldwindow) ? goldwindow.y-coinwindow.height : Graphics.height-coinwindow.height
  446.   else
  447.     coinwindow.y=(goldwindow) ? goldwindow.height : 0
  448.   end
  449.   coinwindow.viewport=msgwindow.viewport
  450.   coinwindow.z=msgwindow.z
  451.   return coinwindow
  452. end
  453.  
  454. def pbDisplayBattlePointsWindow(msgwindow)
  455.   pointsString = ($Trainer) ? $Trainer.battle_points.to_s_formatted : "0"
  456.   pointswindow=Window_AdvancedTextPokemon.new(_INTL("Battle Points:\n<ar>{1}</ar>", pointsString))
  457.   pointswindow.setSkin("Graphics/Windowskins/goldskin")
  458.   pointswindow.resizeToFit(pointswindow.text,Graphics.width)
  459.   pointswindow.width=160 if pointswindow.width<=160
  460.   if msgwindow.y==0
  461.     pointswindow.y=Graphics.height-pointswindow.height
  462.   else
  463.     pointswindow.y=0
  464.   end
  465.   pointswindow.viewport=msgwindow.viewport
  466.   pointswindow.z=msgwindow.z
  467.   return pointswindow
  468. end
  469.  
  470.  
  471.  
  472. #===============================================================================
  473. #
  474. #===============================================================================
  475. def pbCreateStatusWindow(viewport=nil)
  476.   msgwindow=Window_AdvancedTextPokemon.new("")
  477.   if !viewport
  478.     msgwindow.z=99999
  479.   else
  480.     msgwindow.viewport=viewport
  481.   end
  482.   msgwindow.visible=false
  483.   msgwindow.letterbyletter=false
  484.   pbBottomLeftLines(msgwindow,2)
  485.   skinfile=MessageConfig.pbGetSpeechFrame()
  486.   msgwindow.setSkin(skinfile)
  487.   return msgwindow
  488. end
  489.  
  490. def pbCreateMessageWindow(viewport=nil,skin=nil)
  491.   msgwindow=Window_AdvancedTextPokemon.new("")
  492.   if !viewport
  493.     msgwindow.z=99999
  494.   else
  495.     msgwindow.viewport=viewport
  496.   end
  497.   msgwindow.visible=true
  498.   msgwindow.letterbyletter=true
  499.   msgwindow.back_opacity=MessageConfig::WindowOpacity
  500.   pbBottomLeftLines(msgwindow,2)
  501.   $game_temp.message_window_showing=true if $game_temp
  502.   skin=MessageConfig.pbGetSpeechFrame() if !skin
  503.   msgwindow.setSkin(skin)
  504.   return msgwindow
  505. end
  506.  
  507. def pbDisposeMessageWindow(msgwindow)
  508.   $game_temp.message_window_showing=false if $game_temp
  509.   msgwindow.dispose
  510. end
  511.  
  512.  
  513.  
  514. #===============================================================================
  515. # Main message-displaying function
  516. #===============================================================================
  517. def pbMessageDisplay(msgwindow,message,letterbyletter=true,commandProc=nil)
  518.   return if !msgwindow
  519.   oldletterbyletter=msgwindow.letterbyletter
  520.   msgwindow.letterbyletter=(letterbyletter) ? true : false
  521.   ret=nil
  522.   commands=nil
  523.   facewindow=nil
  524.   #animport
  525.   facewindowL=nil
  526.   facewindowR=nil
  527.   goldwindow=nil
  528.   coinwindow=nil
  529.   battlepointswindow=nil
  530.   cmdvariable=0
  531.   cmdIfCancel=0
  532.   msgwindow.waitcount=0
  533.   autoresume=false
  534.   text=message.clone
  535.   msgback=nil
  536.   linecount=(Graphics.height>400) ? 3 : 2
  537.   ### Text replacement
  538.   text.gsub!(/\\sign\[([^\]]*)\]/i) {   # \sign[something] gets turned into
  539.     next "\\op\\cl\\ts[]\\w["+$1+"]"    # \op\cl\ts[]\w[something]
  540.   }
  541.   text.gsub!(/\\\\/,"\5")
  542.   text.gsub!(/\\1/,"\1")
  543.   if $game_actors
  544.     text.gsub!(/\\n\[([1-8])\]/i) {
  545.       m = $1.to_i
  546.       next $game_actors[m].name
  547.     }
  548.   end
  549.   text.gsub!(/\\pn/i,$Trainer.name) if $Trainer
  550.   text.gsub!(/\\pm/i,_INTL("${1}",$Trainer.money.to_s_formatted)) if $Trainer
  551.   text.gsub!(/\\n/i,"\n")
  552.   text.gsub!(/\\\[([0-9a-f]{8,8})\]/i) { "<c2="+$1+">" }
  553.   text.gsub!(/\\pg/i,"\\b") if $Trainer && $Trainer.male?
  554.   text.gsub!(/\\pg/i,"\\r") if $Trainer && $Trainer.female?
  555.   text.gsub!(/\\pog/i,"\\r") if $Trainer && $Trainer.male?
  556.   text.gsub!(/\\pog/i,"\\b") if $Trainer && $Trainer.female?
  557.   text.gsub!(/\\pg/i,"")
  558.   text.gsub!(/\\pog/i,"")
  559.   text.gsub!(/\\b/i,"<c3=3050C8,D0D0C8>")
  560.   text.gsub!(/\\r/i,"<c3=E00808,D0D0C8>")
  561.   text.gsub!(/\\[Ww]\[([^\]]*)\]/) {
  562.     w = $1.to_s
  563.     if w==""
  564.       msgwindow.windowskin = nil
  565.     else
  566.       msgwindow.setSkin("Graphics/Windowskins/#{w}",false)
  567.     end
  568.     next ""
  569.   }
  570.   isDarkSkin = isDarkWindowskin(msgwindow.windowskin)
  571.   text.gsub!(/\\[Cc]\[([0-9]+)\]/) {
  572.     m = $1.to_i
  573.     next getSkinColor(msgwindow.windowskin,m,isDarkSkin)
  574.   }
  575.   loop do
  576.     last_text = text.clone
  577.     text.gsub!(/\\v\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  578.     break if text == last_text
  579.   end
  580.   loop do
  581.     last_text = text.clone
  582.     text.gsub!(/\\l\[([0-9]+)\]/i) {
  583.       linecount = [1,$1.to_i].max
  584.       next ""
  585.     }
  586.     break if text == last_text
  587.   end
  588.   colortag = ""
  589.   if $game_system && $game_system.respond_to?("message_frame") &&
  590.      $game_system.message_frame != 0
  591.     colortag = getSkinColor(msgwindow.windowskin,0,true)
  592.   else
  593.     colortag = getSkinColor(msgwindow.windowskin,0,isDarkSkin)
  594.   end
  595.   text = colortag+text
  596.   ### Controls
  597.   textchunks=[]
  598.   controls=[]
  599.   #animport
  600.   while text[/(?:\\(f|ml|mr|ff|ts|cl|me|se|wt|wtnp|ch)\[([^\]]*)\]|\\(g|cn|pt|wd|wm|op|cl|wu|\.|\||\!|\^))/i]
  601.     textchunks.push($~.pre_match)
  602.     if $~[1]
  603.       controls.push([$~[1].downcase,$~[2],-1])
  604.     else
  605.       controls.push([$~[3].downcase,"",-1])
  606.     end
  607.     text=$~.post_match
  608.   end
  609.   textchunks.push(text)
  610.   for chunk in textchunks
  611.     chunk.gsub!(/\005/,"\\")
  612.   end
  613.   textlen = 0
  614.   for i in 0...controls.length
  615.     control = controls[i][0]
  616.     case control
  617.     when "wt", "wtnp", ".", "|"
  618.       textchunks[i] += "\2"
  619.     when "!"
  620.       textchunks[i] += "\1"
  621.     end
  622.     textlen += toUnformattedText(textchunks[i]).scan(/./m).length
  623.     controls[i][2] = textlen
  624.   end
  625.   text = textchunks.join("")
  626.   unformattedText = toUnformattedText(text)
  627.   signWaitCount = 0
  628.   signWaitTime = Graphics.frame_rate/2
  629.   haveSpecialClose = false
  630.   specialCloseSE = ""
  631.   for i in 0...controls.length
  632.     control = controls[i][0]
  633.     param = controls[i][1]
  634.     case control
  635.     when "op"
  636.       signWaitCount = signWaitTime+1
  637.     when "cl"
  638.       text = text.sub(/\001\z/,"")   # fix: '$' can match end of line as well
  639.       haveSpecialClose = true
  640.       specialCloseSE = param
  641.     when "f"
  642.       facewindow.dispose if facewindow
  643.       facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
  644.       #animport
  645.     when "ml" # Mug Shot (Left)
  646.       facewindowL.dispose if facewindowL
  647.       facewindowL=FaceWindowVXNew.new(param)
  648.       facewindowL.x=8
  649.       facewindowL.y=146-32
  650.     when "mr" # Mug Shot (Right)
  651.       facewindowR.dispose if facewindowR
  652.       facewindowR=FaceWindowVXNew.new(param)
  653.       facewindowR.x=320
  654.       facewindowR.y=146-32
  655.     when "ff"
  656.       facewindow.dispose if facewindow
  657.       facewindow = FaceWindowVX.new(param)
  658.     when "ch"
  659.       cmds = param.clone
  660.       cmdvariable = pbCsvPosInt!(cmds)
  661.       cmdIfCancel = pbCsvField!(cmds).to_i
  662.       commands = []
  663.       while cmds.length>0
  664.         commands.push(pbCsvField!(cmds))
  665.       end
  666.     when "wtnp", "^"
  667.       text = text.sub(/\001\z/,"")   # fix: '$' can match end of line as well
  668.     when "se"
  669.       if controls[i][2]==0
  670.         startSE = param
  671.         controls[i] = nil
  672.       end
  673.     end
  674.   end
  675.   if startSE!=nil
  676.     pbSEPlay(pbStringToAudioFile(startSE))
  677.   elsif signWaitCount==0 && letterbyletter
  678.     pbPlayDecisionSE()
  679.   end
  680.   ########## Position message window  ##############
  681.   pbRepositionMessageWindow(msgwindow,linecount)
  682.   if facewindow
  683.     pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  684.     facewindow.viewport = msgwindow.viewport
  685.     facewindow.z        = msgwindow.z
  686.   end
  687.   if facewindowL
  688.     facewindowL.viewport=msgwindow.viewport
  689.     facewindowL.z=msgwindow.z
  690.   end
  691.   if facewindowR
  692.     facewindowR.viewport=msgwindow.viewport
  693.     facewindowR.z=msgwindow.z
  694.   end
  695.   atTop = (msgwindow.y==0)
  696.   ########## Show text #############################
  697.   msgwindow.text = text
  698.   Graphics.frame_reset if Graphics.frame_rate>40
  699.   loop do
  700.     if signWaitCount>0
  701.       signWaitCount -= 1
  702.       if atTop
  703.         msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
  704.       else
  705.         msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
  706.       end
  707.     end
  708.     for i in 0...controls.length
  709.       next if !controls[i]
  710.       next if controls[i][2]>msgwindow.position || msgwindow.waitcount!=0
  711.       control = controls[i][0]
  712.       param = controls[i][1]
  713.       case control
  714.       when "f"
  715.         facewindow.dispose if facewindow
  716.         facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
  717.         pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  718.         facewindow.viewport = msgwindow.viewport
  719.         facewindow.z        = msgwindow.z
  720. #animport
  721.       when "ml" # Mug Shot (Left)
  722.         facewindowL.dispose if facewindowL
  723.         facewindowL=FaceWindowVXNew.new(param)
  724.         facewindowL.windowskin=nil
  725.         facewindowL.x=8
  726.         facewindowL.y=146-32
  727.         facewindowL.viewport=msgwindow.viewport
  728.         facewindowL.z=msgwindow.z
  729.       when "mr" # Mug Shot (Right)
  730.         facewindowR.dispose if facewindowR
  731.         facewindowR=FaceWindowVXNew.new(param)
  732.         facewindowR.windowskin=nil
  733.         facewindowR.x=320
  734.         facewindowR.y=146-32
  735.         facewindowR.viewport=msgwindow.viewport
  736.         facewindowR.z=msgwindow.z
  737.       when "ff"
  738.         facewindow.dispose if facewindow
  739.         facewindow = FaceWindowVX.new(param)
  740.         pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  741.         facewindow.viewport = msgwindow.viewport
  742.         facewindow.z        = msgwindow.z
  743.       when "g"      # Display gold window
  744.         goldwindow.dispose if goldwindow
  745.         goldwindow = pbDisplayGoldWindow(msgwindow)
  746.       when "cn"     # Display coins window
  747.         coinwindow.dispose if coinwindow
  748.         coinwindow = pbDisplayCoinsWindow(msgwindow,goldwindow)
  749.       when "pt"     # Display battle points window
  750.         battlepointswindow.dispose if battlepointswindow
  751.         battlepointswindow = pbDisplayBattlePointsWindow(msgwindow)
  752.       when "wu"
  753.         msgwindow.y = 0
  754.         atTop = true
  755.         msgback.y = msgwindow.y if msgback
  756.         pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  757.         msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
  758.       when "wm"
  759.         atTop = false
  760.         msgwindow.y = (Graphics.height-msgwindow.height)/2
  761.         msgback.y = msgwindow.y if msgback
  762.         pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  763.       when "wd"
  764.         atTop = false
  765.         msgwindow.y = Graphics.height-msgwindow.height
  766.         msgback.y = msgwindow.y if msgback
  767.         pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  768.         msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
  769.       when "ts"     # Change text speed
  770.         msgwindow.textspeed = (param=="") ? -999 : param.to_i
  771.       when "."      # Wait 0.25 seconds
  772.         msgwindow.waitcount += Graphics.frame_rate/4
  773.       when "|"      # Wait 1 second
  774.         msgwindow.waitcount += Graphics.frame_rate
  775.       when "wt"     # Wait X/20 seconds
  776.         param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  777.         msgwindow.waitcount += param.to_i*Graphics.frame_rate/20
  778.       when "wtnp"   # Wait X/20 seconds, no pause
  779.         param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  780.         msgwindow.waitcount = param.to_i*Graphics.frame_rate/20
  781.         autoresume = true
  782.       when "^"      # Wait, no pause
  783.         autoresume = true
  784.       when "se"     # Play SE
  785.         pbSEPlay(pbStringToAudioFile(param))
  786.       when "me"     # Play ME
  787.         pbMEPlay(pbStringToAudioFile(param))
  788.       end
  789.       controls[i] = nil
  790.     end
  791.     break if !letterbyletter
  792.     Graphics.update
  793.     Input.update
  794.     facewindow.update if facewindow
  795.     #animport
  796.     facewindowL.update if facewindowL
  797.     facewindowR.update if facewindowR
  798.     if autoresume && msgwindow.waitcount==0
  799.       msgwindow.resume if msgwindow.busy?
  800.       break if !msgwindow.busy?
  801.     end
  802.     if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
  803.       if msgwindow.busy?
  804.         pbPlayDecisionSE if msgwindow.pausing?
  805.         msgwindow.resume
  806.       else
  807.         break if signWaitCount==0
  808.       end
  809.     end
  810.     pbUpdateSceneMap
  811.     msgwindow.update
  812.     yield if block_given?
  813.     break if (!letterbyletter || commandProc || commands) && !msgwindow.busy?
  814.   end
  815.   Input.update   # Must call Input.update again to avoid extra triggers
  816.   msgwindow.letterbyletter=oldletterbyletter
  817.   if commands
  818.     $game_variables[cmdvariable]=pbShowCommands(msgwindow,commands,cmdIfCancel)
  819.     $game_map.need_refresh = true if $game_map
  820.   end
  821.   if commandProc
  822.     ret=commandProc.call(msgwindow)
  823.   end
  824.   msgback.dispose if msgback
  825.   goldwindow.dispose if goldwindow
  826.   coinwindow.dispose if coinwindow
  827.   battlepointswindow.dispose if battlepointswindow
  828.   facewindow.dispose if facewindow
  829.   facewindowL.dispose if facewindowL
  830.   facewindowR.dispose if facewindowR
  831.   if haveSpecialClose
  832.     pbSEPlay(pbStringToAudioFile(specialCloseSE))
  833.     atTop = (msgwindow.y==0)
  834.     for i in 0..signWaitTime
  835.       if atTop
  836.         msgwindow.y = -msgwindow.height*i/signWaitTime
  837.       else
  838.         msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-i)/signWaitTime
  839.       end
  840.       Graphics.update
  841.       Input.update
  842.       pbUpdateSceneMap
  843.       msgwindow.update
  844.     end
  845.   end
  846.   return ret
  847. end
  848.  
  849.  
  850.  
  851. #===============================================================================
  852. # Message-displaying functions
  853. #===============================================================================
  854. def pbMessage(message,commands=nil,cmdIfCancel=0,skin=nil,defaultCmd=0,&block)
  855.   ret = 0
  856.   msgwindow = pbCreateMessageWindow(nil,skin)
  857.   if commands
  858.     ret = pbMessageDisplay(msgwindow,message,true,
  859.        proc { |msgwindow|
  860.          next Kernel.pbShowCommands(msgwindow,commands,cmdIfCancel,defaultCmd,&block)
  861.        },&block)
  862.   else
  863.     pbMessageDisplay(msgwindow,message,&block)
  864.   end
  865.   pbDisposeMessageWindow(msgwindow)
  866.   Input.update
  867.   return ret
  868. end
  869.  
  870. def pbConfirmMessage(message,&block)
  871.   return (pbMessage(message,[_INTL("Yes"),_INTL("No")],2,&block)==0)
  872. end
  873.  
  874. def pbConfirmMessageSerious(message,&block)
  875.   return (pbMessage(message,[_INTL("No"),_INTL("Yes")],1,&block)==1)
  876. end
  877.  
  878. def pbMessageChooseNumber(message,params,&block)
  879.   msgwindow = pbCreateMessageWindow(nil,params.messageSkin)
  880.   ret = pbMessageDisplay(msgwindow,message,true,
  881.      proc { |msgwindow|
  882.        next pbChooseNumber(msgwindow,params,&block)
  883.      },&block)
  884.   pbDisposeMessageWindow(msgwindow)
  885.   return ret
  886. end
  887.  
  888. def pbShowCommands(msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
  889.   return 0 if !commands
  890.   cmdwindow=Window_CommandPokemonEx.new(commands)
  891.   cmdwindow.z=99999
  892.   cmdwindow.visible=true
  893.   cmdwindow.resizeToFit(cmdwindow.commands)
  894.   pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  895.   cmdwindow.index=defaultCmd
  896.   command=0
  897.   loop do
  898.     Graphics.update
  899.     Input.update
  900.     cmdwindow.update
  901.     msgwindow.update if msgwindow
  902.     yield if block_given?
  903.     if Input.trigger?(Input::BACK)
  904.       if cmdIfCancel>0
  905.         command=cmdIfCancel-1
  906.         break
  907.       elsif cmdIfCancel<0
  908.         command=cmdIfCancel
  909.         break
  910.       end
  911.     end
  912.     if Input.trigger?(Input::USE)
  913.       command=cmdwindow.index
  914.       break
  915.     end
  916.     pbUpdateSceneMap
  917.   end
  918.   ret=command
  919.   cmdwindow.dispose
  920.   Input.update
  921.   return ret
  922. end
  923.  
  924. def pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0)
  925.   msgwin=msgwindow
  926.   msgwin=pbCreateMessageWindow(nil) if !msgwindow
  927.   oldlbl=msgwin.letterbyletter
  928.   msgwin.letterbyletter=false
  929.   if commands
  930.     cmdwindow=Window_CommandPokemonEx.new(commands)
  931.     cmdwindow.z=99999
  932.     cmdwindow.visible=true
  933.     cmdwindow.resizeToFit(cmdwindow.commands)
  934.     cmdwindow.height=msgwin.y if cmdwindow.height>msgwin.y
  935.     cmdwindow.index=defaultCmd
  936.     command=0
  937.     msgwin.text=help[cmdwindow.index]
  938.     msgwin.width=msgwin.width   # Necessary evil to make it use the proper margins
  939.     loop do
  940.       Graphics.update
  941.       Input.update
  942.       oldindex=cmdwindow.index
  943.       cmdwindow.update
  944.       if oldindex!=cmdwindow.index
  945.         msgwin.text=help[cmdwindow.index]
  946.       end
  947.       msgwin.update
  948.       yield if block_given?
  949.       if Input.trigger?(Input::BACK)
  950.         if cmdIfCancel>0
  951.           command=cmdIfCancel-1
  952.           break
  953.         elsif cmdIfCancel<0
  954.           command=cmdIfCancel
  955.           break
  956.         end
  957.       end
  958.       if Input.trigger?(Input::USE)
  959.         command=cmdwindow.index
  960.         break
  961.       end
  962.       pbUpdateSceneMap
  963.     end
  964.     ret=command
  965.     cmdwindow.dispose
  966.     Input.update
  967.   end
  968.   msgwin.letterbyletter=oldlbl
  969.   msgwin.dispose if !msgwindow
  970.   return ret
  971. end
  972.  
  973. # frames is the number of 1/20 seconds to wait for
  974. def pbMessageWaitForInput(msgwindow,frames,showPause=false)
  975.   return if !frames || frames<=0
  976.   msgwindow.startPause if msgwindow && showPause
  977.   frames = frames*Graphics.frame_rate/20
  978.   frames.times do
  979.     Graphics.update
  980.     Input.update
  981.     msgwindow.update if msgwindow
  982.     pbUpdateSceneMap
  983.     if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
  984.       break
  985.     end
  986.     yield if block_given?
  987.   end
  988.   msgwindow.stopPause if msgwindow && showPause
  989. end
  990.  
  991. def pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width=240)
  992.   window=Window_TextEntry_Keyboard.new(currenttext,0,0,width,64)
  993.   ret=""
  994.   window.maxlength=maxlength
  995.   window.visible=true
  996.   window.z=99999
  997.   pbPositionNearMsgWindow(window,msgwindow,:right)
  998.   window.text=currenttext
  999.   window.passwordChar="*" if passwordbox
  1000.   Input.text_input = true
  1001.   loop do
  1002.     Graphics.update
  1003.     Input.update
  1004.     if Input.triggerex?(:ESCAPE)
  1005.       ret=currenttext
  1006.       break
  1007.     elsif Input.triggerex?(:RETURN)
  1008.       ret=window.text
  1009.       break
  1010.     end
  1011.     window.update
  1012.     msgwindow.update if msgwindow
  1013.     yield if block_given?
  1014.   end
  1015.   Input.text_input = false
  1016.   window.dispose
  1017.   Input.update
  1018.   return ret
  1019. end
  1020.  
  1021. def pbMessageFreeText(message,currenttext,passwordbox,maxlength,width=240,&block)
  1022.   msgwindow=pbCreateMessageWindow
  1023.   retval=pbMessageDisplay(msgwindow,message,true,
  1024.      proc { |msgwindow|
  1025.        next pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width,&block)
  1026.      },&block)
  1027.   pbDisposeMessageWindow(msgwindow)
  1028.   return retval
  1029. end
  1030.  
  1031. #animport
  1032.  
  1033. class FaceWindowVXNew < SpriteWindow_Base
  1034.   def initialize(face)
  1035.     super(0,0,192,192)
  1036.     self.windowskin=nil
  1037.     faceinfo=face.split(",")
  1038.     facefile=pbResolveBitmap("Graphics/Mugshots/"+faceinfo[0])
  1039.     facefile=pbResolveBitmap("Graphics/Pictures/"+faceinfo[0]) if !facefile
  1040.     self.contents.dispose if self.contents
  1041.     @faceIndex=faceinfo[1].to_i
  1042.     @facebitmaptmp=AnimatedBitmap.new(facefile)
  1043.     @facebitmap=BitmapWrapper.new(160,160)
  1044.     @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  1045.        (@faceIndex % 4) * 160,
  1046.        (@faceIndex / 4) * 160, 160, 160
  1047.     ))
  1048.     self.contents=@facebitmap
  1049.   end
  1050.  
  1051.   def update
  1052.     super
  1053.     if @facebitmaptmp.totalFrames>1
  1054.       @facebitmaptmp.update
  1055.       @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  1056.          (@faceIndex % 4) * 160,
  1057.          (@faceIndex / 4) * 160, 160, 160
  1058.       ))
  1059.     end
  1060.   end
  1061.  
  1062.   def dispose
  1063.     @facebitmaptmp.dispose
  1064.     @facebitmap.dispose if @facebitmap
  1065.     super
  1066.   end
  1067. end
  1068.  
  1069. class FaceWindowVXNew < SpriteWindow_Base
  1070.   def initialize(face)
  1071.     super(0,0,192,192)
  1072.     self.windowskin=nil
  1073.     faceinfo=face.split(",")
  1074.     facefile=pbResolveBitmap("Graphics/Faces/"+faceinfo[0]) #Tech added this- not sure why it wasn't in the original?
  1075.     facefile=pbResolveBitmap("Graphics/Mugshots/"+faceinfo[0]) if !facefile
  1076.     facefile=pbResolveBitmap("Graphics/Pictures/"+faceinfo[0]) if !facefile
  1077.     self.contents.dispose if self.contents
  1078.     @faceIndex=faceinfo[1].to_i
  1079.     @facebitmaptmp=AnimatedBitmap.new(facefile)
  1080.     @facebitmap=BitmapWrapper.new(160,160)
  1081.     @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  1082.        (@faceIndex % 4) * 160,
  1083.        (@faceIndex / 4) * 160, 160, 160
  1084.     ))
  1085.     self.contents=@facebitmap
  1086.   end
  1087.  
  1088.   def update
  1089.     super
  1090.     if @facebitmaptmp.totalFrames>1
  1091.       @facebitmaptmp.update
  1092.       @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  1093.          (@faceIndex % 4) * 160,
  1094.          (@faceIndex / 4) * 160, 160, 160
  1095.       ))
  1096.     end
  1097.   end
  1098.  
  1099.   def dispose
  1100.     @facebitmaptmp.dispose
  1101.     @facebitmap.dispose if @facebitmap
  1102.     super
  1103.   end
  1104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement