添加关闭按钮

pull/1/head
Lyf986 9 months ago
parent 1d12b1485c
commit 9d8d7bf208

@ -15,200 +15,204 @@ var 已键入第二数 := false ## 若为是,则按下运算符按键将触发
# 初始化
func _ready():
for Buttons in .get_children():
for btn in Buttons.get_children():
if btn.name.is_valid_int():
btn.pressed.connect(Callable(self, "_number_buttons").bind(btn))
print(.text, , )
for Buttons in .get_children():
for btn in Buttons.get_children():
if btn.name.is_valid_int():
btn.pressed.connect(Callable(self, "_number_buttons").bind(btn))
print(.text, , )
@warning_ignore("unused_parameter")
func _unhandled_input(event) -> void:
if Input.is_action_pressed("ui_text_backspace") or Input.is_action_pressed("ui_cancel"):
退()
if Input.is_action_pressed("1"):
("1")
if Input.is_action_pressed("2"):
("2")
if Input.is_action_pressed("3"):
("3")
if Input.is_action_pressed("4"):
("4")
if Input.is_action_pressed("5"):
("5")
if Input.is_action_pressed("6"):
("6")
if Input.is_action_pressed("7"):
("7")
if Input.is_action_pressed("8"):
("8")
if Input.is_action_pressed("9"):
("9")
if Input.is_action_pressed("0"):
("0")
if Input.is_action_pressed(""):
()
if Input.is_action_pressed("归零") or Input.is_action_pressed("ui_menu") or Input.is_action_pressed("ui_home"):
_on_clear_pressed()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed("等于") or Input.is_action_pressed("ui_accept"):
()
if Input.is_action_pressed("取反"):
()
if Input.is_action_pressed("关于"):
_on__pressed()
if Input.is_action_pressed("ui_text_backspace") or Input.is_action_pressed("ui_cancel"):
退()
if Input.is_action_pressed("1"):
("1")
if Input.is_action_pressed("2"):
("2")
if Input.is_action_pressed("3"):
("3")
if Input.is_action_pressed("4"):
("4")
if Input.is_action_pressed("5"):
("5")
if Input.is_action_pressed("6"):
("6")
if Input.is_action_pressed("7"):
("7")
if Input.is_action_pressed("8"):
("8")
if Input.is_action_pressed("9"):
("9")
if Input.is_action_pressed("0"):
("0")
if Input.is_action_pressed(""):
()
if Input.is_action_pressed("归零") or Input.is_action_pressed("ui_menu") or Input.is_action_pressed("ui_home"):
_on_clear_pressed()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed(""):
()
if Input.is_action_pressed("等于") or Input.is_action_pressed("ui_accept"):
()
if Input.is_action_pressed("取反"):
()
if Input.is_action_pressed("关于"):
_on__pressed()
func ():
if not 使:
.text =
if :
= true
使 = true
else:
.text +=
if not 使:
.text =
if :
= true
使 = true
else:
.text +=
func _number_buttons(btn):
if not 使:
.text = btn.name
if :
= true
使 = true
else:
.text += btn.name
if not 使:
.text = btn.name
if :
= true
使 = true
else:
.text += btn.name
func _on_clear_pressed():
使 = false
= false
= false
.text = ""
.text = "0"
= 0
= 0
= ""
= false
使 = false
= false
= false
.text = ""
.text = "0"
= 0
= 0
= ""
= false
func ():
if str(.text.to_float()) != "0":
.text = str(- .text.to_float())
使 = true
if str(.text.to_float()) != "0":
.text = str(- .text.to_float())
使 = true
func 退():
if 使:
if .text.length() >= 2:
.text = .text.left(-1)
return
.text = "0"
使 = false
= false
if 使:
if .text.length() >= 2:
.text = .text.left(-1)
return
.text = "0"
使 = false
= false
func ():
if :
()
.text = .text
= .text.to_float()
= "/"
.text = str() +
使 = false
= false
= true
if :
()
.text = .text
= .text.to_float()
= "/"
.text = str() +
使 = false
= false
= true
func ():
if :
()
.text = .text
= .text.to_float()
= "*"
.text = str() +
使 = false
= false
= true
if :
()
.text = .text
= .text.to_float()
= "*"
.text = str() +
使 = false
= false
= true
func ():
if :
()
.text = .text
= .text.to_float()
= "-"
.text = str() +
使 = false
= false
= true
if :
()
.text = .text
= .text.to_float()
= "-"
.text = str() +
使 = false
= false
= true
func ():
if :
()
.text = .text
= .text.to_float()
= "+"
.text = str() +
使 = false
= false
= true
if :
()
.text = .text
= .text.to_float()
= "+"
.text = str() +
使 = false
= false
= true
func ():
if == false:
if 使 == true:
.text += "."
= true
else:
.text = "0."
使 = true
= true
if == false:
if 使 == true:
.text += "."
= true
else:
.text = "0."
使 = true
= true
func ():
使 = false
var : float
if .text.right(1) == "=" and != "":
= .text.to_float()
else:
= .text.to_float()
match :
"+":
= +
"-":
= -
"*":
= *
"/":
= /
"":
=
.text = (str() + + str() + "=")
.text = str(snappedf(, 0.0000001))
= false
= false
= false
使 = false
var : float
if .text.right(1) == "=" and != "":
= .text.to_float()
else:
= .text.to_float()
match :
"+":
= +
"-":
= -
"*":
= *
"/":
= /
"":
=
.text = (str() + + str() + "=")
.text = str(snappedf(, 0.0000001))
= false
= false
= false
func _on__pressed():
get_tree().change_scene_to_file("res://关于.tscn")
get_tree().change_scene_to_file("res://关于.tscn")
func _on__pressed():
get_tree().change_scene_to_file("res://设置.tscn")
get_tree().change_scene_to_file("res://设置.tscn")
func (str1:String) -> String:
if str1:
if str1[0] == "0":
if str1[1] == "0" or (str1[1] != "." and str1[1] != "=" and str1[1] != "+" and str1[1] != "-" and str1[1] != "*" and str1[1] != "/"):
return (str1.substr(1))
return str1
if str1:
if str1[0] == "0":
if str1[1] == "0" or (str1[1] != "." and str1[1] != "=" and str1[1] != "+" and str1[1] != "-" and str1[1] != "*" and str1[1] != "/"):
return (str1.substr(1))
return str1
func ():
get_tree().quit()

