Skip to content

Commit c40fe5b

Browse files
committed
fix many
1 parent 14fa720 commit c40fe5b

8 files changed

Lines changed: 86 additions & 243 deletions

File tree

AutoExtractedAssets/Scripts/QiuUTMT Scripts/Resource Exporters/ExportAllRoomsToPNG.csx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (exportFolder is null)
1616
SetProgressBar(null, "Rooms Exported", 0, Data.Rooms.Count);
1717
StartProgressBarUpdater();
1818

19-
using TextureWorkerSkia worker = new();
19+
using TextureWorkerSkia worker = new TextureWorkerSkia();
2020

2121
foreach (UndertaleRoom room in Data.Rooms)
2222
{

UndertaleModToolAvalonia.Android/NativeViews/SoraEditorAndroid.cs

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public static void DoMeOnlyOnce()
4545
themeModel.Dark = true;
4646
themeRegistry.LoadTheme(themeModel);
4747
themeRegistry.SetTheme(themeName);
48-
GrammarRegistry.Instance.LoadGrammars("textmate/language.json");
48+
GrammarRegistry.Instance.LoadGrammars("textmate/language.json");
4949
}
5050
}
5151
public IPlatformHandle CreateControl(IPlatformHandle parent, Func<IPlatformHandle> createDefault)
5252
{
5353
DoMeOnlyOnce();
54-
var parentContext = (parent as AndroidViewControlHandle)?.View.Context
54+
var parentContext = (parent as AndroidViewControlHandle)?.View.Context
5555
?? global::Android.App.Application.Context;
5656

5757
var codeEditor = new CodeEditor(parentContext);
@@ -66,19 +66,10 @@ public IPlatformHandle CreateControl(IPlatformHandle parent, Func<IPlatformHandl
6666
);
6767
codeEditor.EditorLanguage = language;
6868

69-
// Ensure the editor is focusable so it can receive touch events and show the
70-
// text actions popup (copy/cut/paste/select all) on long press
71-
codeEditor.Focusable = true;
72-
codeEditor.FocusableInTouchMode = true;
73-
74-
// Ensure the editor is important for autofill so the system properly manages
75-
// the input connection and text selection actions
76-
codeEditor.ImportantForAutofill = (global::Android.Views.ImportantForAutofill)2;
77-
7869
return new AndroidViewControlHandle(codeEditor);
7970
}
8071

81-
public void SetText(IPlatformHandle androidViewControlHandle, string text)
72+
public void SetText(IPlatformHandle androidViewControlHandle, string text)
8273
{
8374
var codeEditor = (androidViewControlHandle as AndroidViewControlHandle).View as CodeEditor;
8475
codeEditor.SetText(text);
@@ -93,46 +84,19 @@ public string GetText(IPlatformHandle androidViewControlHandle)
9384
public void SetOnTextChanged(IPlatformHandle androidViewControlHandle, Action<string> callback)
9485
{
9586
var codeEditor = (androidViewControlHandle as AndroidViewControlHandle).View as CodeEditor;
96-
var eventClass = Java.Lang.Class.FromType(typeof(ContentChangeEvent));
87+
var eventClass = Java.Lang.Class.FromType(typeof(ContentChangeEvent));
9788
codeEditor.SubscribeAlways(
9889
eventClass,
9990
new TextChangedReceiver(callback, codeEditor)
10091
);
10192
}
10293

103-
public void SetVisible(IPlatformHandle androidViewControlHandle, bool visible)
104-
{
105-
var codeEditor = (androidViewControlHandle as AndroidViewControlHandle)?.View as CodeEditor;
106-
if (codeEditor != null)
107-
{
108-
codeEditor.Visibility = visible ? (global::Android.Views.ViewStates)0 : (global::Android.Views.ViewStates)4;
109-
}
110-
}
111-
112-
public void RequestFocus(IPlatformHandle androidViewControlHandle)
113-
{
114-
var codeEditor = (androidViewControlHandle as AndroidViewControlHandle)?.View as CodeEditor;
115-
if (codeEditor != null)
116-
{
117-
codeEditor.RequestFocus();
118-
}
119-
}
120-
121-
public void SetOnFocusChanged(IPlatformHandle androidViewControlHandle, Action<bool> callback)
122-
{
123-
var view = (androidViewControlHandle as AndroidViewControlHandle)?.View;
124-
if (view != null)
125-
{
126-
view.FocusChange += (s, e) => callback(e.HasFocus);
127-
}
128-
}
129-
13094
private class TextChangedReceiver : Java.Lang.Object, EventManager.INoUnsubscribeReceiver
13195
{
13296
private readonly Action<string> _callback;
13397
private readonly CodeEditor _editor;
13498

135-
public TextChangedReceiver(Action<string> callback, CodeEditor editor)
99+
public TextChangedReceiver(Action<string> callback, CodeEditor editor)
136100
{
137101
_callback = callback;
138102
_editor = editor;
@@ -143,19 +107,4 @@ public void OnEvent(Java.Lang.Object? evt)
143107
_callback?.Invoke(_editor.Text.ToString());
144108
}
145109
}
146-
147-
private class FocusChangeListener : Java.Lang.Object, global::Android.Views.View.IOnFocusChangeListener
148-
{
149-
private readonly Action<bool> _callback;
150-
151-
public FocusChangeListener(Action<bool> callback)
152-
{
153-
_callback = callback;
154-
}
155-
156-
public void OnFocusChange(global::Android.Views.View? v, bool hasFocus)
157-
{
158-
_callback?.Invoke(hasFocus);
159-
}
160-
}
161-
}
110+
}

