Browse Source

Get Android building and running.

CartBlanche 1 week ago
parent
commit
82cdb4faf4

+ 3 - 1
CardsStarterKit/Core/Game/Blackjack.Core.csproj

@@ -14,7 +14,9 @@
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
   </PropertyGroup>
   </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
-    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.*" />
+    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.*">
+      <PrivateAssets>All</PrivateAssets>
+    </PackageReference>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\Framework\Cards.Framework.csproj" />
     <ProjectReference Include="..\..\Framework\Cards.Framework.csproj" />

+ 2 - 4
CardsStarterKit/Core/Game/BlackjackGame.cs

@@ -45,6 +45,8 @@ namespace Blackjack
             else if (UIUtility.IsDesktop)
             else if (UIUtility.IsDesktop)
             {
             {
                 graphicsDeviceManager.IsFullScreen = false;
                 graphicsDeviceManager.IsFullScreen = false;
+                graphicsDeviceManager.PreferredBackBufferWidth = ScreenManager.BASE_BUFFER_WIDTH;
+                graphicsDeviceManager.PreferredBackBufferHeight = ScreenManager.BASE_BUFFER_HEIGHT;
                 IsMouseVisible = true;
                 IsMouseVisible = true;
             }
             }
             else
             else
@@ -66,10 +68,6 @@ namespace Blackjack
         protected override void Initialize()
         protected override void Initialize()
         {
         {
             base.Initialize();
             base.Initialize();
-
-            graphicsDeviceManager.PreferredBackBufferWidth = ScreenManager.BASE_BUFFER_WIDTH;
-            graphicsDeviceManager.PreferredBackBufferHeight = ScreenManager.BASE_BUFFER_HEIGHT;
-            graphicsDeviceManager.ApplyChanges();
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 1 - 1
CardsStarterKit/Core/Game/ScreenManager/ScreenManager.cs

@@ -398,7 +398,7 @@ namespace GameStateManagement
             spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, GlobalTransformation);
             spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, GlobalTransformation);
 
 
             spriteBatch.Draw(blankTexture,
             spriteBatch.Draw(blankTexture,
-                             new Rectangle(0, 0, BASE_BUFFER_WIDTH, BASE_BUFFER_HEIGHT),
+                             new Rectangle(0, 0, backbufferWidth, backbufferHeight),
                              Color.Black * alpha);
                              Color.Black * alpha);
 
 
             spriteBatch.End();
             spriteBatch.End();

+ 16 - 19
CardsStarterKit/Platforms/Android/AndroidManifest.xml

@@ -1,23 +1,20 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
-          package="com.monogame.roleplayinggame" 
-          android:versionCode="1" 
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.cartblanche.blackjack"
+          android:versionCode="1"
           android:versionName="1.0">
           android:versionName="1.0">
-  
-  <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="34" />
-  
-  <uses-permission android:name="android.permission.INTERNET" />
-  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-  <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
-  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-  
-  <application android:allowBackup="true" 
-               android:icon="@drawable/icon" 
-               android:label="@string/app_name"
-               android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
-    
-  </application>
-  
+
   <uses-feature android:glEsVersion="0x00020000" android:required="true" />
   <uses-feature android:glEsVersion="0x00020000" android:required="true" />
-  
+  <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="35" />
+  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+  <uses-permission android:name="android.permission.INTERNET" />
+  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+
+  <application
+    android:hardwareAccelerated="true"
+    android:icon="@drawable/icon"
+    android:isGame="true"
+    android:label="@string/app_name"
+    android:theme="@style/MainTheme" />
+
 </manifest>
 </manifest>

+ 3 - 0
CardsStarterKit/Platforms/Android/BlackJack.Android.csproj

@@ -12,6 +12,9 @@
     <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
     <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
     <AndroidApplication>True</AndroidApplication>
     <AndroidApplication>True</AndroidApplication>
     <SupportedOSPlatformVersion>28.0</SupportedOSPlatformVersion>
     <SupportedOSPlatformVersion>28.0</SupportedOSPlatformVersion>
