Advertisement
Guest User

Composite - with races

a guest
Nov 25th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 36.43 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  CP Composite Character script                                               #
  3. #  Version 1.0                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neon Black                                                #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #  V1.0 - 10.10.2012~10.17.2012                                                #
  21. #   Wrote and debugged main script                                             #
  22. ###--------------------------------------------------------------------------###
  23.  
  24. ###--------------------------------------------------------------------------###
  25. #      Compatibility:                                                          #
  26. #  Alias:      - Cache: character, face, clear                                 #
  27. #                Game_Actor: change_equip                                      #
  28. #                DataManager: load_database                                    #
  29. #  New Methods - Cache: create_composite                                       #
  30. #                Composites: refresh?, list, images, hues, reset_refresh,      #
  31. #                            start_composites, change, clear, refresh          #
  32. #                Composite_List: initialize, init_values, male?, refresh?,     #
  33. #                                refresh=, images, hues, check_image,          #
  34. #                                check_hue, check_value, change                #
  35. #                HueColour: dual_colours, hue_colour_wheel                     #
  36. #                Game_Actor: actor_comp_list, actor_comp_hues                  #
  37. #                Game_Interpreter: creation                                    #
  38. #                Window_CCFace: initialize, refresh                            #
  39. #                Window_CCCharacter: initialize, update, refresh,              #
  40. #                                    draw_character                            #
  41. #                Window_CCGui: initialize, item_max, contents_height,          #
  42. #                              item_height, refresh, i, draw_item              #
  43. #                Window_CCSelect: initialize, item_max, refresh, draw_item     #
  44. #                                 draw_hue_wheel, show, cursor_right,          #
  45. #                                 cursor_left                                  #
  46. #                Scene_CharacterCreation: prepare, start, gui_ok, gui_cancel,  #
  47. #                                         select_ok, select_cancel             #
  48. #                RPG::BaseItem: add_composite_data                             #
  49. #                DataManager: create_composite_additions                       #
  50. ###--------------------------------------------------------------------------###
  51.  
  52. ###--------------------------------------------------------------------------###
  53. #      Instructions:                                                           #
  54. #  Place this script in the "Materials" section of the scripts above "Main".   #
  55. #  To use this script you must have additional composite graphics in a folder  #
  56. #  for characters and a folder for faces.  Charactersets will use composites   #
  57. #  based on their names in the NAMES setting.  Some layers of the composite    #
  58. #  may also change based on the equipped items on the actor associated with    #
  59. #  file name.  There are several tags that work with both actors and equips.   #
  60. #  They are as follows:                                                        #
  61. #                                                                              #
  62. #    tag init[File, hue] - Can only be tagged in actors.  Changes composite    #
  63. #                          layer :tag to file "File" with the defined hue.     #
  64. #                          Do not use colons for layer names or quotes for     #
  65. #                          file names.                                         #
  66. #    gender[male] - Sets the character's initial gender to "male" or "female"  #
  67. #                   depending on which you place in the brackets.  This can    #
  68. #                   only tag actors.                                           #
  69. #    tag image[FileM, FileF] - Changes the default images for layer :tag to    #
  70. #                              file "FileM" for male and file "FileF" for      #
  71. #                              female.  Can tag both actors and equips.  If a  #
  72. #                              tag such as "armor" is used, the tags           #
  73. #                              "armorRear" and "armorHueless" are              #
  74. #                              automatically applied.                          #
  75. #    tag hue[huem, huef] - Changes the hue of layer :tag to huem for male      #
  76. #                          and huef for female.  Can tag actors and equips.    #
  77. #                                                                              #
  78. #  You can also call the character customization screen with the follow        #
  79. #  script call:                                                                #
  80. #    creation(id) or creation("file")                                          #
  81. #  You can place either the ID for the actor whose composite you want the      #
  82. #  player to alter, or you can place the file name for the composite image     #
  83. #  you want the character to alter.                                            #
  84. ###--------------------------------------------------------------------------###
  85.  
  86. ###--------------------------------------------------------------------------###
  87. #      Config:                                                                 #
  88. module CP        # Do not edit                                                 #
  89. module COMPOSITE #  these two lines.                                           #
  90. #                                                                              #
  91. ###-----                                                                -----###
  92. # Determines if facesets are used by the script.  If this is set to false, the #
  93. # face will not be displayed in the customizer and the faceset graphic will    #
  94. # not become a composite if it's name matches the characterset's.              #
  95. USE_FACESETS = true # Default = true                                           #
  96. #                                                                              #
  97. # The folders that store the composite images for charactersets and facesets.  #
  98. # Note that the files contained in them can be named different in case they    #
  99. # need to be on different layers or altered in different ways.                 #
  100. CHAR_FOLDER = "Graphics/Composite/Charas/" # D = "Graphics/Composite/Charas/"  #
  101. FACE_FOLDER = "Graphics/Composite/Faces/" # D = "Graphics/Composite/Faces/"    #
  102. #                                                                              #
  103. # The width and height of the character window in the character customization  #
  104. # screen.  Added in case tall characters are used.  This number includes the   #
  105. # window padding.  Also remember that the sprite will be zoomed to 200%.       #
  106. WINDOW_WIDTH = 90 # Default = 90                                               #
  107. WINDOW_HEIGHT = 112 # Default = 112                                            #
  108. #                                                                              #
  109. # The text options for the character selection GUI.  The PRESET_TEXT refers to #
  110. # actors who have been tagged with "tag init[]".                               #
  111. GUI_CLOSE = "Finish Editing" # Default = "Finish Editing"                      #
  112. PRESET_TEXT = "Preset" # Default = "Preset"                                    #
  113. #                                                                              #
  114. # The number of allowed character spaces for names when input from the editor. #
  115. CHARACTERS = 10 # Default = 6                                                   #
  116. #                                                                              #
  117. ###-----                                                                -----###
  118. # This hash contains the names of the images to create composites from as well #
  119. # as the actor ID they are tied to.  If the linked actor wears armour with     #
  120. # note tags, the composite with this name will change.                         #
  121. NAMES ={
  122.  
  123.   "$Hero1" => 1,
  124. #  "$Hero2" => 2,
  125.  
  126. }
  127. #                                                                              #
  128. # This allows switches to be linked to genders.  If the gender of the player   #
  129. # is changed, the switch is changed.  This can be used for gender based        #
  130. # events.  The switch will be ON for female characters.                        #
  131. SWITCHES ={
  132.  
  133.   1 => 72,
  134. #  2 => 73,
  135.  
  136. }
  137. #                                                                              #
  138. # The names for genders as well as well as which one is default on characters  #
  139. # that do not have pre-defined genders.                                        #
  140. GENDER_NAMES = ["Male", "Female"] # Default = ["Male", "Female"]               #
  141. MALE_DEFAULT = true # Default = true                                           #
  142. #                                                                              #
  143. # The complete list of layers for a composite.  Can contain any number of      #
  144. # layers but they must be in order from LOWEST to HIGHEST.  Note that :Gender  #
  145. # is a reserved tag by the system that refers to the composite's gender.  Also #
  146. # note that tags ending in "All", "Rear", and "Hueless" are used specially by  #
  147. # the system.  "Rear" tags are automatically searched for from every other     #
  148. # tag, "Hueless" tags will never have a hue, and "All" tags are used from the  #
  149. # options of the GUI below to be present in all selections.                    #
  150. ORDER =[
  151.  
  152.   :hairRear,
  153.   :cape,
  154.   :armorRear,
  155.   :headAll,
  156.   :Gender,
  157.   :race,
  158.   :raceHueless,
  159.   :raceRear,
  160.   :eyes,
  161.   :eyesAll,
  162.   :eyesHueless,
  163.   :armor,
  164.   :hair,
  165.   :glasses,
  166.   :helmet,
  167.  
  168.  
  169. ]
  170. #                                                                              #
  171. # These are the default options for the character creation GUI.  Note that the #
  172. # :Name and :Gender tags are reserved by the system, but may be present here   #
  173. # with no arguments.  Other tags follow a certain format as noted below.       #
  174. # :tag - This is the layer the image will show up on.  Automatically makes the #
  175. #        :tagRear, :tagHueless, and :tagAll layer tags and images.             #
  176. # "Name" - The name of the menu option in the GUI.  Quotes are required.       #
  177. # :opTagMale - The name of the MALE tag to use from the options hash below.    #
  178. # :opTagFem - Same as the tag above, but for female composites.  These tags    #
  179. #                will get the list of options to populate for that layer of    #
  180. #                the composite and that section of the GUI.                    #
  181. # true - This determines if the hue of this layer can be changed.  Set to      #
  182. #        false to disable hue change for the layer.                            #
  183. # "TagAll" - The name of the file to place in the :tagAll layer if one exists. #
  184. GUI ={
  185.  
  186. # :tag    => ["Name", :opTagMale,  :opTagFem,  true, "TagAll"],                #
  187.   :Name   => ["Name"],
  188.   :Gender => ["Gender"],
  189.   :race   => ["Race", :opRaceMale, :opRaceFem, false],
  190.   :hair   => ["Hair", :opHairMale, :opHairFem, true],
  191.   :eyes   => ["Eyes", :opEyesM,    :opEyesF,   true, "EyeAll"],
  192.  
  193.  
  194. }
  195. #                                                                              #
  196. # These are the options list that will appear when the sections of the GUI are #
  197. # called from the commands above.  Each contains a large array with any number #
  198. # of smaller, two element arrays.  The smaller arrays contain two elements.    #
  199. # The first is the name to display for that graphic option.  The second is the #
  200. # name of the file to use.  The "Rear" and "Hueless" files will also be        #
  201. # searched for.  For example, if you have a file named "Image" placed on layer #
  202. # :tag, the script will also search for a file "ImageRear" for layer :tagRear, #
  203. # and a file "ImageHueless" for layer :tagHueless.                             #
  204. OPTIONS ={
  205.  
  206.   :opHairMale => [["Shaggy", "Hair1M"], ["Slick", "Hair2M"],
  207.                   ["Spiked", "Hair3M"], ["Fancy", "Hair4M"],
  208.                   ["Short",  "Hair1U"], ["Long",  "Hair2U"], ["Bald",  "BaseM"]],
  209.   :opHairFem => [["Stylish", "Hair1F"], ["Waist Length", "Hair2F"],
  210.                  ["Curled",  "Hair3F"], ["Pigtails",     "Hair4F"],
  211.                  ["Short",   "Hair1U"], ["Long",         "Hair2U"], ["Bald",  "BaseM"]],
  212.   :opEyesM => [["Observant", "Eye1M"], ["Intent", "Eye3M"], ["Closed", "Eye2M"]],
  213.   :opEyesF => [["Observant", "Eye1F"], ["Intent", "Eye3F"], ["Closed", "Eye2F"]],
  214.   :opRaceMale => [["Human", "Humanmale1"], ["Elf", "Elfmale1"], ["Dwarf", "Dwarfmale1"], ["Halfling", "Halflingmale1"], ["Orc", "Orcmale1"], ["Drow", "Drowmale1"], ["Tiefling", "Tieflingmale1"], ["Warforged", "Warforgedmale1"]],
  215.   :opRaceFem => [["Human", "Humanfemale1"], ["Elf", "Elffemale1"], ["Dwarf", "Dwarffemale1"], ["Halfling", "Halflingfemale1"], ["Orc", "Orcfemale1"], ["Drow", "Drowfemale1"], ["Tiefling", "Tieflingfemale1"], ["Warforged", "Warforgedfemale1"]],
  216.  
  217. }
  218. #                                                                              #
  219. # These are the default images that display for certain layers if they are not #
  220. # defined in the actor notebox.  Note that these will NOT automatically apply  #
  221. # for "Rear" and "Hueless".  Also note that you CAN have images for the        #
  222. # :Gender tag.  Each item is an array with the male image's name first         #
  223. # followed by the female image's name.                                         #
  224. STANDARD ={
  225.  
  226.   :headAll => ["HeadAll", "HeadAll"],
  227.   :Gender => ["FaceM", "FaceF"],
  228.   :armor => ["BaseM", "BaseF"],
  229.  
  230. }
  231. #                                                                              #
  232. ###--------------------------------------------------------------------------###
  233.  
  234.  
  235. ###--------------------------------------------------------------------------###
  236. #  The following lines are the actual core code of the script.  While you are  #
  237. #  certainly invited to look, modifying it may result in undesirable results.  #
  238. #  Modify at your own risk!                                                    #
  239. ###--------------------------------------------------------------------------###
  240.  
  241.  
  242. ## These are the regular expressions used later.
  243. INITI_RE = /(.+) init\[(.+)[,]\s*(\d+)\]/i
  244. IMAGE_RE = /(.+) image\[(.+)[,]\s*(.+)\]/i
  245. HUE_RE = /(.+) hue\[(\d+)[,]\s*(\d+)\]/i
  246. GENDER_RE = /gender\[(male|female){1}\]/i
  247.  
  248. end
  249. end
  250.  
  251. $imported = {} if $imported.nil?
  252. $imported["COMPOSITE"] = 1.0
  253.  
  254. module Cache
  255.   class << self  ## Alias for the used methods in this module.
  256.     alias cp_cm_character character
  257.     alias cp_cm_face face
  258.     alias cp_cm_clear clear
  259.   end
  260.  
  261.  def self.character(file, hue = 0) ## Checks if the file is a composite.
  262. return cp_cm_character(file, hue) unless CP::COMPOSITE::NAMES.include?(file)
  263. create_composite(file, "Graphics/Characters/")
  264. load_bitmap("Graphics/Characters/", file)
  265. end
  266.  
  267.   def self.face(file)
  268.     return cp_cm_face(file) unless CP::COMPOSITE::NAMES.include?(file)
  269.     create_composite(file, "Graphics/Faces/")
  270.     load_bitmap("Graphics/Faces/", file)
  271.   end
  272.  
  273.   def self.create_composite(file, f1)
  274.     path = f1 + file  ## Gets the default file's path.
  275.     Composites.refresh if @cache[path].disposed? rescue nil
  276.     return unless Composites.refresh?(file)
  277.     consts = [CP::COMPOSITE::CHAR_FOLDER, CP::COMPOSITE::FACE_FOLDER]
  278.     folder = ["Graphics/Characters/", "Graphics/Faces/"]
  279.     consts.each_with_index do |f2, i|
  280.       next if (f2 == CP::COMPOSITE::FACE_FOLDER && !CP::COMPOSITE::USE_FACESETS)
  281.       paths = folder[i] + file
  282.       Composites.images(file).each_with_index do |image, i|
  283.         @temp = Bitmap.new(f2 + image) rescue next
  284.         break
  285.       end
  286.       #temp = Bitmap.new(paths)
  287.       @temp.clear  ## Creates the composite layer by layer.
  288.       Composites.images(file).each_with_index do |image, i|
  289.         t = Bitmap.new(f2 + image) rescue next
  290.         t.hue_change(Composites.hues(file)[i]) unless Composites.hues(file)[i] == 0
  291.         @temp.blt(0, 0, t, t.rect)
  292.         t.dispose; t = nil
  293.       end
  294.       Composites.reset_refresh(file)
  295.       @cache[paths] = Bitmap.new(@temp.width, @temp.height)
  296.       @cache[paths].blt(0, 0, @temp, @temp.rect)
  297.     end
  298.     @temp = nil
  299.   end
  300.  
  301.   def self.clear
  302.     cp_cm_clear
  303.     Composite.clear
  304.   end
  305. end
  306.  
  307. class Game_System  ## Adds a variable to game system to get saved.
  308.   attr_accessor :cp_lists
  309. end
  310.  
  311. module Composites
  312.   def self.refresh?(file)  ## Check if a certain composite needs refreshing.
  313.     return true if $game_system.cp_lists.nil?
  314.     return $game_system.cp_lists[file].refresh?
  315.   end
  316.  
  317.   def self.list(key)  ## Shows off a composite.
  318.     return $game_system.cp_lists[key]
  319.   end
  320.    
  321.   def self.images(key)  ## Gets all images in a composite.
  322.     start_composites if $game_system.cp_lists.nil?
  323.     return $game_system.cp_lists[key].images
  324.   end
  325.  
  326.   def self.hues(key)  ## Gets all hues in a composite.
  327.     start_composites if $game_system.cp_lists.nil?
  328.     return $game_system.cp_lists[key].hues
  329.   end
  330.  
  331.   def self.reset_refresh(key)  ## Resets a refresh of a composite.
  332.     $game_system.cp_lists[key].refresh = false
  333.   end
  334.  
  335.   def self.start_composites  ## Creates all default composites.
  336.     $game_system.cp_lists = {}
  337.     CP::COMPOSITE::NAMES.each do |name, actor|
  338.       $game_system.cp_lists[name] = Composite_List.new(name, actor)
  339.     end
  340.   end
  341.  
  342.   def self.change(key, name, image, hue, num)
  343.     $game_system.cp_lists[key].change(name, image, hue, num)
  344.   end  ## Changes the settings of a certain composite.
  345.  
  346.   def self.clear  ## Clears all composites.
  347.     $game_system.cp_lists = nil
  348.   end
  349.  
  350.   def self.refresh  ## Refreshes all composites.
  351.     return unless $game_system.cp_lists
  352.     $game_system.cp_lists.each {|i, k| k.refresh = true}
  353.   end
  354. end
  355.  
  356. class Composite_List  ## Creates a composite's default values.
  357.   def initialize(name, actor)
  358.     @list = {}
  359.     @hues = {}
  360.     @values = {}
  361.     @name = name
  362.     @actor = actor
  363.     @refresh = true
  364.     init_values
  365.   end
  366.  
  367.   def init_values(male = nil)  ## Holy mother of God.  This is the good stuff.
  368.     @male = $data_actors[@actor].gender_base if male.nil?
  369.     @male = male unless male.nil?
  370.     if CP::COMPOSITE::SWITCHES.include?(@actor)
  371.       $game_switches[CP::COMPOSITE::SWITCHES[@actor]] = !@male
  372.     end
  373.     CP::COMPOSITE::ORDER.each do |key|
  374.       @hues[key] = 0
  375.       name = nil
  376.       string = key.to_s
  377.       hueless = string.include?("Hueless") ? true : false
  378.       rear = string.include?("Rear") ? true : false
  379.       all = string.include?("All") ? true : false
  380.       string.gsub!(/(Hueless|All|Rear)/, '')
  381.       line = CP::COMPOSITE::GUI[string.to_sym]
  382.       block = @male ? line[1] : line[2] unless line.nil?
  383.       if $data_actors[@actor].composite_init.include?(key) &&
  384.          @male == $data_actors[@actor].gender_base
  385.         name = $data_actors[@actor].composite_init[key][0]
  386.         hues = $data_actors[@actor].composite_init[key][1]
  387.         @hues[key] = hues
  388.       elsif all && !line.nil?
  389.         name = line[4]
  390.       elsif rear && !line.nil?
  391.         name = CP::COMPOSITE::OPTIONS[block][0][1] + "Rear"
  392.       elsif hueless && !line.nil?
  393.         name = CP::COMPOSITE::OPTIONS[block][0][1] + "Hueless"
  394.       elsif !line.nil? && key != :Gender
  395.         name = CP::COMPOSITE::OPTIONS[block][0][1]
  396.       elsif CP::COMPOSITE::STANDARD.include?(key)
  397.         ml = @male ? 0 : 1
  398.         name = CP::COMPOSITE::STANDARD[key][ml]
  399.       end
  400.       @list[key] = name
  401.     end
  402.     CP::COMPOSITE::GUI.each do |ind, vals|
  403.       next if ind == :Name || ind == :Gender
  404.       @values[ind] = [0, 0]
  405.       if $data_actors[@actor].composite_init.include?(ind) &&
  406.          @male == $data_actors[@actor].gender_base
  407.         @values[ind] = [-1, $data_actors[@actor].composite_init[ind][1]]
  408.       end
  409.       next if @list.include?(ind)
  410.       line = CP::COMPOSITE::GUI[ind]
  411.       block = @male ? line[1] : line[2] unless line.nil?
  412.       @list[ind] = CP::COMPOSITE::OPTIONS[block][0][1]
  413.       @hues[ind] = 0
  414.     end
  415.     @refresh = true
  416.   end  ## Yeah, I'm not even gonna try to explain the above.
  417.  
  418.   def male?  ## Check if the composite is male.
  419.     return @male
  420.   end
  421.  
  422.   def refresh?  ## Check if the composite needs refreshing.
  423.     return @refresh
  424.   end
  425.  
  426.   def refresh=(val)  ## Sets the composite's refresh.
  427.     @refresh = val
  428.   end
  429.    
  430.   def images  ## Gets all images from a composite.
  431.     res = []
  432.     g = male? ? 0 : 1
  433.     CP::COMPOSITE::ORDER.each do |key|
  434.       if $game_actors[@actor].actor_comp_list.include?(key)
  435.         val = $game_actors[@actor].actor_comp_list[key][g]
  436.       else
  437.         val = @list[key]
  438.       end
  439.       res.push(val)
  440.     end
  441.     return res
  442.   end
  443.  
  444.   def hues  ## Gets all hues.
  445.     res = []
  446.     g = male? ? 0 : 1
  447.     CP::COMPOSITE::ORDER.each do |key|
  448.       if $game_actors[@actor].actor_comp_hues.include?(key)
  449.         val = $game_actors[@actor].actor_comp_hues[key]
  450.         val = val ? val[g] : 0
  451.       else
  452.         val = @hues[key].nil? ? 0 : @hues[key]
  453.       end
  454.       res.push(val)
  455.     end
  456.     return res
  457.   end
  458.  
  459.   def check_image
  460.     return @list
  461.   end  ## Returns the list of images out of order.
  462.  
  463.   def check_hue
  464.     return @hues
  465.   end  ## Returns the list of hues out of order.
  466.  
  467.   def check_value
  468.     return @values
  469.   end  ## Gets all the values for the GUI.
  470.  
  471.   def change(name, image, hue, num)
  472.     key = name.to_s
  473.     @list[name] = image
  474.     @hues[name] = hue
  475.     @values[name] = [num, hue]
  476.     ["Rear", "All", "Hueless"].each do |s|
  477.       ind = key + s
  478.       next unless @list.include?(ind.to_sym)
  479.       @list[ind.to_sym] = image + s unless s == "All"
  480.       @hues[ind.to_sym] = hue unless s == "Hueless"
  481.       @values[ind.to_sym] = [num, @hues[ind.to_sym]]
  482.     end  ## Changes the values within the composite.
  483.     @refresh = true
  484.   end
  485. end
  486.  
  487. module HueColour  ## Colour wheel for getting 1 of 36 hues.
  488.   def self.dual_colours(hue)
  489.     hue /= 12
  490.     c2 = hue_colour_wheel(hue)
  491.     c1 = Color.new(c2.red, c2.green, c2.blue, 0)
  492.     return [c1, c2]
  493.   end
  494.  
  495.   def self.hue_colour_wheel(hue)
  496.     if @wheel.nil? || @wheel.disposed?
  497.       @wheel = Bitmap.new(30, 1)
  498.       c1 = Color.new(255,   0,   0); c2 = Color.new(255, 255,   0)
  499.       c3 = Color.new(  0, 255,   0); c4 = Color.new(  0, 255, 255)
  500.       c5 = Color.new(  0,   0, 255); c6 = Color.new(255,   0, 255)
  501.       @wheel.gradient_fill_rect( 0, 0, 6, 1, c1, c2)
  502.       @wheel.gradient_fill_rect( 5, 0, 6, 1, c2, c3)
  503.       @wheel.gradient_fill_rect(10, 0, 6, 1, c3, c4)
  504.       @wheel.gradient_fill_rect(15, 0, 6, 1, c4, c5)
  505.       @wheel.gradient_fill_rect(20, 0, 6, 1, c5, c6)
  506.       @wheel.gradient_fill_rect(25, 0, 6, 1, c6, c1)
  507.     end
  508.     return @wheel.get_pixel(hue, 0)
  509.   end
  510. end
  511.  
  512. class Game_Actor < Game_Battler
  513.   alias cp_composite_change_eq change_equip
  514.   def change_equip(slot_id, item)
  515.     cp_composite_change_eq(slot_id, item)
  516.     id = CP::COMPOSITE::NAMES.index(@actor_id)
  517.     return unless id
  518.     Composites.list(id).refresh = true
  519.   end  ## Gets all the composites on the actor if equips are changed.
  520.  
  521.   def actor_comp_list
  522.     list = {}
  523.     equips.each do |eq|
  524.       next unless eq
  525.       eq.composite_hash.each do |key, array|
  526.         list[key] = array
  527.       end
  528.     end
  529.     return list
  530.   end  ## The lists.  Simple, no?
  531.  
  532.   def actor_comp_hues
  533.     list = {}
  534.     equips.each do |eq|
  535.       next unless eq
  536.       eq.composite_hues.each do |key, array|
  537.         list[key] = array
  538.       end
  539.     end
  540.     return list
  541.   end
  542. end
  543.  
  544. class Game_Interpreter
  545.   def creation(char)  ## Allows for easy calling of the scene.
  546.     return if $game_party.in_battle
  547.     if char.is_a?(Integer)
  548.       return unless CP::COMPOSITE::NAMES.has_value?(char)
  549.       char = CP::COMPOSITE::NAMES.index(char)
  550.     else
  551.       return unless CP::COMPOSITE::NAMES.include?(char)
  552.     end
  553.     SceneManager.call(Scene_CharacterCreation)
  554.     SceneManager.scene.prepare(char)
  555.     Fiber.yield
  556.   end
  557. end
  558.  
  559.  
  560. ##------
  561. ## The scene and its windows are below.  I'm lazy and don't feel like stating
  562. ## the obvious on any of those.  Besides, I don't really put sufficiant comments
  563. ## to begin with.
  564. ##------
  565. class Window_CCFace < Window_Base
  566.   def initialize(actor, input)
  567.     super(0, 0, 120, 120)
  568.     self.visible = CP::COMPOSITE::USE_FACESETS
  569.     @input_window = input
  570.     self.y = @input_window.y
  571.     self.x = @input_window.x - (self.width + 8)
  572.     @actor = $data_actors[actor]
  573.     refresh
  574.   end
  575.  
  576.   def refresh
  577.     contents.clear
  578.     draw_face(@actor.face_name, @actor.face_index, 0, 0)
  579.   end
  580. end
  581.  
  582. class Window_CCCharacter < Window_Base
  583.   def initialize(actor, input)
  584.     super(0, 0, CP::COMPOSITE::WINDOW_WIDTH, CP::COMPOSITE::WINDOW_HEIGHT)
  585.     @input_window = input
  586.     self.y = @input_window.y
  587.     self.x = @input_window.x + @input_window.width + 8
  588.     @actor = $data_actors[actor]
  589.     @ticker = 10
  590.     @last_frame = 1
  591.     @frame = 1
  592.     refresh
  593.   end
  594.  
  595.   def update
  596.     @ticker += 1
  597.     @frame = (@ticker % 40) / 10; @frame = 1 if @frame == 3
  598.     return if @frame == @last_frame
  599.     @last_frame = @frame
  600.     refresh
  601.   end
  602.  
  603.   def refresh
  604.     contents.clear
  605.     x = contents.width / 2
  606.     y = contents.height - 6
  607.     draw_character(@actor.character_name, @actor.character_index, x, y, @frame)
  608.   end
  609.  
  610.   def draw_character(character_name, character_index, x, y, frame = 1)
  611.     return unless character_name
  612.     bitmap = Cache.character(character_name)
  613.     sign = character_name[/^[\!\$]./]
  614.     if sign && sign.include?('$')
  615.       cw = bitmap.width / 3
  616.       ch = bitmap.height / 4
  617.     else
  618.       cw = bitmap.width / 12
  619.       ch = bitmap.height / 8
  620.     end
  621.     n = character_index
  622.     src_rect = Rect.new((n%4*3+frame)*cw, (n/4*4)*ch, cw, ch)
  623.     ret_rect = Rect.new(x - cw, y - cw * 2, cw * 2, ch * 2)
  624.     contents.stretch_blt(ret_rect, bitmap, src_rect)
  625.   end
  626. end
  627.  
  628. class Window_CCGui < Window_Selectable
  629.   def initialize(file)
  630.     extra_width = CP::COMPOSITE::WINDOW_WIDTH + 8
  631.     extra_width += 128 if CP::COMPOSITE::USE_FACESETS
  632.     x = (Graphics.width - (180 + extra_width)) / 2
  633.     x += 128 if CP::COMPOSITE::USE_FACESETS
  634.     y = (Graphics.height - fitting_height(item_max * 2)) / 2
  635.     h = [fitting_height(item_max * 2), Graphics.height].min
  636.     super(x, y, 180, h)
  637.     @file = file
  638.     refresh
  639.   end
  640.  
  641.   def item_max
  642.     CP::COMPOSITE::GUI.size + 1
  643.   end
  644.  
  645.   def contents_height
  646.     (item_max * 2) * line_height
  647.   end
  648.  
  649.   def item_height
  650.     line_height * 2
  651.   end
  652.  
  653.   def refresh
  654.     contents.clear
  655.     draw_all_items
  656.   end
  657.  
  658.   def i
  659.     res = []
  660.     CP::COMPOSITE::GUI.each {|ind, val| res.push(ind)}
  661.     return res
  662.   end
  663.  
  664.   def draw_item(index)
  665.     rect = item_rect(index)
  666.     lh = line_height
  667.     if index == CP::COMPOSITE::GUI.size
  668.       text = CP::COMPOSITE::GUI_CLOSE
  669.       change_color(normal_color)
  670.       draw_text(rect.x + 2, rect.y + lh / 2, rect.width - 4, lh, text, 1)
  671.     else
  672.       title = CP::COMPOSITE::GUI[i[index]][0]
  673.       unless i[index] == :Gender || i[index] == :Name
  674.         id = Composites.list(@file).check_value[i[index]][0]
  675.         blk = Composites.list(@file).male? ? 1 : 2
  676.         name = CP::COMPOSITE::OPTIONS[CP::COMPOSITE::GUI[i[index]][blk]][id][0]
  677.         name = CP::COMPOSITE::PRESET_TEXT if id == -1
  678.         hue = Composites.list(@file).check_hue[i[index]]; hue = 0 if hue.nil?
  679.       end
  680.       change_color(system_color)
  681.       draw_text(rect.x + 2, rect.y, rect.width - 4, lh, title)
  682.       case i[index]
  683.       when :Gender
  684.         na = CP::COMPOSITE::GENDER_NAMES
  685.         name = Composites.list(@file).male? ? na[0] : na[1]
  686.         change_color(normal_color)
  687.         draw_text(rect.x + 2, rect.y + lh, rect.width - 6, lh, name, 2)
  688.       when :Name
  689.         name = $game_actors[CP::COMPOSITE::NAMES[@file]].name
  690.         change_color(normal_color)
  691.         draw_text(rect.x + 2, rect.y + lh, rect.width - 6, lh, name, 2)
  692.       else
  693.         if CP::COMPOSITE::GUI[i[index]][3]
  694.           c1, c2 = HueColour.dual_colours(hue)
  695.           r2 = contents.text_size(name).width
  696.           hr = Rect.new(contents.width - (r2 + 6), rect.y + lh + 3, r2 + 1, lh - 6)
  697.           contents.gradient_fill_rect(hr, c1, c2)
  698.         end
  699.         change_color(normal_color)
  700.         draw_text(rect.x + 2, rect.y + lh, rect.width - 6, lh, name, 2)
  701.       end
  702.     end
  703.   end
  704. end
  705.  
  706. class Window_CCSelect < Window_Selectable
  707.   attr_reader :hue
  708.  
  709.   def initialize(file, input)
  710.     super(0, 0, 160, 0)
  711.     @input_window = input
  712.     @file = file
  713.     @data = nil
  714.   end
  715.  
  716.   def item_max
  717.     return 1 if @data.nil?
  718.     return 1 if @data.empty?
  719.     return @data.size
  720.   end
  721.  
  722.   def refresh
  723.     contents.clear
  724.     draw_all_items
  725.     draw_hue_wheel
  726.   end
  727.  
  728.   def draw_item(index)
  729.     rect = item_rect(index); rect.x += 2; rect.width -= 4
  730.     change_color(normal_color)
  731.     draw_text(rect, @data[index])
  732.   end
  733.  
  734.   def draw_hue_wheel
  735.     return unless @hue
  736.     rect = item_rect(item_max); contents.clear_rect(rect)
  737.     rect.y += 4; rect.height -= 8; rect.x += 8
  738.     c1 = Color.new(255,   0,   0); c2 = Color.new(255, 255,   0)
  739.     c3 = Color.new(  0, 255,   0); c4 = Color.new(  0, 255, 255)
  740.     c5 = Color.new(  0,   0, 255); c6 = Color.new(255,   0, 255)
  741.     contents.gradient_fill_rect(rect.x +   0, rect.y, 21, rect.height, c1, c2)
  742.     contents.gradient_fill_rect(rect.x +  20, rect.y, 21, rect.height, c2, c3)
  743.     contents.gradient_fill_rect(rect.x +  40, rect.y, 21, rect.height, c3, c4)
  744.     contents.gradient_fill_rect(rect.x +  60, rect.y, 21, rect.height, c4, c5)
  745.     contents.gradient_fill_rect(rect.x +  80, rect.y, 21, rect.height, c5, c6)
  746.     contents.gradient_fill_rect(rect.x + 100, rect.y, 21, rect.height, c6, c1)
  747.     contents.clear_rect(rect.x + 120, rect.y, 1, rect.height)
  748.     bitmap2 = Bitmap.new(7, 20)
  749.     bitmap2.fill_rect(0, 0, 7, 20, Color.new(255, 255, 255))
  750.     bitmap2.fill_rect(1, 2, 5, 16, HueColour.hue_colour_wheel(@hue / 12))
  751.     off = @hue / 3
  752.     contents.blt(rect.x - 3 + off, rect.y - 2, bitmap2, bitmap2.rect)
  753.   end
  754.  
  755.   def show
  756.     val = @input_window.i[@input_window.index]
  757.     @value = Composites.list(@file).check_value[val]
  758.     @index = val != :Gender ? @value[0] : Composites.list(@file).male? ? 0 : 1
  759.     @index = 0 if @index == -1
  760.     @hue = @value[1] unless val == :Gender
  761.     block = Composites.list(@file).male? ? 1 : 2
  762.     CP::COMPOSITE::GUI.each do |ind, cont|
  763.       next unless ind == val
  764.       if val == :Gender
  765.         @data = CP::COMPOSITE::GENDER_NAMES
  766.       else
  767.         @data = []
  768.         key = CP::COMPOSITE::GUI[val][block]
  769.         for i in 0...CP::COMPOSITE::OPTIONS[key].size
  770.           @data.push(CP::COMPOSITE::OPTIONS[key][i][0])
  771.         end
  772.       end
  773.     end
  774.     add = CP::COMPOSITE::GUI[val][3] ? 1 : 0
  775.     self.height = fitting_height(@data.size + add)
  776.     create_contents
  777.     refresh
  778.     self.x = @input_window.x + 16
  779.     iw = @input_window
  780.     self.y = iw.y + iw.standard_padding + (iw.index * (iw.line_height * 2)) - iw.oy + 28
  781.     self.y = Graphics.height - self.height if y + height > Graphics.height
  782.     super
  783.     activate
  784.   end
  785.  
  786.   def cursor_right(wrap)
  787.     @hue /= 12 ; @hue *= 12
  788.     @hue += 12; @hue -= 360 if @hue >= 360
  789.     draw_hue_wheel
  790.   end
  791.  
  792.   def cursor_left(wrap)
  793.     @hue -= 12; @hue += 360 if @hue < 0
  794.     draw_hue_wheel
  795.   end
  796. end
  797.  
  798. class Scene_CharacterCreation < Scene_MenuBase
  799.   def prepare(file)
  800.     @file = file
  801.   end
  802.  
  803.   def start
  804.     super
  805.     @actor = $data_actors[CP::COMPOSITE::NAMES[@file]]
  806.     @input_window = Window_CCGui.new(@file)
  807.     @chara_window = Window_CCCharacter.new(@actor.id, @input_window)
  808.     @face_window = Window_CCFace.new(@actor.id, @input_window)
  809.     @select_window = Window_CCSelect.new(@file, @input_window)
  810.     @input_window.set_handler(:ok,      method(:gui_ok))
  811.     @input_window.set_handler(:cancel,  method(:gui_cancel))
  812.     @select_window.set_handler(:ok,     method(:select_ok))
  813.     @select_window.set_handler(:cancel, method(:select_cancel))
  814.     @input_window.activate.select(0)
  815.     @select_window.hide
  816.   end
  817.  
  818.   def gui_ok
  819.     val = @input_window.i[@input_window.index]
  820.     if val == :Name
  821.       SceneManager.call(Scene_Name)
  822.       SceneManager.scene.prepare(CP::COMPOSITE::NAMES[@file], CP::COMPOSITE::CHARACTERS)
  823.       @input_window.refresh
  824.     elsif val == nil
  825.       return_scene
  826.     else
  827.       @select_window.show
  828.     end
  829.   end
  830.  
  831.   def gui_cancel
  832.     @input_window.activate.select(@input_window.item_max - 1)
  833.   end
  834.  
  835.   def select_ok
  836.     val = @input_window.i[@input_window.index]
  837.     id = @select_window.index
  838.     if val == :Gender
  839.       if id == 0
  840.         Composites.list(@file).init_values(true)
  841.       elsif id == 1
  842.         Composites.list(@file).init_values(false)
  843.       end
  844.     else
  845.       block = Composites.list(@file).male? ? 1 : 2
  846.       arg = []
  847.       arg.push(@file)
  848.       arg.push(val)
  849.       arg.push(CP::COMPOSITE::OPTIONS[CP::COMPOSITE::GUI[val][block]][id][1])
  850.       arg.push(@select_window.hue)
  851.       arg.push(@select_window.index)
  852.       Composites.change(*arg)
  853.     end
  854.     @select_window.hide
  855.     @chara_window.refresh
  856.     @face_window.refresh
  857.     @input_window.activate.refresh
  858.   end
  859.  
  860.   def select_cancel
  861.     @select_window.hide
  862.     @input_window.activate
  863.   end
  864. end
  865.  
  866. class RPG::BaseItem
  867.   attr_reader :composite_hash
  868.   attr_reader :composite_hues
  869.   attr_reader :composite_init
  870.   attr_reader :gender_base
  871.  
  872.   def add_composite_data
  873.     return if @gender_base; @gender_base = CP::COMPOSITE::MALE_DEFAULT
  874.     @composite_hash = {}; @composite_hues = {}; @composite_init = {}
  875.     self.note.split(/[\r\n]+/).each do |line|
  876.       case line
  877.       when CP::COMPOSITE::INITI_RE
  878.         @composite_init[$1.to_sym] = [$2.to_s, $3.to_i]
  879.         s = []
  880.         [$1.to_s, $2.to_s].each {|v| s.push(v + "Rear")}
  881.         @composite_init[s[0].to_sym] = [s[1], $3.to_i]
  882.         s = []
  883.         [$1.to_s, $2.to_s].each {|v| s.push(v + "Hueless")}
  884.         @composite_init[s[0].to_sym] = [s[1], 0]
  885.       when CP::COMPOSITE::IMAGE_RE
  886.         @composite_hash[$1.to_sym] = [$2.to_s, $3.to_s]
  887.         s = []
  888.         [$1.to_s, $2.to_s, $3.to_s].each {|v| s.push(v + "Rear")}
  889.         @composite_hash[s[0].to_sym] = [s[1], s[2]]
  890.         s = []
  891.         [$1.to_s, $2.to_s, $3.to_s].each {|v| s.push(v + "Hueless")}
  892.         @composite_hash[s[0].to_sym] = [s[1], s[2]]
  893.       when CP::COMPOSITE::HUE_RE
  894.         @composite_hues[$1.to_sym] = [$2.to_i, $3.to_i]
  895.         @composite_hues[($1.to_s + "Rear").to_sym] = [$2.to_i, $3.to_i]
  896.       when CP::COMPOSITE::GENDER_RE
  897.         @gender_base = true if $1.to_s.downcase == "male"
  898.         @gender_base = false if $1.to_s.downcase == "female"
  899.       end
  900.     end
  901.   end
  902. end
  903.  
  904. module DataManager
  905.   class << self
  906.     alias cp_composite_load_database load_database
  907.   end
  908.  
  909.   def self.load_database
  910.     cp_composite_load_database
  911.     create_composite_additions
  912.   end
  913.  
  914.   def self.create_composite_additions
  915.     groups = [$data_actors, $data_weapons, $data_armors]
  916.     for group in groups
  917.       for obj in group
  918.         next if obj.nil?
  919.         obj.add_composite_data if obj.is_a?(RPG::BaseItem)
  920.       end
  921.     end
  922.   end
  923. end
  924.  
  925.  
  926. ###--------------------------------------------------------------------------###
  927. #  End of script.                                                              #
  928. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement