Myownfriend
Member
I've tried everything I could think of to put a window on a viewport but it just won't work. Does anyone know how to?
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
# This class is for all in-game windows.
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Object Initialization !OVERRIDE!
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
# viewport : the viewport you want the window to be a part of.
#--------------------------------------------------------------------------
def initialize(x, y, width, height, viewport = nil)
super(viewport)
@windowskin_name = $game_system.windowskin_name
self.windowskin = RPG::Cache.windowskin(@windowskin_name)
self.x = x
self.y = y
self.width = width
self.height = height
self.z = 100
end
end
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
# This is a superclass of all windows in the game.
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Object Initialization !OVERRIDE!
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
# viewport : the viewport that the window is contained within.
#--------------------------------------------------------------------------
def initialize(x, y, width, height, viewport = nil)
super(viewport)
self.windowskin = Cache.system("Window")
self.x = x
self.y = y
self.y = y
self.width = width
self.height = height
self.z = 100
self.back_opacity = 200
self.openness = 255
create_contents
@opening = false
@closing = false
end
end
class Window_HUD < Window_Base
def initialize(viewport = nil)
super(0, 0, 100, 100, viewport)
# .. other code
end
end
def initialize(x, y, width, height, actor, viewport = nil)
super(x, y, width, height, viewport)
@skillviewport = Viewport.new(0, 33, 640, 416)
@skillstatus_window = Window_SkillStatus.new(0, -106 - 33, 640, 64, @actor, @skillviewport)
@skill_window = Window_Skill_Menu.new(0, 518 - 33, 640, 312, @actor, @skillviewport)
#==============================================================================
# ** Window_SkillStatus
#------------------------------------------------------------------------------
# This window displays the skill user's status on the skill screen.
#==============================================================================
class Window_SkillStatus < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization !OVERRIDE!
# actor : actor
#--------------------------------------------------------------------------
def initialize(actor, viewport = nil)
super(0, 64, 640, 64, viewport)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
refresh
end
end
@skillviewport = Viewport.new(0, 33, 640, 416)
@skillstatus_window = Window_SkillStatus.new($game_party.actors[xxx], @skillviewport) # Where xxx is the position of the party member.
def initialize(x, y, width, height, actor)
def initialize(x, y, width, height, actor, viewport = nil)
super(x, y, width, height)
super(x, y, width, height, viewport)
@skillstatus_window.y = -139
@skillstatus_window.width = 640
@skillstatus_window.height = 64
SephirothSpawn":1b6y9voi said:@khmp: The only way I can think of re-assigning the object a viewport would be to dispose the object, and recreate it on the viewport. I am going to try something out, and actually make something that reads all child classes of Window_Base, auto-adds the viewport setting, and then figure this out. And the Plane, RPG::Weather, Tilemap, Sprite classes
Want a challenge? I want to see you do the same. lol. If you are up to it.
@test = Window_Base.new(0, 0, 32, 32, Viewport.new(0, 0, 32, 32))
SephirothSpawn":1j209587 said:Come on, I am running on less than 2 hours of sleep and a hang over and I can follow... XD
As you said from what you posted, you have to make it so in every window class that inherits from Window_Base, you have to define the viewport. Why not make this automatic for all windows with a plug and play? By reading the child classes of Window_Base, aliasing each classes initialize method, adding a viewport argument, and sending it back to the original initialize method.
Now as for re-assigning the object's viewports, you just need to add a viewport method, dispose the object from the current viewport and recreate it in the new viewport. Honestly this part still seems to be a bit complicated and I am just throwing junk out there. I am not sure it's possible, but dammit, we can try!
# Still no success.
ObjectSpace.each_object(Class) do |c|
if c.ancestors.include?(Window)
c.class_eval do
"alias orig_initialize initialize;" +
"def initialize(*args, viewport = nil);" +
"orig_initialize(*args, viewport);" +
"end;"
end
end
end
class Window_Base
def Window_Base.inherited(sub_class)
# magic here
end
end
class Window_Base
@@sub_classes = []
def Window_Base.inherited(sub_class)
@@sub_classes << sub_class
end
end
class Window_Base
@@sub_classes.each do |sub|
# more magic and sparkle
end
end
@skill_window.viewport
numbnuts":1olnlddz said:@khmp
As long as a solution to my problem is closer to being found that I don't mind lol
There is one thing I wondering about.
Code:@skill_window.viewport
For some reason this is considered an undefined method even though it is listed in the RMXP help as valid method.
viewport = @skill_window.viewport
@skill_window.viewport=
Was that you that we just hit. You so slow.SephirothSpawn":1olnlddz said:EDIT: I can't sleep! I am more frustrated than Ray Charles playing Marco Polo. I had the answer and then... I got hit with the short bus.
sprite = Sprite.new(Viewport.new(0, 0, 640, 480))
viewport = Viewport.new(0, 0, 640, 480)
viewport.add(Sprite.new)
class Window_Base < Window
@@sub_classes = [Window_Base]
def Window_Base.inherited(sub_class)
@@sub_classes << sub_class
end
end
class Window
alias orig_initialize initialize
def initialize(*args)
unless @initialized == true
@initialized = true
orig_initialize(*args)
end
end
end
Window_Base.class_eval("@@sub_classes").each do |sub|
code =<<_END_
class #{sub} < #{sub.superclass}
alias orig_#{sub}_initialize initialize
def initialize(*args)
if args[-1].is_a?(Viewport)
super(args[-1])
if args.size > 1
orig_#{sub}_initialize(*args[0, args.size - 1])
end
else
orig_#{sub}_initialize(*args)
end
end
end
_END_
eval(code)
end
super(args[-1])
class Window
alias orig_initialize initialize
def initialize(*args)
unless @initialized == true
@initialized = true
orig_initialize(*args)
end
end
end
super(args[-1])
if args.size > 1
orig_#{sub}_initialize(*args[0, args.size - 1])
end
class Object
@@subclasses = {}
def self.subclasses
return @@subclasses.has_key?(self) ? @@subclasses[self] : []
end
def self.add_sub_class(superclass, subclass)
@@subclasses[superclass] = [] unless @@subclasses.has_key?(superclass)
@@subclasses[superclass] << subclass unless @@subclasses[self].include?(subclass)
end
def self.inherited(subclass)
self.add_sub_class(subclass.superclass, subclass)
end
end
numbnuts":2ffbktiq said:lol This all sounds very foreign to me lol So, did we find out how to assign windows to viewports yet or are you still trying to figure it out and if you did, how do I implement it?
class Window_Base < Window
@@sub_classes = [Window_Base]
def Window_Base.inherited(sub_class)
@@sub_classes << sub_class
end
end
class Window
alias orig_initialize initialize
def initialize(*args)
unless @initialized == true
@initialized = true
orig_initialize(*args)
end
end
end
Window_Base.class_eval("@@sub_classes").each do |sub|
code =<<_END_
class #{sub} < #{sub.superclass}
alias orig_#{sub}_initialize initialize
def initialize(*args)
if args[-1].is_a?(Viewport)
super(args[-1])
if args.size > 1
orig_#{sub}_initialize(*args[0, args.size - 1])
end
else
orig_#{sub}_initialize(*args)
end
end
end
_END_
eval(code)
end
@test = Viewport.new(0, 0, 640, 240)
@window = Window_Skill.new($game_party.actors[0], @test)