UndertaleModToolAvalonia/NativeViews/ISoraEditorAndroid.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ namespace UndertaleModToolAvalonia.NativeViews;
66
public interface ISoraEditorAndroid
77
{
88
public IPlatformHandle CreateControl(IPlatformHandle parent, Func<IPlatformHandle> createDefault);
9-
public void SetText(IPlatformHandle androidViewControlHandle, string text);
9+
public void SetText(IPlatformHandle androidViewControlHandle, string text);
1010
public string GetText(IPlatformHandle androidViewControlHandle);
1111
public void SetOnTextChanged(IPlatformHandle androidViewControlHandle, Action<string> callback);
12-
public void SetVisible(IPlatformHandle androidViewControlHandle, bool visible);
13-
public void RequestFocus(IPlatformHandle androidViewControlHandle);
14-
public void SetOnFocusChanged(IPlatformHandle androidViewControlHandle, Action<bool> callback);
1512

1613
public static ISoraEditorAndroid? Implementation { get; set; }
17-
}
14+
}

UndertaleModToolAvalonia/NativeViews/SoraEditorControl.cs

Lines changed: 8 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using Avalonia;
33
using Avalonia.Controls;
44
using Avalonia.Data;
5-
using Avalonia.Input;
6-
using Avalonia.Interactivity;
75
using Avalonia.Platform;
86
using AvaloniaEdit;
97
using AvaloniaEdit.Document;
@@ -15,13 +13,9 @@ public class SoraEditorControl: NativeControlHost
1513
{
1614
private IPlatformHandle? _impl;
1715
private string _initialText = string.Empty;
18-
private bool _isSyncingDocument;
19-
private bool _isSyncingFocus;
20-
2116

2217
public SoraEditorControl()
2318
{
24-
Focusable = true;
2519
}
2620

2721
public string Text
@@ -39,8 +33,8 @@ public string Text
3933
public static readonly StyledProperty<TextDocument> DocumentProperty = TextView.DocumentProperty.AddOwner<SoraEditorControl>();
4034
public TextDocument Document
4135
{
42-
get => this.GetValue<TextDocument>(SoraEditorControl.DocumentProperty);
43-
set => this.SetValue(SoraEditorControl.DocumentProperty, value);
36+
get => this.GetValue<TextDocument>(SoraEditorControl.DocumentProperty);
37+
set => this.SetValue(SoraEditorControl.DocumentProperty, value);
4438
}
4539

4640
/// <summary>
@@ -53,69 +47,14 @@ public static ISoraEditorAndroid? Factory
5347
get => ISoraEditorAndroid.Implementation;
5448
}
5549

