Skip to content

Commit 2a0a1f0

Browse files
committed
added go until reflection block
1 parent e63ff99 commit 2a0a1f0

File tree

7 files changed

+228
-29
lines changed

7 files changed

+228
-29
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://u7dv10o8gfva"]
2+
3+
[ext_resource type="Theme" uid="uid://m1x1dnq04rcs" path="res://blocks/block_theme.tres" id="1_stukh"]
4+
[ext_resource type="Theme" uid="uid://bl1ypr528580u" path="res://blocks/block_theme_text.tres" id="2_1s1qk"]
5+
6+
[sub_resource type="RectangleShape2D" id="RectangleShape2D_54lax"]
7+
8+
[node name="Block" type="GoUntilReflectionBlock"]
9+
10+
[node name="Button" type="Button" parent="."]
11+
self_modulate = Color(0.1173, 0.69, 0.4991, 1)
12+
custom_minimum_size = Vector2(0, 50)
13+
offset_right = 521.0
14+
offset_bottom = 50.0
15+
theme = ExtResource("1_stukh")
16+
alignment = 0
17+
icon_alignment = 1
18+
expand_icon = true
19+
20+
[node name="HBoxContainer" type="HBoxContainer" parent="Button"]
21+
layout_mode = 1
22+
anchors_preset = -1
23+
anchor_top = 0.5
24+
anchor_right = 0.942
25+
anchor_bottom = 0.5
26+
offset_top = -18.0
27+
offset_right = -0.142029
28+
offset_bottom = 18.0
29+
grow_horizontal = 2
30+
grow_vertical = 2
31+
theme_override_constants/separation = 16
32+
33+
[node name="Container" type="Container" parent="Button/HBoxContainer"]
34+
layout_mode = 2
35+
36+
[node name="Name" type="Label" parent="Button/HBoxContainer"]
37+
custom_minimum_size = Vector2(225.785, 0)
38+
layout_mode = 2
39+
theme = ExtResource("2_1s1qk")
40+
text = "GOUNTILREFLECTION"
41+
vertical_alignment = 1
42+
metadata/_edit_use_anchors_ = true
43+
44+
[node name="Reflection" type="LineEdit" parent="Button/HBoxContainer"]
45+
custom_minimum_size = Vector2(100, 0)
46+
layout_mode = 2
47+
tooltip_text = "REFLECTION"
48+
theme_override_font_sizes/font_size = 20
49+
text = "50"
50+
alignment = 1
51+
metadata/_edit_use_anchors_ = true
52+
53+
[node name="Darker" type="CheckBox" parent="Button/HBoxContainer"]
54+
layout_mode = 2
55+
tooltip_text = "DARKER"
56+
flat = true
57+
58+
[node name="Speed" type="LineEdit" parent="Button/HBoxContainer"]
59+
custom_minimum_size = Vector2(100, 0)
60+
layout_mode = 2
61+
tooltip_text = "SPEED"
62+
theme_override_font_sizes/font_size = 20
63+
text = "1024"
64+
alignment = 1
65+
metadata/_edit_use_anchors_ = true
66+
67+
[node name="Area2D" type="Area2D" parent="."]
68+
visible = false
69+
collision_layer = 0
70+
priority = 1
71+
72+
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
73+
position = Vector2(165, -51.215)
74+
scale = Vector2(13, 4)
75+
shape = SubResource("RectangleShape2D_54lax")
76+
77+
[node name="StaticBody2D" type="StaticBody2D" parent="."]
78+
visible = false
79+
collision_mask = 0
80+
81+
[node name="CollisionShape2D2" type="CollisionShape2D" parent="StaticBody2D"]
82+
position = Vector2(165, 25)
83+
scale = Vector2(17, 3)
84+
shape = SubResource("RectangleShape2D_54lax")

costume_programing_language/demo/blocks/reset_position.tscn

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ metadata/_edit_use_anchors_ = true
4141
[node name="X" type="LineEdit" parent="Button/HBoxContainer"]
4242
custom_minimum_size = Vector2(100, 0)
4343
layout_mode = 2
44-
tooltip_text = "x, in cm, NAN mens keep original value"
44+
tooltip_text = "x, in cm, NAN means keep original value"
4545
theme_override_font_sizes/font_size = 20
4646
text = "NAN"
4747
alignment = 1
@@ -50,7 +50,7 @@ metadata/_edit_use_anchors_ = true
5050
[node name="Y" type="LineEdit" parent="Button/HBoxContainer"]
5151
custom_minimum_size = Vector2(100, 0)
5252
layout_mode = 2
53-
tooltip_text = "y, in cm, NAN mens keep original value"
53+
tooltip_text = "y, in cm, NAN means keep original value"
5454
theme_override_font_sizes/font_size = 20
5555
text = "NAN"
5656
alignment = 1
@@ -59,7 +59,7 @@ metadata/_edit_use_anchors_ = true
5959
[node name="Angle" type="LineEdit" parent="Button/HBoxContainer"]
6060
custom_minimum_size = Vector2(100, 0)
6161
layout_mode = 2
62-
tooltip_text = "angle, in Rad, NAN mens keep original value"
62+
tooltip_text = "angle, in Rad, NAN means keep original value"
6363
theme_override_font_sizes/font_size = 20
6464
text = "NAN"
6565
alignment = 1

