设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1211|回复: 0
打印 上一主题 下一主题

[已经过期] 繁中輸入法無法使用

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-2-4
帖子
20
跳转到指定楼层
1
发表于 2014-2-10 02:09:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 951121 于 2014-2-10 02:14 编辑


只要輸入文字,按空白鍵或是ENTER選取
就會變成這樣

可以請教大家這是為什麼嗎?
繁中輸入悲劇(艸)
腳本奉上
RUBY 代码复制
  1. module Sword
  2. #=======================================
  3. #★ 魔劍工舖 - 中文輸入法(0)
  4. # [url]http://blog.yam.com/a870053jjkj/[/url]
  5. #=======================================
  6. =begin
  7. ● 所需腳本
  8. 魔劍工舖整合腳本(3):[url]http://blog.yam.com/a870053jjkj/article/25751998[/url]
  9. 全鍵盤按鍵(4):[url]http://blog.yam.com/a870053jjkj/article/24190989[/url]
  10. ========================================
  11. ● 設置腳本
  12. 生成文字輸入框[C]:文字輸入框 = Input_Method.new(字數限制&, 行數限制&, 行距&, 視口&)
  13. 更新文字輸入框[R]:文字輸入框.update
  14. 文字輸入框內容[A]:文字輸入框.text
  15. 文字輸入框X座標[A]:文字輸入框.x
  16. 文字輸入框Y座標[A]:文字輸入框.y
  17. 文字輸入框Z座標[A]:文字輸入框.z
  18. 文字輸入框活動狀態[A]:文字輸入框.active
  19. 文字輸入框顯示狀態[A]:文字輸入框.visible
  20. 每行間的行距[A]:文字輸入框.row_spacing
  21. 設置密碼符號[A]:文字輸入框.cipher
  22. 注音和選字窗口位置類型[A]:文字輸入框.win_seat
  23. 文字游標位置[A]:文字輸入框.index
  24. 文字游標行數[A]:文字輸入框.row
  25. Enter鍵是否空閒[R]:文字輸入框.enter?
  26. 已輸入內容寬度[R]:文字輸入框.width
  27. 已輸入內容高度[R]:文字輸入框.height
  28. 待確認內容確認[R]:文字輸入框.decision
  29. 關閉文字輸入框[R]:文字輸入框.dispose
  30. 更新輸入法狀態[R]:Input_Method.update
  31. 鎖定輸入法[R]:Input_Method.lock(輸入法類型&)
  32. 設置輸入法狀態窗口[R]:Input_Method.statu(X座標&, Y座標&)
  33. 釋放輸入法狀態窗口[R]:Input_Method.statu_dispose
  34. ----------------------------------------
  35. 輸入法類型:0為注音、1為英文
  36. 窗口位置類型:1為左下、2為下、3為右下、7為左上、8為上、9為右上
  37. =end
  38. #=======================================
  39. #● 功能設定
  40. S84_Horizontal = false # 注音輸入框的顯示方式,true表示橫式;false表示直式
  41. S84_Decision = true # 是否啟用待確認內容功能
  42. S84_Default = [Font.new('細明體'), 3] # 文字輸入框預設的 [字體, 窗口位置類型]
  43. S84_Cursor = [0, 1, true] # 文字游標的 [類型, 厚度, 允許更換]
  44. S84_Phonetic = [Font.new('標楷體', 16), 0, 0] # 注音輸入框的 [字體, X修正, Y修正]
  45. S84_Choose = [80, 4, Font.new('細明體', 16)] # 選字窗口的 [寬度, 行距, 字體]
  46. #---------------------------------------
  47. # 字體:可設定Font對象『Font.new('字體名稱', 大小)』或nil使用預設字體
  48. #=======================================
  49.   $Sword ? $Sword[18] = [:中文輸入法, 0] : $Sword = {18=>[:中文輸入法, 0]}
  50. end
  51. #=======================================
  52. #■ 注音輸入框
  53. class WSword_Phonetic < Window_Base
  54.   attr_accessor(:phonetic) # 已輸入注音內容
  55.   attr_accessor(:win_choose) # 關連選字窗口
  56.   attr_accessor(:alter) # 修改標誌
  57.   # 注音表
  58.   Phonetic = {
  59.   49=>'ㄅ', 81=>'ㄆ', 65=>'ㄇ', 90=>'ㄈ', 50=>'ㄉ', 87=>'ㄊ', 83=>'ㄋ', 88=>'ㄌ',
  60.   69=>'ㄍ', 68=>'ㄎ', 67=>'ㄏ', 82=>'ㄐ', 70=>'ㄑ', 86=>'ㄒ', 53=>'ㄓ', 84=>'ㄔ',
  61.   71=>'ㄕ', 66=>'ㄖ', 89=>'ㄗ', 72=>'ㄘ', 78=>'ㄙ', 85=>'ㄧ', 74=>'ㄨ', 77=>'ㄩ',
  62.   56=>'ㄚ', 73=>'ㄛ', 75=>'ㄜ', 188=>'ㄝ', 57=>'ㄞ', 79=>'ㄟ', 76=>'ㄠ', 190=>'ㄡ',
  63.   48=>'ㄢ', 80=>'ㄣ', 186=>'ㄤ', 191=>'ㄥ', 189=>'ㄦ', 32=>' ', 54=>'ˊ', 51=>'ˇ',
  64.   52=>'ˋ', 55=>'˙'}
  65.   #------------------------------------------------------
  66.   #● 初始化
  67.   def initialize
  68.     super(16, 16, 64, 64)
  69.     self.contents = Bitmap.new(1, 1)
  70.     @phonetics = ['', '', '', ''] # [前, 中, 後, 聲]
  71.     @phonetic = ''
  72.     @alter = false # 修改標誌
  73.     @font = Sword::S84_Phonetic[0] ? Sword::S84_Phonetic[0].clone : Font.new
  74.     self.visible, self.z = false, 300
  75.   end
  76.   #------------------------------------------------------
  77.   #● 更新內容
  78.   def refresh
  79.     phonetics = @phonetic.scan(/./) # 分解字串
  80.     return self.visible = false if phonetics.empty? # 沒輸入就不顯示
  81.     size = @font.size # 獲取字體大小
  82.     self.visible = true
  83.     if Sword::S84_Horizontal # 橫式
  84.       self.width = contents.text_size(@phonetic).width + 32
  85.       self.height = size + 32
  86.       self.contents = Bitmap.new(width - 32, height - 32)
  87.       contents.font = @font
  88.       contents.draw_text(0, 0, width - 32, size, @phonetic)
  89.     else # 直式
  90.       self.width = size + 32
  91.       self.height = phonetics.size * size + 32
  92.       self.contents = Bitmap.new(width - 32, height - 32)
  93.       contents.font = @font
  94.       phonetics.each_index{|i| contents.draw_text(0, size * i, size, size, phonetics[i])}
  95.     end
  96.   end
  97.   #------------------------------------------------------
  98.   #● 添加(注音鍵值)
  99.   def add(key)
  100.     return if @win_choose.visible # 選字窗口顯示時不可變更
  101.     @alter = false
  102.     case key
  103.     when 49,81,65,90,50,87,83,88,69,68,67,82,70,86,53,84,71,66,89,72,78 then @phonetics[3], a = '', 0 # 前
  104.     when 85,74,77 then @phonetics[3], a = '', 1 # 中
  105.     when 56,73,75,188,57,79,76,190,48,80,186,191,189 then @phonetics[3], a = '', 2 # 後
  106.     when 32,54,51,52,55 then a = 3 # 聲
  107.     else return # 非合理內容
  108.     end
  109.     @phonetics[a] = Phonetic[key]
  110.     @phonetic = @phonetics.to_s
  111.     refresh
  112.     if a == 3 # 活化選字窗口
  113.       @win_choose.refresh(@phonetic)
  114.     end
  115.   end
  116.   #------------------------------------------------------
  117.   #● 指定注音(注音)
  118.   def set(phonetic)
  119.     @alter = true
  120.     @phonetic = phonetic
  121.     refresh
  122.     @win_choose.refresh(@phonetic, true)
  123.   end
  124.   #------------------------------------------------------
  125.   #● 清除(全部清除)
  126.   def remove(whole = false)
  127.     if whole # 全部清除
  128.       @phonetics = ['', '', '', '']
  129.     else # 尾字清除
  130.       [3, 2, 1, 0].each{|i| (@phonetics[i] = '' ; break) unless @phonetics[i].empty?}
  131.     end
  132.     @phonetic = @phonetics.to_s
  133.     refresh
  134.     @win_choose.visible = false
  135.   end
  136. end
  137. #=======================================
  138. #■ 選字窗口
  139. class WSword_ChooseWord < Window_Selectable
  140.   attr_accessor(:direct) # 直接輸入的字
  141.   #------------------------------------------------------
  142.   #● 初始化
  143.   def initialize
  144.     @font = Sword::S84_Choose[2] ? Sword::S84_Choose[2].clone : Font.new
  145.     super(0, 0, Sword::S84_Choose[0], (@font.size + Sword::S84_Choose[1]) * 11 + 32)
  146.     self.contents = Bitmap.new(width - 32, height - 32)
  147.     contents.font = @font
  148.     @page = 0 # 頁數
  149.     @key = '' # 當前輸入注音
  150.     @direct = nil # 無需選字時要直接輸出的字(只有1個字時才用)
  151.     self.visible, self.z = false, 300
  152.     @chinese = Chinese rescue raise('找不到字庫,請檢查是否有已經放置字庫腳本') # 讀取字庫
  153.   end
  154.   #------------------------------------------------------
  155.   #● 更新內容(注音, 修改標誌)
  156.   def refresh(phonetic = nil, alter = false)
  157.     if phonetic # 讀取新資料
  158.       return RM.se_buzzer unless @chinese[phonetic] # 資料庫未找到該注音的資料時
  159.       return @direct = @chinese[phonetic][0] if @chinese[phonetic].size == 1 && ! alter # 直接輸入
  160.       @key = phonetic
  161.       @page = 0
  162.       @index = 0
  163.       self.visible = true
  164.     end
  165.     contents.clear
  166.     i = 0
  167.     size = @font.size
  168.     w = (Sword::S84_Choose[0] - 32) / 2
  169.     sa = Sword::S84_Choose[1] + size
  170.     # 開始描繪每個選項的字
  171.     @chinese[@key][@page * 10, 10].each do |c|
  172.       contents.draw_text(0, i * sa, w, sa, (i == 9 ? 0 : i + 1).to_s, 1)
  173.       contents.draw_text(w, i * sa, w, sa, c, 1)
  174.       i += 1
  175.     end
  176.     @item_max = i
  177.     @page_size = @chinese[@key].size / 10 - (@chinese[@key].size % 10 == 0 ? 1 : 0) # 頁數上限
  178.     contents.draw_text(0, height - 32 - size, width - 32, size, "#{@page + 1}/#{@page_size + 1}", 1)
  179.   end
  180.   #------------------------------------------------------
  181.   #● 更新游標
  182.   def update_cursor_rect
  183.     cursor_rect.set(0, (Sword::S84_Choose[1] + @font.size) *
  184.     @index, width - 32, Sword::S84_Choose[1] + @font.size)
  185.   end
  186.   def update_cursor
  187.     update_cursor_rect
  188.   end
  189.   #------------------------------------------------------
  190.   #● 更新
  191.   def update
  192.     super
  193.     choose = nil # 代表確定選擇的項目
  194.     if Input.trigger?(37) # 左一頁
  195.       @page -= 1
  196.       @page = @page_size if @page < 0
  197.       refresh
  198.       @index = @item_max - 1 if @index >= @item_max # 換頁時游標位置修正
  199.       RM.se_cursor
  200.     elsif Input.trigger?(39) # 右一頁
  201.       @page += 1
  202.       @page = 0 if @page > @page_size
  203.       refresh
  204.       @index = @item_max - 1 if @index >= @item_max
  205.       RM.se_cursor
  206.     elsif Input.trigger?([13, 32]) # 確定(空白、ENTER)
  207.       choose = @index
  208.     end
  209.     (48..57).each{|i| choose = i == 48 ? 9 : i - 49 if Input.trigger?(i)} unless choose # 左數字鍵
  210.     (96..105).each{|i| choose = i == 96 ? 9 : i - 97 if Input.trigger?(i)} unless choose # 右數字鍵
  211.     if choose # 確認選擇
  212.       return nil unless c = @chinese[@key][@page * 10, 10][choose] # 結果確認
  213.       self.visible = false
  214.       return c # 返回結果
  215.     end
  216.     nil # 尚未選字代表的返回值
  217.   end
  218. end
  219. #=======================================
  220. #■ 輸入法窗口
  221. class Input_Method
  222.   attr_reader(:x) # X座標
  223.   attr_reader(:y) # Y座標
  224.   attr_reader(:z) # Z座標
  225.   attr_reader(:index) # 索引
  226.   attr_reader(:row) # 行數
  227.   attr_reader(:visible) # 隱藏狀態
  228.   attr_reader(:win_seat) # 窗口位置類型
  229.   attr_reader(:windowskin) # 窗口皮膚
  230.   attr_accessor(:cipher) # 密碼
  231.   attr_accessor(:font) # 字體
  232.   attr_accessor(:imports) # 當前輸入的內容
  233.   attr_accessor(:row_spacing) # 行距
  234.   Kind_Max = 2 # 輸入法數量
  235.   Phonetic_keys = WSword_Phonetic::Phonetic.keys
  236.   # 符號資料庫(左方鍵盤用)
  237.   Tilde = { # 半形
  238.   48=>')', 49=>'!', 50=>'@', 51=>'#', 52=>'$', 53=>'%', 54=>'^', 55=>'&', 56=>'*', 57=>'(',
  239.   186=>':', 187=>'+', 188=>'<', 189=>'_', 190=>'>', 191=>'?', 192=>'~', 219=>'{', 220=>'|', 221=>'}', 222=>'"'}
  240.   TILDE = { # 全形
  241.   48=>')', 49=>'!', 50=>'@', 51=>'#', 52=>'$', 53=>'%', 54=>'︿', 55=>'&', 56=>'*', 57=>'(',
  242.   186=>':', 187=>'+', 188=>'<', 189=>'_', 190=>'>', 191=>'?', 192=>'~', 219=>'{', 220=>'|', 221=>'}', 222=>'"'}
  243.   Tilde_keys = Tilde.keys
  244.   # 符號資料庫(右方鍵盤用+空白鍵)
  245.   TildeR = { # 半形
  246.   32=>' ', 96=>'0', 97=>'1', 98=>'2', 99=>'3', 100=>'4', 101=>'5', 102=>'6',
  247.   103=>'7', 104=>'8', 105=>'9', 106=>'*', 107=>'+', 109=>'-', 110=>'.', 111=>'/'}
  248.   TILDER = { # 全形
  249.   32=>' ', 96=>'0', 97=>'1', 98=>'2', 99=>'3', 100=>'4', 101=>'5', 102=>'6',
  250.   103=>'7', 104=>'8', 105=>'9', 106=>'*', 107=>'+', 109=>'-', 110=>'。', 111=>'/'}
  251.   TildeR_keys = TildeR.keys
  252.   # 中文聲符
  253.   Pho_Voice = {32=>' ', 54=>'ˊ', 51=>'ˇ', 52=>'ˋ', 55=>'˙'}
  254.   # 英文大寫資料庫(半)
  255.   English = {
  256.   65=>'A', 66=>'B', 67=>'C', 68=>'D', 69=>'E', 70=>'F', 71=>'G', 72=>'H' ,73=>'I',
  257.   74=>'J', 75=>'K', 76=>'L', 77=>'M', 78=>'N', 79=>'O', 80=>'P', 81=>'Q' ,82=>'R',
  258.   83=>'S', 84=>'T', 85=>'U', 86=>'V', 87=>'W', 88=>'X', 89=>'Y', 90=>'Z', 48=>'0',
  259.   49=>'1', 50=>'2', 51=>'3', 52=>'4', 53=>'5', 54=>'6', 55=>'7', 56=>'8', 57=>'9',
  260.   191=>'/', 186=>';', 187=>'=', 188=>',', 189=>'-', 190=>'.', 191=>'/', 192=>'`',
  261.   219=>'[', 220=>'\\', 221=>']', 222=>'\''}
  262.   English_keys = English.keys
  263.   # 英文小寫資料庫(半)
  264.   English_small = {
  265.   65=>'a', 66=>'b', 67=>'c', 68=>'d', 69=>'e', 70=>'f', 71=>'g', 72=>'h' ,73=>'i',
  266.   74=>'j', 75=>'k', 76=>'l', 77=>'m', 78=>'n', 79=>'o', 80=>'p', 81=>'q' ,82=>'r',
  267.   83=>'s', 84=>'t', 85=>'u', 86=>'v', 87=>'w', 88=>'x', 89=>'y', 90=>'z', 48=>'0',
  268.   49=>'1', 50=>'2', 51=>'3', 52=>'4', 53=>'5', 54=>'6', 55=>'7', 56=>'8', 57=>'9',
  269.   191=>'/', 186=>';', 187=>'=', 188=>',', 189=>'-', 190=>'.', 191=>'/', 192=>'`',
  270.   219=>'[', 220=>'\\', 221=>']',  222=>'\''}
  271.   # 英文大寫資料庫(全)
  272.   ENGLISH = {
  273.   65=>'A', 66=>'B', 67=>'C', 68=>'D', 69=>'E', 70=>'F', 71=>'G', 72=>'H' ,
  274.   73=>'I', 74=>'J', 75=>'K', 76=>'L', 77=>'M', 78=>'N', 79=>'O', 80=>'P',
  275.   81=>'Q', 82=>'R', 83=>'S', 84=>'T', 85=>'U', 86=>'V', 87=>'W', 88=>'X',
  276.   89=>'Y', 90=>'Z', 48=>'0', 49=>'1', 50=>'2', 51=>'3', 52=>'4', 53=>'5',
  277.   54=>'6', 55=>'7', 56=>'8', 57=>'9', 186=>';', 187=>'=', 188=>',',
  278.   189=>'-', 190=>'。', 191=>'/', 192=>'‵', 219=>'[', 220=>'\', 221=>']', 222=>'’'}
  279.   # 英文小寫資料庫(全)
  280.   ENGLISH_SMALL = {
  281.   65=>'a', 66=>'b', 67=>'c', 68=>'d', 69=>'e', 70=>'f', 71=>'g', 72=>'h' ,
  282.   73=>'i', 74=>'j', 75=>'k', 76=>'l', 77=>'m', 78=>'n', 79=>'o', 80=>'p',
  283.   81=>'q', 82=>'r', 83=>'s', 84=>'t', 85=>'u', 86=>'v', 87=>'w', 88=>'x',
  284.   89=>'y', 90=>'z', 48=>'0', 49=>'1', 50=>'2', 51=>'3', 52=>'4', 53=>'5',
  285.   54=>'6', 55=>'7', 56=>'8', 57=>'9', 186=>';', 187=>'=', 188=>',',
  286.   189=>'-', 190=>'。', 191=>'/', 192=>'‵', 219=>'[', 220=>'\', 221=>']', 222=>'’',}
  287.   @@caps_lock = @@fully = false # 大寫標誌, 全形標誌
  288.   @@fully_true = false # 全形標誌變更標誌
  289.   @@kind, @@lock = 0, [] # 輸入法種類, 鎖定的輸入法種類
  290.   @@win_method_statu = nil # 輸入法狀態窗口
  291.   @@manage = {} # 已生成文字輸入框列表
  292.   @@active = nil # 正在活動對象
  293.   @@win_choose = @@win_phonetic = nil # 選字窗口, 注音輸入框
  294.   #------------------------------------------------------
  295.   #● 初始化(字數限制, 行數限制, 視口)
  296.   def initialize(max = 0, row_max = 0, viewport = nil)
  297.     if @@manage.empty? # 未存在文字輸入窗時就生成
  298.       @@win_choose = WSword_ChooseWord.new # 選字窗口
  299.       @@win_phonetic = WSword_Phonetic.new # 注音輸入框
  300.       @@win_phonetic.win_choose = @@win_choose # 關連
  301.     end
  302.     @@manage[self.__id__] = self # 加入列表
  303.     @viewport = viewport # 視口
  304.     @font = Sword::S84_Default[0] ? Sword::S84_Default[0].clone : Font.new # 字體
  305.     @cipher = '' # 密碼符號
  306.     @imports = [[]] # 每行當前輸入的單個文字
  307.     @show = [[]] # 用於顯示於文字輸入框的文字
  308.     @index = @row = @row_spacing = 0 # 索引、行數、行距
  309.     @insert = Sword::S84_Cursor[0] # 文字游標類型
  310.     @max = max # 字數限制
  311.     @row_max = row_max # 最大行數
  312.     @win_seat = Sword::S84_Default[1] # 窗口位置類型
  313.     @cursor_size = [0, 0] # 文字游標 [寬度, 高度]
  314.     @avail = [] # 按鍵無效列表 [Enter, 聲符(包含右邊小鍵盤), 空白]
  315.     @affirm = [0, 0, [], 0, 0] # 等待確認輸入 [X座標, Y座標, 注音, 起始, 終點]
  316.     @windowskin = nil # 窗口皮膚
  317.     @spr_import = Sprite.new(@viewport) # 輸入窗口
  318.     @spr_import.bitmap = Bitmap.new(1, 1) # 一開始計算單個字寬度用的位圖
  319.     @spr_cursor = Sprite.new(@viewport) # 文字游標
  320.     @spr_cursor.bitmap = Bitmap.new(50, 50)
  321.     @cursor_update = 0 # 文字游標的閃爍計數
  322.     self.x, self.y, self.z = 0, 0, 200
  323.     self.active = @@active.nil? # 活動對象(第1個文字輸入框有效)
  324.     @visible = true # 顯示狀態
  325.   end
  326.   #------------------------------------------------------
  327.   #● 獲取文字
  328.   def text
  329.     text = ''
  330.     @imports.each{|import| text += import.to_s + "\n"}
  331.     text[-1] = ''
  332.     text
  333.   end
  334.   #------------------------------------------------------
  335.   #● 修改文字=(新文字)
  336.   def text=(text)
  337.     @imports = [[]] # 清空
  338.     i = 0
  339.     text.split(/\n/).each do |item|
  340.       @imports[i] = item.scan(/./)
  341.       i += 1
  342.     end
  343.     refresh
  344.     cursor_refresh
  345.   end
  346.   #------------------------------------------------------
  347.   #● 獲取已輸入內容的寬度
  348.   def width
  349.     return @cursor_size[0] if @spr_import.bitmap.width == 1 # 沒有文字就返回0
  350.     @spr_import.bitmap.width + (self.index == @imports[@row].size ? @cursor_size[0] : 0)
  351.   end
  352.   #------------------------------------------------------
  353.   #● 獲取已輸入內容的高度
  354.   def height
  355.     @spr_import.bitmap.height + (@imports[@row + 1] ? 0 : @cursor_size[1])
  356.   end
  357.   #------------------------------------------------------
  358.   #● 設定X座標=(新X座標)
  359.   def x=(x)
  360.     @spr_import.x = @x = x
  361.     @spr_cursor.x = x + @spr_import.bitmap.text_size(@imports[@row][0, @index].to_s).width
  362.     win_phonetic_seat
  363.   end
  364.   #------------------------------------------------------
  365.   #● 設定Y座標=(新Y座標)
  366.   def y=(y)
  367.     @spr_import.y = @y = y
  368.     @spr_cursor.y = y + @row * (@font.size + @row_spacing)
  369.     win_phonetic_seat
  370.   end
  371.   #------------------------------------------------------
  372.   #● 設定Z座標=(新Z座標)
  373.   def z=(z)
  374.     @spr_import.z = @spr_cursor.z = @z = z
  375.   end
  376.   #------------------------------------------------------
  377.   #● 變更索引=(新索引)
  378.   def index=(index)
  379.     if @affirm[2].empty?
  380.       @index = [[index, @imports[@row].size].min, 0].max
  381.     else @index = [[index, @affirm[4] + 1].min, @affirm[3]].max
  382.     end
  383.     cursor_refresh
  384.   end
  385.   #------------------------------------------------------
  386.   #● 獲取活動狀態
  387.   def active
  388.     equal?(@@active) ? true : false
  389.   end
  390.   #------------------------------------------------------
  391.   #● 變更窗口位置類型
  392.   def win_seat=(win_seat)
  393.     @win_seat = win_seat
  394.     win_phonetic_seat
  395.   end
  396.   #------------------------------------------------------
  397.   #● 變更活動狀態=(活動標誌)
  398.   def active=(active)
  399.     @spr_cursor.visible = active
  400.     if active && ! self.active # 不處於活動狀態的輸入框設為true
  401.       if @@active # 如果有其他的文字輸入框活動的情況
  402.         @@win_phonetic.remove(true)
  403.         @@win_choose.visible = false
  404.         @@active.decision
  405.         @@active.active = false
  406.       end
  407.       @@active = self
  408.       @spr_cursor.visible = true
  409.       cursor_refresh
  410.     elsif ! active && self.active # 處於活動狀態的輸入框設為false
  411.       @@active = nil
  412.     end
  413.   end
  414.   #------------------------------------------------------
  415.   #● 隱藏狀態變更=(隱藏標誌)
  416.   def visible=(visible)
  417.     @spr_cursor.visible = @spr_import.visible = @visible = visible
  418.   end
  419.   #------------------------------------------------------
  420.   #● 變更行數=(新行數)
  421.   def row=(row)
  422.     @row = [row, 0].max
  423.     @row = [@row, @row_max - 1].min if @row_max > 0
  424.     cursor_refresh
  425.   end
  426.   #------------------------------------------------------
  427.   #● 可以輸入判斷(準備添加的字)
  428.   def import?(c = '')
  429.     return true if @max == 0 # 無限制的場合
  430.     if @max > 0 # 字數
  431.       n = -1 # 字數計數
  432.       @imports.each{|imports| n += 1 ; n += imports.size}
  433.       n += 1 unless c.empty?
  434.     else ; n = (text + c).size # 字元數
  435.     end
  436.     return @max.abs >= n # 返回結果
  437.   end
  438.   #------------------------------------------------------
  439.   #● 可以換行判斷
  440.   def row?
  441.     return true if @row_max <= 0 # 無限制的場合
  442.     return @row_max > @imports.size # 返回結果
  443.   end
  444.   #------------------------------------------------------
  445.   #● 到達底行時,Enter是否可用
  446.   def enter?
  447.     return false if ! @affirm[2].empty? || @@win_phonetic.visible || ! active
  448.     row? ? false : (@avail[0] ? false : true)
  449.   end
  450.   #------------------------------------------------------
  451.   #● 更新內容
  452.   def refresh
  453.     # 計算所需資料
  454.     imports, width = [], 0 # 已轉換字串文字列表, 最大寬度
  455.     @show = [[]] # 清空
  456.     @imports.each_index do |i|
  457.       @show[i] = @cipher[0] ? Array.new(@imports[i].size, @cipher) : @imports[i] # 轉密碼
  458.       import = @show[i].to_s # 轉換為字串
  459.       if a = @spr_import.bitmap.text_size(import).width # 獲取這個字的寬度
  460.         width = a if a > width # 設定最大寬度
  461.       end
  462.       imports << import
  463.     end
  464.     # 描繪文字內容
  465.     width = 1 if width == 0 # 沒有文字的情況下
  466.     row = @font.size + @row_spacing # 行距計算
  467.     @spr_import.bitmap = Bitmap.new(width, row * @show.size) # 重新產生位圖
  468.     @spr_import.bitmap.font = @font
  469.     imports.each_index{|i| import = imports[i]
  470.     @spr_import.bitmap.draw_text(0, row * i, width, @font.size, import)}
  471.     # 描繪待確認文字虛線
  472.     unless @affirm[2].empty?
  473.       width = @spr_import.bitmap.text_size(@show[@row][@affirm[3]..@affirm[4]].to_s).width
  474.       x = 0
  475.       while x < width
  476.         @spr_import.bitmap.fill_rect(@affirm[0] + x, @affirm[1] + @font.size - 1, 2, 1, @font.color)
  477.         x += 3
  478.       end
  479.     end
  480.     cursor_refresh
  481.     win_phonetic_seat
  482.   end
  483.   #------------------------------------------------------
  484.   #● 更新文字游標內容
  485.   def cursor_refresh
  486.     @cursor_update = 0
  487.     return unless @spr_cursor.visible = active && visible # 移動文字游標時的顯示
  488.     @spr_cursor.x = @x + @spr_import.bitmap.text_size(@show[@row][0, @index].to_s).width
  489.     @spr_cursor.y = @y + @row * (@font.size + @row_spacing)
  490.     @spr_cursor.bitmap.clear
  491.     @spr_cursor.bitmap.font = @font
  492.     case @insert
  493.     when 0 # |
  494.       @spr_cursor.bitmap.fill_rect(0, 0, Sword::S84_Cursor[1], @font.size, @font.color)
  495.       @cursor_size = [Sword::S84_Cursor[1], 0]
  496.     when 1 # _
  497.       width = @spr_cursor.bitmap.text_size(@show[@row][@index] ? @show[@row][@index] : ' ').width
  498.       @spr_cursor.bitmap.fill_rect(0, @font.size, width, Sword::S84_Cursor[1], @font.color)
  499.       @cursor_size = [width, Sword::S84_Cursor[1]]
  500.     end
  501.   end
  502.   #------------------------------------------------------
  503.   #● 更新窗口
  504.   def update
  505.     return unless active # 不活動就中斷
  506.     #○ 文字游標閃爍更新
  507.     if @visible # 文字輸入框顯示時
  508.       @cursor_update += 1 # 增加游標閃爍計數
  509.       @spr_cursor.visible = ! @spr_cursor.visible if @cursor_update % 20 == 0
  510.     end
  511.     #○ 任何時機均可執行處
  512.     Input_Method.update # 輸入法按鍵判斷
  513.     if Input.trigger?(45) && Sword::S84_Cursor[2] # 切換文字游標樣式
  514.       @insert = @insert == 0 ? 1 : 0
  515.       cursor_refresh
  516.     elsif Input.press?(16) && Input.trigger?(32) # 切換全半形(追加處理)
  517.       @avail[2] = true # 封鎖空白的使用權
  518.     end
  519.     #○ 注音輸入法相關
  520.     if @@win_choose.direct # 當選字窗口只有1個字可選時直接輸入
  521.       @avail[1] = true # 封鎖聲符的使用權
  522.       add(@@win_choose.direct)
  523.       @@win_phonetic.remove(true)
  524.       @@win_choose.direct = nil
  525.       return
  526.     elsif @@win_choose.visible # 選字窗口顯示時
  527.       @avail[1] = true # 封鎖聲符的使用權
  528.       if c = @@win_choose.update # 更新結果為已經選擇文字時
  529.         add(c)
  530.         @@win_phonetic.remove(true)
  531.         @avail[0] = true # 封鎖Enter的使用權
  532.       end
  533.       if Input.repeat?(8) then @@win_phonetic.remove # 清除一個注音
  534.       elsif Input.trigger?(27) then @@win_phonetic.remove(true) # 清除所有注音
  535.       end
  536.       return
  537.     elsif @@win_phonetic.visible # 注音輸入框顯示時
  538.       if Input_Method.kind != 0 # 非注音輸入法時
  539.         @@win_phonetic.remove(true)
  540.         @@win_choose.visible = false
  541.         return
  542.       end
  543.       Phonetic_keys.each do |key| if Input.trigger?(key) # 注音輸入
  544.         @@win_phonetic.add(key)
  545.         win_phonetic_seat
  546.       end end
  547.       if Input.repeat?(8) then @@win_phonetic.remove # 清除一個注音
  548.       elsif Input.trigger?(27) then @@win_phonetic.remove(true) # 清除所有注音
  549.       end
  550.       return
  551.     end
  552.     #○ 恢復被限制的使用權
  553.     @avail[0] = false unless Input.press?(13) if @avail[0] # 恢復Enter使用權
  554.     @avail[1] = false if Input.press?(Pho_Voice.keys + TildeR_keys, true).empty? if @avail[1] # 恢復聲符使用權
  555.     @avail[2] = false unless Input.press?(16) if @avail[2] # 恢復空白使用權
  556.     #○ 等待確認文字處理
  557.     unless @affirm[2].empty?
  558.       if Input.trigger?(40) # 重新開啟選字窗口
  559.         return if @index == @affirm[4] + 1 || @affirm[2][@index - @affirm[3]] == true
  560.         win_phonetic_seat
  561.         @@win_phonetic.set(@affirm[2][@index - @affirm[3]])  
  562.       elsif Input.trigger?(13) # 確認結果
  563.         @avail[0] = true # 封鎖Enter使用權
  564.         return decision
  565.       end
  566.     end
  567.     #○ 不再注音輸入顯現時的按鍵執行
  568.     case
  569.     when Input.repeat?(8) then remove # 清除前一個字
  570.     when Input.repeat?(46) then remove(true) # 清除後一個字
  571.     when Input.trigger?(27) then self.text = '' # 清空
  572.     when Input.repeat?(37) # 左移
  573.       return if @index == @affirm[3] unless @affirm[2].empty?
  574.       if @row > 0 && self.index == 0
  575.         @row -= 1 ; self.index = @imports[@row].size
  576.       else ; self.index -= 1
  577.       end
  578.     when Input.repeat?(39) # 右移
  579.       return if @index == @affirm[4] + 1 unless @affirm[2].empty?
  580.       if @imports[@row + 1] && self.index == @imports[@row].size
  581.         @row += 1 ; self.index = 0
  582.       else ; self.index += 1
  583.       end
  584.     when Input.repeat?(38) # 上移
  585.       return unless @affirm[2].empty?
  586.       self.row -= 1 if @row > 0
  587.     when Input.repeat?(40) # 下移
  588.       return unless @affirm[2].empty?
  589.       self.row += 1 if @imports[@row + 1]
  590.     when Input.repeat?(13) && ! @avail[0] # 換行
  591.       return unless @affirm[2].empty? # 待確認內容情況
  592.       return if ! import?("\n") || ! row? # 已達限制就中斷
  593.       a = @imports[@row][@index..@imports[@row].size-1] # 獲取換到下行的文字
  594.       @imports[@row].slice!(@index..@imports[@row].size-1) # 剪下?!
  595.       @row += 1
  596.       @imports[@row, 0] = [a] # 貼上?!
  597.       refresh
  598.       self.index = 0 # 文字游標移動行頭
  599.     end
  600.     #○ 處理各個輸入法都可用的符號輸入(空白鍵和右方數字鍵)
  601.     TildeR_keys.each{|key| add(Input_Method.fully ? TILDER[key] : TildeR[key]) if Input.repeat?(key)} unless @avail[1]
  602.     #○ 各類輸入法的處理
  603.     case Input_Method.kind
  604.     when 0 # 注音輸入
  605.       if Input.press?(192) # 按下~在按下符號鍵視同輸入全形符號
  606.         Tilde_keys.each{|key| next if key == 192
  607.         add(Input.press?(16) ? TILDE[key] : ENGLISH[key]) if Input.trigger?(key)}
  608.         return
  609.       elsif Input.press?(16) then return english_import # 按下Shift視同英打
  610.       end
  611.       Pho_Voice.each do |key, value| # 聲符輸入開始
  612.         add(value) if Input.repeat?(key) && key != 32 # 輸入聲符
  613.         return if Input.press?(key) # 按住期間不可輸入注音
  614.       end unless @avail[1]
  615.       Phonetic_keys.each do |key| if Input.trigger?(key) # 注音輸入開始
  616.         @@win_phonetic.add(key)
  617.         win_phonetic_seat
  618.       end end
  619.     when 1 # 英文輸入
  620.       english_import # 英文輸入開始
  621.     end
  622.   end
  623.   #------------------------------------------------------
  624.   #● 英文輸入處理
  625.   def english_import
  626.     fully, caps_lock = Input_Method.fully, Input_Method.caps_lock
  627.     English_keys.each do |key| if Input.repeat?(key)
  628.       press = Input.press?(16) # Shift按下確認
  629.       case
  630.       when fully && TILDE[key] && press then add(TILDE[key]) # 全形符號
  631.       when Tilde[key] && press then add(Tilde[key]) # 半形符號
  632.       when fully && caps_lock != press then add(ENGLISH[key]) # 全形大寫
  633.       when fully && ! caps_lock != press then add(ENGLISH_SMALL[key]) # 全形小寫
  634.       when caps_lock != press then add(English[key]) # 半形大寫
  635.       when ! caps_lock != press then add(English_small[key]) # 半形小寫
  636.       end
  637.     end end
  638.   end
  639.   #------------------------------------------------------
  640.   #● 添加字到文字輸入框(添加的字)
  641.   def add(c)
  642.     return if /[  ]/ === c if @avail[2] # 空白輸入封鎖時中斷
  643.     # 修改的場合
  644.     if @@win_phonetic.alter
  645.       @@win_phonetic.alter = false
  646.       @imports[@row][@index, 1] = c
  647.       self.index += 1
  648.       return refresh
  649.     end
  650.     return unless import?(c) # 突破限制字數就中斷
  651.     # 是否可選字判斷
  652.     if Sword::S84_Decision
  653.       case
  654.       when buffer = Choose[c] # 符號
  655.       when buffer = @@win_phonetic.phonetic.empty? ? nil : @@win_phonetic.phonetic # 注音
  656.       when @affirm[2].size > 0 then buffer = true # 處理
  657.       end
  658.       # 待確認文字處理
  659.       if buffer
  660.         if @affirm[2].empty? # 尚未存在待輸入內容時
  661.           # 紀錄文字游標X座標, Y座標, 最小索引位置, 最大索引位置
  662.           @affirm[0], @affirm[1], @affirm[3], @affirm[4] =
  663.           @spr_cursor.x - @x, @spr_cursor.y - @y, @index, @index - 1
  664.         end
  665.         @affirm[2] << buffer
  666.         @affirm[4] += 1 # 最大索引增加
  667.       end
  668.     end
  669.     # 直接輸出
  670.     @imports[@row][@index, 0] = c
  671.     refresh
  672.     self.index += 1
  673.   end
  674.   #------------------------------------------------------
  675.   #● 清除(delete鍵標誌)
  676.   def remove(delete = false)
  677.     if delete # delete鍵
  678.       unless @affirm[2].empty? # 只能刪除待確認文字
  679.         return if @index == @affirm[4] + 1 # 游標在待確認文字最左邊就中斷
  680.         @affirm[2].delete_at(@index - @affirm[3])
  681.         @affirm[4] -= 1
  682.       end
  683.       @imports[@row].delete_at(@index)
  684.       cursor_refresh # 純粹更新文字游標用
  685.     else # BACKSPACE鍵
  686.       unless @affirm[2].empty? # 只能刪除待確認文字
  687.         return if @index == @affirm[3] # 游標在待確認文字最左邊就中斷
  688.         @affirm[2].delete_at(@index - @affirm[3] - 1)
  689.         @affirm[4] -= 1
  690.       end
  691.       if @index > 0 # 文字游標非在最左邊時
  692.         @imports[@row].delete_at(@index - 1)
  693.         self.index -= 1
  694.       else # 文字游標在最左邊時
  695.         if @row > 0 # 在第2行以上的場合
  696.           a = @imports[@row] # 獲取要移動到上一行的字
  697.           @imports.delete_at(@row) # 剪下?!
  698.           @row -= 1
  699.           @imports[@row] += a # 貼上?!
  700.           self.index = @imports[@row].size - a.size # 文字游標移至最右邊
  701.         end
  702.       end
  703.     end
  704.     refresh
  705.   end
  706.   #------------------------------------------------------
  707.   #● 確認
  708.   def decision
  709.     @affirm[2].clear
  710.     refresh
  711.   end
  712.   #------------------------------------------------------
  713.   #● 設定注音輸入框的位置(類型索引)
  714.   def win_phonetic_seat(type = nil)
  715.     pho, cho = @@win_phonetic, @@win_choose # 縮短名稱
  716.     pho.x = [[@spr_cursor.x + Sword::S84_Phonetic[1], RM.width - pho.width].min, 0].max
  717.     pho.y = [[@spr_cursor.y + Sword::S84_Phonetic[2] + @font.size, RM.height - pho.height].min, 0].max
  718.     case type ? type : @win_seat
  719.     when 1 # 左側下方
  720.       cho.x = pho.x - cho.width
  721.       return win_phonetic_seat(3) if cho.x < 0
  722.       cho.y = [pho.y, RM.height - cho.height].min
  723.     when 2 # 下方
  724.       cho.y = pho.y + pho.height
  725.       return win_phonetic_seat(8) if cho.y + cho.height > RM.height
  726.       cho.x = [pho.x, RM.width - pho.width].min
  727.     when 3 # 右側下方
  728.       cho.x = pho.x + pho.width
  729.       return win_phonetic_seat(1) if cho.x + cho.width > RM.width
  730.       cho.y = [pho.y, RM.height - cho.height].min
  731.     when 7 # 左側上方
  732.       cho.x = pho.x - cho.width
  733.       return win_phonetic_seat(9) if cho.x < 0
  734.       cho.y = [pho.y - cho.height + pho.height, 0].max
  735.     when 8 # 上方
  736.       cho.y = pho.y - cho.height
  737.       return win_phonetic_seat(2) if cho.y < 0
  738.       cho.x = [pho.x, RM.width - pho.width].min
  739.     when 9 # 右側上方
  740.       cho.x = pho.x + pho.width
  741.       return win_phonetic_seat(7) if cho.x + cho.width > RM.width
  742.       cho.y = [pho.y - cho.height + pho.height, 0].max
  743.     end
  744.   end
  745.   #------------------------------------------------------
  746.   #● 釋放窗口
  747.   def dispose
  748.     @spr_import.dispose
  749.     @spr_cursor.dispose
  750.     if active # 如果釋放對象為活動窗口時
  751.       @@active = nil
  752.       if @@win_phonetic.visible # 注音輸入框如果顯示,就清除掉
  753.         @@win_phonetic.remove(true)
  754.         @@win_choose.visible = false
  755.       end
  756.     end
  757.     @@manage.delete(self.__id__) # 清除紀錄
  758.     if @@manage.empty? # 文字輸入框清除光就釋放
  759.       @@win_phonetic.dispose
  760.       @@win_choose.dispose
  761.     end
  762.   end
  763.   #------------------------------------------------------
  764.   #● 設置輸入法狀態窗口(X座標, Y座標)
  765.   def self.statu(x = nil, y = nil)
  766.     @@win_method_statu = WSword_MethodStatu.new unless @@win_method_statu # 生成
  767.     @@win_method_statu.x = x if x
  768.     @@win_method_statu.y = y if y
  769.     @@win_method_statu.refresh
  770.   end
  771.   #------------------------------------------------------
  772.   #● 釋放輸入法狀態窗口
  773.   def self.statu_dispose
  774.     return unless @@win_method_statu # 已經釋放就中斷
  775.     @@win_method_statu.dispose
  776.     @@win_method_statu = nil
  777.   end
  778.   #------------------------------------------------------
  779.   #● 獲取輸入法號
  780.   def self.kind
  781.     @@lock[0] ? @@lock[0] : @@kind
  782.   end
  783.   #------------------------------------------------------
  784.   #● 獲取大寫標誌
  785.   def self.caps_lock
  786.     @@lock[1].nil? ? @@caps_lock : @@lock[1]
  787.   end
  788.   #------------------------------------------------------
  789.   #● 獲取全形標誌
  790.   def self.fully
  791.     @@lock[2].nil? ? @@fully : @@lock[2]
  792.   end
  793.   #------------------------------------------------------
  794.   #● 鎖定輸入法(輸入法種類, 大寫標誌, 全型標誌)
  795.   def self.lock(kind = nil, caps_lock = nil, fully = nil)
  796.     @@lock = [kind, caps_lock, fully]
  797.     @@win_method_statu.refresh if @@win_method_statu # 更新輸入法狀態窗口
  798.   end
  799.   #------------------------------------------------------
  800.   #● 更新按鍵
  801.   def self.update
  802.     if Input.trigger?(20) # 切換大小寫
  803.       @@caps_lock = ! @@caps_lock
  804.       @@win_method_statu.refresh if @@win_method_statu # 更新輸入法狀態窗口
  805.     elsif Input.trigger?(17) # 切換輸入法
  806.       @@kind += 1
  807.       @@kind = 0 if @@kind == Kind_Max
  808.       @@win_method_statu.refresh if @@win_method_statu # 更新輸入法狀態窗口
  809.     elsif Input.press?(16) && Input.trigger?(32) # 切換全半形
  810.       @@fully = ! @@fully
  811.       @@win_method_statu.refresh if @@win_method_statu # 更新輸入法狀態窗口
  812.     end
  813.   end
  814. end
  815. #=======================================
  816. #■ 輸入法狀態窗口
  817. class WSword_MethodStatu < Window_Base
  818.   #------------------------------------------------------
  819.   #● 初始化
  820.   def initialize
  821.     super(0, 0, 96, 64)
  822.     self.contents = Bitmap.new(width - 32, height - 32)
  823.   end
  824.   #------------------------------------------------------
  825.   #● 更新內容
  826.   def refresh
  827.     contents.clear
  828.     contents.draw_text(0, 0, 32, 32,
  829.     Input_Method.kind == 0 ? 'ㄅ' : (Input_Method.caps_lock ? 'A' : 'a'), 1)
  830.     contents.fill_rect(36, 4, 24, 24, contents.font.color)
  831.     contents.fill_rect(36 + 12, 5, 11, 22, Color.new(0, 0, 0, 0)) unless Input_Method.fully
  832.   end
  833. end
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-6-14 05:28

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表