56-
public new bool Focus()
57-
{
58-
// Delegate focus to the native Android editor
59-
if (_impl is not null && Factory is not null)
60-
{
61-
Factory.RequestFocus(_impl);
62-
return true;
63-
}
64-
return base.Focus();
65-
}
66-
67-
protected override void OnGotFocus(GotFocusEventArgs e)
68-
{
69-
base.OnGotFocus(e);
70-
71-
// When Avalonia sets focus to this control, delegate to the native editor
72-
if (!_isSyncingFocus && _impl is not null && Factory is not null)
73-
{
74-
_isSyncingFocus = true;
75-
try
76-
{
77-
Factory.RequestFocus(_impl);
78-
}
79-
finally
80-
{
81-
_isSyncingFocus = false;
82-
}
83-
}
84-
}
85-
86-
/// <summary>
87-
/// Called when the native Android editor gains or loses focus.
88-
/// When the native control gains focus (e.g. from a user tap), we claim
89-
/// Avalonia focus so that the framework does not redirect it elsewhere.
90-
/// </summary>
91-
private void OnNativeFocusChanged(bool hasFocus)
92-
{
93-
if (_isSyncingFocus)
94-
return;
95-
96-
if (hasFocus)
97-
{
98-
_isSyncingFocus = true;
99-
try
100-
{
101-
// Claim Avalonia focus so the framework knows this control is active
102-
base.Focus();
103-
}
104-
finally
105-
{
106-
_isSyncingFocus = false;
107-
}
108-
}
109-
}
110-
11150
protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
11251
{
11352
if (Factory is null)
11453
return base.CreateNativeControlCore(parent);
11554

11655
_impl = Factory.CreateControl(parent, () => base.CreateNativeControlCore(parent));
11756

118-
// Set initial text if it was set before the control was created
57+
// Set initial text if it was set before the control was created
11958
if (!string.IsNullOrEmpty(_initialText))
12059
{
12160
Factory.SetText(_impl, _initialText);
@@ -131,13 +70,10 @@ protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle paren
13170
// Hook up native text changed callback
13271
Factory.SetOnTextChanged(_impl, OnNativeTextChanged);
13372

134-
// Hook up native focus changed callback for bidirectional focus sync
135-
Factory.SetOnFocusChanged(_impl, OnNativeFocusChanged);
136-
13773
return _impl;
13874
}
13975

140-
protected override void DestroyNativeControlCore(IPlatformHandle control)
76+
protected override void DestroyNativeControlCore(IPlatformHandle control)
14177
{
14278
_impl = null;
14379
base.DestroyNativeControlCore(control);
@@ -149,84 +85,13 @@ protected override void DestroyNativeControlCore(IPlatformHandle control)
14985
private void OnNativeTextChanged(string newText)
15086
{
15187
// Sync back to Document if bound
152-
_isSyncingDocument = true;
153-
try
154-
{
155-
var doc = Document;
156-
if (doc != null && doc.Text != newText)
157-
{
158-
doc.Text = newText;
159-
}
160-
}
161-
finally
88+
var doc = Document;
89+
if (doc != null && doc.Text != newText)
16290
{
163-
_isSyncingDocument = false;
91+
doc.Text = newText;
16492
}
16593

16694
// Raise TextChanged event
16795
TextChanged?.Invoke(this, EventArgs.Empty);
16896
}
169-
170-
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
171-
{
172-
base.OnPropertyChanged(change);
173-
174-
if (change.Property == DocumentProperty)
175-
{
176-
if (change.NewValue is TextDocument newDoc)
177-
{
178-
// Sync document text to native editor
179-
if (_impl is not null && Factory is not null)
180-
{
181-
try
182-
{
183-
Factory.SetText(_impl, newDoc.Text);
184-
}
185-
catch (ObjectDisposedException)
186-
{
187-
// Native control disposed, will be recreated when tab is re-selected
188-
}
189-
}
190-
else
191-
{
192-
_initialText = newDoc.Text;
193-
}
194-
195-
// Listen for document text changes
196-
newDoc.TextChanged += OnDocumentTextChanged;
197-
}
198-
199-
if (change.OldValue is TextDocument oldDoc)
200-
{
201-
oldDoc.TextChanged -= OnDocumentTextChanged;
202-
}
203-
}
204-
else if (change.Property == IsVisibleProperty)
205-
{
206-
// Propagate visibility changes to the native Android view so it doesn't
207-
// render on top of overlay dialogs
208-
if (_impl is not null && Factory is not null)
209-
{
210-
Factory.SetVisible(_impl, IsVisible);
211-
}
212-
}
213-
}
214-
215-
private void OnDocumentTextChanged(object? sender, EventArgs e)
216-
{
217-
if (_isSyncingDocument || _impl is null)
218-
return;
219-
220-
try
221-
{
222-
if (Factory is not null && sender is TextDocument doc)
223-
{
224-
Factory.SetText(_impl, doc.Text);
225-
}
226-
}
227-
catch (ObjectDisposedException)
228-
{
229-
// Native control has been disposed (e.g. tab switched away), ignore
230-
}
231-
}
232-
}
97+
}

UndertaleModToolAvalonia/ResourceViews/UndertaleCodeView.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<ThemeVariantScope RequestedThemeVariant="Dark">
7777
<nativeViews:SoraEditorControl x:Name="GMLTextEditorSora"
7878
Document="{Binding GMLTextDocument}"
79-
LostFocus="GMLTextEditor_LostFocus"
79+
8080
TextChanged="GMLTextEditor_TextChanged">
8181
</nativeViews:SoraEditorControl>
8282
</ThemeVariantScope>
@@ -85,7 +85,7 @@
8585
<ThemeVariantScope RequestedThemeVariant="Dark">
8686
<nativeViews:SoraEditorControl x:Name="ASMTextEditorSora"
8787
Document="{Binding ASMTextDocument}"
88-
LostFocus="ASMTextEditor_LostFocus"
88+
8989
TextChanged="ASMTextEditor_TextChanged">
9090
</nativeViews:SoraEditorControl>
9191
</ThemeVariantScope>

0 commit comments

Comments
 (0)