Advertisement
Guest User

หน้าจอไอเท็มแสดงรูปด้านขวา

a guest
Oct 31st, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.87 KB | None | 0 0
  1. #==============================================================================
  2. # หน้าจอไอเท็มแสดงรูปด้านขวา
  3. # ผู้เขียน : jojo741963
  4. # เวอร์ชั่น : 1.0 - 31/10/2014
  5. #------------------------------------------------------------------------------
  6. # คุณสมบัติ :
  7. #  แสดงรูปไอเท็มด้านขวาของ Scene_Item
  8. #------------------------------------------------------------------------------
  9. # วิธีใช้ :
  10. #  นำสคริปต์นี้ไปวางเหนือสคริปต์ Main และใต้ Scene_Debug
  11. #    หารูปที่จะใช้แสดงประกอบไอเท็มไอดีที่ต้องการ กำหนดชื่อได้จากส่วนตั้งค่าข้างล่าง ใส่ในโฟลเดอร์ Pictures
  12. #    **ไม่จำเป็นต้องหามาใส่ทุกรูปก็ได้ ไอเท็มไหนที่ไม่มีรูป จะเป็นช่องว่างๆ เอาไว้
  13. #==============================================================================
  14.  
  15. module Item_Help
  16.  
  17.   #กำหนดชื่อของไฟล์รูปภาพ ที่ต้องตามหลังด้วย ไอดีของไอเท็ม อยู่ในโฟลเดอร์ Pictures
  18.   Name = "item_pic"
  19.  
  20.   #ต้องการให้แสดงจำนวนไอเท็มด้วยหรือไม่
  21.   Amount_item = true
  22.  
  23.   #ความโปร่งใสของวินโดว์รูป ถ้าต้องการให้โปร่งใส ก็ใส่เป็น 0
  24.   Window_Back_Opacity = 255
  25.  
  26. end
  27.  
  28.  
  29. #==============================================================================
  30. # * Window_Item
  31. #------------------------------------------------------------------------------
  32. #  In the item picture and the battle picture, it is the window which indicates the summary
  33. # of the possession item.
  34. #==============================================================================
  35.  
  36. class Window_Item < Window_Selectable
  37.   #--------------------------------------------------------------------------
  38.   # - Object initialization
  39.   #--------------------------------------------------------------------------
  40.   def initialize
  41.     super(0, 64, 320, 416)
  42.     @column_max = 1
  43.     refresh
  44.     self.index = 0
  45.     # When it is in the midst of fighting, it moves the window to the picture center, makes translucent
  46.     if $game_temp.in_battle
  47.       self.y = 64
  48.       self.height = 256
  49.       self.width = 640
  50.       self.back_opacity = 160
  51.     end
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # - Acquisition of item
  55.   #--------------------------------------------------------------------------
  56.   def item
  57.     return @data[self.index]
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # - Refreshment
  61.   #--------------------------------------------------------------------------
  62.   def refresh
  63.     if self.contents != nil
  64.       self.contents.dispose
  65.       self.contents = nil
  66.     end
  67.     @data = []
  68.     # Adding the item
  69.     for i in 1...$data_items.size
  70.       if $game_party.item_number(i) > 0
  71.         @data.push($data_items[i])
  72.       end
  73.     end
  74.     # While fighting if other than it adds also the weapon and the guard
  75.     unless $game_temp.in_battle
  76.       for i in 1...$data_weapons.size
  77.         if $game_party.weapon_number(i) > 0
  78.           @data.push($data_weapons[i])
  79.         end
  80.       end
  81.       for i in 1...$data_armors.size
  82.         if $game_party.armor_number(i) > 0
  83.           @data.push($data_armors[i])
  84.         end
  85.       end
  86.     end
  87.    
  88.     #กำหนดให้แสดงไอเท็มชิ้นต่อช่อง
  89.     if Item_Help::Amount_item == false && $game_temp.in_battle == false
  90.       @data = []
  91.       for i in 1...$data_items.size
  92.         if $game_party.item_number(i) > 0
  93.           for a in 1..$game_party.item_number(i)
  94.             @data.push($data_items[i])
  95.           end
  96.         end
  97.       end
  98.       for i in 1...$data_weapons.size
  99.         if $game_party.weapon_number(i) > 0
  100.           for a in 1..$game_party.weapon_number(i)
  101.             @data.push($data_weapons[i])
  102.           end
  103.         end
  104.       end
  105.       for i in 1...$data_armors.size
  106.         if $game_party.armor_number(i) > 0
  107.           for a in 1..$game_party.armor_number(i)
  108.             @data.push($data_armors[i])
  109.           end
  110.         end
  111.       end
  112.     end
  113.    
  114.     # If the number of items is not 0, it draws up bit map, drawing all item
  115.     @item_max = @data.size
  116.     if @item_max > 0
  117.       self.contents = Bitmap.new(width - 32, row_max * 32)
  118.       self.contents.font.name = $fontface
  119.       self.contents.font.size = $fontsize
  120.       for i in 0...@item_max
  121.         draw_item(i)
  122.       end
  123.     end
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # - Drawing of item
  127.   #     index : Item number
  128.   #--------------------------------------------------------------------------
  129.   def draw_item(index)
  130.     item = @data[index]
  131.     case item
  132.     when RPG::Item
  133.       number = $game_party.item_number(item.id)
  134.     when RPG::Weapon
  135.       number = $game_party.weapon_number(item.id)
  136.     when RPG::Armor
  137.       number = $game_party.armor_number(item.id)
  138.     end
  139.     if item.is_a?(RPG::Item) and
  140.        $game_party.item_can_use?(item.id)
  141.       self.contents.font.color = normal_color
  142.     else
  143.       self.contents.font.color = disabled_color
  144.     end
  145.     x = 4 #+ index % 2 * (288 + 32)
  146.     y = index * 32 #index / * 32
  147.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  148.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  149.     bitmap = RPG::Cache.icon(item.icon_name)
  150.     opacity = self.contents.font.color == normal_color ? 255 : 128
  151.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  152.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  153.     if Item_Help::Amount_item
  154.       self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  155.       self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  156.     end
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # - Help text renewal
  160.   #--------------------------------------------------------------------------
  161.   def update_help
  162.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  163.   end
  164. end
  165.  
  166. class Window_Item_Help < Window_Base
  167.   #--------------------------------------------------------------------------
  168.   # - Object initialization
  169.   #--------------------------------------------------------------------------
  170.   def initialize
  171.     super(320, 64, 320, 416)
  172.     self.contents = Bitmap.new(width - 32, height - 32)
  173.     self.contents.font.name = $fontface
  174.     self.contents.font.size = $fontsize
  175.     self.back_opacity =  Item_Help::Window_Back_Opacity
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # - Refreshment
  179.   #--------------------------------------------------------------------------
  180.   def set_item(item)
  181.     self.contents.clear
  182.    
  183.     bitmap = RPG::Cache.picture(Item_Help::Name + item.id.to_s) rescue nil
  184.     src_rect = Rect.new(0, 0, bitmap.width, bitmap.height) rescue bitmap
  185.     self.contents.blt(140-(bitmap.width/2), 188-(bitmap.height/2), bitmap, src_rect) rescue bitmap
  186.    
  187.   end
  188. end
  189.  
  190. #==============================================================================
  191. # * Scene_Item
  192. #------------------------------------------------------------------------------
  193. #  It is the class which processes the item picture.
  194. #==============================================================================
  195.  
  196. class Scene_Item
  197.   #--------------------------------------------------------------------------
  198.   # - Main processing
  199.   #--------------------------------------------------------------------------
  200.   def main
  201.     # Drawing up the help window and the item window
  202.     @help_window = Window_Help.new
  203.     @item_window = Window_Item.new
  204.     # Help window association
  205.     @item_window.help_window = @help_window
  206.     # Target window compilation (invisibility non actively setting)
  207.     @target_window = Window_Target.new
  208.     @target_window.visible = false
  209.     @target_window.active = false
  210.     #เพิ่ม
  211.     @item_help_window = Window_Item_Help.new
  212.     #จบ
  213.     # Transition execution
  214.     Graphics.transition
  215.     # Main loop
  216.     loop do
  217.       # Renewing the game picture
  218.       Graphics.update
  219.       # Updating the information of input
  220.       Input.update
  221.       # Frame renewal
  222.       update
  223.       # When the picture changes, discontinuing the loop
  224.       if $scene != self
  225.         break
  226.       end
  227.     end
  228.     # Transition preparation
  229.     Graphics.freeze
  230.     # Releasing the window
  231.     @help_window.dispose
  232.     @item_window.dispose
  233.     @target_window.dispose
  234.     #เพิ่ม
  235.     @item_help_window.dispose
  236.     #จบ
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # - Frame renewal
  240.   #--------------------------------------------------------------------------
  241.   def update
  242.     # Renewing the window
  243.     @help_window.update
  244.     @item_window.update
  245.     @target_window.update
  246.     #เพิ่ม
  247.     @item_help_window.set_item(@item_window.item)
  248.     #จบ
  249.     # When the item window is active,: Update_item is called
  250.     if @item_window.active
  251.       update_item
  252.       return
  253.     end
  254.     # When the target window is active,: Update_target is called
  255.     if @target_window.active
  256.       update_target
  257.       return
  258.     end
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # - When frame renewal (the item window is active)
  262.   #--------------------------------------------------------------------------
  263.   def update_item
  264.     # The B when button is pushed
  265.     if Input.trigger?(Input::B)
  266.       # Performing cancellation SE
  267.       $game_system.se_play($data_system.cancel_se)
  268.       # Change to menu screen
  269.       $scene = Scene_Menu.new(0)
  270.       return
  271.     end
  272.     # When C button is pushed
  273.     if Input.trigger?(Input::C)
  274.       # Acquiring the data which presently is selected in the item window
  275.       @item = @item_window.item
  276.       # When it is not the use item
  277.       unless @item.is_a?(RPG::Item)
  278.         # Performing buzzer SE
  279.         $game_system.se_play($data_system.buzzer_se)
  280.         return
  281.       end
  282.       # When you cannot use
  283.       unless $game_party.item_can_use?(@item.id)
  284.         # Performing buzzer SE
  285.         $game_system.se_play($data_system.buzzer_se)
  286.         return
  287.       end
  288.       # Performing decision SE
  289.       $game_system.se_play($data_system.decision_se)
  290.       # When the effective range takes part,
  291.       if @item.scope >= 3
  292.         # Active conversion target window
  293.         @item_window.active = false
  294.         #ปรับตำแหน่ง @target_window
  295.         @target_window.x = 304#(@item_window.index + 1) % 2 * 304
  296.         @target_window.visible = true
  297.         @target_window.active = true
  298.         # Setting cursor position the effective range (the single unit/the whole) according to
  299.         if @item.scope == 4 || @item.scope == 6
  300.           @target_window.index = -1
  301.         else
  302.           @target_window.index = 0
  303.         end
  304.       # When the effective range is other than taking part
  305.       else
  306.         # When common event ID is effective
  307.         if @item.common_event_id > 0
  308.           # Common event call reservation
  309.           $game_temp.common_event_id = @item.common_event_id
  310.           # When using the item performing SE
  311.           $game_system.se_play(@item.menu_se)
  312.           # In case of consumable
  313.           if @item.consumable
  314.             # The item which you use is decreased 1
  315.             $game_party.lose_item(@item.id, 1)
  316.             # Redrawing the item of the item window
  317.             @item_window.draw_item(@item_window.index)
  318.           end
  319.           # Change to map picture
  320.           $scene = Scene_Map.new
  321.           return
  322.         end
  323.       end
  324.       return
  325.     end
  326.   end
  327.   #--------------------------------------------------------------------------
  328.   # - When frame renewal (the target window is active)
  329.   #--------------------------------------------------------------------------
  330.   def update_target
  331.     # The B when button is pushed
  332.     if Input.trigger?(Input::B)
  333.       # Performing cancellation SE
  334.       $game_system.se_play($data_system.cancel_se)
  335.       # When with the item and so on is cut off and it becomes not be able to use
  336.       unless $game_party.item_can_use?(@item.id)
  337.         # Rewriting the contents of the item window
  338.         @item_window.refresh
  339.       end
  340.       # Eliminating the target window
  341.       @item_window.active = true
  342.       @target_window.visible = false
  343.       @target_window.active = false
  344.       return
  345.     end
  346.     # When C button is pushed
  347.     if Input.trigger?(Input::C)
  348.       # When the item is consumed
  349.       if $game_party.item_number(@item.id) == 0
  350.         # Performing buzzer SE
  351.         $game_system.se_play($data_system.buzzer_se)
  352.         return
  353.       end
  354.       # When the target is the whole
  355.       if @target_window.index == -1
  356.         # Applying the use effect of the item to the whole party
  357.         used = false
  358.         for i in $game_party.actors
  359.           used |= i.item_effect(@item)
  360.         end
  361.       end
  362.       # When the target is the single unit
  363.       if @target_window.index >= 0
  364.         # Applying the use effect of the item to the actor of the target
  365.         target = $game_party.actors[@target_window.index]
  366.         used = target.item_effect(@item)
  367.       end
  368.       # When the item was used
  369.       if used
  370.         # When using the item performing SE
  371.         $game_system.se_play(@item.menu_se)
  372.         # In case of consumable
  373.         if @item.consumable
  374.           # The item which you use is decreased 1
  375.           $game_party.lose_item(@item.id, 1)
  376.           # Redrawing the item of the item window
  377.           @item_window.draw_item(@item_window.index)
  378.         end
  379.         # Rewriting the contents of the target window
  380.         @target_window.refresh
  381.         # In case of total destruction
  382.         if $game_party.all_dead?
  383.           # Change to game over picture
  384.           $scene = Scene_Gameover.new
  385.           return
  386.         end
  387.         # When common event ID is effective
  388.         if @item.common_event_id > 0
  389.           # Common event call reservation
  390.           $game_temp.common_event_id = @item.common_event_id
  391.           # Change to map picture
  392.           $scene = Scene_Map.new
  393.           return
  394.         end
  395.       end
  396.       # When the item was not used
  397.       unless used
  398.         # Performing buzzer SE
  399.         $game_system.se_play($data_system.buzzer_se)
  400.       end
  401.       return
  402.     end
  403.   end
  404. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement