Added set checkbox and OnCanvasElement Node
This commit is contained in:
parent
0ac46b3bb5
commit
dda2396313
42
Sources/armory/logicnode/CanvasSetCheckBoxNode.hx
Normal file
42
Sources/armory/logicnode/CanvasSetCheckBoxNode.hx
Normal file
|
@ -0,0 +1,42 @@
|
|||
package armory.logicnode;
|
||||
|
||||
import iron.Scene;
|
||||
import armory.trait.internal.CanvasScript;
|
||||
|
||||
class CanvasSetCheckBoxNode extends LogicNode {
|
||||
|
||||
var canvas: CanvasScript;
|
||||
var element: String;
|
||||
var value: Bool;
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
}
|
||||
|
||||
#if arm_ui
|
||||
function update() {
|
||||
if (!canvas.ready) return;
|
||||
|
||||
// This Try/Catch hacks around an issue where the handles are
|
||||
// not created yet, even though canvas.ready is true.
|
||||
try {
|
||||
canvas.getHandle(element).selected = value;
|
||||
tree.removeUpdate(update);
|
||||
}
|
||||
catch (e: Dynamic) {}
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
override function run(from: Int) {
|
||||
element = inputs[1].get();
|
||||
value = inputs[2].get();
|
||||
canvas = Scene.active.getTrait(CanvasScript);
|
||||
if (canvas == null) canvas = Scene.active.camera.getTrait(CanvasScript);
|
||||
|
||||
// Ensure canvas is ready
|
||||
tree.notifyOnUpdate(update);
|
||||
update();
|
||||
}
|
||||
#end
|
||||
}
|
64
Sources/armory/logicnode/OnCanvasElementNode.hx
Normal file
64
Sources/armory/logicnode/OnCanvasElementNode.hx
Normal file
|
@ -0,0 +1,64 @@
|
|||
package armory.logicnode;
|
||||
|
||||
import iron.Scene;
|
||||
import armory.trait.internal.CanvasScript;
|
||||
|
||||
class OnCanvasElementNode extends LogicNode {
|
||||
|
||||
var canvas: CanvasScript;
|
||||
var element: String;
|
||||
|
||||
public var property0: String;
|
||||
public var property1: String;
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
super(tree);
|
||||
|
||||
// Ensure canvas is ready
|
||||
tree.notifyOnUpdate(update);
|
||||
}
|
||||
|
||||
#if arm_ui
|
||||
function update() {
|
||||
|
||||
element = inputs[0].get();
|
||||
|
||||
if(!Scene.active.ready) return;
|
||||
canvas = Scene.active.getTrait(CanvasScript);
|
||||
if (canvas == null) canvas = Scene.active.camera.getTrait(CanvasScript);
|
||||
if(canvas == null) return;
|
||||
if (!canvas.ready) return;
|
||||
if(canvas.getElement(element) == null) return;
|
||||
|
||||
var mouse = iron.system.Input.getMouse();
|
||||
var b = false;
|
||||
switch (property0) {
|
||||
case "Down":
|
||||
b = mouse.down(property1);
|
||||
case "Started":
|
||||
b = mouse.started(property1);
|
||||
case "Released":
|
||||
b = mouse.released(property1);
|
||||
}
|
||||
if (b)
|
||||
{
|
||||
|
||||
var x1 = canvas.getElement(element).x;
|
||||
var y1 = canvas.getElement(element).y;
|
||||
var x2 = x1 + canvas.getElement(element).width;
|
||||
var y2 = y1 + canvas.getElement(element).height;
|
||||
|
||||
var mouseX = mouse.x;
|
||||
var mouseY = mouse.y;
|
||||
|
||||
if((mouseX >= x1) && (mouseX <= x2))
|
||||
{
|
||||
if((mouseY >= y1) && (mouseY <= y2))
|
||||
{
|
||||
runOutput(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
18
blender/arm/logicnode/canvas_set_checkbox.py
Normal file
18
blender/arm/logicnode/canvas_set_checkbox.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import bpy
|
||||
from bpy.props import *
|
||||
from bpy.types import Node, NodeSocket
|
||||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class CanvasSetCheckBoxNode(Node, ArmLogicTreeNode):
|
||||
'''Set canvas check box'''
|
||||
bl_idname = 'LNCanvasSetCheckBoxNode'
|
||||
bl_label = 'Canvas Set Check Box'
|
||||
bl_icon = 'QUESTION'
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAction', 'In')
|
||||
self.inputs.new('NodeSocketString', 'Element')
|
||||
self.inputs.new('NodeSocketBool', 'Value')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
|
||||
add_node(CanvasSetCheckBoxNode, category='Canvas')
|
30
blender/arm/logicnode/input_on_canvas_element.py
Normal file
30
blender/arm/logicnode/input_on_canvas_element.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import bpy
|
||||
from bpy.props import *
|
||||
from bpy.types import Node, NodeSocket
|
||||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class OnCanvasElementNode(Node, ArmLogicTreeNode):
|
||||
'''On canvas element node'''
|
||||
bl_idname = 'LNOnCanvasElementNode'
|
||||
bl_label = 'On Canvas Element'
|
||||
bl_icon = 'CURVE_PATH'
|
||||
property0: EnumProperty(
|
||||
items = [('Down', 'Down', 'Down'),
|
||||
('Started', 'Started', 'Started'),
|
||||
('Released', 'Released', 'Released')],
|
||||
name='', default='Down')
|
||||
property1: EnumProperty(
|
||||
items = [('left', 'left', 'left'),
|
||||
('right', 'right', 'right'),
|
||||
('middle', 'middle', 'middle')],
|
||||
name='Mouse button', default='left')
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('NodeSocketString','Element')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.prop(self, 'property0')
|
||||
layout.prop(self, 'property1')
|
||||
|
||||
add_node(OnCanvasElementNode, category='Input')
|
Loading…
Reference in a new issue