+    <ApplicationId>com.cartblanche.blackjack</ApplicationId>
+    <ApplicationVersion>1</ApplicationVersion>
+    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
   </PropertyGroup>
   </PropertyGroup>
   
   
   <ItemGroup>
   <ItemGroup>

+ 1 - 0
CardsStarterKit/Platforms/Android/MainActivity.cs

@@ -11,6 +11,7 @@ namespace BlackJack.Android
         Label = "@string/app_name",
         Label = "@string/app_name",
         MainLauncher = true,
         MainLauncher = true,
         Icon = "@drawable/icon",
         Icon = "@drawable/icon",
+        Theme = "@style/Theme.Splash",
         AlwaysRetainTaskState = true,
         AlwaysRetainTaskState = true,
         LaunchMode = LaunchMode.SingleInstance,
         LaunchMode = LaunchMode.SingleInstance,
         ScreenOrientation = ScreenOrientation.SensorLandscape,
         ScreenOrientation = ScreenOrientation.SensorLandscape,

BIN
CardsStarterKit/Platforms/Android/Resources/drawable-hdpi/icon.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-hdpi/splash.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-mdpi/icon.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-mdpi/splash.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-xhdpi/icon.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-xhdpi/splash.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-xxhdpi/icon.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-xxhdpi/splash.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-xxxhdpi/icon.png


BIN
CardsStarterKit/Platforms/Android/Resources/drawable-xxxhdpi/splash.png


+ 17 - 0
CardsStarterKit/Platforms/Android/Resources/values/Styles.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+  <style name="Theme.Splash" parent="android:Theme">
+    <item name="android:windowBackground">@drawable/splash</item>
+    <item name="android:windowNoTitle">true</item>
+  </style>
+  <style name="MainTheme">
+    <!-- Set theme colors from https://aka.ms/material-colors -->
+    <!-- colorPrimary is used for the default action bar background -->
+    <!--<item name="colorPrimary">#2196F3</item>-->
+    <!-- colorPrimaryDark is used for the status bar -->
+    <!--<item name="colorPrimaryDark">#1976D2</item>-->
+    <!-- colorAccent is used as the default value for colorControlActivated
+         which is used to tint widgets -->
+    <!--<item name="colorAccent">#FF4081</item>-->
+  </style>
+</resources>

+ 4 - 0
CardsStarterKit/Platforms/Android/Resources/values/ic_launcher_background.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="ic_launcher_background">#9ACEEB</color>
+</resources>

+ 106 - 0
CardsStarterKit/Tools/ScaleAndroidIcons.ps1

