godot引擎c++源码深度解析系列二

记录每次研究源码的突破,今天已经将打字练习的功能完成了一个基本模型,先来看下运行效果。

godot源码增加打字练习的demo

这个里面需要研究以下c++的控件页面的开发和熟悉,毕竟好久没有使用c++了,先来看以下代码吧。

cpp 复制代码
	//第一排 显示文本  计时器 已完成个数  重新开始按钮
	HBoxContainer *version_info_first = memnew(HBoxContainer);
	// Add a dummy control node for spacing.
	Control *v_spacer_first = memnew(Control);
	version_info_first->add_child(v_spacer_first);
	hbc->add_child(version_info_first);
	VBoxContainer *hbc_first = memnew(VBoxContainer);
	hbc_first->set_h_size_flags(Control::SIZE_EXPAND_FILL);
	hbc_first->set_alignment(BoxContainer::ALIGNMENT_CENTER);
	hbc_first->add_theme_constant_override("separation", 30 * EDSCALE);
	vbc->add_child(hbc_first);
	typing_label_time = memnew(Label);
	typing_label_time->set_text("timer:"); 
	version_info_first->add_child(typing_label_time);
	typing_label_count = memnew(Label);
	typing_label_count->set_text("complete"); 
	version_info_first->add_child(typing_label_count);
	typing_restart_btn = memnew(Button);
	typing_restart_btn->set_text("restart");
	typing_restart_btn->connect("pressed", callable_mp(this, &EditorApathysTyping::_version_button_pressed));
	version_info_first->add_child(typing_restart_btn); 

就这样就实现了文本框,输入框和按钮的实现,以及对应的事件,后面还有很多的功能,都需要慢慢的研究。

cpp 复制代码
void EditorApathysTyping::_on_search_term_changed(const String &p_term) {
	ERR_PRINT(vformat("Blah: %s", p_term));
	String arr[17] = { "def", "div", "format", "enter", "tr", "table", "image", "td", "html", "float", "str", "var", "int", "else", "if", "for", "start" };
	int start = 0;
	int end = 16;

	int index = (rand() % (end - start)) + start;

	ERR_PRINT(vformat("Blah: %d", index));

	String should = typing_text_input_should->get_text();
	if (should == p_term) {
		typing_text_input_should->set_text(arr[index]);
		typing_text_input->set_text("");
	}
	if (should.count(should) < p_term.count(p_term)) {

	}

下一步开始研究加工车间的面板,虽有难度,但也有挑战。加油吧

我们的目标你也来看一下吧

元宇宙汽车人变形

相关推荐
MFXWW23 小时前
从 Python 到 3D 开发:Ursina 引擎零基础入门学习路径与核心开发思路
python·游戏引擎·游戏程序·ursina
mxwin14 小时前
Unity URP 半透明阴影的局限性
unity·游戏引擎
空中海14 小时前
第四篇:Unity高级阶段(架构级开发能力)
unity·架构·游戏引擎
DaLiangChen16 小时前
Unity URP 绘制参考网格 Shader 教程(抗锯齿 + 渐变淡出)
unity·游戏引擎
空中海17 小时前
第三篇:Unity进阶阶段(商业项目能力)
unity·游戏引擎
Yuk丶21 小时前
Procedural Dialogue Engine - UE4程序化对话系统的技术实现
c++·游戏引擎·ue4·游戏程序·虚幻
RReality1 天前
【Unity Shader URP】屏幕空间扭曲后处理(Screen Space Distortion)实战教程
ui·unity·游戏引擎·图形渲染·材质
空中海1 天前
第六篇:Unity专项方向
unity·游戏引擎
mxwin1 天前
Unity Shader 屏幕空间反射 (SSR) 原理解析
jvm·unity·游戏引擎·shader
心前阳光1 天前
Unity之利用特性给ScriptableObject分组
unity·游戏引擎