#============================================================================== # ■ XP-RGSS-50 ワールドマップ [データ] by Claimh #============================================================================== #============================================================================== # ■ Game_System #============================================================================== class Game_System #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :worldmap # 世界地図情報 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias init_map_system initialize def initialize init_map_system @worldmap = WorldMap::WorldMapInfo.new end end module WorldMap #============================================================================== # ■ WorldMapInfo : ワールドマップ情報クラス #============================================================================== class WorldMapInfo #-------------------------------------------------------------------------- # ● 初期化 #-------------------------------------------------------------------------- def initialize reset end def reset @region = {} end #-------------------------------------------------------------------------- # ● リージョンID配列 #-------------------------------------------------------------------------- def ids return REGION.keys.sort end #-------------------------------------------------------------------------- # ● データ取得 #-------------------------------------------------------------------------- def [](region_id) if @region[region_id].nil? @region[region_id] = RegionInfo.new(region_id) end return @region[region_id] end #-------------------------------------------------------------------------- # ● エイリアスリンク変換処理 #-------------------------------------------------------------------------- def convert_aliaslink(map_id) if ALIAS_LINK[map_id].nil? return map_id else return ALIAS_LINK[map_id] end end #-------------------------------------------------------------------------- # ● 現在のマップIDからタウン情報を参照する #-------------------------------------------------------------------------- def get_mapid_to_town(map_id) map_id = convert_aliaslink(map_id) # エイリアスリンク変換 for region_id in ids for town_id in self.[](region_id).ids if @region[region_id][town_id].map_id == map_id # 地域情報を返却 return @region[region_id][town_id] end end end p "err:couldn't search map_id to town" p "呼び出し位置がリージョンに登録されてません map_id=#{map_id}" exit end #-------------------------------------------------------------------------- # ● 地域名の配列リストを作成する #-------------------------------------------------------------------------- def make_region_list list = [] for region_id in ids if self.[](region_id).visible list.push(@region[region_id]) end end return list end #-------------------------------------------------------------------------- # ● 地点名の配列リストを作成する #-------------------------------------------------------------------------- def make_town_list(region_s) list = [] for town_id in region_s.ids if region_s[town_id].visible list.push(region_s[town_id]) end end return list end end #============================================================================= # ■ RegionInfo : リージョン情報クラス #----------------------------------------------------------------------------- # このクラスは $game_system.worldmap[リージョンID] で参照できます。 #============================================================================= class RegionInfo #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :region_id # 地域ID attr_accessor :region_name # 地域名 attr_accessor :region_map # 地図ファイル名 attr_accessor :region_info # 地域説明文 attr_reader :town # 地点情報 attr_accessor :visible # 表示ON/OFF attr_accessor :enable # 選択許可 #-------------------------------------------------------------------------- # ● 初期化 #-------------------------------------------------------------------------- def initialize(id) @region_id = id region = REGION[id] @region_name = region[0] @region_map = region[1].dup @region_info = region[2].dup @town = {} @visible = region[4].nil? ? false : region[4] @enable = true end #-------------------------------------------------------------------------- # ● タウンID配列 #-------------------------------------------------------------------------- def ids return REGION[@region_id][R_TOWN].keys.sort end #-------------------------------------------------------------------------- # ● データ取得 #-------------------------------------------------------------------------- def [](town_id) if @town[town_id].nil? @town[town_id] = TownInfo.new(@region_id, town_id) end return @town[town_id] end #-------------------------------------------------------------------------- # ● マップのビットマップ取得 #-------------------------------------------------------------------------- def map_bitmap return RPG::Cache.picture(@region_map) end end #============================================================================= # ■ TownInfo : 移動地点情報クラス #----------------------------------------------------------------------------- # このクラスは $game_system.worldmap[リージョンID][タウンID] で参照できます。 #============================================================================= class TownInfo #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :region_id # 地域ID attr_reader :town_id # 地点ID attr_accessor :map_id # マップID attr_accessor :map_pos # 地図位置 attr_accessor :player # 移動後:プレイヤー位置 attr_accessor :icon # 表示アイコン attr_accessor :town_info # 地点情報 attr_accessor :visible # 表示ON/OFF attr_accessor :enable # 選択許可 #-------------------------------------------------------------------------- # ● 初期化 #-------------------------------------------------------------------------- def initialize(region_id, town_id) @region_id = region_id @town_id = town_id town = REGION[@region_id][R_TOWN][@town_id] @map_id = town[0] @map_pos = town[1].dup @player = town[2].dup @icon = town[3].nil? ? nil : town[3].dup @town_info = town[4].dup @visible = town[5].nil? ? false : town[5] @enable = true end #-------------------------------------------------------------------------- # ● 移動地点名 #-------------------------------------------------------------------------- def town_name map_info = load_data(sprintf("Data/MapInfos.rxdata")) return map_info[@map_id].name end end #-------------------------------------------------------------------------- # ● 構文解析[テキスト置換] #-------------------------------------------------------------------------- def self.decode(textdata) text = textdata.dup # \\n[ID]:IDで指定したアクターの名前 text.gsub!(/\\n\[([0-9]+)\]/) { $game_actors[$1.to_i].name } # \\e[ID]:IDで指定したエネミーの名前 text.gsub!(/\\e\[([0-9]+)\]/) { $data_enemies[$1.to_i].name } # \\m[ID]:IDで指定したマップ名 text.gsub!(/\\m\[([0-9]+)\]/) { map_name($1.to_i) } return text end #-------------------------------------------------------------------------- # ● 情報の描画 #-------------------------------------------------------------------------- def self.draw_info_text(bitmap, x, y, w, text_h, txt) txt = "" if txt.nil? text = self.decode(txt) xx = 0 line = 0 # 便宜上 text.gsub!(/\\\\/) { "\000" } # \\c[n] : 文字色変更 text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } # \\+ : ボールド表示 開始/終了 text.gsub!(/\\[+]/) { "\002" } # \\- : イタリック表示 開始/終了 text.gsub!(/\\[-]/) { "\003" } # \\x[n] : X軸方向 n の場所から描画 text.gsub!(/\\[Xx]\[([0-9]+)\]/) { "\004[#{$1}]" } # \\n : 改行 text.gsub!(/\\[Nn]/) { "\005" } # \\icon : アイコン表示 text.gsub!(/\\icon\[(.*?+)\]/) { "\006[#{$1}]" } bold = bitmap.font.bold italic = bitmap.font.italic color = bitmap.font.color.dup while ((c = text.slice!(/./m)) != nil) break if INFO_MAX <= line # \\ の場合、本来の文字に戻す c = "\\" if c == "\000" # \\c[n] : 文字色変更 if c == "\001" # 文字色を変更 text.sub!(/\[([0-9]+)\]/, "") case $1.to_i when 0; bitmap.font.color = Color.new(255, 255, 255, 255) when 1; bitmap.font.color = Color.new(128, 128, 255, 255) when 2; bitmap.font.color = Color.new(255, 128, 128, 255) when 3; bitmap.font.color = Color.new(128, 255, 128, 255) when 4; bitmap.font.color = Color.new(128, 255, 255, 255) when 5; bitmap.font.color = Color.new(255, 128, 255, 255) when 6; bitmap.font.color = Color.new(255, 255, 128, 255) when 7; bitmap.font.color = Color.new(192, 192, 192, 255) when 8; bitmap.font.color = Color.new(192, 224, 255, 255) end next # 次の文字へ end # \\+ : ボールド表示 開始/終了 if c == "\002" bitmap.font.bold = !bitmap.font.bold next # 次の文字へ end # \\- : イタリック表示 開始/終了 if c == "\003" bitmap.font.italic = !bitmap.font.italic next # 次の文字へ end if c == "\004" # 文字色を変更 text.sub!(/\[([0-9]+)\]/, "") xx = $1.to_i next # 次の文字へ end # \\n : 改行 if c == "\005" xx = 0; y += text_h; line += 1 next # 次の文字へ end # \\icon : アイコン表示 if c == "\006" text.sub!(/\[(.*?+)\]/, "") xx += self.draw_icon(bitmap, x+xx, y, text_h, $1.to_s) next # 次の文字へ end # 文字を描画 bitmap.draw_text(x+xx, y, 40, text_h, c) # x に描画した文字の幅を加算 xx += bitmap.text_size(c).width # 自動改行 if xx > w xx = 0; y += text_h; line += 1 end end # 念のため、元に戻す bitmap.font.bold = bold bitmap.font.italic = italic bitmap.font.color = color.dup end #-------------------------------------------------------------------------- # ● 用語情報の描画(Icon) \\icon用 #-------------------------------------------------------------------------- def self.draw_icon(bitmap, x, y, h, file_name) bit = RPG::Cache.icon(file_name) src_rect = Rect.new(0, 0, bit.width, bit.height) bitmap.blt(x, y + (h - bit.height) / 2, bit, src_rect) return src_rect.width end end