Port gdscript to haxe/kiss
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://scripts/EntryContainer.gd" type="Script" id=1]
|
||||
[ext_resource path="res://build/src/EntryPanel.cs" type="Script" id=1]
|
||||
|
||||
[node name="EntryPanel" type="PanelContainer"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
mouse_filter = 1
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"haxe_script": "res://scripts/EntryPanel.hx"
|
||||
}
|
||||
|
||||
[node name="EntryLabel" type="Label" parent="."]
|
||||
margin_left = 7.0
|
||||
|
@@ -15,3 +15,5 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 8.0
|
||||
margin_bottom = 36.0
|
||||
|
||||
[connection signal="tab_changed" from="PlaygroundTabContainer" to="." method="_on_PlaygroundTabContainer_tab_changed"]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://scripts/Playground.gd" type="Script" id=1]
|
||||
[ext_resource path="res://build/src/PlaygroundEntries.cs" type="Script" id=1]
|
||||
|
||||
[node name="Playground" type="ScrollContainer"]
|
||||
anchor_right = 1.0
|
||||
@@ -16,3 +16,6 @@ margin_right = 1280.0
|
||||
margin_bottom = 720.0
|
||||
rect_min_size = Vector2( 1280, 720 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"haxe_script": "res://scripts/PlaygroundEntries.hx"
|
||||
}
|
||||
|
@@ -1,28 +0,0 @@
|
||||
extends PanelContainer
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
var z = 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
|
||||
func _on_EntryPanel_mouse_entered():
|
||||
var current_focus_z = get_parent().current_focus_z
|
||||
if is_nan(current_focus_z) or current_focus_z <= self.z:
|
||||
get_parent().current_focus = self
|
||||
get_parent().current_focus_z = self.z
|
||||
|
||||
func _on_EntryPanel_mouse_exited():
|
||||
if get_parent().current_focus == self:
|
||||
get_parent().current_focus = null
|
||||
get_parent().current_focus_z = NAN
|
26
projects/nat-godot-playground/scripts/EntryPanel.hx
Normal file
26
projects/nat-godot-playground/scripts/EntryPanel.hx
Normal file
@@ -0,0 +1,26 @@
|
||||
package;
|
||||
|
||||
class EntryPanel extends PanelContainer {
|
||||
public var z:Single = 0;
|
||||
public var e:Entry = null;
|
||||
var parent:PlaygroundEntries = null;
|
||||
|
||||
public override function _Ready() {
|
||||
parent = cast(getParent());
|
||||
}
|
||||
|
||||
public function _on_EntryPanel_mouse_entered() {
|
||||
var currentFocusZ = parent.currentFocusZ;
|
||||
if (Mathf.isNaN(currentFocusZ) || currentFocusZ <= this.z) {
|
||||
parent.currentFocus = this;
|
||||
parent.currentFocusZ = this.z;
|
||||
}
|
||||
}
|
||||
|
||||
public function _on_EntryPanel_mouse_exited() {
|
||||
if (parent.currentFocus == this) {
|
||||
parent.currentFocus = null;
|
||||
parent.currentFocusZ = Mathf.NA_N;
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,9 +9,12 @@
|
||||
// Create Entry node:
|
||||
->[archive e pos &opt ui]
|
||||
(let [:PackedScene ePanelScene (GD.load "res://EntryPanel.tscn")
|
||||
:PanelContainer ePanel (cast (ePanelScene.instance))
|
||||
:EntryPanel ePanel (cast (ePanelScene.instance))
|
||||
:Label eLabel (getNode ePanel "EntryLabel")]
|
||||
(set eLabel.text (readComponentOr e Name ""))
|
||||
(set ePanel.rectPosition (new Vector2 pos.x pos.y))
|
||||
(set ePanel.z pos.z)
|
||||
(set ePanel.e e)
|
||||
(pgEntries.addChild ePanel)
|
||||
ePanel)
|
||||
// Draw line:
|
||||
|
@@ -1,27 +0,0 @@
|
||||
extends Control
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
var current_focus = null
|
||||
var current_focus_z = NAN
|
||||
|
||||
func get_drag_data(position):
|
||||
return current_focus
|
||||
|
||||
func can_drop_data(position, data):
|
||||
return data != null
|
||||
|
||||
func drop_data(position, data):
|
||||
data.rect_position = position
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
29
projects/nat-godot-playground/scripts/PlaygroundEntries.hx
Normal file
29
projects/nat-godot-playground/scripts/PlaygroundEntries.hx
Normal file
@@ -0,0 +1,29 @@
|
||||
package;
|
||||
|
||||
class PlaygroundEntries extends Control {
|
||||
|
||||
public var currentFocus:EntryPanel = null;
|
||||
public var currentFocusZ = Mathf.NA_N;
|
||||
var ui:GodotUI = null;
|
||||
|
||||
public override function _Ready() {
|
||||
var rootNode:RootNode = cast(getParent().getParent().getParent());
|
||||
ui = rootNode.ui;
|
||||
}
|
||||
|
||||
public override function getDragData(position:Vector2) {
|
||||
return currentFocus;
|
||||
}
|
||||
|
||||
public override function canDropData(position:Vector2, data:Dynamic) {
|
||||
return data != null;
|
||||
}
|
||||
|
||||
public override function dropData(position:Vector2, data:Dynamic):Void {
|
||||
var data:EntryPanel = cast(data);
|
||||
data.rectPosition = position;
|
||||
kiss.Prelude.print(ui);
|
||||
kiss.Prelude.print(data.e);
|
||||
ui.playgroundSystem().savePosition(data.e, position.x, position.y, data.z);
|
||||
}
|
||||
}
|
@@ -3,24 +3,31 @@
|
||||
(prop &mut :TabContainer pgTabs)
|
||||
(prop &mut :PackedScene pgScene)
|
||||
|
||||
|
||||
(defNew []
|
||||
[
|
||||
// TODO find a better way to pass the archiveDir to a Godot game
|
||||
:Archive archive
|
||||
(let [archiveDir (or (Sys.getEnv "NAT_DIR") (throw "NAT_DIR environment variable must be set"))]
|
||||
(new Archive archiveDir))
|
||||
:GodotUI ui
|
||||
(new GodotUI archive this)
|
||||
]
|
||||
&first (super))
|
||||
|
||||
(method &override &public :Void _Ready []
|
||||
(printThroughGD)
|
||||
|
||||
(set pgTabs (getNode this "PlaygroundTabContainer"))
|
||||
(set pgScene (GD.load "res://Playground.tscn"))
|
||||
|
||||
// TODO find a better way to pass the archiveDir to a Godot game
|
||||
(let [archiveDir
|
||||
(or (Sys.getEnv "NAT_DIR") (throw "NAT_DIR environment variable must be set"))
|
||||
archive
|
||||
(new Archive archiveDir)]
|
||||
|
||||
(doFor =>key playground archive.playgrounds
|
||||
(doFor =>key playground archive.playgrounds
|
||||
(unless (= key "default")
|
||||
(let [pg (pgScene.instance)]
|
||||
(set pg.name key)
|
||||
(pgTabs.addChild pg))))
|
||||
|
||||
(let [ui (new GodotUI archive this)
|
||||
controller (new ArchiveController archive ui)]
|
||||
(set ui.controller controller))))
|
||||
(set ui.controller (new ArchiveController archive ui)))
|
||||
|
||||
(method :Void _on_PlaygroundTabContainer_tab_changed [:Int tab]
|
||||
(when ui.controller (.switchPlaygroundKey (ui.playgroundSystem) .name (pgTabs.getChild tab))))
|
Reference in New Issue
Block a user