# encoding: UTF-8 #============================================================================== # Multiplayer Chat — bindable action + menu skill (fixed) #============================================================================== module MPChatAction KEY_SYMBOL = :CHAT KEY_NAME = 'CHAT' KEY_PATH = 'Graphics/Online/chat.png' ITEM_NAME = 'mp_chat_skill' TEXT_NAME = 'mp/chat/name' TEXT_DESC = 'mp/chat/desc' KEY_ROW = [KEY_SYMBOL, 'DataInput:Key/Chat', 'Chat', [-1]] PAD_ROW = [KEY_SYMBOL, 'DataInput:Key/Chat', 'Chat', -1] class << self attr_accessor :chat_skill_id end def self.assign_attr(obj, attr, value) return if obj.nil? setter = (attr.to_s + '=').to_sym return unless obj.respond_to?(setter) obj.send(setter, value) rescue end def self.install_key_rows # Chat is opened only through assigned skill slots. end def self.read_ini_key(index) $LonaINI['Keyboard']["#{KEY_NAME}_#{index}"] rescue nil end def self.write_ini_key(index, value) $LonaINI['Keyboard']["#{KEY_NAME}_#{index}"] = value rescue end def self.ensure_keyboard_binding begin Input::SYM_KEYS[KEY_SYMBOL] ||= [0, 0, 0] rescue return end changed = false 0.upto(2) do |i| if Input::SYM_KEYS[KEY_SYMBOL][i].to_i != 0 Input::SYM_KEYS[KEY_SYMBOL][i] = 0 changed = true end next if read_ini_key(i).to_s == '0' write_ini_key(i, '0') changed = true end begin if defined?(WolfPad) && WolfPad.respond_to?(:keys) pad_val = nil begin pad_val = $LonaINI['GamePad'][KEY_NAME] rescue pad_val = nil end if WolfPad.keys[KEY_SYMBOL].to_i != -1 WolfPad.keys[KEY_SYMBOL] = -1 changed = true end if pad_val.to_s != '-1' begin $LonaINI['GamePad'][KEY_NAME] = '-1' rescue end changed = true end end rescue end begin $LonaINI.save if changed rescue end end def self.install_text begin $game_text[TEXT_NAME] = 'Чат' $game_text[TEXT_DESC] = 'Открыть многопользовательский чат. Это действие можно назначить в слот навыка.' rescue end end def self.ensure_chat_skill return nil unless defined?($data_skills) && $data_skills if @chat_skill_id && $data_skills[@chat_skill_id] && chat_skill?($data_skills[@chat_skill_id]) install_text return @chat_skill_id end existing = nil begin existing = $data_skills.compact.find { |s| chat_skill?(s) } rescue existing = nil end if existing begin @chat_skill_id = existing.id rescue @chat_skill_id = nil end install_text return @chat_skill_id end template = nil begin template = $data_skills.compact.find { |s| s && s.respond_to?(:item_name) && s.respond_to?(:id) } rescue template = nil end return nil unless template skill = nil begin skill = template.clone rescue begin skill = template.dup rescue skill = nil end end return nil unless skill id = $data_skills.length assign_attr(skill, :id, id) assign_attr(skill, :item_name, ITEM_NAME) assign_attr(skill, :name, TEXT_NAME) assign_attr(skill, :description, TEXT_DESC) assign_attr(skill, :icon_index, KEY_PATH) assign_attr(skill, :type, 'other') begin $data_skills[id] = skill rescue return nil end begin if defined?($data_SkillName) && $data_SkillName.respond_to?(:[]=) $data_SkillName[ITEM_NAME] = skill end rescue end @chat_skill_id = id install_text id end def self.chat_skill_id ensure_chat_skill unless @chat_skill_id @chat_skill_id end def self.chat_skill id = chat_skill_id return nil if id.nil? begin $data_skills[id] rescue nil end end def self.chat_skill?(obj) return false if obj.nil? begin return true if obj.respond_to?(:item_name) && obj.item_name == ITEM_NAME rescue end begin return true if !@chat_skill_id.nil? && obj.respond_to?(:id) && obj.id == @chat_skill_id rescue end false end def self.chat_slot?(slot) sid = nil begin sid = slot.id if slot.respond_to?(:id) rescue sid = nil end sid = slot if sid.nil? sid = sid.to_i rescue 0 return false if sid <= 0 id = chat_skill_id.to_i return true if id > 0 && sid == id begin skill = $data_skills[sid] if defined?($data_skills) && $data_skills return chat_skill?(skill) rescue end false end def self.key_symbol if defined?($game_player) && $game_player && $game_player.respond_to?(:hotkey_chat) && $game_player.hotkey_chat $game_player.hotkey_chat else KEY_SYMBOL end end def self.key_text '' end def self.hud_font_name begin return MPSafeFont.skill_menu_name if defined?(MPSafeFont) && MPSafeFont.respond_to?(:skill_menu_name) return MPSafeFont.name if defined?(MPSafeFont) && MPSafeFont.respond_to?(:name) rescue end "VL Gothic" end def self.skill_info_font_name begin return MPSafeFont.skill_menu_info_name if defined?(MPSafeFont) && MPSafeFont.respond_to?(:skill_menu_info_name) return MPSafeFont.skill_menu_name if defined?(MPSafeFont) && MPSafeFont.respond_to?(:skill_menu_name) rescue end hud_font_name end def self.skill_font_size begin return FONT_MOD::MENU_M_S if defined?(FONT_MOD) && FONT_MOD.const_defined?(:MENU_M_S) rescue end 16 end def self.skill_info_font_size begin return FONT_MOD::MENU_L_S if defined?(FONT_MOD) && FONT_MOD.const_defined?(:MENU_L_S) rescue end skill_font_size end def self.draw_icon_to(bitmap, x, y) begin src = Cache.normal_bitmap(KEY_PATH) bitmap.blt(x, y, src, Rect.new(0, 0, 24, 24)) return true rescue begin bitmap.fill_rect(x, y, 24, 24, Color.new(32, 32, 32, 180)) bitmap.font.size = 14 bitmap.font.outline = false bitmap.draw_text(x, y - 1, 24, 24, 'C', 1) rescue end return false end end def self.draw_slot_to(bitmap) bitmap.clear begin bitmap.font.size = 16 bitmap.font.outline = false bitmap.font.bold = true bitmap.font.color.set(255, 255, 50, 255) rescue end begin box_x = [(bitmap.width - 24) / 2, 0].max bitmap.fill_rect(box_x - 1, 19, 26, 26, Color.new(70, 0, 0, 180)) bitmap.fill_rect(box_x, 20, 24, 24, Color.new(0, 0, 0, 180)) bitmap.fill_rect(box_x, 20, 24, 1, Color.new(255, 120, 0, 220)) bitmap.fill_rect(box_x, 43, 24, 1, Color.new(255, 120, 0, 220)) bitmap.fill_rect(box_x, 20, 1, 24, Color.new(255, 120, 0, 220)) bitmap.fill_rect(box_x + 23, 20, 1, 24, Color.new(255, 120, 0, 220)) draw_icon_to(bitmap, box_x, 20) rescue end end def self.consume_as_chat_action(key) return false if key.nil? return false unless defined?($game_player) && $game_player triggered = false begin triggered = Input.trigger?(key) || (Input.press?(key) && (($game_player.instance_variable_get(:@prevSkillKey) rescue nil) != key)) rescue triggered = false end return false unless triggered begin $game_player.instance_variable_set(:@prevSkillKey, key) rescue end begin SndLib.sys_ok rescue end begin MPChat.toggle rescue begin MPChat.open rescue end end true end end MPChatAction.ensure_keyboard_binding MPChatAction.ensure_chat_skill class Game_Player < Game_Character attr_accessor :hotkey_chat alias mp_chat_action_initialize_hotkey_fixed3 initialize_hotkey def initialize_hotkey mp_chat_action_initialize_hotkey_fixed3 @hotkey_chat = MPChatAction::KEY_SYMBOL end alias mp_chat_action_process_hotkey_input_fixed3 process_hotkey_input def process_hotkey_input(key, slot) return if MPChatAction.chat_slot?(slot) && MPChatAction.consume_as_chat_action(key) mp_chat_action_process_hotkey_input_fixed3(key, slot) end alias mp_chat_action_process_skill_roster_input_fixed3 process_skill_roster_input def process_skill_roster_input(key, whichroster = 0, which_skill = 0) if !key.nil? && @slot_RosterArray && whichroster < @slot_RosterArray.size begin skill_id = @slot_RosterArray[whichroster][which_skill] return if MPChatAction.chat_slot?(skill_id) && MPChatAction.consume_as_chat_action(key) rescue end end mp_chat_action_process_skill_roster_input_fixed3(key, whichroster, which_skill) end alias mp_chat_action_process_custom_skill_fixed3 process_custom_skill def process_custom_skill(key, skill_id) return if MPChatAction.chat_slot?(skill_id) && MPChatAction.consume_as_chat_action(key) mp_chat_action_process_custom_skill_fixed3(key, skill_id) end end class Map_Hud alias mp_chat_action_draw_hotkey_icon_get_icon_index_fixed3 draw_hotkey_icon_get_icon_index def draw_hotkey_icon_get_icon_index(original_bitmap, hotkey_sprite, skill_id, sort_index, sym) return MPChatAction::KEY_PATH if MPChatAction.chat_slot?(skill_id) mp_chat_action_draw_hotkey_icon_get_icon_index_fixed3(original_bitmap, hotkey_sprite, skill_id, sort_index, sym) end end module MPChat class << self def open_key_triggered? false end end end class Menu_SkillAndHotkey < Menu_ContentBase alias mp_chat_action_initialize_fixed3 initialize def initialize(*args) MPChatAction.ensure_chat_skill mp_chat_action_initialize_fixed3(*args) mp_chat_action_create_slot_sprite end def mp_chat_action_create_slot_sprite return if @mp_chat_action_sprite vp = nil begin vp = @buff_viewport rescue vp = nil end @mp_chat_action_sprite = Sprite.new(vp) @mp_chat_action_sprite.bitmap = Bitmap.new(40, 48) @mp_chat_action_sprite.x = 597 @mp_chat_action_sprite.y = 290 @mp_chat_action_sprite.z = 3 + (System_Settings::SCENE_Menu_Contents_Z rescue 0) @mp_chat_action_sprite.visible = (@buff_viewport.visible rescue false) mp_chat_action_refresh_slot_sprite end def mp_chat_action_refresh_slot_sprite return unless @mp_chat_action_sprite && @mp_chat_action_sprite.bitmap begin source_name = if defined?(@skill_icons) && @skill_icons && @skill_icons.bitmap @skill_icons.bitmap.font.name else nil end @mp_chat_action_sprite.bitmap.font.name = source_name.to_s.strip == "" ? MPChatAction.hud_font_name : source_name rescue end MPChatAction.draw_slot_to(@mp_chat_action_sprite.bitmap) end def mp_chat_action_chat_skill_selected? return false if !@skills || @cursor_real_index.nil? MPChatAction.chat_skill?(@skills[@cursor_real_index]) rescue false end alias mp_chat_action_refresh_skill_icons_fixed3 refresh_skill_icons def refresh_skill_icons MPChatAction.ensure_chat_skill mp_chat_action_refresh_skill_icons_fixed3 return if !@buff_icons || !@buff_icons.bitmap return if !@skills chat_skill = MPChatAction.chat_skill return if chat_skill.nil? return if @skills.any? { |s| MPChatAction.chat_skill?(s) } old_bitmap = @buff_icons.bitmap begin old_font_name = old_bitmap.font.name rescue old_font_name = nil end new_bitmap = Bitmap.new(old_bitmap.width, old_bitmap.height + 27) new_bitmap.blt(0, 0, old_bitmap, old_bitmap.rect) old_bitmap.dispose rescue nil @buff_icons.bitmap = new_bitmap begin font_name = old_font_name.to_s font_name = MPChatAction.hud_font_name if font_name.strip == "" @buff_icons.bitmap.font.name = font_name @buff_icons.bitmap.font.size = MPChatAction.skill_font_size @buff_icons.bitmap.font.outline = false @buff_icons.bitmap.font.color = Color.new(224, 128, 64) rescue end @skills = @skills.dup @skills << chat_skill index = @skills.length - 1 begin MPChatAction.draw_icon_to(@buff_icons.bitmap, 0, index * 27) rescue end begin draw_text_on_canvas(@buff_icons, 26, 27 * index, 'Чат', true) rescue begin @buff_icons.bitmap.draw_text(26, 27 * index - 1, 96, 24, 'Чат') rescue end end @buff_icon_rect_record ||= [] if @buff_icon_rect_record.size < 9 @buff_icon_rect_record << [@icon_viewport_default_x, @icon_viewport_default_y + 27 * index, 123, 32] end @last_icon_index = @skills.size % 9 end alias mp_chat_action_refresh_skill_info_fixed3 refresh_skill_info def refresh_skill_info if mp_chat_action_chat_skill_selected? @reuqest_refresh_info = false @reuqest_refresh_info_delay = 0 @buff_info.bitmap.dispose if @buff_info.bitmap @buff_info.bitmap = Bitmap.new(299,312) begin @buff_info.bitmap.font.name = MPChatAction.skill_info_font_name rescue end @buff_info.bitmap.font.size = MPChatAction.skill_info_font_size @buff_info.bitmap.font.outline = false draw_text_on_canvas(@buff_info, 13, 13, 'Многопользовательский чат') @buff_info.bitmap.font.size = MPChatAction.skill_font_size @buff_info.bitmap.font.outline = false desc = "Открывает многопользовательский чат.\nВыбери эту строку и нажми любой слот навыка\n(A/S/D/F/Q/W/E/R/SP), чтобы назначить туда чат." draw_text_on_canvas(@buff_info, 13, 33, desc) return end mp_chat_action_refresh_skill_info_fixed3 end alias mp_chat_action_update_input_fixed3 update_input def update_input MPChatAction.ensure_chat_skill mp_chat_action_update_input_fixed3 end alias mp_chat_action_update_hotkey_set_input_fixed3 update_hotkey_set_input def update_hotkey_set_input MPChatAction.ensure_chat_skill mp_chat_action_update_hotkey_set_input_fixed3 mp_chat_action_refresh_slot_sprite if mp_chat_action_chat_skill_selected? end alias mp_chat_action_update_hotkey_unset_input_fixed3 update_hotkey_unset_input def update_hotkey_unset_input mp_chat_action_update_hotkey_unset_input_fixed3 mp_chat_action_refresh_slot_sprite if mp_chat_action_chat_skill_selected? end alias mp_chat_action_refresh_fixed3 refresh def refresh(*args) mp_chat_action_refresh_fixed3(*args) mp_chat_action_refresh_slot_sprite end alias mp_chat_action_show_fixed3 show def show(*args) mp_chat_action_show_fixed3(*args) if @mp_chat_action_sprite @mp_chat_action_sprite.visible = true mp_chat_action_refresh_slot_sprite end end alias mp_chat_action_hide_fixed3 hide def hide(*args) mp_chat_action_hide_fixed3(*args) @mp_chat_action_sprite.visible = false if @mp_chat_action_sprite end alias mp_chat_action_dispose_fixed3 dispose def dispose if @mp_chat_action_sprite @mp_chat_action_sprite.bitmap.dispose rescue nil @mp_chat_action_sprite.dispose rescue nil @mp_chat_action_sprite = nil end mp_chat_action_dispose_fixed3 end end