Skip to content

Commit 05c8062

Browse files
committed
fix: settings window support for unity2021
1 parent 0c02ac7 commit 05c8062

File tree

10 files changed

+334
-145
lines changed

10 files changed

+334
-145
lines changed

Editor/View/JahroEditorView.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public void CreateGUI()
5656
{
5757
Application.OpenURL(JahroConfig.ChangelogUrl);
5858
};
59+
var projectPageLink = root.Q<Button>("ProjectPageLink");
60+
projectPageLink.clicked += () =>
61+
{
62+
Application.OpenURL("https://console.jahro.io");
63+
};
64+
65+
ConfigureFooterLinks(root.Q<VisualElement>("Footer"));
5966

6067
_welcomeView.OnValidationSuccess += OnAPIKeyValidated;
6168
_settingsView.OnResetApiKey += ResetApiKey;
@@ -185,5 +192,23 @@ private void UpdateUI(VersionChecker.VersionResponse response)
185192
_versionButton.style.backgroundColor = new Color(0.02f, 0.59f, 0.41f);
186193
}
187194
}
195+
196+
private void ConfigureFooterLinks(VisualElement root)
197+
{
198+
SetupLinkButton(root, "HomeLink", "https://jahro.io?utm_source=unity-client&utm_medium=settings&utm_content=footer");
199+
SetupLinkButton(root, "DocsLink", "https://docs.jahro.io/?utm_source=unity-client&utm_medium=settings&utm_content=footer");
200+
SetupLinkButton(root, "DiscordLink", "https://discord.gg/txcHFRDeV4");
201+
SetupLinkButton(root, "GitHubLink", "https://github.com/jahro-console/unity-package");
202+
SetupLinkButton(root, "ReportIssueLink", "https://github.com/jahro-console/unity-package/issues");
203+
}
204+
205+
private void SetupLinkButton(VisualElement root, string buttonName, string url)
206+
{
207+
var button = root.Q<Button>(buttonName);
208+
if (button != null)
209+
{
210+
button.clicked += () => Application.OpenURL(url);
211+
}
212+
}
188213
}
189214
}

Editor/View/JahroEditorView.uss

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,6 @@
268268
-unity-font-style: bold;
269269
}
270270