@ -7,88 +7,88 @@ const CONFIG_PATH := "user://settings.cfg"
func _ready():
()
()
()
()
func (index):
if index == 0:
return ()
elif index == 1:
TranslationServer.set_locale("zh")
elif index == 2:
TranslationServer.set_locale("zht")
elif index == 3:
TranslationServer.set_locale("en")
elif index == 4:
TranslationServer.set_locale("jp")
elif index == 5:
TranslationServer.set_locale("es")
else:
push_error("切换语言时,选项“%d”不存在!" % index)
TranslationServer.set_locale("en")
return index
if index == 0:
return ()
elif index == 1:
TranslationServer.set_locale("zh")
elif index == 2:
TranslationServer.set_locale("zht")
elif index == 3:
TranslationServer.set_locale("en")
elif index == 4:
TranslationServer.set_locale("jp")
elif index == 5:
TranslationServer.set_locale("es")
else:
push_error("切换语言时,选项“%d”不存在!" % index)
TranslationServer.set_locale("en")
return index
func (index):
var file := ConfigFile.new()
file.set_value("General", "Language", index)
var error := file.save(CONFIG_PATH)
if error != OK:
push_error("Failed to save config: %d" % error)
var file := ConfigFile.new()
file.set_value("General", "Language", index)
var error := file.save(CONFIG_PATH)
if error != OK:
push_error("Failed to save config: %d" % error)
func (index):
return ((index))
return ((index))
func ():
var file := ConfigFile.new()
if FileAccess.file_exists(CONFIG_PATH):
var error := file.load(CONFIG_PATH)
if error == OK:
return file.get_value("General", "Language", 0)
else:
push_warning("Failed to load config: %d", error)
return ()
var file := ConfigFile.new()
if FileAccess.file_exists(CONFIG_PATH):
var error := file.load(CONFIG_PATH)
if error == OK:
return file.get_value("General", "Language", 0)
else:
push_warning("Failed to load config: %d", error)
return ()
func ():
return (())
return (())
func ():
var locale := OS.get_locale()
if locale == "zh_CN":
(1)
elif locale == "zh_TW":
(2)
elif locale == "en":
(3)
elif locale == "jp":
(4)
elif locale == "es":
(5)
else:
(3)
return 0
var locale := OS.get_locale()
if locale == "zh_CN":
(1)
elif locale == "zh_TW":
(2)
elif locale == "en":
(3)
elif locale == "jp":
(4)
elif locale == "es":
(5)
else:
(3)
return 0
func ():
return (0)
return (0)
#func 根据语言切换主题(index):
#if index == 1 or index == 3 or index == 5:
#应该使用字体 = true
##propagate_call(“update”)
#else:
#应该使用字体 = false
#if index == 1 or index == 3 or index == 5:
#应该使用字体 = true
##propagate_call(“update”)
#else:
#应该使用字体 = false
func ():
# 获取系统类型
var sys_name := OS.get_name()
# 根据系统类型判断是否调整窗口DPI
if sys_name == "Windows" or sys_name == "macOS" or sys_name == "Linux" or sys_name == "BSD":
get_viewport().size = Vector2(DisplayServer.screen_get_dpi() * 3.5, DisplayServer.screen_get_dpi() * 6.2)
# 获取系统类型
var sys_name := OS.get_name()
# 根据系统类型判断是否调整窗口DPI
if sys_name == "Windows" or sys_name == "macOS" or sys_name == "Linux" or sys_name == "BSD":
get_viewport().size = Vector2(DisplayServer.screen_get_dpi() * 3.5, DisplayServer.screen_get_dpi() * 6.2)

