[XP][VXA] Localization

Started by ForeverZer0, July 26, 2012, 09:39:00 pm

Previous topic - Next topic

Zexion

Sorry i was busy today, but that's right. I forgot that I changed culture to language. I didn't think of that because I thought i had used the script from the original demo :P
Glad u figured it out though.

Rairun

December 22, 2015, 09:02:47 pm #41 Last Edit: December 22, 2015, 09:04:45 pm by Rairun
Great script! I have two questions:

- If I decide to go commercial with my game (not sure I will), am I allowed to use the VXA version of this script?

- I have been able to make this script work with pretty much all text I'm using in my game, except for this modified version of an Atelier RGSS script. Would it be complicated to make both scripts work together? I need to be able to have a comment like <Text = \loc[1]>

#==============================================================================
# +++ MOG - Event Text Popup (v1.1) +++
#==============================================================================
# By Moghunter
# https://atelierrgss.wordpress.com/
#- English
#1 - You're free to use all Atelier-Rgss scripts in commercial or non-commercial projects.
#2 - You're free to edit and adapt my scripts.
#==============================================================================
# Apresenta o um texto em cima do evento.
#==============================================================================
# Para ativa basta colocar um comentário com o prefixo:
#
# <Text = X>
# <Offset_text = x, y>
#
# X - Texto apresentado no evento.
#
# Exemplo
#
# <Text = Teleport>
# <Text = Save Point>
#
#==============================================================================
module MOG_EVENT_TEXT_POPUP
 #Definição da fonte.
 FONT_SIZE = 16
 FONT_BOLD = true
 FONT_COLOR = Color.new(255,255,255)
 #Definição da prioridade do Texto
 SCREEN_Z = 550
end  

#==============================================================================
# ■ Game CharacterBase
#==============================================================================
class Game_CharacterBase  
 attr_accessor :text
 attr_accessor :opacity
 attr_accessor :erased
 attr_accessor :offset_text
end

#==============================================================================
# ■ Game Event
#==============================================================================
class Game_Event < Game_Character  
 
#--------------------------------------------------------------------------
# ● Setup Page Setting
#--------------------------------------------------------------------------                    
 alias mog_event_text_setup_page_settings setup_page_settings
 def setup_page_settings
     mog_event_text_setup_page_settings
     setup_event_text
     setup_event_offset_text
 end
   
#--------------------------------------------------------------------------
# ● Setup Event Text
#--------------------------------------------------------------------------                      
 def setup_event_text
     return if @list == nil
     for command in @list
     if command.code == 108
        if command.parameters[0] =~ /<Text = ([^>]*)>/
           @text = $1
 
        end  
      end
     end
  end

  #
def setup_event_offset_text
     return if @list == nil
    for command in @list
    if command.code == 108
       if command.parameters[0] =~ /<Offset_text = (\-?\d+), (\-?\d+)>/
           @offset_text = [$1.to_i, $2.to_i]
           p @offset_text
        end
      end
     end
 end  
 
  #
 

end  