271-
.tab-view > .unity-tab-view-item {
272-
flex-grow: 0;
273-
flex-shrink: 0;
274-
flex-basis: 300px;
275-
}
276-
277271
.settings-item-title {
278272
color: var(--foreground);
279273
font-size: 16px;
@@ -291,3 +285,52 @@
291285
.error-text {
292286
color: var(--error);
293287
}
288+
289+
.tab-view {
290+
flex-grow: 1;
291+
}
292+
293+
.tab-header {
294+
background-color: var(--background-muted);
295+
border-radius: 6px;
296+
padding: 4px;
297+
}
298+
299+
.tab-button {
300+
background-color: transparent;
301+
border-width: 0;
302+
padding: 8px 16px;
303+
margin: 0 4px;
304+
border-radius: 4px;
305+
font-size: 14px;
306+
color: var(--foreground);
307+
-unity-font-style: bold;
308+
transition: background-color 0.2s;
309+
}
310+
311+
.tab-button:hover {
312+
background-color: var(--background-hover);
313+
}
314+
315+
.tab-button-active {
316+
background-color: var(--primary);
317+
color: var(--foreground);
318+
}
319+
320+
.footer-button {
321+
background-color: rgba(0, 0, 0, 0);
322+
border-left-color: rgba(0, 0, 0, 0);
323+
border-right-color: rgba(0, 0, 0, 0);
324+
border-top-color: rgba(0, 0, 0, 0);
325+
border-bottom-color: rgba(0, 0, 0, 0);
326+
color: rgb(255, 255, 255);
327+
}
328+
329+
.footer-button:hover {
330+
background-color: rgba(0, 0, 0, 0);
331+
border-left-color: rgba(0, 0, 0, 0);
332+
border-right-color: rgba(0, 0, 0, 0);
333+
border-top-color: rgba(0, 0, 0, 0);
334+
border-bottom-color: rgba(0, 0, 0, 0);
335+
color: rgb(159, 159, 159);
336+
}

Editor/View/JahroEditorView.uxml

Lines changed: 98 additions & 89 deletions
Large diffs are not rendered by default.

Editor/View/SettingsTabView.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using UnityEngine.UIElements;
2+
3+
namespace JahroConsole.Editor
4+
{
5+
public class SettingsTabView
6+
{
7+
private Button _accountButton;
8+
private Button _settingsButton;
9+
private VisualElement _accountContainer;
10+
private VisualElement _settingsContainer;
11+
12+
public SettingsTabView(VisualElement root)
13+
{
14+
var tabsContainer = root.Q<VisualElement>("TabsControl");
15+
16+
_accountButton = tabsContainer.Q<Button>("AccountTab");
17+
_accountButton.clicked += () => SwitchToTab("account");
18+
19+
_settingsButton = tabsContainer.Q<Button>("SettingTab");
20+
_settingsButton.clicked += () => SwitchToTab("settings");
21+
22+
_accountContainer = root.Q<VisualElement>("AccountContainer");
23+
_settingsContainer = root.Q<VisualElement>("SettingsContainer");
24+
25+
SwitchToTab("account");
26+
}
27+
28+
public void SwitchToTab(string tabName)
29+
{
30+
31+
if (_accountContainer != null && _settingsContainer != null)
32+
{
33+
if (tabName == "account")
34+
{
35+
_accountContainer.style.display = DisplayStyle.Flex;
36+
_settingsContainer.style.display = DisplayStyle.None;
37+
38+
_accountButton.AddToClassList("tab-button-active");
39+
_settingsButton.RemoveFromClassList("tab-button-active");
40+
}
41+
else
42+
{
43+
_accountContainer.style.display = DisplayStyle.None;
44+
_settingsContainer.style.display = DisplayStyle.Flex;
45+
46+
_accountButton.RemoveFromClassList("tab-button-active");
47+
_settingsButton.AddToClassList("tab-button-active");
48+
}
49+
}
50+
}
51+
}
52+
}

Editor/View/SettingsTabView.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/View/SettingsView.cs

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using UnityEditor.UIElements;
77
using UnityEditor;
88
using System.Collections.Generic;
9-
using Unity.Properties;
109
using UnityEditor.Compilation;
1110
using System.Linq;
1211

@@ -15,10 +14,10 @@ namespace JahroConsole.Editor
1514
public class SettingsView
1615
{
1716
private VisualElement _container;
18-
private TabView _tabView;
1917
private KeyValidator.ValidateKeyResponse _validationData;
2018
private JahroProjectSettings _projectSettings;
2119

20+
private SettingsTabView _tabView;
2221
private Label _projectNameLabel;
2322
private Label _teamNameLabel;
2423
private Label _apiKeyLabel;
@@ -43,9 +42,10 @@ public class SettingsView
4342
public SettingsView(VisualElement root)
4443
{
4544
_container = root.Q<VisualElement>("SettingsBlock");
46-
_tabView = _container.Q<TabView>();
45+
_tabView = new SettingsTabView(_container);
46+
var tabViewContainer = _container.Q<VisualElement>("TabView");
4747

48-
var accountTab = _tabView.Q<VisualElement>("AccountTab");
48+
var accountTab = tabViewContainer.Q<VisualElement>("AccountContainer");
4949
_projectNameLabel = accountTab.Q<Label>("ProjectName");
5050
_teamNameLabel = accountTab.Q<Label>("TeamName");
5151
_apiKeyLabel = accountTab.Q<VisualElement>("APIKeyContainer").Q<Label>("TeamName");
@@ -56,7 +56,7 @@ public SettingsView(VisualElement root)
5656
_teamOverviewButton = linksContainer.Q<Button>("TeamOverviewButton");
5757
_accountSettingsButton = linksContainer.Q<Button>("AccountSettingsButton");
5858

59-
var settingsTab = _tabView.Q<VisualElement>("SettingsTab");
59+
var settingsTab = tabViewContainer.Q<VisualElement>("SettingsContainer");
6060
var scrollView = settingsTab.Q<ScrollView>();
6161
_jahroEnableToggle = scrollView.Q<Toggle>("JahroEnableToggle");
6262
_autoDisableToggle = scrollView.Q<Toggle>("AutoDisableToggle");
@@ -181,80 +181,93 @@ private void SetupDataBinding()
181181
{
182182
if (_projectSettings == null) return;
183183

184-
_container.ClearBindings();
185-
_container.dataSource = _projectSettings;
184+
if (_jahroEnableToggle != null)
185+
{
186+
_jahroEnableToggle.value = _projectSettings.JahroEnabled;
187+
_jahroEnableToggle.RegisterValueChangedCallback(evt =>
188+
{
189+
_projectSettings.JahroEnabled = evt.newValue;
190+
SaveProjectSettings();
191+
});
192+
}
186193

187-
BindToggle(_jahroEnableToggle, "_jahroEnabled");
188-
BindToggle(_autoDisableToggle, "_autoDisableInRelease");
189-
BindToggle(_keyboardShortcutsToggle, "_useLaunchKeyboardShortcut");
190-
BindToggle(_mobileTapAreaToggle, "_useLaunchTapArea");
191-
BindToggle(_dublicateLogsToggle, "_duplicateToUnityConsole");
194+
if (_autoDisableToggle != null)
195+
{
196+
_autoDisableToggle.value = _projectSettings.AutoDisableInRelease;
197+
_autoDisableToggle.RegisterValueChangedCallback(evt =>
198+
{
199+
_projectSettings.AutoDisableInRelease = evt.newValue;
200+
SaveProjectSettings();
201+
});
202+
}
192203

193-
if (_launchKeyField != null)
204+
if (_keyboardShortcutsToggle != null)
205+
{
206+
_keyboardShortcutsToggle.value = _projectSettings.UseLaunchKeyboardShortcut;
207+
_keyboardShortcutsToggle.RegisterValueChangedCallback(evt =>
208+
{
209+
_projectSettings.UseLaunchKeyboardShortcut = evt.newValue;
210+
SaveProjectSettings();
211+
});
212+
}
213+
214+
if (_mobileTapAreaToggle != null)
215+
{
216+
_mobileTapAreaToggle.value = _projectSettings.UseLaunchTapArea;
217+
_mobileTapAreaToggle.RegisterValueChangedCallback(evt =>
218+
{
219+
_projectSettings.UseLaunchTapArea = evt.newValue;
220+
SaveProjectSettings();
221+
});
222+
}
223+
224+
if (_dublicateLogsToggle != null)
194225
{
195-
_launchKeyField.SetBinding("value", new DataBinding
226+
_dublicateLogsToggle.value = _projectSettings.DuplicateToUnityConsole;
227+
_dublicateLogsToggle.RegisterValueChangedCallback(evt =>
196228
{
197-
dataSourcePath = new PropertyPath("_launchKey")
229+
_projectSettings.DuplicateToUnityConsole = evt.newValue;
230+
SaveProjectSettings();
198231
});
232+
}
199233

234+
if (_launchKeyField != null)
235+
{
236+
_launchKeyField.value = _projectSettings.LaunchKey;
200237
_launchKeyField.RegisterValueChangedCallback(evt =>
201238
{
202-
if (_projectSettings != null)
203-
{
204-
_projectSettings.LaunchKey = (KeyCode)evt.newValue;
205-
SaveProjectSettings();
206-
}
239+
_projectSettings.LaunchKey = (KeyCode)evt.newValue;
240+
SaveProjectSettings();
207241
});
208242
}
209243

210244
if (_assembliesField != null)
211245
{
212246
_assembliesField.RegisterValueChangedCallback(evt =>
213247
{
214-
if (_projectSettings != null && _assembliesNames != null && _assembliesNames.Count > 0)
248+
if (_assembliesNames != null && _assembliesNames.Count > 0)
215249
{
216250
_assembliesFlag = (int)evt.newValue;
217251

218-
bool listChanged = false;
252+
_projectSettings.ActiveAssemblies.Clear();
219253

220254
for (int i = 0; i < _assembliesNames.Count; i++)
221255
{
222-
string name = _assembliesNames[i];
223-
bool active = _projectSettings.ActiveAssemblies.Contains(name);
224256
int layer = 1 << i;
225257
bool selected = (_assembliesFlag & layer) != 0;
226258

227-
if (!active && selected)
228-
{
229-
_projectSettings.ActiveAssemblies.Add(name);
230-
listChanged = true;
231-
}
232-
else if (active && !selected)
259+
if (selected)
233260
{
234-
_projectSettings.ActiveAssemblies.Remove(name);
235-
listChanged = true;
261+
_projectSettings.ActiveAssemblies.Add(_assembliesNames[i]);
236262
}
237263
}
238264

239-
if (listChanged)
240-
{
241-
SaveProjectSettings();
242-
}
265+
SaveProjectSettings();
243266
}
244267
});
245268
}
246269
}
247270

248-
private void BindToggle(Toggle toggle, string propertyPath)
249-
{
250-
if (toggle == null) return;
251-
252-
toggle.SetBinding("value", new DataBinding
253-
{
254-
dataSourcePath = new PropertyPath(propertyPath)
255-
});
256-
}
257-
258271
private void OnResetApiKeyClicked()
259272
{
260273
if (UnityEditor.EditorUtility.DisplayDialog(

Editor/View/SettingsView.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/View/WelcomeView.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Core/Context/VersionChecker.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)