@@ -0,0 +1,106 @@
+# Scale Android Icons to Multiple Densities
+# This script takes a source icon and scales it to all required Android densities
+
+param(
+    [string]$SourceIcon = "..\Platforms\Android\Resources\drawable\icon.png",
+    [string]$OutputBase = "..\Platforms\Android\Resources"
+)
+
+Add-Type -AssemblyName System.Drawing
+
+# Define Android density sizes for launcher icons
+$densities = @{
+    "drawable-mdpi" = 48
+    "drawable-hdpi" = 72
+    "drawable-xhdpi" = 96
+    "drawable-xxhdpi" = 144
+    "drawable-xxxhdpi" = 192
+}
+
+# Resolve paths
+$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
+$sourcePath = Join-Path $scriptDir $SourceIcon
+$outputBasePath = Join-Path $scriptDir $OutputBase
+
+Write-Host "Source icon: $sourcePath" -ForegroundColor Cyan
+Write-Host "Output base: $outputBasePath" -ForegroundColor Cyan
+Write-Host ""
+
+if (-not (Test-Path $sourcePath)) {
+    Write-Host "Error: Source icon not found at $sourcePath" -ForegroundColor Red
+    exit 1
+}
+
+# Load source image
+$sourceImage = [System.Drawing.Image]::FromFile($sourcePath)
+Write-Host "Source image size: $($sourceImage.Width)x$($sourceImage.Height)" -ForegroundColor Yellow
+
+# Check if image is square
+if ($sourceImage.Width -ne $sourceImage.Height) {
+    Write-Host "Warning: Source image is not square. Will scale to fit within square bounds." -ForegroundColor Yellow
+    $maxDimension = [Math]::Max($sourceImage.Width, $sourceImage.Height)
+} else {
+    $maxDimension = $sourceImage.Width
+}
+
+Write-Host ""
+
+# Process each density
+foreach ($density in $densities.GetEnumerator()) {
+    $targetSize = $density.Value
+    $outputDir = Join-Path $outputBasePath $density.Key
+    $outputPath = Join-Path $outputDir "icon.png"
+
+    # Create directory if it doesn't exist
+    if (-not (Test-Path $outputDir)) {
+        New-Item -Path $outputDir -ItemType Directory -Force | Out-Null
+    }
+
+    Write-Host "Scaling to $($density.Key): ${targetSize}x${targetSize} px" -ForegroundColor Green
+
+    # Create new bitmap
+    $newBitmap = New-Object System.Drawing.Bitmap($targetSize, $targetSize)
+    $graphics = [System.Drawing.Graphics]::FromImage($newBitmap)
+
+    # Set high quality rendering
+    $graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
+    $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
+    $graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
+    $graphics.CompositingQuality = [System.Drawing.Drawing2D.CompositingQuality]::HighQuality
+
+    # Calculate scaling to fit within target size (maintain aspect ratio)
+    $scaleWidth = $targetSize / $sourceImage.Width
+    $scaleHeight = $targetSize / $sourceImage.Height
+    $scale = [Math]::Min($scaleWidth, $scaleHeight)
+
+    $newWidth = [int]($sourceImage.Width * $scale)
+    $newHeight = [int]($sourceImage.Height * $scale)
+
+    # Center the image
+    $x = [int](($targetSize - $newWidth) / 2)
+    $y = [int](($targetSize - $newHeight) / 2)
+
+    # Clear background (transparent)
+    $graphics.Clear([System.Drawing.Color]::Transparent)
+
+    # Draw the scaled image
+    $destRect = New-Object System.Drawing.Rectangle($x, $y, $newWidth, $newHeight)
+    $srcRect = New-Object System.Drawing.Rectangle(0, 0, $sourceImage.Width, $sourceImage.Height)
+    $graphics.DrawImage($sourceImage, $destRect, $srcRect, [System.Drawing.GraphicsUnit]::Pixel)
+
+    # Save the image
+    $newBitmap.Save($outputPath, [System.Drawing.Imaging.ImageFormat]::Png)
+
+    # Cleanup
+    $graphics.Dispose()
+    $newBitmap.Dispose()
+
+    Write-Host "  -> Saved to: $outputPath" -ForegroundColor Gray
+}
+
+# Cleanup source image
+$sourceImage.Dispose()
+
+Write-Host ""
+Write-Host "Icon scaling complete!" -ForegroundColor Green
+Write-Host "All density icons have been generated." -ForegroundColor Green

+ 99 - 0
CardsStarterKit/Tools/ScaleAndroidSplash.ps1