#==============================================================================
# ■ Sprite Character Text
#==============================================================================
class Sprite_Character_Text < Sprite_Base
 
 include MOG_EVENT_TEXT_POPUP
 
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------                    
 def initialize(viewport = nil,character,sprite)
     super(viewport)
     text_size = character.text.to_s.split(//)
     w = 32 + (FONT_SIZE / 2) * text_size.size rescue nil
     w = 32 if w == nil or w < 32
     self.bitmap = Bitmap.new(w,32)
     self.bitmap.font.size = FONT_SIZE
     self.bitmap.font.bold = FONT_BOLD
     self.bitmap.font.color = FONT_COLOR
     self.bitmap.draw_text(0,0,self.width,self.height,character.text.to_s,1) rescue nil
     update_position(character,sprite)
 end
 
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------                    
 def dispose
     super
     self.bitmap.dispose
 end  

#--------------------------------------------------------------------------
# ● Update Position
#--------------------------------------------------------------------------                    
 def update_position(character,sprite)
     if character.erased
        self.visible = false
        return
      end
     self.x = character.screen_x - self.width / 2 + character.offset_text[0]
     self.y = character.screen_y - (sprite.height + self.height) + character.offset_text[1]
     self.z = character.screen_z + SCREEN_Z
     self.visible = character.transparent == true ? false : true
     self.opacity = character.opacity
 end

end

#==============================================================================
# ■ Sprite Character
#==============================================================================
class Sprite_Character < Sprite_Base

#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------                    
 alias mog_event_text_initialize initialize
 def initialize(viewport, character = nil)
     mog_event_text_initialize(viewport, character)
     @character_text = ""
     @character_offset_text = [0,0]
     create_event_text
 end  
 
#--------------------------------------------------------------------------
# ● Create Event Text
#--------------------------------------------------------------------------                    
 def create_event_text
     return if @character == nil
     return if @character.text == nil
     return if @character.text == @character_text
     dispose_event_text
   if Input.press?(:X)
     @event_text = Sprite_Character_Text.new(viewport,@character,self)
     @character_text = @character.text
     @character_offset_text = @character.offset_text
   end
 end

#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------                  
 alias mog_event_text_dispose dispose
 def dispose
     mog_event_text_dispose
     dispose_event_text
 end  
 
#--------------------------------------------------------------------------
# ● Dispose Event Text
#--------------------------------------------------------------------------                    
 def dispose_event_text
     return if @event_text == nil
     @event_text.dispose ; @event_text = nil
     @character_offset_text = [0,0]
 end
 
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------                    
 alias mog_event_text_update update
 def update
     mog_event_text_update
     create_event_text ; update_event_text
 end  
 
#--------------------------------------------------------------------------
# ● Update Event Text
#--------------------------------------------------------------------------                    
 def update_event_text
     return if @event_text == nil
     if Input.press?(:X)
     @event_text.update_position(@character,self)
   else
     @character_text = ""
     end
 end
   
end

$mog_rgss3_event_text_popup = true

KK20

Because the XP version does not have any terms of use, VXA does not either.

Try replacing:

  def setup_event_text
      return if @list == nil
      for command in @list
      if command.code == 108
         if command.parameters[0] =~ /<Text = ([^>]*)>/
            @text = Localization.localize($1)
   
         end 
       end
      end
   end

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Rairun

December 23, 2015, 05:04:43 am #43 Last Edit: December 23, 2015, 05:56:51 am by Rairun
Sorry if I'm being stupid, but I just want to be 100% sure - does having no terms of use amount to being free to use commercially? I ask because I don't have any terms of use for my photography, for example, but I'm pretty sure I could still enforce copyright if I wanted to.

Also, thanks! I'm going to try again tonight when I'm on my laptop, but I think I've tried your exact solution, and it didn't work. :( If I remember it correctly, it threw a script error here:

      self.x = character.screen_x - self.width / 2 + character.offset_text[0]


EDIT: Actually, no, that would make no sense. I think the script error happened when I included \loc[1] in the comment without modifying the script. When I modified the script, I believe I got a method error? I'll check again tonight.

KK20

Unless the script explicitly says you can't use it in commercial games (without the creator's consent), then the script can be freely used anywhere. There's no mention of that on the OP, so you are allowed to assume that the script can be used commercially.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Rairun

Thanks for the info!

Also, you were right, your change fixes the issue! I initially got a crash, but it was because I made a mistake setting up the text offset - nothing to do with the localization part. Cheers.

orochii

Hi, sorry for posting in this old topic but I needed to get this out of my chest. For some reason I had been having problems with "special" characters such as áéíóú♥. For some reason it showed diamonds with question marks (a.k.a. unknown characters), depending on how many bytes it comprised of, so for example á showed 2 and ♥ showed 3 of these unknown characters.

I did achieve to fix it on my game after some experimentation, trial, error, and reading some StackOverflow. The thing is that I found that, for some reason, strings read from the INI file, even if the INI file is UTF8 with no BOM, were formatted in ASCII 8-bit. Much more weird is the fact that printing them with a regular draw_text works just fine. But things like letter-by-letter messages, or anything that reads one character at a time, did show these as unknown characters.

So anyway, I fixed it by doing this. I modified the self.localize method, just by adding force_encoding.
#-----------------------------------------------------------------------------
  # * Parses a string for localization codes and returns it
  #-----------------------------------------------------------------------------
  def self.localize(string)
    if string != nil
      return string.gsub(/\\[Ll][Aa][Nn][Gg]\[(.+)\]/) { a = self.read($1).force_encoding('UTF-8')}
    end
  end

Seems to work fine because the data it reads it's actually UTF-8, so it really doesn't need to reconvert, just remember it that it is a UTF-8 string, not ASCII! Same bytes, wrong way of reading.

I don't know if anyone else had this problem, but I just wanted to share, since it gave me some pain.

Blizzard

There is something with String#scan with "./m" or something similar that solves this problem. I did this in RMX-OS with the chatbox. Download RMX-OS and search for scan in the client script.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.