OSDN Git Service

UICustomを追加
authorh2so5 <h2so5@git.sourceforge.jp>
Sun, 30 Sep 2012 06:15:28 +0000 (15:15 +0900)
committerh2so5 <h2so5@git.sourceforge.jp>
Sun, 30 Sep 2012 06:15:28 +0000 (15:15 +0900)
client/Card.cpp
client/WindowManager.cpp
client/bin/system/js/mmo.js
client/ui/UICustom.cpp [new file with mode: 0644]
client/ui/UICustom.hpp [new file with mode: 0644]
client/ui/include.hpp

index 2505648..ceb0ca3 100644 (file)
@@ -1189,6 +1189,7 @@ void Card::SetFunctions()
                 UIBase::SetObjectTemplate<UILabel>("Label", &object_template);\r
                 UIBase::SetObjectTemplate<UIList>("List", &object_template);\r
                 UIBase::SetObjectTemplate<UIGroup>("Group", &object_template);\r
+                UIBase::SetObjectTemplate<UICustom>("Custom", &object_template);\r
                 auto script_object = object_template->NewInstance();\r
                 script_object->SetPointerInInternalField(0, this);\r
                 context->Global()->Set(String::New("UI"), script_object);\r
index d8fd783..4b68b64 100644 (file)
@@ -66,7 +66,10 @@ void WindowManager::Update()
        auto card_manager = manager_accessor_->card_manager().lock();
        BOOST_FOREACH(const auto& card, card_manager->cards()) {
                if (auto ptr = card->GetWindow()) {
-                       ptr->Update();
+                               card->script().With([&](const Handle<Context>& context)
+                               {
+                                       ptr->Update();
+                               });
                }
        }
 }
@@ -77,7 +80,10 @@ void WindowManager::Draw()
        BOOST_FOREACH(const auto& card, card_manager->cards()) {
                if (auto ptr = card->GetWindow()) {
                        if (ptr->visible()) {
-                               ptr->Draw();
+                               card->script().With([&](const Handle<Context>& context)
+                               {
+                                       ptr->Draw();
+                               });
                        }
                }
        }
index 4c9f140..456c660 100644 (file)
                Object.merge(options, defaults, false, false);
                return Object.merge(new UI._Group, options);
        };
