mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 22:15:33 +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
|
inline void
|
||||||
disposableAddChild(VALUE disp, VALUE child)
|
disposableAddChild(VALUE disp, VALUE child)
|
||||||
{
|
{
|
||||||
|
if (NIL_P(disp) || NIL_P(child))
|
||||||
|
return;
|
||||||
|
|
||||||
VALUE children = rb_iv_get(disp, "children");
|
VALUE children = rb_iv_get(disp, "children");
|
||||||
|
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
if (NIL_P(children))
|
if (NIL_P(children))
|
||||||
{
|
{
|
||||||
children = rb_ary_new();
|
children = rb_ary_new();
|
||||||
rb_iv_set(disp, "children", children);
|
rb_iv_set(disp, "children", children);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
exists = RTEST(rb_funcall(children, rb_intern("include?"), 1, child));
|
||||||
|
}
|
||||||
|
|
||||||
/* Assumes children are never removed until destruction */
|
if (!exists)
|
||||||
rb_ary_push(children, child);
|
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
|
inline void
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
#include "debugwriter.h"
|
||||||
|
|
||||||
#include "sceneelement-binding.h"
|
#include "sceneelement-binding.h"
|
||||||
#include "disposable-binding.h"
|
#include "disposable-binding.h"
|
||||||
|
@ -54,6 +55,12 @@ RB_METHOD(viewportElementSetViewport)
|
||||||
|
|
||||||
if (!NIL_P(viewportObj))
|
if (!NIL_P(viewportObj))
|
||||||
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
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); );
|
GUARD_EXC( ve->setViewport(viewport); );
|
||||||
|
|
||||||
|
@ -83,6 +90,7 @@ viewportElementInitialize(int argc, VALUE *argv, VALUE self)
|
||||||
/* Construct object */
|
/* Construct object */
|
||||||
C *ve = new C(viewport);
|
C *ve = new C(viewport);
|
||||||
|
|
||||||
|
|
||||||
/* Set property objects */
|
/* Set property objects */
|
||||||
rb_iv_set(self, "viewport", viewportObj);
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue