#============================================================================== # ■ 共通定義 #------------------------------------------------------------------------------ # 様々な使い道がある可能性が大きいもの # すこしずつ増やしていく予定 # # *月の下の宿 # URL:http://gekkasou.shiteyattari.com/ #============================================================================== #============================================================================= # ■ Vocab #============================================================================== module Vocab #能力値の名称1("〜〜能力値") Basic = "基本" #能力値の名称2("能力値〜〜") Round = "補正" end #============================================================================= # ■ Basic Functions #============================================================================== module An_BF module_function #-------------------------------------------------------------------------- # ● 能力値名称の取得 #-------------------------------------------------------------------------- def get_vocab_names(type) case type when 0 return Vocab::atk when 1 return Vocab::def when 2 return Vocab::spi when 3 return Vocab::agi end end #-------------------------------------------------------------------------- # ● 基本能力値の取得 #-------------------------------------------------------------------------- def get_basic_params(actor, type) case type when 0..3 return $data_actors[actor.id].parameters[type + 2, actor.level] end end #-------------------------------------------------------------------------- # ● 能力値(補正込み)の取得 #-------------------------------------------------------------------------- def get_params(actor, type) case type when 0 return actor.atk when 1 return actor.def when 2 return actor.spi when 3 return actor.agi end end #-------------------------------------------------------------------------- # ● ネスト検索(配列, 検索対象) #-------------------------------------------------------------------------- def search(array, object) for i in array return true if i == object if i.is_a?(Array) return serch(array, object) end end return false end end #============================================================================== # ■ Game_Party #============================================================================== class Game_Party < Game_Unit #-------------------------------------------------------------------------- # ● 最少レベルの取得 #-------------------------------------------------------------------------- def min_level level = 0 for i in @actors actor = $game_actors[i] level = actor.level if level > actor.level end return level end #-------------------------------------------------------------------------- # ● 合計レベルの取得 #-------------------------------------------------------------------------- def sum_level level = 0 for i in @actors actor = $game_actors[i] level += actor.level end return level end #-------------------------------------------------------------------------- # ● 平均レベルの取得 #-------------------------------------------------------------------------- def avg_level return 0 if @actors.size == 0 return sum_level / @actors.size end end #============================================================================== # ■ Bitmap #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● 改行機能付き描画 #-------------------------------------------------------------------------- def draw_line_text(x, y, width, text, align = 0) text = "" if text.nil? text.sub!(/^\n/, "") note = text.split(/\n/) xx = 0 yy = 0 wlh = Window_Base::WLH dx = 0 dummy = Bitmap.new(544, 416) for n in note for i in n.scan(/./) text_width = dummy.text_size(i).width if xx + text_width >= width xx = 0 yy += wlh end dummy.draw_text(xx, yy, 120, wlh, i) xx += text_width dx = xx if dx < xx end xx = 0 yy += wlh end dest = Rect.new(x, y, [width, dx].min, dummy.height) src = Rect.new(0, 0, dx, dummy.height) offset = width - dx case align when 1 # 中央揃え dest.x += offset / 2 when 2 # 右揃え dest.x += offset end stretch_blt(dest, dummy, src) dummy.dispose end end #============================================================================== # ■ Window_Base #============================================================================== class Window_Base < Window #-------------------------------------------------------------------------- # ● 描画色判別 #-------------------------------------------------------------------------- def up_or_down_color(value) if value < 0 return power_down_color elsif value > 0 return power_up_color else return normal_color end end #-------------------------------------------------------------------------- # ● 基本能力値の描画 #-------------------------------------------------------------------------- def draw_actor_basic_parameter(actor, x, y, type) parameter_name = Vocab::Basic + An_BF::get_vocab_names(type) parameter_value = An_BF::get_basic_params(actor, type) self.contents.font.color = system_color self.contents.draw_text(x, y, 120, WLH, parameter_name) self.contents.font.color = normal_color self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2) end #-------------------------------------------------------------------------- # ● 武具能力値の描画 #-------------------------------------------------------------------------- def draw_actor_round_parameter(actor, x, y, type) parameter_name = An_BF::get_vocab_names(type) + Vocab::Round parameter_value = An_BF::get_params(actor, type) parameter_value -= An_BF::get_basic_params(actor, type) self.contents.font.color = system_color self.contents.draw_text(x, y, 120, WLH, parameter_name) self.contents.font.color = up_or_down_color(parameter_value) self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2) end #-------------------------------------------------------------------------- # ● ミニサイズ描画 #-------------------------------------------------------------------------- def draw_mini(*array) self.contents.font.size = 16 self.contents.draw_text(*array) self.contents.font.size = Font.default_size end #-------------------------------------------------------------------------- # ● ミニサイズ矩形取得 #-------------------------------------------------------------------------- def rect_mini(text) self.contents.font.size = 16 rect = self.contents.text_size(text) self.contents.font.size = Font.default_size return rect end end #============================================================================== # ■ Window_An_Mini_Command #============================================================================== class Window_An_Mini_Command < Window_Command #-------------------------------------------------------------------------- # ● オブジェクト初期化 # s1 :桁数 # s2 :列数 (0:コマンド数に合わせる) # s3 :各コマンドの横の長さ (空白の幅は別) #-------------------------------------------------------------------------- def initialize(commands, s1, s2 = 0, spacing = 32, s3 = 140) @commands = commands @ones_width = s3 @an_size = s1 super(s3 + 32, commands, s1, s2, spacing) self.height = WLH + 32 create_contents refresh update_scroll end #-------------------------------------------------------------------------- # ● ウィンドウ内容の作成 #-------------------------------------------------------------------------- def create_contents self.contents.dispose width = (@ones_width + @spacing) * @column_max - 32 height = (@item_max + @column_max - 1) / @column_max * WLH self.contents = Bitmap.new(width, height) end #-------------------------------------------------------------------------- # ● 項目を描画する矩形の取得 #-------------------------------------------------------------------------- def item_rect(index) rect = Rect.new(0, 0, 0, 0) rect.width = @ones_width rect.height = WLH rect.x = index % @column_max * (@ones_width + @spacing) rect.y = index / @column_max * WLH return rect end #-------------------------------------------------------------------------- # ● スクロールの更新 #-------------------------------------------------------------------------- def update_scroll x = item_rect(@index).x y = item_rect(@index).y # x座標補正 if x + @ones_width + @spacing >= self.ox + self.width - 32 self.ox = x - self.width + @ones_width + 32 elsif x <= self.ox self.ox = x end # y座標補正 if y + WLH >= self.oy + self.height - 32 self.oy = y - (self.height - 56) elsif y < self.oy self.oy = y end end #-------------------------------------------------------------------------- # ● カーソルの更新 #-------------------------------------------------------------------------- def update_cursor if @index < 0 # カーソル位置が 0 未満の場合 self.cursor_rect.empty # カーソルを無効とする else # カーソル位置が 0 以上の場合 rect = item_rect(@index) # 選択されている項目の矩形を取得 update_scroll rect.x -= self.ox rect.y -= self.oy # 矩形をスクロール位置に合わせる self.cursor_rect = rect # カーソルの矩形を更新 end end def width=(width) super([width, @ones_width + 32].max) end def height=(height) super([height, WLH + 32].max) end end #スペシャルサンクス #http://tkool.web-ghost.net/wiki/wiki.cgi?page=FrontPage #============================================================================== # ■ Font #============================================================================== class Font def marshal_dump;end def marshal_load(obj);end end #============================================================================== # ■ Bitmap #============================================================================== class Bitmap # メモリ転送用の関数 RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i') RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i') def _dump(limit) data = "rgba" * width * height RtlMoveMemory_pi.call(data, address, data.length) [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # ついでに圧縮 end def self._load(str) w, h, zdata = str.unpack("LLa*"); b = new(w, h) RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4); b end # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 生データの先頭(注意:上下反転) def address buffer, ad = "xxxx", object_id * 2 + 16 RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8 RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16 RtlMoveMemory_pi.call(buffer, ad, 4); return buffer.unpack("L")[0] end end #Ver1.08