finally ads YES

This commit is contained in:
Ellpeck 2020-06-10 23:03:48 +02:00
parent 4e55392fe3
commit 12b4177e3b
3 changed files with 12328 additions and 2479 deletions

View file

@ -1,13 +1,17 @@
using System;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.Content.PM; using Android.Content.PM;
using Android.Net; using Android.Gms.Ads;
using Android.OS; using Android.OS;
using Android.Views; using Android.Views;
using Android.Widget;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Misc; using MLEM.Misc;
using TouchyTickets; using TouchyTickets;
using static Android.Views.ViewGroup.LayoutParams;
using Uri = Android.Net.Uri;
namespace Android { namespace Android {
[Activity( [Activity(
@ -22,32 +26,64 @@ namespace Android {
public class Activity1 : AndroidGameActivity { public class Activity1 : AndroidGameActivity {
private GameImpl game; private GameImpl game;
private View view; private LinearLayout mainView;
protected override void OnCreate(Bundle bundle) { protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle); base.OnCreate(bundle);
// render under notches
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
// set up the game
TextInputWrapper.Current = new TextInputWrapper.Mobile(); TextInputWrapper.Current = new TextInputWrapper.Mobile();
this.game = new GameImpl(new AndroidAnalytics(this)); this.game = new GameImpl(new AndroidAnalytics(this));
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window); this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
this.game.GraphicsDeviceManager.IsFullScreen = true;
this.game.OnLoadContent += game => { this.game.OnLoadContent += game => {
game.InputHandler.HandleMouse = false; game.InputHandler.HandleMouse = false;
game.UiSystem.LinkBehavior = l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l.Match.Groups[1].Value))); game.UiSystem.LinkBehavior = l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l.Match.Groups[1].Value)));
}; };
this.game.GraphicsDeviceManager.IsFullScreen = true;
this.view = this.game.Services.GetService(typeof(View)) as View;
this.SetContentView(this.view); var gameView = this.game.Services.GetService(typeof(View)) as View;
gameView.LayoutChange += (o, args) => {
// force the game size to update when the ad size changes
this.game.GraphicsDeviceManager.PreferredBackBufferWidth = args.Right - args.Left;
this.game.GraphicsDeviceManager.PreferredBackBufferHeight = args.Bottom - args.Top;
this.game.GraphicsDeviceManager.ApplyChanges();
};
// render under notches
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
// ad layout
var adLayout = new LinearLayout(this) {Orientation = Orientation.Vertical};
adLayout.SetGravity(GravityFlags.Bottom);
var ad = new AdView(this) {
AdSize = AdSize.SmartBanner,
#if DEBUG
AdUnitId = "ca-app-pub-3940256099942544/6300978111"
#else
AdUnitId = "ca-app-pub-5754829579653773/7841535920"
#endif
};
ad.LoadAd(new AdRequest.Builder().Build());
adLayout.AddView(ad);
// total layout that is displayed
this.mainView = new LinearLayout(this) {Orientation = Orientation.Vertical};
this.mainView.LayoutParameters = new LinearLayout.LayoutParams(MatchParent, MatchParent);
this.mainView.AddView(gameView);
// height of 0 but high weight causes this element so scale based on the ad's height
gameView.LayoutParameters = new LinearLayout.LayoutParams(MatchParent, 0, 1);
this.mainView.AddView(adLayout);
adLayout.LayoutParameters = new LinearLayout.LayoutParams(MatchParent, WrapContent);
this.SetContentView(this.mainView);
this.game.Run(); this.game.Run();
} }
public override void OnWindowFocusChanged(bool hasFocus) { public override void OnWindowFocusChanged(bool hasFocus) {
base.OnWindowFocusChanged(hasFocus);
// hide the status bar // hide the status bar
this.view.SystemUiVisibility = (StatusBarVisibility) (SystemUiFlags.LayoutStable | SystemUiFlags.LayoutHideNavigation | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky); this.mainView.SystemUiVisibility = (StatusBarVisibility) (SystemUiFlags.LayoutStable | SystemUiFlags.LayoutHideNavigation | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky);
base.OnWindowFocusChanged(hasFocus);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -284,7 +284,7 @@ namespace TouchyTickets {
IsHidden = true, IsHidden = true,
OnDrawn = (e, time, batch, alpha) => batch.Draw(batch.GetBlankTexture(), e.DisplayArea, ColorExtensions.FromHex(0xff86bccf) * alpha) OnDrawn = (e, time, batch, alpha) => batch.Draw(batch.GetBlankTexture(), e.DisplayArea, ColorExtensions.FromHex(0xff86bccf) * alpha)
}; };
var upgradeHeader = upgradeUi.AddChild(new Group(Anchor.AutoLeft, new Vector2(1, 0.27F), false)); var upgradeHeader = upgradeUi.AddChild(new Group(Anchor.AutoLeft, new Vector2(1)));
upgradeHeader.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.Stars + "<i star>", true) {TextScale = 0.3F}); upgradeHeader.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.Stars + "<i star>", true) {TextScale = 0.3F});
upgradeHeader.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.8F, 30), Localization.Get("EarnStar")) { upgradeHeader.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.8F, 30), Localization.Get("EarnStar")) {
PositionOffset = new Vector2(0, 4), PositionOffset = new Vector2(0, 4),
@ -318,9 +318,10 @@ namespace TouchyTickets {
upgradeHeader.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => string.Format(Localization.Get("RequiresTickets"), PrettyPrintNumber(GameImpl.Instance.GetStarPrice()), GameImpl.Instance.GetMaxStars()), true) { upgradeHeader.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => string.Format(Localization.Get("RequiresTickets"), PrettyPrintNumber(GameImpl.Instance.GetStarPrice()), GameImpl.Instance.GetMaxStars()), true) {
PositionOffset = new Vector2(0, 2) PositionOffset = new Vector2(0, 2)
}); });
var upgradeList = upgradeUi.AddChild(new Panel(Anchor.AutoLeft, new Vector2(1, 0.73F), Vector2.Zero, false, true, new Point(10, 30), false) { var upgradeList = upgradeUi.AddChild(new Panel(Anchor.AutoLeft, new Vector2(1), Vector2.Zero, false, true, new Point(10, 30), false) {
ChildPadding = new Padding(5, 15, 5, 5) ChildPadding = new Padding(5, 15, 5, 5)
}); });
upgradeHeader.OnAreaUpdated += e => upgradeList.Size = new Vector2(1, (upgradeUi.DisplayArea.Height - upgradeHeader.DisplayArea.Height) / e.Scale);
PopulateUpgradeList(upgradeList); PopulateUpgradeList(upgradeList);
this.uiSystem.Add("Upgrade", upgradeUi); this.uiSystem.Add("Upgrade", upgradeUi);