• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Custom Message Position

  • 1,224
    Posts
    10
    Years
    Trying to add a new type of Message that lets me set the x and y values of it, however with what I currently have the y value will not change. Anybody know why?
    Code:
    def Kernel.pbCustomMessage(message,skin=nil,newx=nil,newy=nil,newwidth=nil,&block)
      ret=0
      msgwindow=Kernel.pbCreateMessageWindow(nil,skin)
      msgwindow.x=newx if newx!=nil
      if newwidth!=nil
        newlength=message.split(" ")
        newlength=newlength.max.length
        msgwindow.width=newwidth+newlength
      else
      msgwindow.width=Graphics.width-msgwindow.x
      end
      msgwindow.y=newy if newy!=nil
      Kernel.pbMessageDisplay(msgwindow,message,&block)
      Kernel.pbDisposeMessageWindow(msgwindow)
      Input.update
      return ret
    end
    Edit: Added customizable width. Still no y value
     
    Last edited:
  • 1,224
    Posts
    10
    Years
    Woot, figured out a way. Added a new text shortcut similar to \pn and such, this one is \q[XX] where XX is the y value to change it to

    Code:
    def Kernel.pbMessageDisplay(msgwindow,message,letterbyletter=true,commandProc=nil)
      return if !msgwindow
      oldletterbyletter=msgwindow.letterbyletter
      msgwindow.letterbyletter=(letterbyletter ? true : false)
      ret=nil
      count=0
      commands=nil
      facewindow=nil
      goldwindow=nil
      coinwindow=nil
      cmdvariable=0
      cmdIfCancel=0
      msgwindow.waitcount=0
      autoresume=false
      text=message.clone
      msgback=nil
      linecount=(Graphics.height>400) ? 3 : 2
      ### Text replacement
      text.gsub!(/\\\\/,"\5")
      if $game_actors
        text.gsub!(/\\[Nn]\[([1-8])\]/){ 
           m=$1.to_i
           next $game_actors[m].name
        }
      end
      text.gsub!(/\\[Ss][Ii][Gg][Nn]\[([^\]]*)\]/){ 
         next "\\op\\cl\\ts[]\\w["+$1+"]"
      }
      text.gsub!(/\\[Pp][Nn]/,$Trainer.name) if $Trainer
      text.gsub!(/\\[Pp][Mm]/,_INTL("${1}",$Trainer.money)) if $Trainer
      text.gsub!(/\\[Nn]/,"\n")
      text.gsub!(/\\\[([0-9A-Fa-f]{8,8})\]/){ "<c2="+$1+">" }
      text.gsub!(/\\[Pp][Gg]/,"\\b") if $Trainer && $Trainer.gender==0
      text.gsub!(/\\[Pp][Gg]/,"\\r") if $Trainer && $Trainer.gender==1
      text.gsub!(/\\[Pp][Oo][Gg]/,"\\r") if $Trainer && $Trainer.gender==0
      text.gsub!(/\\[Pp][Oo][Gg]/,"\\b") if $Trainer && $Trainer.gender==1
      text.gsub!(/\\[Pp][Gg]/,"")
      text.gsub!(/\\[Pp][Oo][Gg]/,"")
      text.gsub!(/\\[Bb]/,"<c2=6546675A>")
      text.gsub!(/\\[Rr]/,"<c2=043C675A>")
      text.gsub!(/\\1/,"\1")
      colortag=""
      isDarkSkin=isDarkWindowskin(msgwindow.windowskin)
      if ($game_message && $game_message.background>0) ||
         ($game_system && $game_system.respond_to?("message_frame") &&
          $game_system.message_frame != 0)
        colortag=getSkinColor(msgwindow.windowskin,0,true)
      else
        colortag=getSkinColor(msgwindow.windowskin,0,isDarkSkin)
      end
      text.gsub!(/\\[Cc]\[([0-9]+)\]/){ 
         m=$1.to_i
         next getSkinColor(msgwindow.windowskin,m,isDarkSkin)
      }
      begin
        last_text = text.clone
        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
      end until text == last_text
      begin
        last_text = text.clone
        text.gsub!(/\\[Ll]\[([0-9]+)\]/) { 
           linecount=[1,$1.to_i].max;
           next "" 
        }
      end until text == last_text
      text=colortag+text
      ### Controls
      textchunks=[]
      controls=[]
      while text[/(?:\\([WwFf]|[Ff][Ff]|[Tt][Ss]|[Cc][Ll]|[Mm][Ee]|[Ss][Ee]|[Ww][Tt]|[Ww][Tt][Nn][Pp]|[Cc][Hh]|[Qq])\[([^\]]*)\]|\\([Gg]|[Cc][Nn]|[Ww][Dd]|[Ww][Mm]|[Oo][Pp]|[Cc][Ll]|[Ww][Uu]|[\.]|[\|]|[\!]|[\x5E])())/i]
        textchunks.push($~.pre_match)
        if $~[1]
          controls.push([$~[1].downcase,$~[2],-1])
        else
          controls.push([$~[3].downcase,"",-1])
        end
        text=$~.post_match
      end
      textchunks.push(text)
      for chunk in textchunks
        chunk.gsub!(/\005/,"\\")
      end
      textlen=0
      for i in 0...controls.length
        control=controls[i][0]
        if control=="wt" || control=="wtnp" || control=="." || control=="|"
          textchunks[i]+="\2"
        elsif control=="!"
          textchunks[i]+="\1"
        end
        textlen+=toUnformattedText(textchunks[i]).scan(/./m).length
        controls[i][2]=textlen
      end
      text=textchunks.join("")
      unformattedText=toUnformattedText(text)
      signWaitCount=0
      haveSpecialClose=false
      specialCloseSE=""
      for i in 0...controls.length
        control=controls[i][0]
        param=controls[i][1]
        if control=="f"
          facewindow.dispose if facewindow
          facewindow=PictureWindow.new("Graphics/Pictures/#{param}")
        elsif control=="op"
          signWaitCount=21
        elsif control=="cl"
          text=text.sub(/\001\z/,"") # fix: '$' can match end of line as well
          haveSpecialClose=true
          specialCloseSE=param
        elsif control=="se" && controls[i][2]==0
          startSE=param
          controls[i]=nil
        elsif control=="ff"
          facewindow.dispose if facewindow
          facewindow=FaceWindowVX.new(param)
        elsif control=="q"
          yval=param.to_i
        elsif control=="ch"
          cmds=param.clone
          cmdvariable=pbCsvPosInt!(cmds)
          cmdIfCancel=pbCsvField!(cmds).to_i
          commands=[]
          while cmds.length>0
            commands.push(pbCsvField!(cmds))
          end
        elsif control=="wtnp" || control=="^"
          text=text.sub(/\001\z/,"") # fix: '$' can match end of line as well
        end
      end
      if startSE!=nil
        pbSEPlay(pbStringToAudioFile(startSE))
      elsif signWaitCount==0 && letterbyletter
        pbPlayDecisionSE()
      end
      ########## Position message window  ##############
      pbRepositionMessageWindow(msgwindow,linecount)
      if $game_message && $game_message.background==1
        msgback=IconSprite.new(0,msgwindow.y,msgwindow.viewport)
        msgback.z=msgwindow.z-1
        msgback.setBitmap("Graphics/System/MessageBack")
      end
      if facewindow
        pbPositionNearMsgWindow(facewindow,msgwindow,:left)
        facewindow.viewport=msgwindow.viewport
        facewindow.z=msgwindow.z
      end
      atTop=(msgwindow.y==0)
      ########## Show text #############################
      msgwindow.text=text
      Graphics.frame_reset if Graphics.frame_rate>40
      begin
        if signWaitCount>0
          signWaitCount-=1
          if atTop
            msgwindow.y=-(msgwindow.height*(signWaitCount)/20)
          else
            msgwindow.y=Graphics.height-(msgwindow.height*(20-signWaitCount)/20)
          end
        end
        for i in 0...controls.length
          if controls[i] && controls[i][2]<=msgwindow.position && msgwindow.waitcount==0
            control=controls[i][0]
            param=controls[i][1]
            if control=="f"
              facewindow.dispose if facewindow
              facewindow=PictureWindow.new("Graphics/Pictures/#{param}")
              pbPositionNearMsgWindow(facewindow,msgwindow,:left)
              facewindow.viewport=msgwindow.viewport
              facewindow.z=msgwindow.z
            elsif control=="ts"
              if param==""
                msgwindow.textspeed=-999
              else
                msgwindow.textspeed=param.to_i
              end
            elsif control=="ff"
              facewindow.dispose if facewindow
              facewindow=FaceWindowVX.new(param)
              pbPositionNearMsgWindow(facewindow,msgwindow,:left)
              facewindow.viewport=msgwindow.viewport
              facewindow.z=msgwindow.z
            elsif control=="g" # Display gold window
              goldwindow.dispose if goldwindow
              goldwindow=pbDisplayGoldWindow(msgwindow)
            elsif control=="cn" # Display coins window
              coinwindow.dispose if coinwindow
              coinwindow=pbDisplayCoinsWindow(msgwindow,goldwindow)
            elsif control=="wu"
              msgwindow.y=0
              atTop=true
              msgback.y=msgwindow.y if msgback
              pbPositionNearMsgWindow(facewindow,msgwindow,:left)
              msgwindow.y=-(msgwindow.height*(signWaitCount)/20)
            elsif control=="wm"
              atTop=false
              msgwindow.y=(Graphics.height/2)-(msgwindow.height/2)
              msgback.y=msgwindow.y if msgback
              pbPositionNearMsgWindow(facewindow,msgwindow,:left)
            elsif control=="wd"
              atTop=false
              msgwindow.y=(Graphics.height)-(msgwindow.height)
              msgback.y=msgwindow.y if msgback
              pbPositionNearMsgWindow(facewindow,msgwindow,:left)
              msgwindow.y=Graphics.height-(msgwindow.height*(20-signWaitCount)/20)
            elsif control=="."
              msgwindow.waitcount+=Graphics.frame_rate/4
            elsif control=="|"
              msgwindow.waitcount+=Graphics.frame_rate
            elsif control=="wt" # Wait
              param=param.sub(/\A\s+/,"").sub(/\s+\z/,"")
              msgwindow.waitcount+=param.to_i*2
            elsif control=="w" # Windowskin
              if param==""
                msgwindow.windowskin=nil
              else
                msgwindow.setSkin("Graphics/Windowskins/#{param}")
              end
              msgwindow.width=msgwindow.width  # Necessary evil
            elsif control=="^" # Wait, no pause
              autoresume=true
            elsif control=="wtnp" # Wait, no pause
              param=param.sub(/\A\s+/,"").sub(/\s+\z/,"")
              msgwindow.waitcount=param.to_i*2
              autoresume=true
            elsif control=="se" # Play SE
              pbSEPlay(pbStringToAudioFile(param))
            elsif control=="me" # Play ME
              pbMEPlay(pbStringToAudioFile(param))
            end
            controls[i]=nil
          end
        end
        if yval
            msgwindow.y=yval
        end
        break if !letterbyletter
        Graphics.update
        Input.update
        facewindow.update if facewindow
        if $DEBUG && Input.trigger?(Input::F6)
          pbRecord(unformattedText)
        end
        if autoresume && msgwindow.waitcount==0
          msgwindow.resume if msgwindow.busy?
          break if !msgwindow.busy?
        end
        if (Input.trigger?(Input::C) || Input.trigger?(Input::B))
          if msgwindow.busy?
            pbPlayDecisionSE() if msgwindow.pausing?
            msgwindow.resume
          else
            break if signWaitCount==0
          end
        end
        pbUpdateSceneMap
        msgwindow.update
        yield if block_given?
      end until (!letterbyletter || commandProc || commands) && !msgwindow.busy?
      Input.update # Must call Input.update again to avoid extra triggers
      msgwindow.letterbyletter=oldletterbyletter
      if commands
        $game_variables[cmdvariable]=Kernel.pbShowCommands(
           msgwindow,commands,cmdIfCancel)
        $game_map.need_refresh = true if $game_map
      end
      if commandProc
        ret=commandProc.call(msgwindow)
      end
      msgback.dispose if msgback
      goldwindow.dispose if goldwindow
      coinwindow.dispose if coinwindow
      facewindow.dispose if facewindow
      if haveSpecialClose
        pbSEPlay(pbStringToAudioFile(specialCloseSE))
        atTop=(msgwindow.y==0)
        for i in 0..20
          if atTop
            msgwindow.y=-(msgwindow.height*(i)/20)
          else
            msgwindow.y=Graphics.height-(msgwindow.height*(20-i)/20)
          end
          Graphics.update
          Input.update
          pbUpdateSceneMap
          msgwindow.update
        end
      end
      return ret
    end
     
    Back
    Top