diff --git a/android/app/src/main/java/com/metin2/ava2/Ava2Activity.java b/android/app/src/main/java/com/metin2/ava2/Ava2Activity.java index 300fd294..8aed03ff 100644 --- a/android/app/src/main/java/com/metin2/ava2/Ava2Activity.java +++ b/android/app/src/main/java/com/metin2/ava2/Ava2Activity.java @@ -1,8 +1,14 @@ package com.metin2.ava2; +import android.content.Context; import android.content.pm.ActivityInfo; +import android.graphics.Insets; +import android.os.Build; +import android.view.View; +import android.view.WindowInsets; import org.libsdl.app.SDLActivity; +import org.libsdl.app.SDLSurface; /** * SDLActivity with command-line arguments for development runs: @@ -26,4 +32,37 @@ public class Ava2Activity extends SDLActivity { public void setOrientationBis(int w, int h, boolean resizable, String hint) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } + + @Override + protected SDLSurface createSDLSurface(Context context) { + return new Ava2Surface(context); + } + + /** + * SDL folds the system-gesture insets into the safe area. In landscape fullscreen the status bar + * is hidden, but its swipe-down gesture zone still reported a 120 px top inset, which pushed the + * top HUD row down. Keep SDL's left/right/bottom; take the top only from what really covers the + * screen there (display cutout and visible system bars). + */ + static class Ava2Surface extends SDLSurface { + Ava2Surface(Context context) { + super(context); + } + + @Override + public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { + WindowInsets result = super.onApplyWindowInsets(v, insets); + if (Build.VERSION.SDK_INT >= 30 /* Android 11 (R) */) { + Insets combined = insets.getInsets(WindowInsets.Type.systemBars() | + WindowInsets.Type.systemGestures() | + WindowInsets.Type.mandatorySystemGestures() | + WindowInsets.Type.tappableElement() | + WindowInsets.Type.displayCutout()); + Insets covering = insets.getInsets(WindowInsets.Type.systemBars() | + WindowInsets.Type.displayCutout()); + SDLActivity.onNativeInsetsChanged(combined.left, combined.right, covering.top, combined.bottom); + } + return result; + } + } } diff --git a/docs/PORT-PLAN.md b/docs/PORT-PLAN.md index 7193e502..86d13730 100644 --- a/docs/PORT-PLAN.md +++ b/docs/PORT-PLAN.md @@ -1568,3 +1568,24 @@ Verified: `ava2.speedtree_forest` (without that option the 9 asset tests are skipped). - Desktop phone layout and the device both render trees with real branches and fronds. - Device game phase: 60.3 fps, max frame gap 16.6 ms, 0 frames over 25 ms. + +### 2026-10-13 Mobile HUD: minimap frame and top inset + +- Minimap outside its frame (preview): with `--preview-data` no map loads, so + `miniMap.Render` returns early and the green circle was app_loop's dev radar, drawn at + the fixed PC spot `(screen_width - 132, 5)`. `CPythonMiniMap::Render` now records the + window position before the map check (`GetScreenPosition`), and the radar draws there. + It opens the minimap once via `ShowMiniMap()` (normally `AtlasInfo` does that on map + load), so `CanShow()` follows its close/open buttons. A real map was not affected. +- Top HUD row too low: SDL folds system-gesture insets into the safe area. In landscape + fullscreen the status bar is hidden but its swipe zone still gave a 120 px (67 logical) + top inset. `Ava2Activity.Ava2Surface` re-sends the insets with the top taken only from + the display cutout and visible system bars (device cutout is left-only). +- The preview keyboard-hint header is not drawn in touch mode; it overlapped the HUD. +- `--game-script` now also runs with `--preview-data` (desktop probing of the mobile HUD). + +Verified on the device: minimap inside its frame, portrait/status bars and the entry row +at the top edge. Desktop ctest 59/59. + +Outstanding: after a tap the cursor stays where the finger lifted, so hover tooltips +(e.g. "[F6] Battle pass") remain until the next touch. diff --git a/src/app/app_loop.cpp b/src/app/app_loop.cpp index a4aef526..842b1fc3 100644 --- a/src/app/app_loop.cpp +++ b/src/app/app_loop.cpp @@ -27,6 +27,7 @@ #include "python_event_manager.h" #include "python_system.h" #include "python_background.h" +#include "python_minimap.h" #include "eter_base/Random.h" #include #include @@ -776,6 +777,7 @@ ava2::app::AppLoop::Frame RunClient(ava2::app::AppLoop* loop, int argc, char** a // Initialize Minimap Radar System ava2::MinimapManager minimap_mgr; + bool minimap_preview_opened = false; minimap_mgr.SetWorldBounds(outdoor_terrain.GetWorldMinX(), outdoor_terrain.GetWorldMaxX(), outdoor_terrain.GetWorldMinZ(), outdoor_terrain.GetWorldMaxZ()); std::string minimap_path = "map/metin2_map_a1/001003/minimap.dds"; @@ -2113,25 +2115,25 @@ const auto profileActiveStart = std::chrono::steady_clock::now(); } #ifdef AVA2_HAS_PYTHON + // One-shot integration verification against the real GameWindow (also with --preview-data). + if (last_phase == "game" && python && !game_script.empty() && !game_script_executed && rendered_game_frames >= 3) { + FILE* script = std::fopen(game_script.c_str(), "rb"); + if (!script) throw std::runtime_error("Cannot open --game-script"); + std::string code; + char chunk[4096]; + while (size_t size = std::fread(chunk, 1, sizeof(chunk), script)) code.append(chunk, size); + const bool failed = std::ferror(script); + std::fclose(script); + if (failed) throw std::runtime_error("Cannot read --game-script"); + python->execute(code); + game_script_executed = true; + } if (last_phase == "game" && !preview_data) { int rotateInput=0,pitchInput=0,zoomInput=0; ava2::GetCameraInput(rotateInput,pitchInput,zoomInput); orbit_camera.SetYaw(orbit_camera.GetYaw()+rotateInput*60.0f*dt); orbit_camera.SetPitch(orbit_camera.GetPitch()+pitchInput*45.0f*dt); if (zoomInput) orbit_camera.SetDistance(orbit_camera.GetDistance()*std::exp(zoomInput*dt)); - // One-shot integration verification against the real GameWindow. - if (python && !game_script.empty() && !game_script_executed && rendered_game_frames >= 3) { - FILE* script = std::fopen(game_script.c_str(), "rb"); - if (!script) throw std::runtime_error("Cannot open --game-script"); - std::string code; - char chunk[4096]; - while (size_t size = std::fread(chunk, 1, sizeof(chunk), script)) code.append(chunk, size); - const bool failed = std::ferror(script); - std::fclose(script); - if (failed) throw std::runtime_error("Cannot read --game-script"); - python->execute(code); - game_script_executed = true; - } // Network/loading callbacks can replace the map during this frame. // Resolve owners again after pumping packets instead of retaining freed terrain. active_terrain = ava2::CPythonBackground::Instance().GetTerrain(); @@ -2499,8 +2501,30 @@ const auto profileActiveStart = std::chrono::steady_clock::now(); SDL_UpdateTexture(minimap_texture.get(), nullptr, minimap_surface->pixels, minimap_surface->pitch); minimap_last_radar = radar;minimap_radar_valid = true; } + // Inside the uiminimap.MiniMap frame (the mobile HUD moves it), at the + // offset its OnRender passes to miniMap.Render; hidden with the minimap. SDL_FRect dst = { static_cast(screen_width - 132), 5.0f, 128.0f, 128.0f }; - SDL_RenderTexture(renderer.get(), minimap_texture.get(), nullptr, &dst); + bool radar_shown = true; +#ifdef AVA2_HAS_PYTHON + if (python) { + auto& mini_map = ava2::CPythonMiniMap::Instance(); + float sx = 0.0f, sy = 0.0f; + mini_map.GetScreenPosition(&sx, &sy); + if (sx != 0.0f || sy != 0.0f) { + dst.x = sx; dst.y = sy; + // No map loads in preview, so MiniMap.AtlasInfo never opens the minimap; + // open it once so its close/open buttons drive the radar. + if (!minimap_preview_opened) { + python->execute( + "if 'stream' in globals() and stream.curPhaseWindow and hasattr(stream.curPhaseWindow, 'interface'):\n" + " stream.curPhaseWindow.interface.wndMiniMap.ShowMiniMap()\n"); + minimap_preview_opened = true; + } + radar_shown = mini_map.CanShow(); + } + } +#endif + if (radar_shown) SDL_RenderTexture(renderer.get(), minimap_texture.get(), nullptr, &dst); } } } @@ -2543,8 +2567,8 @@ const auto profileActiveStart = std::chrono::steady_clock::now(); } } - if (original_phase_mode && preview_data) { - // Informative header for interactive mode + if (original_phase_mode && preview_data && !touch_mode) { + // Informative header for interactive mode (keyboard hints; the mobile HUD owns the top row) SDL_SetRenderDrawColor(renderer.get(), 200, 220, 240, 200); std::string hud; if (last_phase == "select") { diff --git a/src/scripting/python_minimap.cpp b/src/scripting/python_minimap.cpp index 08185c37..75a5a3fa 100644 --- a/src/scripting/python_minimap.cpp +++ b/src/scripting/python_minimap.cpp @@ -293,13 +293,8 @@ void CPythonMiniMap::Update(float fCenterX, float fCenterY) void CPythonMiniMap::Render(float fScreenX, float fScreenY) { - // CPythonBackground::IsMapReady is implied by GetOutdoorMap (the terrain block loaded). - if (!GetOutdoorMap()) - return; - - if (!m_bShow) - return; - + // Record the window position even before a map is ready: the --preview-data radar + // (app_loop) draws into the minimap frame through GetScreenPosition. if (m_fScreenX != fScreenX || m_fScreenY != fScreenY) { m_fScreenX = fScreenX; @@ -307,6 +302,13 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY) __SetPosition(); } + // CPythonBackground::IsMapReady is implied by GetOutdoorMap (the terrain block loaded). + if (!GetOutdoorMap()) + return; + + if (!m_bShow) + return; + // Draw the native terrain minimap tiles under the existing player/NPC marks. auto* device = CGraphicDevice::InstancePtr(); if (auto* renderer = device ? device->GetRenderer() : nullptr) { @@ -1037,6 +1039,7 @@ void CPythonMiniMap::ShowAtlas() { m_bShowAtlas = true; } void CPythonMiniMap::HideAtlas() { m_bShowAtlas = false; } bool CPythonMiniMap::CanShowAtlas() { return m_bShowAtlas; } bool CPythonMiniMap::CanShow() { return m_bShow; } +void CPythonMiniMap::GetScreenPosition(float* pfx, float* pfy) const { *pfx = m_fScreenX; *pfy = m_fScreenY; } void CPythonMiniMap::Show() { m_bShow = true; } void CPythonMiniMap::Hide() { m_bShow = false; } diff --git a/src/scripting/python_minimap.h b/src/scripting/python_minimap.h index b4896dda..ed4232c6 100644 --- a/src/scripting/python_minimap.h +++ b/src/scripting/python_minimap.h @@ -63,6 +63,8 @@ public: void Update(float fCenterX, float fCenterY); void Render(float fScreenX, float fScreenY); + // Last position passed to Render (0,0 before the minimap window first rendered). + void GetScreenPosition(float* pfx, float* pfy) const; void Show(); void Hide();