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

202 lines
5.1 KiB

1 year ago
extends Control
@onready var = $"面板/背景色/屏键容器/结果显示容器/MarginContainer/VBoxContainer/上个工作区"
@onready var = $"面板/背景色/屏键容器/结果显示容器/MarginContainer/VBoxContainer/工作区"
@onready var = $"面板/背景色/屏键容器/MarginContainer2/上下键盘分隔"
var 使 := false ## 工作区内是否有数字
1 year ago
var : float
var : float
var := ""
var := false ## 工作区内是否为小数(防止两个小数点出现)
var := false
var := false ## 若为是,则按下运算符按键将触发一次运算
1 year ago
# 初始化
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")
1 year ago
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
1 year ago
使 = true
else:
.text +=
func _number_buttons(btn):
if not 使:
.text = btn.name
if :
= true
1 year ago
使 = true
else:
.text += btn.name
func _on_clear_pressed():
使 = false
= false
= false
1 year ago
.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
1 year ago
func ():
if :
12 months ago
()
.text = .text
1 year ago
= .text.to_float()
= "/"
.text = str() +
使 = false
1 year ago
= false
= true
1 year ago
func ():
if :
12 months ago
()
.text = .text
1 year ago
= .text.to_float()
= "*"
.text = str() +
使 = false
1 year ago
= false
= true
1 year ago
func ():
if :
12 months ago
()
.text = .text
1 year ago
= .text.to_float()
= "-"
.text = str() +
使 = false
1 year ago
= false
= true
1 year ago
func ():
if :
12 months ago
()
.text = .text
1 year ago
= .text.to_float()
= "+"
.text = str() +
使 = false
1 year ago
= false
= true
1 year ago
func ():
if == false:
if 使 == true:
.text += "."
= true
else:
.text = "0."
使 = true
= true
func ():
使 = false
var : float
12 months ago
if .text.right(1) == "=":
= .text.to_float()
else:
= .text.to_float()
1 year ago
match :
"+":
= +
"-":
= -
"*":
= *
"/":
= /
.text = str() + + str() + "="
1 year ago
.text = str(snappedf(, 0.0000000001))
= false
12 months ago
= false
1 year ago
func _on__pressed():
get_tree().change_scene_to_file("res://关于.tscn")