1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 01:09:23 +01:00

modified link behavior for paragraphs to be easier to modify

This commit is contained in:
Ellpeck 2020-06-09 18:56:01 +02:00
parent a0837fdcb7
commit f2c544dc65
4 changed files with 23 additions and 10 deletions

View file

@ -1,5 +1,7 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Net;
using Android.OS;
using Android.Views;
using Microsoft.Xna.Framework;
@ -31,8 +33,12 @@ namespace Demos.Android {
this.game = new GameImpl();
// reset MlemGame width and height to use device's aspect ratio
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
// disable mouse handling for android to make emulator behavior more coherent
this.game.OnLoadContent += game => game.InputHandler.HandleMouse = false;
this.game.OnLoadContent += game => {
// disable mouse handling for android to make emulator behavior more coherent
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
this.game.GraphicsDeviceManager.IsFullScreen = true;
this.view = this.game.Services.GetService(typeof(View)) as View;

View file

@ -83,6 +83,10 @@
<Project>{997f4739-7bec-4621-b9ca-68deb2d74412}</Project>
<Name>MLEM.Startup</Name>
</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">
<Project>{1d6ab762-43c4-4775-8924-707c7ec3f142}</Project>
<Name>MLEM</Name>

View file

@ -241,13 +241,8 @@ namespace MLEM.Ui.Elements {
link.IsSelected = false;
};
this.OnPressed += e => {
foreach (var code in token.AppliedCodes.OfType<LinkCode>()) {
try {
Process.Start(code.Match.Groups[1].Value);
} catch (Exception) {
// ignored
}
}
foreach (var code in token.AppliedCodes.OfType<LinkCode>())
this.System?.LinkBehavior?.Invoke(code);
};
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
@ -99,6 +100,12 @@ namespace MLEM.Ui {
/// </summary>
public TextFormatter TextFormatter;
/// <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 ui controls are also the place to change bindings for controller and keyboard input.
/// </summary>
@ -213,7 +220,8 @@ namespace MLEM.Ui {
};
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>