mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 21:39:57 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
a091b53f69
23 changed files with 204 additions and 56 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -22,8 +22,10 @@ __pycache__
|
|||
|
||||
object_script.*
|
||||
rpgscript.bat
|
||||
rpgscript - mklang.bat
|
||||
oneshot_JA_2_merge.pot
|
||||
xScripts.rxdata
|
||||
|
||||
.qmake.stash
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
CMakeFiles/
|
||||
|
|
|
|||
11
mklang.rb
11
mklang.rb
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/ruby
|
||||
#encoding: utf-8
|
||||
|
||||
require 'get_pomo'
|
||||
require 'zlib'
|
||||
|
|
@ -11,10 +12,16 @@ end
|
|||
src_file = ARGV[0]
|
||||
dst_file = ARGV[1]
|
||||
|
||||
po = GetPomo::PoFile.parse(File.read(src_file))
|
||||
po = GetPomo::PoFile.parse(File.read(src_file, :encoding => 'utf-8'))
|
||||
|
||||
File.open(dst_file, 'wb') do |file|
|
||||
file.write(Marshal.dump(po.map do |t|
|
||||
[Zlib.crc32(t.msgid), t.msgstr]
|
||||
id = t.msgid
|
||||
msg = t.msgstr
|
||||
id = id.gsub("\\\\","\\")
|
||||
id = id.gsub("\\\"", "\"")
|
||||
msg = msg.gsub("\\\\","\\")
|
||||
msg = msg.gsub("\\\"", "\"")
|
||||
[Zlib.crc32(id), msg]
|
||||
end.to_h))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class Credits_Message
|
|||
end
|
||||
@sprite_text = Sprite.new(@viewport)
|
||||
@contents = Bitmap.new(320, 240)
|
||||
Language.register_text_sprite(self.class.name + "_contents", @contents)
|
||||
@contents.font.size = 16
|
||||
@sprite_text.bitmap = @contents
|
||||
@sprite_bg.z = 0
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Desktop_Message
|
|||
@sprite_bg.zoom_x = @sprite_bg.zoom_y = 2
|
||||
@sprite_text = Sprite.new(@viewport)
|
||||
@contents = Bitmap.new(640, HEIGHT)
|
||||
Language.register_text_sprite(self.class.name + "_contents", @contents)
|
||||
@sprite_text.bitmap = @contents
|
||||
@sprite_text.y = (480 - HEIGHT) / 2
|
||||
@sprite_bg.z = 0
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class Doc_Message
|
|||
#@sprite_bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 128))
|
||||
@sprite_text = Sprite.new(@viewport)
|
||||
@contents = Bitmap.new(200, 216)
|
||||
Language.register_text_sprite(self.class.name + "_contents", @contents)
|
||||
@contents.font.size = 16
|
||||
@sprite_text.bitmap = @contents
|
||||
@sprite_text.x = 120
|
||||
|
|
|
|||
|
|
@ -25,9 +25,14 @@ module EdText
|
|||
sleep 0.2
|
||||
end
|
||||
result = nil
|
||||
# so here, we strip unescaped newlines from the untranslated text
|
||||
# for the translator to find the right string. Then from the
|
||||
# translated text, we replace escaped newlines with empty strings.
|
||||
# yeah.
|
||||
text = Language.tr(text.to_s.gsub(/\s*\n\s*/, " ").strip)
|
||||
.to_s.gsub(/\s*\\n\s*/, "").strip
|
||||
thread = Thread.new do
|
||||
result = Oneshot.msgbox(type, text
|
||||
.gsub(/\s+\n\s+/, " ")
|
||||
.gsub("\\p", $game_oneshot.player_name) +
|
||||
" " * 10)
|
||||
# HACK: Fuck
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class Ed_Message
|
|||
@sprite_bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 128))
|
||||
@sprite_text = Sprite.new(@viewport)
|
||||
@contents = Bitmap.new(640, HEIGHT)
|
||||
Language.register_text_sprite(self.class.name + "_contents", @contents)
|
||||
@sprite_text.bitmap = @contents
|
||||
@sprite_text.y = (480 - HEIGHT) / 2
|
||||
@sprite_bg.z = 0
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class FastTravel
|
|||
@bg.bitmap = Bitmap.new(640, 480)
|
||||
@bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 128))
|
||||
@title = Sprite.new(@viewport)
|
||||
Language.register_text_sprite(self.class.name + "_title", @title)
|
||||
@title.bitmap = Bitmap.new(320, TITLE_MARGIN)
|
||||
@title.bitmap.font.size = 40
|
||||
@title.y = TITLE_TOP_MARGIN
|
||||
|
|
|
|||
|
|
@ -58,7 +58,15 @@ class Game_Picture
|
|||
# blend_type : blend method
|
||||
#--------------------------------------------------------------------------
|
||||
def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
|
||||
@name = name
|
||||
# Localization: check if this picture exists
|
||||
# in the appropriate language folder, else
|
||||
# default to the base graphics folder
|
||||
translation_name = "#{$persistent.langcode}/#{name}"
|
||||
if File.exists?("Graphics/Pictures/#{translation_name}.png")
|
||||
@name = translation_name
|
||||
else
|
||||
@name = name
|
||||
end
|
||||
@origin = origin
|
||||
@x = x.to_f
|
||||
@y = y.to_f
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ class Interpreter
|
|||
# Create full text string
|
||||
choices = false
|
||||
text = @list[@index].parameters[0].strip
|
||||
|
||||
# Translate text
|
||||
text = Language.tr(text).clone
|
||||
|
||||
if text.start_with?('$')
|
||||
is_doc = true
|
||||
text.slice!(0)
|
||||
|
|
@ -31,11 +35,11 @@ class Interpreter
|
|||
# 401: another line of text
|
||||
if @list[@index+1].code == 401
|
||||
@index += 1
|
||||
text << " " << @list[@index].parameters[0].rstrip
|
||||
text << " " << Language.tr(@list[@index].parameters[0].rstrip).clone
|
||||
elsif @list[@index+1].code == 101 && (is_doc || is_credits)
|
||||
# 101: Another message box
|
||||
# Tack on if we're a doc
|
||||
new_text = @list[@index+1].parameters[0].strip
|
||||
new_text = Language.tr(@list[@index+1].parameters[0].strip).clone
|
||||
if new_text.start_with?('$')
|
||||
text << "\n\n" << new_text[1..-1]
|
||||
@index += 1
|
||||
|
|
@ -64,9 +68,7 @@ class Interpreter
|
|||
end
|
||||
text.gsub!(/\s*\\n\s*/, '\\n')
|
||||
text.strip!
|
||||
|
||||
# Translate text
|
||||
text = Language.tr(text).clone
|
||||
text = Language.tr(text)
|
||||
|
||||
# Parse first line for portrait specifier
|
||||
if text[0,1] == '@'
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ begin
|
|||
|
||||
# Load persistent data
|
||||
Persistent.load
|
||||
$persistent.lang = 'ja'
|
||||
|
||||
# Prepare for transition
|
||||
Graphics.freeze
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ class Persistent
|
|||
end
|
||||
Language.set(@lang)
|
||||
end
|
||||
|
||||
def langcode
|
||||
self.lang.full.to_s
|
||||
end
|
||||
|
||||
# MARSHAL
|
||||
def marshal_dump
|
||||
|
|
@ -49,7 +53,7 @@ class Persistent
|
|||
|
||||
# Save/Load global instance of persistent
|
||||
FILE_NAME = Oneshot::SAVE_PATH + '/persistent.dat'
|
||||
def self.save
|
||||
def save
|
||||
File.open(FILE_NAME, 'wb') do |file|
|
||||
Marshal.dump($persistent, file)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ def load_perma_flags
|
|||
|
||||
begin
|
||||
read_perma_flags(PERMA_FLAGS_NAME)
|
||||
rescue TypeError => e
|
||||
rescue TypeError, ArgumentError => e
|
||||
puts "oops: #{e.message}"
|
||||
EdText.err("p-settings.dat corrupt. Attempting to load backup.")
|
||||
for i in 1..6
|
||||
|
|
@ -177,7 +177,7 @@ def load_perma_flags
|
|||
begin
|
||||
read_perma_flags(Oneshot::SAVE_PATH + "/save_backups/p-settings" + (i).to_s + ".bk")
|
||||
break
|
||||
rescue TypeError => e2
|
||||
rescue TypeError, ArgumentError => e2
|
||||
puts "oops: #{e2.message}"
|
||||
EdText.err("p-settings" + (i).to_s + ".bk corrupt. Attempting to load backup.")
|
||||
end
|
||||
|
|
@ -210,7 +210,7 @@ def real_load
|
|||
#load save data
|
||||
begin
|
||||
load(SAVE_FILE_NAME)
|
||||
rescue TypeError => e
|
||||
rescue TypeError, ArgumentError => e
|
||||
puts "oops: #{e.message}"
|
||||
EdText.err("save.dat corrupt. Attempting to load backup.")
|
||||
for i in 1..6
|
||||
|
|
@ -224,7 +224,7 @@ def real_load
|
|||
begin
|
||||
load(Oneshot::SAVE_PATH + "/save_backups/save" + (i).to_s + ".bk")
|
||||
break
|
||||
rescue TypeError => e2
|
||||
rescue TypeError, ArgumentError => e2
|
||||
puts "oops: #{e2.message}"
|
||||
EdText.err("save" + (i).to_s + ".bk corrupt. Attempting to load backup.")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class Scene_Map
|
|||
# either telling them they can't quit during a cutscene
|
||||
# or telling them they're saving and quitting
|
||||
if $game_system.map_interpreter.running?
|
||||
EdText.info("You cannot perform this action during cutscenes.")
|
||||
EdText.info(tr("You cannot perform this action during cutscenes."))
|
||||
return
|
||||
else
|
||||
$game_temp.common_event_id = 35
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ class Sprite_MapText < Sprite
|
|||
self.zoom_x = 2
|
||||
self.zoom_y = 2
|
||||
self.bitmap = Bitmap.new(200, 24)
|
||||
|
||||
|
||||
#calculate text width
|
||||
spacewidth = self.bitmap.text_size(' ').width
|
||||
width = 0
|
||||
|
||||
|
||||
text.split(' ').each do |word|
|
||||
|
||||
# Get width of this word
|
||||
|
|
@ -22,17 +22,21 @@ class Sprite_MapText < Sprite
|
|||
width += spacewidth
|
||||
end
|
||||
width -= spacewidth
|
||||
|
||||
|
||||
if width <= 0
|
||||
width = 1
|
||||
end
|
||||
|
||||
self.bitmap.dispose
|
||||
self.bitmap = Bitmap.new(width, 24)
|
||||
self.bitmap.font.color = Color.new(81, 33, 129, 255)
|
||||
self.bitmap.draw_text(0,0, width, 24, text)
|
||||
self.bitmap.draw_text(0,0, width, 24, text)
|
||||
|
||||
self.src_rect.set(0, 0, width, 24)
|
||||
self.oy = 24
|
||||
self.ox = width/2
|
||||
|
||||
|
||||
|
||||
|
||||
update
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class Window_Help < Window_Base
|
|||
def initialize
|
||||
super(16, 16, 608, 64)
|
||||
self.contents = Bitmap.new(width - 32, height - 32)
|
||||
Language.register_text_sprite(self.class.name + "_contents", self.contents)
|
||||
self.visible = false
|
||||
self.back_opacity = 230
|
||||
self.z = 9998
|
||||
|
|
@ -21,15 +22,12 @@ class Window_Help < Window_Base
|
|||
# align : alignment (0..flush left, 1..center, 2..flush right)
|
||||
#--------------------------------------------------------------------------
|
||||
def set_text(text, align = 0)
|
||||
# If at least one part of text and alignment differ from last time
|
||||
if text != @text or align != @align
|
||||
# Redraw text
|
||||
self.contents.clear
|
||||
self.contents.font.color = normal_color
|
||||
self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
|
||||
@text = text
|
||||
@align = align
|
||||
@actor = nil
|
||||
end
|
||||
# Redraw text
|
||||
self.contents.clear
|
||||
self.contents.font.color = normal_color
|
||||
self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
|
||||
@text = text
|
||||
@align = align
|
||||
@actor = nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class Window_InputNumber < Window_Base
|
|||
dummy_bitmap.dispose
|
||||
super(0, 0, @cursor_width * @digits_max + 32, 64)
|
||||
self.contents = Bitmap.new(width - 32, height - 32)
|
||||
# Language.register_text_sprite(self.class.name + "_contents", self.contents)
|
||||
self.z += 9999
|
||||
self.opacity = 0
|
||||
@index = 0
|
||||
|
|
|
|||
|
|
@ -197,8 +197,9 @@ class Window_Item < Window_Selectable
|
|||
# * Open
|
||||
#--------------------------------------------------------------------------
|
||||
def open
|
||||
update_help
|
||||
refresh
|
||||
|
||||
|
||||
# Search for selected item and auto-select
|
||||
if $game_variables[1] > 0
|
||||
@data.each_with_index do |item, i|
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ class Window_MainMenu < Window_Selectable
|
|||
|
||||
# Set up menu options
|
||||
@commands = Array.new
|
||||
@commands << tr('Travel')
|
||||
@commands << tr('Notes')
|
||||
@commands << tr('Settings')
|
||||
@commands << 'Travel'
|
||||
@commands << 'Notes'
|
||||
@commands << 'Settings'
|
||||
@item_max = @commands.size
|
||||
@column_max = @item_max
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ class Window_MainMenu < Window_Selectable
|
|||
|
||||
# Render menu
|
||||
self.contents = Bitmap.new(width - 32, 32)
|
||||
Language.register_text_sprite(self.class.name + "_contents", self.contents)
|
||||
for i in 0...@item_max
|
||||
draw_item(i, normal_color)
|
||||
end
|
||||
|
|
@ -47,7 +48,7 @@ class Window_MainMenu < Window_Selectable
|
|||
# Update item
|
||||
rect = Rect.new(w * index, 0, w - 32, 32)
|
||||
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
|
||||
self.contents.draw_text(rect, @commands[index], 1)
|
||||
self.contents.draw_text(rect, tr(@commands[index]), 1)
|
||||
end
|
||||
#--------------------------------------------------------------------------
|
||||
# * Disable Item
|
||||
|
|
@ -59,6 +60,10 @@ class Window_MainMenu < Window_Selectable
|
|||
|
||||
# Open/show the menu
|
||||
def open
|
||||
# redraw in case language has been updated
|
||||
for i in 0...@item_max
|
||||
draw_item(i, normal_color)
|
||||
end
|
||||
self.opacity = 0
|
||||
self.contents_opacity = 0
|
||||
self.visible = true
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class Window_Message < Window_Selectable
|
|||
def initialize
|
||||
super(16, 336, 608, 128)
|
||||
self.contents = Bitmap.new(width - 32, height - 32)
|
||||
Language.register_text_sprite(self.class.name + "_contents", self.contents)
|
||||
self.visible = false
|
||||
self.z = 9999
|
||||
self.back_opacity = 210
|
||||
|
|
|
|||
|
|
@ -7,14 +7,15 @@ class Window_Settings
|
|||
SETTINGS_FILE_NAME = Oneshot::SAVE_PATH + '/settings.conf'
|
||||
|
||||
def save_settings
|
||||
$persistent.save
|
||||
File.open(SETTINGS_FILE_NAME, 'w') do |file|
|
||||
file.puts('bgm_volume=' + Audio.bgm_volume.to_s)
|
||||
file.puts('sfx_volume=' + Audio.sfx_volume.to_s)
|
||||
file.puts('fullscreen=' + Graphics.fullscreen.to_s)
|
||||
file.puts('default_run=' + $game_switches[251].to_s)
|
||||
file.puts('colorblind_mode=' + $game_switches[252].to_s)
|
||||
file.puts('frameskip=' + Graphics.frameskip.to_s)
|
||||
end
|
||||
file.puts('bgm_volume=' + Audio.bgm_volume.to_s)
|
||||
file.puts('sfx_volume=' + Audio.sfx_volume.to_s)
|
||||
file.puts('fullscreen=' + Graphics.fullscreen.to_s)
|
||||
file.puts('default_run=' + $game_switches[251].to_s)
|
||||
file.puts('colorblind_mode=' + $game_switches[252].to_s)
|
||||
file.puts('frameskip=' + Graphics.frameskip.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def self.load_settings
|
||||
|
|
@ -75,6 +76,7 @@ class Window_Settings
|
|||
@title.bitmap.font.size = 40
|
||||
@title.y = TITLE_TOP_MARGIN
|
||||
@title.x = MARGIN
|
||||
Language.register_text_sprite(self.class.name + "_title", @title)
|
||||
@data_sprites = []
|
||||
@viewport.z = 9998
|
||||
|
||||
|
|
@ -110,10 +112,16 @@ class Window_Settings
|
|||
tr('Default movement'),
|
||||
tr('Colorblind mode'),
|
||||
tr('Frameskip'),
|
||||
tr('Language'),
|
||||
tr('Configure Controls (Press F1)'),
|
||||
]
|
||||
|
||||
@index = 0
|
||||
# Load our language settings from persistent, stored differently
|
||||
@lang_index = Language::LANGUAGES.index($persistent.langcode)
|
||||
if @lang_index.nil?
|
||||
@lang_index = 0
|
||||
end
|
||||
|
||||
# Create title
|
||||
@title.bitmap.clear
|
||||
|
|
@ -126,6 +134,7 @@ class Window_Settings
|
|||
spr.x = MARGIN
|
||||
spr.y = TITLE_MARGIN + TITLE_TOP_MARGIN + ITEM_SPACING * i
|
||||
spr.opacity = 0
|
||||
Language.register_text_sprite(self.class.name + "_option_#{i}", spr)
|
||||
redraw_setting(spr, i)
|
||||
|
||||
@data_sprites << spr
|
||||
|
|
@ -168,9 +177,13 @@ class Window_Settings
|
|||
else
|
||||
spr.bitmap.draw_text(260, 0, spr.bitmap.width, spr.bitmap.height, tr("OFF"))
|
||||
end
|
||||
end
|
||||
when 6 # Language
|
||||
l = Language::LANGUAGES[@lang_index] rescue Language::LANGUAGES[0]
|
||||
spr.bitmap.draw_text(260, 0, spr.bitmap.width, spr.bitmap.height, l)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def redraw_setting_index(i)
|
||||
if !@data_sprites.kind_of?(Array)
|
||||
return
|
||||
|
|
@ -181,6 +194,16 @@ class Window_Settings
|
|||
redraw_setting(@data_sprites[i], i)
|
||||
end
|
||||
|
||||
|
||||
def redraw_all_settings
|
||||
@title.bitmap.clear
|
||||
@title.bitmap.draw_text(0, 0, @title.bitmap.width, @title.bitmap.height, tr("Settings"))
|
||||
for i in 0..7
|
||||
redraw_setting_index(i)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
if @fade_in
|
||||
self.opacity += 20
|
||||
|
|
@ -276,15 +299,16 @@ class Window_Settings
|
|||
Audio.bgm_volume -= 1
|
||||
if old_vol > 1
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.bgm_volume/2) + 75)
|
||||
redraw_setting_index(0)
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT) || (Input.press?(Input::RIGHT) && (@right_hold_timer >= 15))
|
||||
@right_hold_timer -= 2
|
||||
Audio.bgm_volume += 1
|
||||
if old_vol < 100
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.bgm_volume/2) + 75)
|
||||
redraw_setting_index(0)
|
||||
end
|
||||
end
|
||||
redraw_setting_index(0)
|
||||
|
||||
when 1 #sfx vol
|
||||
old_vol = Audio.sfx_volume
|
||||
|
|
@ -293,15 +317,16 @@ class Window_Settings
|
|||
Audio.sfx_volume -= 1
|
||||
if old_vol > 1
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.sfx_volume/2) + 75)
|
||||
redraw_setting_index(1)
|
||||
end
|
||||
elsif Input.trigger?(Input::RIGHT) || (Input.press?(Input::RIGHT) && (@right_hold_timer >= 15))
|
||||
@right_hold_timer -= 2
|
||||
Audio.sfx_volume += 1
|
||||
if old_vol < 100
|
||||
Audio.se_play("Audio/SE/text_robot.wav", 70, (Audio.sfx_volume/2) + 75)
|
||||
redraw_setting_index(1)
|
||||
end
|
||||
end
|
||||
redraw_setting_index(1)
|
||||
|
||||
when 2 #fullscreen
|
||||
if Input.trigger?(Input::ACTION) || Input.trigger?(Input::LEFT) || Input.trigger?(Input::RIGHT)
|
||||
|
|
@ -354,6 +379,24 @@ class Window_Settings
|
|||
end
|
||||
redraw_setting_index(5)
|
||||
end
|
||||
|
||||
when 6 #language
|
||||
if Input.trigger?(Input::ACTION) || Input.trigger?(Input::RIGHT)
|
||||
@lang_index += 1
|
||||
if @lang_index >= Language::LANGUAGES.length
|
||||
@lang_index = 0
|
||||
end
|
||||
$persistent.lang = Language::LANGUAGES[@lang_index]
|
||||
redraw_all_settings()
|
||||
end
|
||||
if Input.trigger?(Input::LEFT)
|
||||
@lang_index -= 1
|
||||
if @lang_index < 0
|
||||
@lang_index = Language::LANGUAGES.length - 1
|
||||
end
|
||||
$persistent.lang = Language::LANGUAGES[@lang_index]
|
||||
redraw_all_settings()
|
||||
end
|
||||
end
|
||||
|
||||
if Input.trigger?(Input::CANCEL)
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ Persistent
|
|||
# Internationalization
|
||||
i18n_Language
|
||||
i18n_English
|
||||
#i18n_Japanese
|
||||
|
||||
# Data
|
||||
Data_Item
|
||||
|
|
|
|||
|
|
@ -1,32 +1,56 @@
|
|||
# Classes for translating text similar to GNU gettext
|
||||
|
||||
# Translator class: translate text to another language
|
||||
|
||||
# for debug REMOVE BEFORE COMMITTING / BUILDING
|
||||
# require "zlib"
|
||||
|
||||
class Language
|
||||
FONT_WESTERN = 'Terminus (TTF)'
|
||||
FONT_CJK = 'WenQuanYi Micro Hei'
|
||||
LANG_WESTERN = [
|
||||
'en', 'fr', 'pt_BR', 'es'
|
||||
]
|
||||
LANG_CJK = [
|
||||
'ja', 'ko', 'zh_CN'
|
||||
]
|
||||
LANGUAGES = LANG_WESTERN + LANG_CJK
|
||||
|
||||
class << self
|
||||
def set(lc)
|
||||
dbg_print(lc.lang)
|
||||
@data = nil
|
||||
@tr = nil
|
||||
script = nil
|
||||
[lc.full.to_s, lc.lang.to_s].each do |name|
|
||||
begin
|
||||
@tr, script = load_data("Languages/#{name}.rxdata")
|
||||
break
|
||||
rescue
|
||||
path = "Languages/#{name}.loc"
|
||||
dbg_print(path)
|
||||
if FileTest.exist?(path)
|
||||
File.open(path, "rb") do |file|
|
||||
@data = Marshal.load(file)
|
||||
if LANG_CJK.include? name
|
||||
Font.default_name = FONT_CJK
|
||||
else
|
||||
Font.default_name = FONT_WESTERN
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
exec(script) if script
|
||||
reset_fonts(@text_sprites)
|
||||
Oneshot.set_yes_no(tr('Yes'), tr('No'))
|
||||
end
|
||||
|
||||
# Translate some text
|
||||
def tr(string)
|
||||
#dbg_print(caller_locations(1, 1).first.tap{|loc| puts "#{loc.path}:#{loc.lineno}"})
|
||||
dbg_print(string)
|
||||
if @data
|
||||
@data[Zlib::crc32(string)] || string
|
||||
rv = @data[Zlib::crc32(string)] || string
|
||||
else
|
||||
string
|
||||
rv = string
|
||||
end
|
||||
dbg_print(rv)
|
||||
return rv
|
||||
end
|
||||
|
||||
# Turn all database items into translatable strings
|
||||
|
|
@ -41,6 +65,44 @@ class Language
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def dbg_print(str)
|
||||
# dbg = IO.new(STDERR.fileno)
|
||||
# if str.nil?
|
||||
# dbg.write("null\n")
|
||||
# else
|
||||
# dbg.write(str.to_s + "\n")
|
||||
# end
|
||||
# dbg.close()
|
||||
end
|
||||
|
||||
def register_text_sprite(key, spr)
|
||||
dbg_print(key)
|
||||
if @text_sprites.nil?
|
||||
@text_sprites = Hash.new()
|
||||
end
|
||||
@text_sprites[key] = spr
|
||||
end
|
||||
|
||||
def reset_fonts(sprites)
|
||||
if sprites.kind_of?(Array)
|
||||
sprites.each do |spr|
|
||||
if spr.kind_of?(Sprite) and !spr.disposed?
|
||||
spr.bitmap.font.name = Font.default_name
|
||||
end
|
||||
end
|
||||
elsif sprites.kind_of?(Hash)
|
||||
sprites.each_value do |spr|
|
||||
if spr.kind_of?(Sprite) and !spr.disposed?
|
||||
spr.bitmap.font.name = Font.default_name
|
||||
elsif spr.kind_of?(Bitmap) and !spr.disposed?
|
||||
spr.font.name = Font.default_name
|
||||
end
|
||||
end
|
||||
elsif sprites.kind_of?(Sprite) and not sprites.disposed?
|
||||
sprites.bitmap.font.name = Font.default_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue