Advertisement
diamondandplatinum3

Morality Metre for Menu ~ RGSS3

Dec 8th, 2012
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.96 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Morality Metre for Menu
  3. #             Version: 2.0
  4. #             Authors: DiamondandPlatinum3
  5. #             Date: December 8, 2012
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This script puts a morality bar inside of your menu, allowing you to have
  10. #    different colours and titles along with it.
  11. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. #------------------------------------------------------------------------------
  13. #  Instructions:
  14. #  
  15. #     In the editable region below you can set up what is necessary
  16. #
  17. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  18. module DiamondandPlatinum3
  19.   module MoralityMetre
  20.     #===========================================
  21.     #   Editable Region
  22.     #===========================================
  23.     WINDOW_X_POSITION = 0
  24.     WINDOW_Y_POSITION = 240
  25.     WINDOW_WIDTH      = 160
  26.     WINDOW_HEIGHT     = 80
  27.     WINDOW_VISIBLE    = true # Even if the window is not visible, the gauge and
  28.                              # name will be. They are still located inside of the
  29.                              # window however, so you still need to position it properly
  30.                          
  31.                              
  32.     GAUGE_WIDTH   = 144  # Gauge Width in Pixels (Keep it less than the window width)
  33.     GAUGE_HEIGHT  = 30   # Gauge Height in Pixels (Keep it less than the window height)
  34.    
  35.    
  36.     MORALITY_VARIABLE_ID    = 2     # Which Variable is holding your morality?
  37.                                     # This is an Event Variable.
  38.                                    
  39.     MORALITY_VARIABLE_RANGE = 200   # The Number you put in here is the highest amount of morality
  40.                                     # you can possibly obtain, this represents good morality
  41.    
  42.                                    
  43.     NEUTRAL_RANGE = 25 # This is actually a percentage out of 100, basically by default
  44.                        # you can be 25% Good or Evil and still have the Neutral
  45.                        # Colours be shown for the gauge (albeit either darker or
  46.                        # lighter). Once you're more good or evil than that, your
  47.                        # other morality colours will be displayed.
  48.                                  
  49.                        
  50.                                       #   Red,    Green,  Blue
  51.     MORALITY_EVIL_COLOUR              = [ 255,    0,      0   ]
  52.     MORALITY_EVIL_COLOUR_GRADIENT     = [ 200,    75,     25  ]
  53.     MORALITY_NEUTRAL_COLOUR           = [ 255,    255,    255 ]
  54.     MORALITY_NEUTRAL_COLOUR_GRADIENT  = [ 0,      127,    127 ]
  55.     MORALITY_GOOD_COLOUR              = [ 0,      55,     200 ]
  56.     MORALITY_GOOD_COLOUR_GRADIENT     = [ 75,     75,     200 ]
  57.    
  58.    
  59.     BLUR_TEXT                   = true  # Blur Text if Evil Enough?
  60.     MORALITY_EVIL_BLUR_POINT    = 50    # What "Percentage" of Evil do you need to
  61.                                         # be before the text title becomes blured?
  62.        
  63.     OUTLINE_TEXT                = true  # Outline Text if Good Enough?
  64.     MORALITY_GOOD_OUTLINE_POINT = 50    # What Percentage of good do you have to
  65.                                         # be before the text title has a holy outline?
  66.    
  67.                                      
  68.     # In this section: If your Morality variable is equal to or higher than that
  69.     # number, the Line of text next to it will be your title.
  70.     # You can add or remove lines by copy-paste / removing lines
  71.     #-------------------------------------------
  72.     MORALITY_NAME = [ # No touching this line
  73.     #-------------------------------------------
  74.     [ 0,    "Lucifer"     ],
  75.     [ 15,   "Evil"        ],
  76.     [ 45,   "Terrible"    ],
  77.     [ 70,   "Jerk"        ],
  78.     [ 90,   "Neutral"     ],
  79.     [ 110,  "Kind"        ],
  80.     [ 140,  "Hero"        ],
  81.     [ 170,  "Angel"       ],
  82.     [ 190,  "Benevolent"  ],
  83.     #===========================================
  84.     ]     # End of Editable Region
  85.     #===========================================
  86.   end
  87. end
  88.  
  89.  
  90. #==============================================================================
  91. # ** Import
  92. #------------------------------------------------------------------------------
  93. #  Just used so that the patches can complain if this script doesn't exist or
  94. #  is not placed above them.
  95. #==============================================================================
  96. ($diamondandplatinum3_scripts ||= {})[:MoralityMetre_Ver20] = true
  97.  
  98.  
  99. #==============================================================================
  100. # ** Scene_Menu
  101. #------------------------------------------------------------------------------
  102. #  This class performs the menu screen processing.
  103. #==============================================================================
  104.  
  105. class Scene_Menu < Scene_MenuBase
  106.   #--------------------------------------------------------------------------
  107.   # * Start Processing
  108.   #--------------------------------------------------------------------------
  109.   alias dp3_scenemenu_start_18dyb09     start
  110.   #--------------------------------------------------------------------------
  111.   def start( *args )
  112.     @moralitymetre_window = Window_MoralityMetre.new
  113.    
  114.     # Call Orginal Method
  115.     dp3_scenemenu_start_18dyb09( *args )
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * Dispose
  119.   #--------------------------------------------------------------------------
  120.   alias dp3_scenemenu_terminate_18dyb09     terminate
  121.   #--------------------------------------------------------------------------
  122.   def terminate
  123.     # Call Original Method
  124.     dp3_scenemenu_terminate_18dyb09()
  125.    
  126.     @moralitymetre_window.dispose unless @moralitymetre_window.disposed?
  127.   end
  128. end
  129.  
  130.  
  131.  
  132.  
  133. #==============================================================================
  134. # ** Window_MoralityMetre
  135. #------------------------------------------------------------------------------
  136. #  Defines the window and its contents
  137. #==============================================================================
  138. class Window_MoralityMetre < Window_Base
  139.   include DiamondandPlatinum3::MoralityMetre
  140.   #--------------------------------------------------------------------------
  141.   # * Object Initialization
  142.   #--------------------------------------------------------------------------
  143.   def initialize()
  144.     super(WINDOW_X_POSITION, WINDOW_Y_POSITION, WINDOW_WIDTH, WINDOW_HEIGHT)
  145.     self.opacity = 0 if !WINDOW_VISIBLE
  146.     contents.font.size = 25
  147.     refresh
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # * Refresh
  151.   #--------------------------------------------------------------------------
  152.   def refresh
  153.     contents.clear
  154.     colour1 = self.get_colour1()
  155.     colour2 = self.get_colour2()
  156.     gauge_y_pos = (contents.height - GAUGE_HEIGHT)
  157.    
  158.     # Change Text Colour if 50% Good
  159.     contents.font.out_color = colour2 if OUTLINE_TEXT && get_should_text_be_outlined?()
  160.    
  161.     # Draw Text
  162.     contents.draw_text( 0, 0, contents.width, 25, self.get_title(), 1 )
  163.    
  164.     # Blur Text if 50% Evil
  165.     contents.blur if BLUR_TEXT && get_should_text_be_blured?()
  166.  
  167.     # Draw Morality Gauge
  168.     draw_gauge(0, gauge_y_pos, contents.width, 1.0, colour1, colour2)
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # * Draw Gauge
  172.   #--------------------------------------------------------------------------
  173.   def draw_gauge(x, y, width, rate, color1, color2)
  174.     fill_w = (width * rate).to_i
  175.     gauge_y = y
  176.     contents.fill_rect(x, gauge_y, GAUGE_WIDTH, GAUGE_HEIGHT, gauge_back_color)
  177.     contents.gradient_fill_rect(x, gauge_y, fill_w, GAUGE_HEIGHT, color1, color2, true)
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # * Get Gauge Colour 1
  181.   #--------------------------------------------------------------------------
  182.   def get_colour1
  183.     var = $game_variables[MORALITY_VARIABLE_ID].to_f
  184.     neutral = (MORALITY_VARIABLE_RANGE * 0.5).to_f
  185.    
  186.     red = green = blue = 0
  187.     # Neutral ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188.     if (var < get_neutral_range_plus(neutral) && var > get_neutral_range_minus( neutral ))
  189.       var  /= get_neutral_range_plus(neutral)
  190.       red   = var * MORALITY_NEUTRAL_COLOUR[0]
  191.       green = var * MORALITY_NEUTRAL_COLOUR[1]
  192.       blue  = var * MORALITY_NEUTRAL_COLOUR[2]
  193.     # Evil ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  194.     elsif var < neutral
  195.       var   = get_evil_morality_variable_percentage( var, neutral )
  196.       red   = var * MORALITY_EVIL_COLOUR[0]
  197.       green = var * MORALITY_EVIL_COLOUR[1]
  198.       blue  = var * MORALITY_EVIL_COLOUR[2]
  199.     # Good ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  200.     else
  201.       var   = get_good_morality_variable_percentage( var, neutral )
  202.       red   = var * MORALITY_GOOD_COLOUR[0]
  203.       green = var * MORALITY_GOOD_COLOUR[1]
  204.       blue  = var * MORALITY_GOOD_COLOUR[2]
  205.     end
  206.     return Color.new( red, green, blue )
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Get Gauge Colour 2
  210.   #--------------------------------------------------------------------------
  211.   def get_colour2
  212.     var = $game_variables[MORALITY_VARIABLE_ID].to_f
  213.     neutral = (MORALITY_VARIABLE_RANGE * 0.5).to_f
  214.    
  215.    
  216.     red = green = blue = 0
  217.     # Neutral ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218.     if (var < get_neutral_range_plus(neutral) && var > get_neutral_range_minus( neutral ))
  219.       var  /= get_neutral_range_plus(neutral)
  220.       red   = var * MORALITY_NEUTRAL_COLOUR_GRADIENT[0]
  221.       green = var * MORALITY_NEUTRAL_COLOUR_GRADIENT[1]
  222.       blue  = var * MORALITY_NEUTRAL_COLOUR_GRADIENT[2]
  223.     # Evil ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  224.     elsif var < neutral
  225.       var   = get_evil_morality_variable_percentage( var, neutral )
  226.       red   = var * MORALITY_EVIL_COLOUR_GRADIENT[0]
  227.       green = var * MORALITY_EVIL_COLOUR_GRADIENT[1]
  228.       blue  = var * MORALITY_EVIL_COLOUR_GRADIENT[2]
  229.     # Good ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  230.     else
  231.       var   = get_good_morality_variable_percentage( var, neutral )
  232.       red   = var * MORALITY_GOOD_COLOUR_GRADIENT[0]
  233.       green = var * MORALITY_GOOD_COLOUR_GRADIENT[1]
  234.       blue  = var * MORALITY_GOOD_COLOUR_GRADIENT[2]
  235.     end
  236.     return Color.new( red, green, blue )
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Get "Should Text be Blured?"
  240.   #--------------------------------------------------------------------------
  241.   def get_should_text_be_blured?()
  242.     threshhold = ((MORALITY_VARIABLE_RANGE * 0.5) * (MORALITY_EVIL_BLUR_POINT * 0.01))
  243.     return $game_variables[MORALITY_VARIABLE_ID] <= threshhold
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Get "Should Text be Outlined?"
  247.   #--------------------------------------------------------------------------
  248.   def get_should_text_be_outlined?()
  249.     threshhold = ((MORALITY_VARIABLE_RANGE * 0.5) * (1.0 + (MORALITY_GOOD_OUTLINE_POINT * 0.01)))
  250.     return $game_variables[MORALITY_VARIABLE_ID] >= threshhold
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # * Get Neutral Range
  254.   #--------------------------------------------------------------------------
  255.   def get_neutral_range
  256.     return NEUTRAL_RANGE.to_f * 0.01
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * Get Neutral Range +
  260.   #--------------------------------------------------------------------------
  261.   def get_neutral_range_plus( number )
  262.     return number * ( 1.0 + get_neutral_range())
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * Get Neutral Range -
  266.   #--------------------------------------------------------------------------
  267.   def get_neutral_range_minus( number )
  268.     return number * get_neutral_range()
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * Get Evil Morality Variable Percentage
  272.   #--------------------------------------------------------------------------
  273.   def get_evil_morality_variable_percentage( var, neutral )
  274.     return ((var - neutral) * -1) / neutral
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # * Get Good Morality Variable Percentage
  278.   #--------------------------------------------------------------------------
  279.   def get_good_morality_variable_percentage( var, neutral )
  280.     return (var - neutral) / neutral
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # * Get Title
  284.   #--------------------------------------------------------------------------
  285.   def get_title
  286.     title = "Unknown"
  287.     MORALITY_NAME.each do |innerarray|
  288.       title = innerarray[1] if $game_variables[MORALITY_VARIABLE_ID] >= innerarray[0]
  289.     end
  290.     return title
  291.   end
  292. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement