From 4d433c9f4df4f312879a7ffc07b54bbb6101f24b Mon Sep 17 00:00:00 2001 From: Rampastring Date: Mon, 14 Oct 2024 01:02:29 +0300 Subject: [PATCH] Move recent files panel to top of main menu --- src/TSMapEditor/UI/MainMenu.cs | 83 +++++++++++++------------- src/TSMapEditor/UI/RecentFilesPanel.cs | 2 +- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/TSMapEditor/UI/MainMenu.cs b/src/TSMapEditor/UI/MainMenu.cs index f24d6bd6..5834dada 100644 --- a/src/TSMapEditor/UI/MainMenu.cs +++ b/src/TSMapEditor/UI/MainMenu.cs @@ -114,50 +114,12 @@ 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; @@ -165,7 +127,7 @@ public override void Initialize() 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; @@ -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; diff --git a/src/TSMapEditor/UI/RecentFilesPanel.cs b/src/TSMapEditor/UI/RecentFilesPanel.cs index f846c353..6550b6f2 100644 --- a/src/TSMapEditor/UI/RecentFilesPanel.cs +++ b/src/TSMapEditor/UI/RecentFilesPanel.cs @@ -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);