-
+       
+       
+       // UICustom
+       UI.Custom = function(options) {
+               options = options || {};
+               var defaults = {
+                       docking: UI.DOCKING_TOP | UI.DOCKING_LEFT | UI.DOCKING_RIGHT
+               };
+               Object.merge(options, defaults, false, false);
+               
+               return (function (obj) {
+                       obj._processinput = function() {
+                               obj.processinput.call(obj);
+                       }
+                       obj._update = function() {
+                               obj.update.call(obj);
+                       }
+                       obj._draw = function() {
+                               obj.draw.call(obj);
+                       }
+                       return obj;
+               })(Object.merge(new UI._Custom, options));
+               
+       };
+       
        // PlayerFunctions
 
        Player.myself = function(){
diff --git a/client/ui/UICustom.cpp b/client/ui/UICustom.cpp
new file mode 100644 (file)
index 0000000..a76ca3a
--- /dev/null
@@ -0,0 +1,146 @@
+//
+// UICustom.cpp
+//
+
+/**
+* @module global
+* @submodule UI
+ */
+
+/**
+ * @class Custom
+ * @namespace UI
+ * @extends UI.Base
+ */
+
+#include "UICustom.hpp"
+#include "../ScriptEnvironment.hpp"
+#include "../../common/Logger.hpp"
+
+UICustom::UICustom()
+{
+}
+
+UICustom::~UICustom()
+{
+}
+
+Handle<Value> UICustom::Property_processinput(Local<String> property, const AccessorInfo &info)
+{
+    assert(info.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+    return self->processinput_;
+}
+
+void UICustom::Property_set_processinput(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+    assert(info.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+
+    self->processinput_ = Persistent<Function>::New(value.As<Function>());
+}
+
+Handle<Value> UICustom::Property_update(Local<String> property, const AccessorInfo &info)
+{
+    assert(info.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+    return self->update_;
+}
+
+void UICustom::Property_set_update(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+    assert(info.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+
+    self->update_ = Persistent<Function>::New(value.As<Function>());
+}
+
+Handle<Value> UICustom::Property_draw(Local<String> property, const AccessorInfo &info)
+{
+    assert(info.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+    return self->draw_;
+}
+
+void UICustom::Property_set_draw(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+    assert(info.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UICustomPtr*>(info.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+
+    self->draw_ = Persistent<Function>::New(value.As<Function>());
+}
+
+void UICustom::DefineInstanceTemplate(Handle<ObjectTemplate>* object)
+{
+    UIBase::DefineInstanceTemplate(object);
+
+       SetProperty(object, "_processinput", Property_processinput, Property_set_processinput);
+       SetProperty(object, "_update", Property_update, Property_set_update);
+       SetProperty(object, "_draw", Property_draw, Property_set_draw);
+
+       SetFunction(object, "drawLine", Function_drawLine);
+}
+
+void UICustom::ProcessInput(InputManager* input)
+{
+    if (!visible_) {
+        return;
+    }
+       if (!processinput_.IsEmpty()) {
+               processinput_->Call(Context::GetCurrent()->Global(), 0, nullptr);
+       }
+}
+
+void UICustom::Update()
+{
+    if (!visible_) {
+        return;
+    }
+
+       if (!update_.IsEmpty()) {
+               update_->Call(Context::GetCurrent()->Global(), 0, nullptr);
+       }
+}
+
+void UICustom::Draw()
+{
+    if (!visible_) {
+        return;
+    }
+
+       if (!draw_.IsEmpty()) {
+               draw_->Call(Context::GetCurrent()->Global(), 0, nullptr);
+       }
+}
+
+Handle<Value> UICustom::Function_drawLine(const Arguments& args)
+{
+    assert(args.This()->InternalFieldCount() > 0);
+    auto self = std::dynamic_pointer_cast<UICustom>(
+            *static_cast<UIBasePtr*>(args.This()->GetPointerFromInternalField(0))
+    );
+    assert(self);
+
+       DrawLine(100, 100, 200, 200, GetColor(255,255,255));
+
+    return Undefined();
+}
+
diff --git a/client/ui/UICustom.hpp b/client/ui/UICustom.hpp
new file mode 100644 (file)
index 0000000..e9488dd
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// UICustom.hpp
+//
+
+#pragma once
+
+#include "UIBase.hpp"
+
+class UICustom : public UIBase {
+    public:
+        UICustom();
+        ~UICustom();
+        void ProcessInput(InputManager* input);
+        void Update();
+        void Draw();
+
+    public:
+        static void DefineInstanceTemplate(Handle<ObjectTemplate>* object);
+
+       private:
+               Persistent<Function> processinput_, update_, draw_;
+
+               static Handle<Value> Property_processinput(Local<String> property, const AccessorInfo &info);
+               static void Property_set_processinput(Local<String> property, Local<Value> value, const AccessorInfo& info);
+               static Handle<Value> Property_update(Local<String> property, const AccessorInfo &info);
+               static void Property_set_update(Local<String> property, Local<Value> value, const AccessorInfo& info);
+               static Handle<Value> Property_draw(Local<String> property, const AccessorInfo &info);
+               static void Property_set_draw(Local<String> property, Local<Value> value, const AccessorInfo& info);
+
+       private:
+               static Handle<Value> Function_drawLine(const Arguments& args);
+
+};
+
+typedef std::shared_ptr<UICustom> UICustomPtr;
\ No newline at end of file
index 48703e8..536afcf 100644 (file)
@@ -10,3 +10,4 @@
 #include "UILabel.hpp"
 #include "UIList.hpp"
 #include "UIGroup.hpp"
+#include "UICustom.hpp"