costume_programing_language/demo/translations.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ MOTORSINVERSED:,inversed motor:,opačný chod:
5151
LEFTMOTOR:,left motor:,lavý motor:
5252
RIGHTMOTOR:,right motor:,pravý motor:
5353
ANGLE:,angle:,uhol:
54+
SENDFILETOROBOT,send file to robot,poslať súbor na robota
55+
SEND,send,poslať
56+
PICKFILE,pick file,vybrať súbor
57+
IPADDRESS,IP address:,IP adressa:
58+
RESETPOSITION,reset position,resetuj pozíciu
59+
GOUNTILREFLECTION,go until reflection,choď do odrazu
60+
REFLECTION,"Reflection, 0←>100","Odraz, 0←>100"

costume_programing_language/demo/ui.tscn

Lines changed: 67 additions & 26 deletions
Large diffs are not rendered by default.

costume_programing_language/src/register_types.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
2525
GDREGISTER_RUNTIME_CLASS(RotateToAngleBlock);
2626
GDREGISTER_RUNTIME_CLASS(RotateToPositionBlock);
2727
GDREGISTER_RUNTIME_CLASS(ResetPositionBlock);
28+
GDREGISTER_RUNTIME_CLASS(GoUntilReflectionBlock);
2829
GDREGISTER_RUNTIME_CLASS(ArmStopBlock);
2930
GDREGISTER_RUNTIME_CLASS(ArmRunBlock);
3031
GDREGISTER_RUNTIME_CLASS(ArmRunToAbsBlock);

costume_programing_language/src/sub_blocks.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ void MainBlock::load(String path) {
7878
case 'P': // RotateToPosition block
7979
block = ResourceLoader::get_singleton()->load("res://blocks/rotate_to_pos_block.tscn");
8080
break;
81+
case 'F': // GoUntilReflection block
82+
block = ResourceLoader::get_singleton()->load("res://blocks/go_until_reflection.tscn");
83+
break;
8184
case 'L':
8285
case 'R': // Arm blocks
8386
switch(words[1][0]){
@@ -444,6 +447,50 @@ void ResetPositionBlock::set_parameters(PackedStringArray parameters) {
444447
angle->set_text(parameters[2]);
445448
}
446449

450+
// GoUntilReflectionBlock
451+
void GoUntilReflectionBlock::_bind_methods(){
452+
453+
}
454+
455+
GoUntilReflectionBlock::GoUntilReflectionBlock(): Block() {
456+
457+
}
458+
459+
GoUntilReflectionBlock::~GoUntilReflectionBlock() {
460+
Block::~Block();
461+
}
462+
463+
void GoUntilReflectionBlock::_ready() {
464+
Block::_ready();
465+
466+
// getting block parameters
467+
reflection = get_node<LineEdit>("Button/HBoxContainer/Reflection");
468+
darker = get_node<CheckBox>("Button/HBoxContainer/Darker");
469+
speed = get_node<LineEdit>("Button/HBoxContainer/Speed");
470+
}
471+
472+
String GoUntilReflectionBlock::write() {
473+
if(reflection == nullptr || darker == nullptr || speed == nullptr) {
474+
UtilityFunctions::push_error("GoUntilReflectionBlock parameters not set correctly!");
475+
return "error\n";
476+
}
477+
String command = "F " + reflection->get_text() + " " + (darker->is_pressed()? "1" : "0") + " " + speed->get_text() + "\n";
478+
if (next != nullptr) command += next->write();
479+
return command;
480+
}
481+
482+
void GoUntilReflectionBlock::set_parameters(PackedStringArray parameters) {
483+
if(parameters.size() < 3) return;
484+
UtilityFunctions::print("Setting values for GoUntilReflectionBlock");
485+
if(reflection == nullptr || darker == nullptr || speed == nullptr){
486+
UtilityFunctions::push_error("GoUntilReflectionBlock parameters not set correctly!");
487+
return;
488+
}
489+
reflection->set_text(parameters[0]);
490+
darker->set_pressed(bool(parameters[1] == "1"));
491+
speed->set_text(parameters[2]);
492+
}
493+
447494
// ArmStopBlock
448495
void ArmStopBlock::_bind_methods(){
449496

costume_programing_language/src/sub_blocks.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ class ResetPositionBlock : public Block {
160160
void set_parameters(PackedStringArray parameters) override;
161161
};
162162

163+
class GoUntilReflectionBlock : public Block {
164+
GDCLASS(GoUntilReflectionBlock, Block)
165+
private:
166+
protected:
167+
static void _bind_methods();
168+
LineEdit *reflection = nullptr;
169+
CheckBox *darker = nullptr;
170+
LineEdit *speed = nullptr;
171+
172+
public:
173+
GoUntilReflectionBlock();
174+
~GoUntilReflectionBlock();
175+
176+
void _ready() override;
177+
178+
String write() override;
179+
void set_parameters(PackedStringArray parameters) override;
180+
};
181+
163182
class ArmStopBlock : public Block {
164183
GDCLASS(ArmStopBlock, Block)
165184
private:

0 commit comments

Comments
 (0)