mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 14:05:32 +02:00
Move RGSS1 viewport elements to new parent when 'viewport=' is called
This commit is contained in:
parent
6a006f1b13
commit
f719c27f57
2 changed files with 36 additions and 2 deletions
|
@ -31,16 +31,42 @@
|
|||
inline void
|
||||
disposableAddChild(VALUE disp, VALUE child)
|
||||
{
|
||||
if (NIL_P(disp) || NIL_P(child))
|
||||
return;
|
||||
|
||||
VALUE children = rb_iv_get(disp, "children");
|
||||
|
||||
bool exists = false;
|
||||
|
||||
if (NIL_P(children))
|
||||
{
|
||||
children = rb_ary_new();
|
||||
rb_iv_set(disp, "children", children);
|
||||
}
|
||||
else {
|
||||
exists = RTEST(rb_funcall(children, rb_intern("include?"), 1, child));
|
||||
}
|
||||
|
||||
/* Assumes children are never removed until destruction */
|
||||
rb_ary_push(children, child);
|
||||
if (!exists)
|
||||
rb_ary_push(children, child);
|
||||
}
|
||||
|
||||
inline void
|
||||
disposableRemoveChild(VALUE disp, VALUE child)
|
||||
{
|
||||
if (NIL_P(disp) || NIL_P(child))
|
||||
return;
|
||||
|
||||
VALUE children = rb_iv_get(disp, "children");
|
||||
if (NIL_P(children))
|
||||
return;
|
||||
|
||||
VALUE index = rb_funcall(children, rb_intern("index"), 1, child);
|
||||
if (NIL_P(index))
|
||||
return;
|
||||
|
||||
rb_funcall(children, rb_intern("delete_at"), 1, index);
|
||||
|
||||
}
|
||||
|
||||
inline void
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "sharedstate.h"
|
||||
#include "binding-util.h"
|
||||
#include "binding-types.h"
|
||||
#include "debugwriter.h"
|
||||
|
||||
#include "sceneelement-binding.h"
|
||||
#include "disposable-binding.h"
|
||||
|
@ -54,6 +55,12 @@ RB_METHOD(viewportElementSetViewport)
|
|||
|
||||
if (!NIL_P(viewportObj))
|
||||
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||
|
||||
if (rgssVer == 1) {
|
||||
VALUE vp = viewportElementGetViewport<C>(0, 0, self);
|
||||
disposableRemoveChild(vp, self);
|
||||
disposableAddChild(viewportObj, self);
|
||||
}
|
||||
|
||||
GUARD_EXC( ve->setViewport(viewport); );
|
||||
|
||||
|
@ -83,6 +90,7 @@ viewportElementInitialize(int argc, VALUE *argv, VALUE self)
|
|||
/* Construct object */
|
||||
C *ve = new C(viewport);
|
||||
|
||||
|
||||
/* Set property objects */
|
||||
rb_iv_set(self, "viewport", viewportObj);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue