You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
568_Calc/Scripts/主界面.gd

198 lines
4.9 KiB

extends Control
@onready var = $"面板/背景色/屏键容器/结果显示容器/MarginContainer/VBoxContainer/上个工作区"
@onready var = $"面板/背景色/屏键容器/结果显示容器/MarginContainer/VBoxContainer/工作区"
@onready var = $"面板/背景色/屏键容器/MarginContainer2/上下键盘分隔"
var 使 := false ## 工作区内是否有数字
var : float
var : float
var := ""
var := false ## 工作区内是否为小数(防止两个小数点出现)
var := false
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))
@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("等于"):
()
if Input.is_action_pressed("取反"):
()
if Input.is_action_pressed("关于"):
_on__pressed()
func ():
if not 使:
.text =
if :
= true
使 = true
else:
.text +=
func _number_buttons(btn):
if not 使:
.text = btn.name
if :
= true
使 = true
else:
.text += btn.name
func _on_clear_pressed():
使 = false
= false
= false
.text = ""
.text = "0"
= false
func ():
var : float
= .text.to_float()
= -
if not 使:
.text = "-" + str()
else:
.text = str()
.text = str()
使 = true
func 退():
if 使:
if .text.length() >= 2:
.text = .text.left(-1)
else:
.text = "0"
使 = false
= false
func ():
if :
()
= .text.to_float()
= "/"
.text = str() +
使 = false
= false
= true
func ():
if :
()
= .text.to_float()
= "*"
.text = str() +
使 = false
= false
= true
func ():
if :
()
= .text.to_float()
= "-"
.text = str() +
使 = false
= false
= true
func ():
if :
()
= .text.to_float()
= "+"
.text = str() +
使 = false
= false
= true
func ():
if == false:
if 使 == true:
.text += "."
= true
else:
.text = "0."
使 = true
= true
func ():
使 = false
var : float
= .text.to_float()
match :
"+":
= +
"-":
= -
"*":
= *
"/":
= /
.text = str() + + str() + "="
.text = str(snappedf(, 0.0000000001))
func ():
()
.text = .text
func _on__pressed():
get_tree().change_scene_to_file("res://关于.tscn")