-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
97 lines (91 loc) · 3.93 KB
/
Copy pathMain.cs
File metadata and controls
97 lines (91 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Godot;
using System;
public partial class Main : Control
{
[Export] internal string target_name = "Undefined";
internal DateTime target_date = DateTime.MaxValue;
public override void _Ready()
{
if (OS.GetLocale() == "zh_TW" || OS.GetLocale() == "zh_HK" || OS.GetLocale() == "zh_MO")
{
TranslationServer.SetLocale("zh_TW");
}
else if (OS.GetLocaleLanguage() == "zh")
{
TranslationServer.SetLocale("zh_CN");
}
else
{
TranslationServer.SetLocale("en");
}
if (FileAccess.FileExists("user://Settings.ini"))
{
var cfg = new ConfigFile();
cfg.Load("user://Settings.ini");
TranslationServer.SetLocale(cfg.GetValue("Settings","Language","en").AsString());
target_name = cfg.GetValue("Settings","TargetName","Undefined").AsString();
target_date = new DateTime(cfg.GetValue("Settings","TargetDate",DateTime.MaxValue.Ticks).AsInt64());
GetWindow().AlwaysOnTop = cfg.GetValue("Settings","AlwaysOnTop",GetWindow().AlwaysOnTop).AsBool();
}
if (!DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless))
{
GetNode<Button>("SettingsButton").Visible = true;
GetNode<Button>("CreditsButton").Visible = true;
GetNode<CheckButton>("CheckButton").Visible = true;
}
GetNode<CheckButton>("CheckButton").ButtonPressed = GetWindow().AlwaysOnTop;
}
public override void _Process(double delta)
{
var day_left = (target_date - DateTime.Today).TotalDays;
var container = GetNode<PanelContainer>("PanelContainer/CenterContainer/PanelContainer");
if (DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless))
{
DisplayServer.WindowSetMousePassthrough([container.Position,container.Position+(new Vector2(container.Size.X,0)),container.Position+container.Size,container.Position+(new Vector2(0,container.Size.Y))]);
}
GetNode<Label>("PanelContainer/CenterContainer/PanelContainer/VBoxContainer/Label").Text = TranslationServer.Translate("locUntilDays").ToString().Replace("{TARGET}",target_name).Replace("{DAY}", day_left.ToString()).Replace("{dayS}", (day_left > 1 ? "s" : ""));
if (Input.IsActionJustPressed("edit_mode"))
{
DisplayServer.WindowSetFlag(DisplayServer.WindowFlags.Borderless,!DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless));
GetNode<Button>("SettingsButton").Visible = !DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless);
GetNode<Button>("CreditsButton").Visible = !DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless);
GetNode<CheckButton>("CheckButton").Visible = !DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless);
DisplayServer.WindowSetMousePassthrough([]);
}
if ((!DisplayServer.WindowGetFlag(DisplayServer.WindowFlags.Borderless)) || new Rect2(container.Position,container.Size).HasPoint(GetGlobalMousePosition()))
{
GetNode<Label>("PanelContainer/CenterContainer/PanelContainer/VBoxContainer/Label2").Modulate = new Color(1,1,1,1);
GetNode<PanelContainer>("PanelContainer/CenterContainer/PanelContainer").SelfModulate = new Color(1,1,1,1);
}
else
{
GetNode<Label>("PanelContainer/CenterContainer/PanelContainer/VBoxContainer/Label2").Modulate = new Color(1,1,1,0);
GetNode<PanelContainer>("PanelContainer/CenterContainer/PanelContainer").SelfModulate = new Color(1,1,1,0);
}
}
public void _on_settings_button_pressed()
{
GetNode<Settings>("Settings").Visible = true;
GetNode<Settings>("Settings").Init();
}
public void _on_credits_button_pressed()
{
GetNode<Window>("Credits").Visible = true;
}
public void _on_credits_close_requested()
{
GetNode<Window>("Credits").Visible = false;
}
public void _on_github_pressed()
{
OS.ShellOpen("https://github.com/SheepYhangCN/DateCountdown");
}
public void _on_check_button_toggled(bool toggled)
{
GetWindow().AlwaysOnTop = toggled;
var cfg = new ConfigFile();
cfg.Load("user://Settings.ini");
cfg.SetValue("Settings","AlwaysOnTop",toggled);
cfg.Save("user://Settings.ini");
}
}