优化功能和人机交互

pull/1/head
PJ568 12 months ago
parent ab7330072e
commit 70166c938d

@ -10,6 +10,8 @@ var 第一个数字 : float
var : float var : float
var := "" var := ""
var := false ## 工作区内是否为小数(防止两个小数点出现) var := false ## 工作区内是否为小数(防止两个小数点出现)
var := false
var := false ## 若为是,则按下运算符按键将触发一次运算
# 初始化 # 初始化
func _ready(): func _ready():
@ -19,6 +21,7 @@ func _ready():
btn.pressed.connect(Callable(self, "_number_buttons").bind(btn)) btn.pressed.connect(Callable(self, "_number_buttons").bind(btn))
@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"):
退() 退()
@ -65,6 +68,8 @@ func _unhandled_input(event) -> void:
func (): func ():
if not 使: if not 使:
.text = .text =
if :
= true
使 = true 使 = true
else: else:
.text += .text +=
@ -73,14 +78,17 @@ func 按下数字按钮(键):
func _number_buttons(btn): func _number_buttons(btn):
if not 使: if not 使:
.text = btn.name .text = btn.name
if :
= true
使 = true 使 = true
else: else:
.text += btn.name .text += btn.name
func _on_clear_pressed(): func _on_clear_pressed():
使 = false 使 = false
= false
= false
.text = "" .text = ""
.text = "0" .text = "0"
= false = false
@ -105,38 +113,51 @@ func 按下退格():
else: else:
.text = "0" .text = "0"
使 = false 使 = false
= false
func (): func ():
使 = false if :
()
= .text.to_float() = .text.to_float()
= "/" = "/"
.text = str() + .text = str() +
使 = false
= false = false
= true
func (): func ():
使 = false if :
()
= .text.to_float() = .text.to_float()
= "*" = "*"
.text = str() + .text = str() +
使 = false
= false = false
= true
func (): func ():
使 = false if :
()
= .text.to_float() = .text.to_float()
= "-" = "-"
.text = str() + .text = str() +
使 = false
= false = false
= true
func (): func ():
使 = false if :
()
= .text.to_float() = .text.to_float()
= "+" = "+"
.text = str() + .text = str() +
使 = false
= false = false
= true
func (): func ():
@ -163,9 +184,14 @@ func 等于():
= * = *
"/": "/":
= / = /
.text = str() + + str() .text = str() + + str() + "="
.text = str(snappedf(, 0.0000000001)) .text = str(snappedf(, 0.0000000001))
func ():
()
.text = .text
func _on__pressed(): func _on__pressed():
get_tree().change_scene_to_file("res://关于.tscn") get_tree().change_scene_to_file("res://关于.tscn")

Loading…
Cancel
Save