@ -5,14 +5,14 @@ extends Control
#func _ready():
#本场景.set("theme", "res://Assets/样式/得意黑字体.tres")
#本场景.set("theme", "res://Assets/样式/得意黑字体.tres")
@warning_ignore("unused_parameter")
func _unhandled_input(event) -> void:
if Input.is_action_pressed("归零") or Input.is_action_pressed("ui_menu") or Input.is_action_pressed("ui_home") or Input.is_action_pressed("ui_text_backspace") or Input.is_action_pressed("关于") or Input.is_action_pressed("ui_cancel"):
_on__pressed()
if Input.is_action_pressed("归零") or Input.is_action_pressed("ui_menu") or Input.is_action_pressed("ui_home") or Input.is_action_pressed("ui_text_backspace") or Input.is_action_pressed("关于") or Input.is_action_pressed("ui_cancel"):
_on__pressed()
func _on__pressed():
get_tree ().change_scene_to_file("res://主界面.tscn")
get_tree ().change_scene_to_file("res://主界面.tscn")

@ -7,18 +7,18 @@ extends Control
@warning_ignore("unused_parameter")
func _unhandled_input(event) -> void:
if Input.is_action_pressed("归零") or Input.is_action_pressed("ui_menu") or Input.is_action_pressed("ui_home") or Input.is_action_pressed("ui_text_backspace") or Input.is_action_pressed("关于") or Input.is_action_pressed("ui_cancel"):
_on__pressed()
if Input.is_action_pressed("归零") or Input.is_action_pressed("ui_menu") or Input.is_action_pressed("ui_home") or Input.is_action_pressed("ui_text_backspace") or Input.is_action_pressed("关于") or Input.is_action_pressed("ui_cancel"):
_on__pressed()
func _ready():
#本场景.set("theme", "res://Assets/样式/得意黑字体.tres")
.selected = Global.()
#本场景.set("theme", "res://Assets/样式/得意黑字体.tres")
.selected = Global.()
func _on__pressed():
get_tree ().change_scene_to_file("res://主界面.tscn")
get_tree ().change_scene_to_file("res://主界面.tscn")
func _on__item_selected(index):
Global.(index)
Global.(index)

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://g4du8c33vab5"]
[gd_scene load_steps=10 format=3 uid="uid://g4du8c33vab5"]
[ext_resource type="Theme" uid="uid://dgo8n2bba7imi" path="res://Assets/样式/得意黑字体.tres" id="1_3h7g3"]
[ext_resource type="Script" path="res://Scripts/主界面.gd" id="1_y82yl"]
@ -11,6 +11,8 @@
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_yp77b"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_0gc2k"]
[node name="主界面" type="Control"]
layout_mode = 3
anchors_preset = 15
@ -327,6 +329,23 @@ icon = ExtResource("3_o66lt")
icon_alignment = 1
expand_icon = true
[node name="MarginContainer2" type="MarginContainer" parent="面板/背景色"]
layout_mode = 1
offset_right = 40.0
offset_bottom = 40.0
theme_override_constants/margin_left = 32
theme_override_constants/margin_top = 32
[node name="关闭" type="Button" parent="面板/背景色/MarginContainer2"]
custom_minimum_size = Vector2(64, 64)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 32
theme_override_styles/normal = ExtResource("2_asaep")
theme_override_styles/focus = SubResource("StyleBoxEmpty_0gc2k")
text = "X"
[connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/上键盘/Clear" to="." method="_on_clear_pressed"]
[connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/上键盘/Or" to="." method="按下正负"]
[connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/上键盘/Back" to="." method="按下退格"]
@ -338,3 +357,4 @@ expand_icon = true
[connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/下键盘/=" to="." method="等于"]
[connection signal="pressed" from="面板/背景色/MarginContainer/顶按钮容器/关于" to="." method="_on_关于_pressed"]
[connection signal="pressed" from="面板/背景色/MarginContainer/顶按钮容器/设置" to="." method="_on_设置_pressed"]
[connection signal="pressed" from="面板/背景色/MarginContainer2/关闭" to="." method="当关闭按钮按下"]

Loading…
Cancel
Save