添加关闭按钮

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

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

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

@ -5,14 +5,14 @@ extends Control
#func _ready(): #func _ready():
#本场景.set("theme", "res://Assets/样式/得意黑字体.tres") #本场景.set("theme", "res://Assets/样式/得意黑字体.tres")
@warning_ignore("unused_parameter") @warning_ignore("unused_parameter")
func _unhandled_input(event) -> void: 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"): 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() _on__pressed()
func _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") @warning_ignore("unused_parameter")
func _unhandled_input(event) -> void: 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"): 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() _on__pressed()
func _ready(): func _ready():
#本场景.set("theme", "res://Assets/样式/得意黑字体.tres") #本场景.set("theme", "res://Assets/样式/得意黑字体.tres")
.selected = Global.() .selected = Global.()
func _on__pressed(): func _on__pressed():
get_tree ().change_scene_to_file("res://主界面.tscn") get_tree ().change_scene_to_file("res://主界面.tscn")
func _on__item_selected(index): 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="Theme" uid="uid://dgo8n2bba7imi" path="res://Assets/样式/得意黑字体.tres" id="1_3h7g3"]
[ext_resource type="Script" path="res://Scripts/主界面.gd" id="1_y82yl"] [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_yp77b"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_0gc2k"]
[node name="主界面" type="Control"] [node name="主界面" type="Control"]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
@ -327,6 +329,23 @@ icon = ExtResource("3_o66lt")
icon_alignment = 1 icon_alignment = 1
expand_icon = true 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/上下键盘分隔/上键盘/Clear" to="." method="_on_clear_pressed"]
[connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/上键盘/Or" to="." method="按下正负"] [connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/上键盘/Or" to="." method="按下正负"]
[connection signal="pressed" from="面板/背景色/屏键容器/MarginContainer2/上下键盘分隔/上键盘/Back" 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="面板/背景色/屏键容器/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="面板/背景色/MarginContainer/顶按钮容器/设置" to="." method="_on_设置_pressed"] [connection signal="pressed" from="面板/背景色/MarginContainer/顶按钮容器/设置" to="." method="_on_设置_pressed"]
[connection signal="pressed" from="面板/背景色/MarginContainer2/关闭" to="." method="当关闭按钮按下"]

Loading…
Cancel
Save