IceDragon200

[VXA]Shell

Jun 13th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.75 KB | None | 0 0
  1. #==============================================================================#
  2. # ♥ Shell
  3. #==============================================================================#
  4. # // • Created By    : IceDragon
  5. # // • Modified By   : IceDragon
  6. # // • Data Created  : 02/06/2012
  7. # // • Data Modified : 02/06/2012
  8. # // • Version       : 1.0
  9. #==============================================================================#
  10. # ● Explanation
  11. #   A very bare class used as a lightweight window
  12. #   This class also includes methods from:
  13. #     Surface
  14. #     RectExpansion (Standard only)
  15. #     OpenClose
  16. # ● Author Comments
  17. #   >_> Hell its just a cheap ass stripped down window, that happens to
  18. #   be clone-able. Anyway I use Shells when making fancy sprite based menus
  19. #   >_> They can also be used with most of the WindowAddons (Naise O:)
  20. #   >_>
  21. #   <_<
  22. #   >_< WUT!?
  23. #==============================================================================#
  24. # ● Change Log
  25. #     ♣ 02/06/2012 V1.0
  26. #
  27. #==============================================================================#
  28. class Shell
  29.   include MACL::Mixin::Surface
  30.   include MACL::Mixin::RectExpansion
  31.   include Mixin::OpenClose
  32.   def initialize(*args,&block)
  33.     @cube = Cube.new(0,0,0,0,0,0) # // Making use of that cube class now XD
  34.     @ox, @oy = 0, 0
  35.     @viewport = nil
  36.     @active   = false
  37.     @opacity  = 255
  38.     @visible  = true
  39.     @openness = 255
  40.     @padding  = 0
  41.     @padding_bottom = 0
  42.     _set(*args,&block)
  43.     init_internal()
  44.     post_init()
  45.   end  
  46.   public
  47.   def set(*args,&block)
  48.     _set(*args,&block)
  49.     _update_position()
  50.     _update_size()
  51.   end
  52.   def move(x=self.x,y=self.y,width=self.width,height=self.height)
  53.     @cube.x = x
  54.     @cube.y = y
  55.     @cube.width = width
  56.     @cube.height = height
  57.     _update_position()
  58.     _update_size()
  59.   end    
  60.   def cube # // Returns a duplicate of the internal @cube (Cube)
  61.     @cube.dup
  62.   end  
  63.   def x
  64.     @cube.x
  65.   end
  66.   def y
  67.     @cube.y
  68.   end
  69.   def z
  70.     @cube.z
  71.   end  
  72.   def width
  73.     @cube.width
  74.   end  
  75.   def height
  76.     @cube.height
  77.   end
  78.   def x=(n)
  79.     @cube.x = n
  80.     _update_position()
  81.   end  
  82.   def y=(n)
  83.     @cube.y = n
  84.     _update_position()
  85.   end  
  86.   def z=(n)
  87.     @cube.z = n
  88.     _update_position()
  89.   end  
  90.   def width=(n)
  91.     @cube.width = n
  92.     _update_size()
  93.   end  
  94.   def height=(n)
  95.     @cube.height = n
  96.     _update_size()
  97.   end  
  98.   attr_reader :ox
  99.   def ox=(n)  
  100.     @ox = n
  101.     _update_oposition()
  102.   end  
  103.   attr_reader :oy
  104.   def oy=(n)  
  105.     @oy = n
  106.     _update_oposition()
  107.   end  
  108.   attr_reader :viewport
  109.   def viewport=(n)
  110.     @viewport = n
  111.     #_update_viewport()
  112.     _update_all() # // . x . Dont make it a habit to reassign Viewports
  113.   end  
  114.   attr_reader :active
  115.   def active=(n)
  116.     @active = n
  117.     _update_active()
  118.   end  
  119.   attr_reader :visible
  120.   def visible=(n)
  121.     @visible = n
  122.     _update_visible()
  123.   end  
  124.   attr_reader :opacity
  125.   def opacity=(n)
  126.     @opacity = n.clamp(0,255).to_i
  127.     _update_opacity()
  128.   end  
  129.   attr_reader :openness
  130.   def openness=(n)
  131.     @openness = n.clamp(0,255).to_i
  132.     _update_openness()
  133.   end    
  134.   attr_reader :padding
  135.   def padding=(n)
  136.     @padding = n
  137.     _update_padding()
  138.   end  
  139.   attr_accessor :padding_bottom
  140.   def show
  141.     self.visible = true
  142.     self
  143.   end
  144.   def hide
  145.     self.visible = false
  146.     self
  147.   end
  148.   def activate
  149.     self.active = true
  150.     self
  151.   end
  152.   def deactivate
  153.     self.active = false
  154.     self
  155.   end
  156.   def disposed?
  157.     @disposed == true
  158.   end  
  159.   def dispose()
  160.     raise RGSSError.new("Object Already Disposed") if disposed?
  161.     _dispose_objs()
  162.     @disposed = true
  163.   end
  164.   def update
  165.     _update_objs()
  166.   end
  167.   private
  168.   def init_internal()
  169.   end  
  170.   def post_init()
  171.     _update_all()
  172.   end  
  173.   def _update_all()
  174.     _update_position()
  175.     _update_oposition()
  176.     _update_size()
  177.     _update_active()
  178.     _update_visible()
  179.     _update_viewport()
  180.     _update_opacity()
  181.     _update_openness()
  182.     _update_padding()
  183.   end  
  184.   def _set(*args,&block)
  185.     x,y,z,w,h = 0,0,0,0,0
  186.     case args[0]
  187.     when Shell
  188.       x,y,z,w,h,l = *args[0].cube.to_a
  189.     when Rect, Polygon#, Window
  190.       x,y,w,h = *args[0].to_rect.to_a
  191.     when Hash  
  192.       x,y,z,w,h = args[0].get_values(:x,:y,:z,:width,:height)
  193.     else
  194.       x,y,w,h = *args
  195.     end
  196.     @cube.x      = x || 0
  197.     @cube.y      = y || 0
  198.     @cube.z      = z || 0
  199.     @cube.width  = w || 0
  200.     @cube.height = h || 0
  201.   end  
  202.   def _objs()
  203.     []
  204.   end
  205.   def _obj_enabled?(n)
  206.     true
  207.   end  
  208.   def _dispose_objs()
  209.     _each_obj(){|o|o.dispose unless o.disposed? if o}
  210.   end  
  211.   def _update_objs()
  212.     _each_obj(){|o|o.update}
  213.   end  
  214.   def _each_obj()
  215.     _objs.each { |o| yield o }
  216.   end
  217.   def _update_position()
  218.     begin
  219.       _each_obj { |o| o.x, o.y, o.z = self.x, self.y, self.z } if _obj_enabled?(:position)
  220.     rescue => ex
  221.       puts self
  222.       raise ex
  223.     end  
  224.     # // You add stuff :D
  225.   end
  226.   def _update_oposition()
  227.     _each_obj { |o| o.ox, o.oy = self.ox, self.oy } if _obj_enabled?(:oposition)
  228.     # // You add stuff :D
  229.   end  
  230.   def _update_size()
  231.     _each_obj { |o| o.width, o.height = self.width, self.height } if _obj_enabled?(:size)
  232.     # // You add stuff :D
  233.   end  
  234.   def _update_active()
  235.     _each_obj { |o| o.active = self.active if o.respond_to?(:active=) } if _obj_enabled?(:active)
  236.     # // You add stuff :D
  237.   end  
  238.   def _update_visible()
  239.     _each_obj { |o| o.visible = self.visible } if _obj_enabled?(:visible)
  240.     # // You add stuff :D
  241.   end  
  242.   def _update_opacity()
  243.     _each_obj { |o| o.opacity = self.opacity } if _obj_enabled?(:opacity)
  244.     # // You add stuff :D
  245.   end  
  246.   def _update_viewport()
  247.     _each_obj { |o| o.viewport = self.viewport } if _obj_enabled?(:viewport)
  248.     # // You add stuff :D
  249.   end
  250.   def _update_openness()
  251.     # // You add stuff :D
  252.   end
  253.   def _update_padding()
  254.     # // You add stuff :D
  255.   end  
  256.   def _redraw() # // Redraw everything in the container . x . super stuff
  257.   end  
  258.   def _redraw!() # // Redraw && Update All
  259.     _update_all() # // Initialial Update
  260.     _redraw()
  261.     _update_all() # // Final Update
  262.   end
  263. end
  264. #==============================================================================#
  265. # ♥ Shell::Base
  266. #==============================================================================#
  267. class Shell::Base < Shell
  268. end  
  269. #==============================================================================#
  270. # // >_> Your wondering why the hell that(^Shell::Base) is empty aren't you?
  271. # // <_< Basically you use the Shell::Base instead of the main class for
  272. # // the WindowAddons.
  273. # // Why?
  274. # // >_> Its an inheritance thing...
  275. # // If you should take a look in the WindowAddons script
  276. # // You'll notice super in the x=, y=, z= etc..etc methods in the Base module
  277. # // >_>; <_<; >_<"
  278. # // Anyway, back to the inheritance
  279. # // . x . WindowAddons works like this:
  280. # // My_Window < (Addons go here) < Window::Base < WindowAddon::Base < Window
  281. # // 'include' places the module before the current class in the hierachy
  282. # // Mentioned before; Window has x=, y=, z=, etc...etc..
  283. # // So if you placed the AddonBase BEFORE Window... . x . bad things would happen
  284. # // . x . You couldn't call (x=, y=, z=)'s super since they didn't exist then.
  285. # // super calls the parent's method >.> So when a Addon calls say x='s super
  286. # // If there was a addon before it, it calls that one, and it chains all the way
  287. # // up till it reaches the Window's x= method. o3o Here is an example
  288. # // Window::Cheese (Has Header, ScrollBar, WinButtons installed)
  289. # // .x. You do something like (window.x = 3)
  290. # // What happens?
  291. # //   x=(n)
  292. # //     (Window::Cheese)x=(n)>> To the next
  293. # //     (WinButtons)   x=(n) >> again
  294. # //     (ScrollBar)    x=(n) >> and again...
  295. # //     (Header)       x=(n) >> yet again...
  296. # //     (WindowBase)   x=(n) >> again......
  297. # //     (WindowAddons::Base)x=(n) >> again...
  298. # //     (Window)       x=(n)  And your journey ends here
  299. # // O_O Yup shit like that happens, it goes back.... WAY BACK
  300. # // So anyway...
  301. # // Just remember, you need a base class to work with the WindowAddons
  302. # // >_>
  303. # // <_<
  304. # // >_<
  305. # // >.> And so there is teh reason for the empty class
  306. # // Oh one more thing . x.  If you overwrite the methods in the child class
  307. # // And you dont call super, the entire super line gets broken .x.
  308. # // So x= would be a useless thingy . x .
  309. # // Lesson: Dont overwrite important methods.
  310. # // <.<; >.>; >,<;.. I wrote too much....
  311. #=■==========================================================================■=#
  312. #                           // ● End of File ● //                              #
  313. #=■==========================================================================■=#
Advertisement
Add Comment
Please, Sign In to add comment