-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartupPage.cs
119 lines (99 loc) · 4.62 KB
/
StartupPage.cs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using static CaravelEditor.EditorForm;
namespace CaravelEditor
{
public partial class StartupPage : UserControl
{
public EditorForm Eform
{
get; set;
}
private Dictionary<string, ComplexButton> m_ProjectButtons = new Dictionary<string,ComplexButton>();
public StartupPage()
{
InitializeComponent();
RecentProjects.WrapContents = true;
RecentProjects.FlowDirection = FlowDirection.LeftToRight;
this.Resize += new EventHandler((object sender, EventArgs e) =>
{
RecentProjects.Size = new Size(this.Size.Width-(50+RecentProjects.Location.X), this.Size.Height - (100+RecentProjects.Location.Y));
RecentProjects.PerformLayout();
});
}
public void PopulateProjects()
{
BringToFront();
LoadLastProjects();
foreach (var proj in Eform.LastLoadedProjects)
{
var complexButton = new ComplexButton();
complexButton.BackColor = System.Drawing.SystemColors.ControlDarkDark;
complexButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
complexButton.FlatAppearance.BorderSize = 0;
complexButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
complexButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
complexButton.Image = new Bitmap(global::CaravelEditor.Properties.Resources.open, new Size(32, 32));
complexButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
complexButton.Location = new System.Drawing.Point(3, 3);
complexButton.Name = "complexButton" + proj.ProjectName;
complexButton.Padding = new System.Windows.Forms.Padding(10, 0, 10, 0);
complexButton.Size = new System.Drawing.Size(300, 80);
complexButton.Subtitle = proj.ProjectScene;
complexButton.SubtitleColor = System.Drawing.SystemColors.AppWorkspace;
complexButton.SubtitleFont = new System.Drawing.Font("Microsoft Sans Serif", 10.875F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
complexButton.TabIndex = 4;
complexButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
complexButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
complexButton.Title = proj.ProjectName;
complexButton.UseVisualStyleBackColor = false;
complexButton.Click += new EventHandler(loadRecentProjectButton_Click);
m_ProjectButtons.Add(proj.ProjectName, complexButton);
this.RecentProjects.Controls.Add(complexButton);
}
}
private void openProjectButton_Click(object sender, EventArgs e)
{
Eform.openProjectToolStripMenuItem_Click(sender, e);
}
private void loadRecentProjectButton_Click(object sender, EventArgs e)
{
var button = sender as ComplexButton;
var projInfo = Eform.LastLoadedProjects.Find(p => p.ProjectName == button.Title);
Eform.OpenProject(projInfo.FullProjectPath);
if (projInfo.ProjectScene != "")
{
Eform.LoadNewScene(projInfo.FullScenePath);
}
}
private void LoadLastProjects()
{
if (!File.Exists("settings.xml"))
{
return;
}
var doc = new XmlDocument();
doc.Load("settings.xml");
var rootNode = doc.FirstChild;
var recentProjs = rootNode.SelectNodes("LastProjects/*");
int numProjs = 0;
foreach (XmlNode proj in recentProjs)
{
if (numProjs >= 6)
{
break;
}
var projName = proj.Attributes["name"].Value;
var scene = proj.Attributes["scene"].Value;
var projPath = proj.Attributes["projPath"].Value;
var scenePath = proj.Attributes["scenePath"].Value;
Eform.LastLoadedProjects.Add(new ProjectInfo(projName, scene, projPath, scenePath));
numProjs++;
}
}
}
}