@@ -0,0 +1,99 @@
+# Scale Android Splash Screens to Multiple Densities
+# This script takes a source splash image and scales it to all required Android densities
+
+param(
+    [string]$SourceSplash = "..\Platforms\Android\Resources\drawable\icon.png",  # Using icon as base for now
+    [string]$OutputBase = "..\Platforms\Android\Resources",
+    [int]$Width = 480,   # Default landscape width for splash
+    [int]$Height = 320   # Default landscape height for splash
+)
+
+Add-Type -AssemblyName System.Drawing
+
+# Define Android density multipliers for splash screens (landscape orientation)
+$densities = @{
+    "drawable-mdpi" = @{ Width = 480; Height = 320 }      # 1x
+    "drawable-hdpi" = @{ Width = 800; Height = 480 }      # 1.5x
+    "drawable-xhdpi" = @{ Width = 1280; Height = 720 }    # 2x
+    "drawable-xxhdpi" = @{ Width = 1600; Height = 960 }   # 3x
+    "drawable-xxxhdpi" = @{ Width = 1920; Height = 1280 } # 4x
+}
+
+# Resolve paths
+$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
+$sourcePath = Join-Path $scriptDir $SourceSplash
+$outputBasePath = Join-Path $scriptDir $OutputBase
+
+Write-Host "Source splash: $sourcePath" -ForegroundColor Cyan
+Write-Host "Output base: $outputBasePath" -ForegroundColor Cyan
+Write-Host ""
+
+if (-not (Test-Path $sourcePath)) {
+    Write-Host "Error: Source splash not found at $sourcePath" -ForegroundColor Red
+    exit 1
+}
+
+# Load source image
+$sourceImage = [System.Drawing.Image]::FromFile($sourcePath)
+Write-Host "Source image size: $($sourceImage.Width)x$($sourceImage.Height)" -ForegroundColor Yellow
+Write-Host ""
+
+# Process each density
+foreach ($density in $densities.GetEnumerator()) {
+    $targetWidth = $density.Value.Width
+    $targetHeight = $density.Value.Height
+    $outputDir = Join-Path $outputBasePath $density.Key
+    $outputPath = Join-Path $outputDir "splash.png"
+
+    # Create directory if it doesn't exist
+    if (-not (Test-Path $outputDir)) {
+        New-Item -Path $outputDir -ItemType Directory -Force | Out-Null
+    }
+
+    Write-Host "Creating splash for $($density.Key): ${targetWidth}x${targetHeight} px" -ForegroundColor Green
+
+    # Create new bitmap with solid background color
+    $newBitmap = New-Object System.Drawing.Bitmap($targetWidth, $targetHeight)
+    $graphics = [System.Drawing.Graphics]::FromImage($newBitmap)
+
+    # Set high quality rendering
+    $graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
+    $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
+    $graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
+    $graphics.CompositingQuality = [System.Drawing.Drawing2D.CompositingQuality]::HighQuality
+
+    # Fill background with a color (matching the launcher background color from ic_launcher_background.xml)
+    $backgroundColor = [System.Drawing.Color]::FromArgb(255, 154, 206, 235)  # #9ACEEB
+    $graphics.Clear($backgroundColor)
+
+    # Calculate scaling to fit icon centered in splash screen (maintain aspect ratio)
+    # Use 40% of splash screen height for icon size
+    $iconHeight = [int]($targetHeight * 0.4)
+    $scale = $iconHeight / $sourceImage.Height
+    $iconWidth = [int]($sourceImage.Width * $scale)
+
+    # Center the icon
+    $x = [int](($targetWidth - $iconWidth) / 2)
+    $y = [int](($targetHeight - $iconHeight) / 2)
+
+    # Draw the scaled icon
+    $destRect = New-Object System.Drawing.Rectangle($x, $y, $iconWidth, $iconHeight)
+    $srcRect = New-Object System.Drawing.Rectangle(0, 0, $sourceImage.Width, $sourceImage.Height)
+    $graphics.DrawImage($sourceImage, $destRect, $srcRect, [System.Drawing.GraphicsUnit]::Pixel)
+
+    # Save the image
+    $newBitmap.Save($outputPath, [System.Drawing.Imaging.ImageFormat]::Png)
+
+    # Cleanup
+    $graphics.Dispose()
+    $newBitmap.Dispose()
+
+    Write-Host "  -> Saved to: $outputPath" -ForegroundColor Gray
+}
+
+# Cleanup source image
+$sourceImage.Dispose()
+
+Write-Host ""
+Write-Host "Splash screen scaling complete!" -ForegroundColor Green
+Write-Host "All density splash screens have been generated." -ForegroundColor Green