mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
modified link behavior for paragraphs to be easier to modify
This commit is contained in:
parent
a0837fdcb7
commit
f2c544dc65
4 changed files with 23 additions and 10 deletions
|
@ -1,5 +1,7 @@
|
||||||
using Android.App;
|
using Android.App;
|
||||||
|
using Android.Content;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
|
using Android.Net;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
@ -31,8 +33,12 @@ namespace Demos.Android {
|
||||||
this.game = new GameImpl();
|
this.game = new GameImpl();
|
||||||
// reset MlemGame width and height to use device's aspect ratio
|
// reset MlemGame width and height to use device's aspect ratio
|
||||||
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
|
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
|
||||||
|
this.game.OnLoadContent += game => {
|
||||||
// disable mouse handling for android to make emulator behavior more coherent
|
// disable mouse handling for android to make emulator behavior more coherent
|
||||||
this.game.OnLoadContent += game => game.InputHandler.HandleMouse = false;
|
game.InputHandler.HandleMouse = false;
|
||||||
|
// make text links be opened properly
|
||||||
|
game.UiSystem.LinkBehavior = l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l.Match.Groups[1].Value)));
|
||||||
|
};
|
||||||
// set the game to fullscreen to cause the status bar to be hidden
|
// set the game to fullscreen to cause the status bar to be hidden
|
||||||
this.game.GraphicsDeviceManager.IsFullScreen = true;
|
this.game.GraphicsDeviceManager.IsFullScreen = true;
|
||||||
this.view = this.game.Services.GetService(typeof(View)) as View;
|
this.view = this.game.Services.GetService(typeof(View)) as View;
|
||||||
|
|
|
@ -83,6 +83,10 @@
|
||||||
<Project>{997f4739-7bec-4621-b9ca-68deb2d74412}</Project>
|
<Project>{997f4739-7bec-4621-b9ca-68deb2d74412}</Project>
|
||||||
<Name>MLEM.Startup</Name>
|
<Name>MLEM.Startup</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj">
|
||||||
|
<Project>{6f00629a-8b87-4264-8896-19983285e32f}</Project>
|
||||||
|
<Name>MLEM.Ui</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\MLEM\MLEM.csproj">
|
<ProjectReference Include="..\MLEM\MLEM.csproj">
|
||||||
<Project>{1d6ab762-43c4-4775-8924-707c7ec3f142}</Project>
|
<Project>{1d6ab762-43c4-4775-8924-707c7ec3f142}</Project>
|
||||||
<Name>MLEM</Name>
|
<Name>MLEM</Name>
|
||||||
|
|
|
@ -241,13 +241,8 @@ namespace MLEM.Ui.Elements {
|
||||||
link.IsSelected = false;
|
link.IsSelected = false;
|
||||||
};
|
};
|
||||||
this.OnPressed += e => {
|
this.OnPressed += e => {
|
||||||
foreach (var code in token.AppliedCodes.OfType<LinkCode>()) {
|
foreach (var code in token.AppliedCodes.OfType<LinkCode>())
|
||||||
try {
|
this.System?.LinkBehavior?.Invoke(code);
|
||||||
Process.Start(code.Match.Groups[1].Value);
|
|
||||||
} catch (Exception) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
@ -99,6 +100,12 @@ namespace MLEM.Ui {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TextFormatter TextFormatter;
|
public TextFormatter TextFormatter;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The action that should be executed when a <see cref="LinkCode"/> in a paragraph's <see cref="Paragraph.TokenizedText"/> is pressed.
|
||||||
|
/// The actual link stored in the link code is stored in its <see cref="LinkCode.Match"/>'s 1st group.
|
||||||
|
/// By default, the browser is opened with the given link's address.
|
||||||
|
/// </summary>
|
||||||
|
public Action<LinkCode> LinkBehavior = l => Process.Start(l.Match.Groups[1].Value);
|
||||||
|
/// <summary>
|
||||||
/// The <see cref="UiControls"/> that this ui system is controlled by.
|
/// The <see cref="UiControls"/> that this ui system is controlled by.
|
||||||
/// The ui controls are also the place to change bindings for controller and keyboard input.
|
/// The ui controls are also the place to change bindings for controller and keyboard input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -213,7 +220,8 @@ namespace MLEM.Ui {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.TextFormatter = new TextFormatter();
|
this.TextFormatter = new TextFormatter();
|
||||||
this.TextFormatter.Codes.Add(new Regex("<l(?: ([^>]+))?>"), (f, m, r) => new LinkCode(m, r, 1 / 16F, 0.85F, t => this.Controls.MousedElement is Paragraph.Link link && link.Token == t));
|
this.TextFormatter.Codes.Add(new Regex("<l(?: ([^>]+))?>"), (f, m, r) => new LinkCode(m, r, 1 / 16F, 0.85F,
|
||||||
|
t => this.Controls.MousedElement is Paragraph.Link l1 && l1.Token == t || this.Controls.TouchedElement is Paragraph.Link l2 && l2.Token == t));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue