Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
Move recent files panel to top of main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Oct 13, 2024
1 parent afae894 commit 4d433c9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
83 changes: 43 additions & 40 deletions src/TSMapEditor/UI/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,58 +114,20 @@ public override void Initialize()
AddChild(btnBrowseMapPath);
btnBrowseMapPath.LeftClick += BtnBrowseMapPath_LeftClick;

var lblDirectoryListing = new XNALabel(WindowManager);
lblDirectoryListing.Name = nameof(lblDirectoryListing);
lblDirectoryListing.X = Constants.UIEmptySideSpace;
lblDirectoryListing.Y = tbMapPath.Bottom + Constants.UIVerticalSpacing * 2;
lblDirectoryListing.Text = "Alternatively, select a map file below:";
AddChild(lblDirectoryListing);

lbFileList = new FileBrowserListBox(WindowManager);
lbFileList.Name = nameof(lbFileList);
lbFileList.X = Constants.UIEmptySideSpace;
lbFileList.Y = lblDirectoryListing.Bottom + Constants.UIVerticalSpacing;
lbFileList.Width = Width - (Constants.UIEmptySideSpace * 2);
lbFileList.Height = 420;
lbFileList.FileSelected += LbFileList_FileSelected;
lbFileList.FileDoubleLeftClick += LbFileList_FileDoubleLeftClick;
AddChild(lbFileList);

if (hasRecentFiles)
{
const int recentFilesHeight = 150;
lbFileList.Height -= recentFilesHeight + Constants.UIVerticalSpacing;

var lblRecentFiles = new XNALabel(WindowManager);
lblRecentFiles.Name = nameof(lblRecentFiles);
lblRecentFiles.X = lbFileList.X;
lblRecentFiles.Y = lbFileList.Bottom + Constants.UIVerticalSpacing;
lblRecentFiles.Text = "Recent files:";
AddChild(lblRecentFiles);

var recentFilesPanel = new RecentFilesPanel(WindowManager);
recentFilesPanel.X = lblRecentFiles.X;
recentFilesPanel.Y = lblRecentFiles.Bottom + Constants.UIVerticalSpacing;
recentFilesPanel.Width = lbFileList.Width;
recentFilesPanel.Height = recentFilesHeight - lblRecentFiles.Height - (Constants.UIVerticalSpacing * 2);
recentFilesPanel.FileSelected += RecentFilesPanel_FileSelected;
AddChild(recentFilesPanel);
}

btnLoad = new EditorButton(WindowManager);
btnLoad.Name = nameof(btnLoad);
btnLoad.Width = 150;
btnLoad.Text = "Load";
btnLoad.Y = Height - btnLoad.Height - Constants.UIEmptyBottomSpace;
btnLoad.X = lbFileList.Right - btnLoad.Width;
btnLoad.X = Width - btnLoad.Width - Constants.UIEmptySideSpace;
AddChild(btnLoad);
btnLoad.LeftClick += BtnLoad_LeftClick;

var btnCreateNewMap = new EditorButton(WindowManager);
btnCreateNewMap.Name = nameof(btnCreateNewMap);
btnCreateNewMap.Width = 150;
btnCreateNewMap.Text = "New Map...";
btnCreateNewMap.X = lbFileList.X;
btnCreateNewMap.X = Constants.UIEmptySideSpace;
btnCreateNewMap.Y = btnLoad.Y;
AddChild(btnCreateNewMap);
btnCreateNewMap.LeftClick += BtnCreateNewMap_LeftClick;
Expand All @@ -178,6 +140,47 @@ public override void Initialize()
lblCopyright.CenterOnControlVertically(btnCreateNewMap);
lblCopyright.X = btnCreateNewMap.Right + ((btnLoad.X - btnCreateNewMap.Right) - lblCopyright.Width) / 2;

int directoryListingY = tbMapPath.Bottom + Constants.UIVerticalSpacing * 2;

if (hasRecentFiles)
{
const int recentFilesHeight = 150;

var lblRecentFiles = new XNALabel(WindowManager);
lblRecentFiles.Name = nameof(lblRecentFiles);
lblRecentFiles.X = Constants.UIEmptySideSpace;
lblRecentFiles.Y = directoryListingY;
lblRecentFiles.Text = "Recent files:";
AddChild(lblRecentFiles);

var recentFilesPanel = new RecentFilesPanel(WindowManager);
recentFilesPanel.X = lblRecentFiles.X;
recentFilesPanel.Y = lblRecentFiles.Bottom + Constants.UIVerticalSpacing;
recentFilesPanel.Width = Width - (Constants.UIEmptySideSpace * 2);
recentFilesPanel.Height = recentFilesHeight - lblRecentFiles.Height - (Constants.UIVerticalSpacing * 2);
recentFilesPanel.FileSelected += RecentFilesPanel_FileSelected;
AddChild(recentFilesPanel);

directoryListingY = recentFilesPanel.Bottom + Constants.UIVerticalSpacing;
}

var lblDirectoryListing = new XNALabel(WindowManager);
lblDirectoryListing.Name = nameof(lblDirectoryListing);
lblDirectoryListing.X = Constants.UIEmptySideSpace;
lblDirectoryListing.Y = directoryListingY;
lblDirectoryListing.Text = "Alternatively, select a map file below:";
AddChild(lblDirectoryListing);

lbFileList = new FileBrowserListBox(WindowManager);
lbFileList.Name = nameof(lbFileList);
lbFileList.X = Constants.UIEmptySideSpace;
lbFileList.Y = lblDirectoryListing.Bottom + Constants.UIVerticalSpacing;
lbFileList.Width = Width - (Constants.UIEmptySideSpace * 2);
lbFileList.Height = btnLoad.Y - Constants.UIEmptyTopSpace - lbFileList.Y;
lbFileList.FileSelected += LbFileList_FileSelected;
lbFileList.FileDoubleLeftClick += LbFileList_FileDoubleLeftClick;
AddChild(lbFileList);

settingsPanel = new SettingsPanel(WindowManager);
settingsPanel.Name = nameof(settingsPanel);
settingsPanel.X = Width;
Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/UI/RecentFilesPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void Initialize()
fileLabel.Name = nameof(fileLabel) + i.ToString(CultureInfo.InvariantCulture);
fileLabel.X = Constants.UIEmptySideSpace;
fileLabel.Y = y;
fileLabel.Text = (i + 1).ToString(CultureInfo.InvariantCulture) + ") " + string.Join(Environment.NewLine, Renderer.GetFixedTextLines(path, fileLabel.FontIndex, Width - fileLabel.X - Constants.UIEmptySideSpace));
fileLabel.Text = (i + 1).ToString(CultureInfo.InvariantCulture) + ") " + path;
fileLabel.Tag = entries[i];
fileLabel.LeftClick += (s, e) => FileSelected?.Invoke(this, new FileSelectedEventArgs(path));
AddChild(fileLabel);
Expand Down

0 comments on commit 4d433c9

Please sign in to comment.