Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db7bb624e4 | ||
|
|
4a8a554396 | ||
|
|
ffc7577ddc | ||
|
|
b577e8411b | ||
|
|
10103c82a0 | ||
|
|
4e7c737c1c | ||
|
|
6c96e8a119 | ||
|
|
87829c5dd6 | ||
|
|
e736bb7ec7 | ||
|
|
3236a6176a | ||
|
|
fae1cb89bb | ||
|
|
7b01f675a7 | ||
|
|
beefec7df0 | ||
|
|
f8ee130b45 | ||
|
|
f12ef05421 | ||
|
|
1732b31031 | ||
|
|
b14ca1c8c9 |
No files matched your search
@@ -1,106 +0,0 @@
|
||||
name: Android Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Build Release APK
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x droid/gradlew
|
||||
|
||||
- name: Create keystore directory
|
||||
run: mkdir -p ~/.android
|
||||
|
||||
- name: Decode Keystore
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
echo "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore
|
||||
echo "Keystore decoded successfully"
|
||||
|
||||
- name: Copy Assets to Android Project
|
||||
run: ./scripts/copy-android-assets.sh
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
|
||||
- name: Build Release APK
|
||||
working-directory: ./droid
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
||||
run: |
|
||||
./gradlew assembleRelease \
|
||||
-Pkeystore.password="$KEYSTORE_PASSWORD" \
|
||||
-Pkeystore.path="/home/runner/.android/inbe-release.keystore" \
|
||||
--stacktrace
|
||||
|
||||
- name: Rename APK
|
||||
run: |
|
||||
VERSION=$(grep "versionName" droid/app/build.gradle | awk '{print $2}' | tr -d '"')
|
||||
find droid/app/build/outputs/apk/release -name "*-universal-release.apk" -exec cp {} inbe-$VERSION.apk \; 2>/dev/null || true
|
||||
|
||||
- name: Upload APK to Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-apk
|
||||
path: inbe-*.apk
|
||||
if-no-files-found: warn
|
||||
|
||||
- name: Create and Push Tag (if new version)
|
||||
id: tag_version
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
VERSION=$(grep "versionName" droid/app/build.gradle | awk '{print $2}' | tr -d '"')
|
||||
TAG="v$VERSION"
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG exists, skipping"
|
||||
echo "tag_pushed=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "$TAG" -m "Release $VERSION"
|
||||
git push origin "$TAG"
|
||||
echo "tag_pushed=true" >> $GITHUB_OUTPUT
|
||||
echo "tag_name=$TAG" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Create GitHub Release
|
||||
if: steps.tag_version.outputs.tag_pushed == 'true'
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ steps.tag_version.outputs.tag_name }}
|
||||
files: inbe-*.apk
|
||||
generate_release_notes: true
|
||||
draft: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,37 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Test Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential zlib1g-dev
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
@@ -0,0 +1,316 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Test Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential zlib1g-dev
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
|
||||
build-web:
|
||||
name: Build Web
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Web Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential zlib1g-dev zip
|
||||
|
||||
- name: Set up Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
|
||||
"$HOME/emsdk/emsdk" install latest
|
||||
"$HOME/emsdk/emsdk" activate latest
|
||||
echo "EMSDK=$HOME/emsdk" >> "$GITHUB_ENV"
|
||||
echo "EM_CONFIG=$HOME/emsdk/.emscripten" >> "$GITHUB_ENV"
|
||||
echo "$HOME/emsdk" >> "$GITHUB_PATH"
|
||||
echo "$HOME/emsdk/upstream/emscripten" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Build Web ZIP
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make package-unpackaged-assets
|
||||
make web
|
||||
mkdir -p build/release/web
|
||||
cp build/dist/inbe-web.zip build/release/web/
|
||||
|
||||
- name: Upload Web Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-web
|
||||
path: build/release/web/*
|
||||
if-no-files-found: error
|
||||
|
||||
build-linux:
|
||||
name: Build Linux
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Linux Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
curl \
|
||||
libcurl4-openssl-dev \
|
||||
libdrm-dev \
|
||||
libegl1-mesa-dev \
|
||||
libgbm-dev \
|
||||
libgles2-mesa-dev \
|
||||
libsdl2-dev \
|
||||
patchelf \
|
||||
pkg-config \
|
||||
zip
|
||||
|
||||
- name: Install AppImage Tools
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
curl -L -o "$HOME/.local/bin/linuxdeploy" \
|
||||
https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
|
||||
curl -L -o "$HOME/.local/bin/linuxdeploy-plugin-appimage" \
|
||||
https://github.com/linuxdeploy/linuxdeploy-plugin-appimage/releases/download/1-alpha-20250213-1/linuxdeploy-plugin-appimage-x86_64.AppImage
|
||||
curl -L -o "$HOME/.local/bin/appimagetool" \
|
||||
https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
|
||||
chmod +x "$HOME/.local/bin/linuxdeploy" "$HOME/.local/bin/linuxdeploy-plugin-appimage" "$HOME/.local/bin/appimagetool"
|
||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Build Linux AppImage
|
||||
env:
|
||||
APPIMAGE_EXTRACT_AND_RUN: "1"
|
||||
RAY_RAYLIB_CONFIG: -DSUPPORT_SCREEN_CAPTURE=0 -DSUPPORT_COMPRESSION_API=0 -DSUPPORT_AUTOMATION_EVENTS=0 -DSUPPORT_CLIPBOARD_IMAGE=0 -DSUPPORT_FILEFORMAT_BMP=0 -DSUPPORT_FILEFORMAT_GIF=0 -DSUPPORT_FILEFORMAT_QOI=0 -DSUPPORT_FILEFORMAT_DDS=0 -DSUPPORT_FILEFORMAT_TTF=0
|
||||
run: |
|
||||
set -euo pipefail
|
||||
RAY_SDL_INCLUDE_DIR="$(pkg-config --variable=includedir sdl2 | sed 's,/SDL2$,,')"
|
||||
RAY_CFLAGS="$(pkg-config --cflags sdl2 libdrm gbm egl glesv2)"
|
||||
RAY_LDLIBS="$(pkg-config --libs sdl2 libdrm gbm egl glesv2)"
|
||||
RAY_SDL_LDLIBS="$(pkg-config --libs sdl2)"
|
||||
export RAY_SDL_INCLUDE_DIR RAY_CFLAGS RAY_LDLIBS RAY_SDL_LDLIBS
|
||||
make appimage
|
||||
mkdir -p build/release/linux
|
||||
find build/dist/linux -maxdepth 1 -type f -name '*.AppImage' -exec cp {} build/release/linux/ \;
|
||||
test -n "$(find build/release/linux -type f -print -quit)"
|
||||
|
||||
- name: Upload Linux Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-linux
|
||||
path: build/release/linux/*
|
||||
if-no-files-found: error
|
||||
|
||||
build-windows:
|
||||
name: Build Windows
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Windows Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
gcc-mingw-w64-i686-win32 \
|
||||
gcc-mingw-w64-x86-64-win32 \
|
||||
zlib1g-dev \
|
||||
zip
|
||||
if [ -x /usr/bin/x86_64-w64-mingw32-gcc-win32 ]; then
|
||||
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-win32
|
||||
fi
|
||||
if [ -x /usr/bin/i686-w64-mingw32-gcc-win32 ]; then
|
||||
sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-win32
|
||||
fi
|
||||
|
||||
- name: Build Windows ZIP
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make windows
|
||||
mkdir -p build/release/windows
|
||||
find build/dist/windows -maxdepth 1 -type f -name '*.zip' -exec cp {} build/release/windows/ \;
|
||||
test -n "$(find build/release/windows -type f -print -quit)"
|
||||
|
||||
- name: Upload Windows Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-windows
|
||||
path: build/release/windows/*
|
||||
if-no-files-found: error
|
||||
|
||||
build-android:
|
||||
name: Build Android
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
|
||||
- name: Install Android SDK Components
|
||||
run: |
|
||||
set -euo pipefail
|
||||
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
|
||||
yes | "$SDKMANAGER" --licenses >/dev/null || true
|
||||
"$SDKMANAGER" "platforms;android-35" "build-tools;34.0.0" "ndk;25.1.8937393" "cmake;3.22.1"
|
||||
|
||||
- name: Prepare Android signing key
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p ~/.android
|
||||
echo "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore
|
||||
|
||||
- name: Copy Android Assets
|
||||
run: ./scripts/copy-android-assets.sh
|
||||
|
||||
- name: Build Android APK
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
chmod +x droid/gradlew
|
||||
./droid/gradlew -p droid assembleRelease \
|
||||
-Pkeystore.path="$HOME/.android/inbe-release.keystore" \
|
||||
-Pkeystore.alias="$KEY_ALIAS" \
|
||||
-Pkeystore.password="$KEYSTORE_PASSWORD" \
|
||||
--stacktrace
|
||||
make android-copy-release-apks
|
||||
|
||||
- name: Collect Android Release Files
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p build/release/android
|
||||
VERSION=$(sed -n 's/^#define INBE_VERSION_STRING "\([^"]*\)".*/\1/p' src/core/version.h)
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Could not read INBE_VERSION_STRING"
|
||||
exit 1
|
||||
fi
|
||||
cp "build/android/inbe-$VERSION.apk" build/release/android/
|
||||
|
||||
- name: Upload Android Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-android
|
||||
path: build/release/android/*
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build-web
|
||||
- build-linux
|
||||
- build-windows
|
||||
- build-android
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download Release Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: release-*
|
||||
path: build/release
|
||||
merge-multiple: true
|
||||
|
||||
- name: Verify Release Artifacts
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test -n "$(find build/release -type f -print -quit)"
|
||||
|
||||
- name: Create and Push Tag If Version Is New
|
||||
id: tag_version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION=$(sed -n 's/^#define INBE_VERSION_STRING "\([^"]*\)".*/\1/p' src/core/version.h)
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Could not read INBE_VERSION_STRING"
|
||||
exit 1
|
||||
fi
|
||||
TAG="v$VERSION"
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG exists, skipping release"
|
||||
echo "tag_pushed=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "$TAG" -m "Release $VERSION"
|
||||
git push origin "$TAG"
|
||||
echo "tag_pushed=true" >> "$GITHUB_OUTPUT"
|
||||
echo "tag_name=$TAG" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Create GitHub Release
|
||||
if: steps.tag_version.outputs.tag_pushed == 'true'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ steps.tag_version.outputs.tag_name }}
|
||||
files: build/release/*
|
||||
generate_release_notes: true
|
||||
draft: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,8 +1,23 @@
|
||||
# Changelog
|
||||
## [1.3.5] - 2026-06-18
|
||||
### Fixed
|
||||
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
|
||||
|
||||
## [1.3.4] - 2026-06-18
|
||||
### Changed
|
||||
- Reorganized WHM and Meditation into practice-owned modules for cleaner code boundaries.
|
||||
- Split the meditation manual into an image intro page and a shorter music/gong setup page.
|
||||
- Expanded release automation to build Web, Linux AppImage, Windows, APK, and AAB artifacts after tests pass.
|
||||
|
||||
## [1.3.3] - 2026-06-17
|
||||
### Fixed
|
||||
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
|
||||
|
||||
## [1.3.2] - 2026-06-17
|
||||
### Fixed
|
||||
- Unified scroll containers so content stays out of scrollbar tracks and scroll positions clamp cleanly at the bottom.
|
||||
- Android meditation audio downloads now show a localized network-permission/connectivity modal when the host cannot be resolved.
|
||||
- Windows builds now support runtime meditation audio downloads.
|
||||
|
||||
## [1.3.1] - 2026-06-17
|
||||
### Fixed
|
||||
|
||||
@@ -72,6 +72,7 @@ SQLITE_INCLUDE := -I$(SQLITE_BUILD_DIR)
|
||||
TEST_BIN_DIR := $(BUILD_BIN_DIR)/tests
|
||||
STORAGE_IMPORT_TEST := $(TEST_BIN_DIR)/storage_import_test
|
||||
FLINT_TEXT_SCALING_TEST := $(TEST_BIN_DIR)/flint_text_scaling_test
|
||||
LOCALE_KEYS_TEST := $(TEST_BIN_DIR)/locale_keys_test
|
||||
FLINT_RUNTIME_ASSET_CFLAGS := -DFLINT_HAS_LIBCURL=1 $(FLINT_CURL_CFLAGS)
|
||||
FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
|
||||
|
||||
@@ -79,10 +80,19 @@ APP_SRCS := \
|
||||
src/main.c \
|
||||
src/core/breath_engine.c \
|
||||
src/app/app.c \
|
||||
src/app/app_settings.c \
|
||||
src/app/device_preferences.c \
|
||||
src/session/session.c \
|
||||
src/practices/practice_registry.c \
|
||||
src/practices/whm/whm_practice.c \
|
||||
src/practices/whm/whm_session.c \
|
||||
src/practices/whm/whm_manual.c \
|
||||
src/practices/whm/whm_config.c \
|
||||
src/practices/meditation/meditation_practice.c \
|
||||
src/practices/meditation/meditation_session.c \
|
||||
src/practices/meditation/meditation_manual.c \
|
||||
src/practices/meditation/meditation_config.c \
|
||||
src/screens/habits_screen.c \
|
||||
src/session/meditation_music.c \
|
||||
src/practices/meditation/meditation_music.c \
|
||||
src/core/locale.c \
|
||||
src/core/theme.c \
|
||||
src/storage/data.c \
|
||||
@@ -95,7 +105,7 @@ APP_SRCS := \
|
||||
src/screens/settings/settings_screen.c
|
||||
|
||||
LOCALE_FILES := $(wildcard locales/*.txt)
|
||||
IMAGE_FILES := assets/whm/1.jpg assets/whm/2.jpg
|
||||
IMAGE_FILES := assets/practices/whm/1.jpg assets/practices/whm/2.jpg assets/practices/meditation/1.jpg
|
||||
SOUND_FILES := $(wildcard assets/sounds/*.ogg)
|
||||
FONT_OUTPUTS := assets/fonts/locales.png assets/fonts/locales.dat assets/fonts/locales-8.png assets/fonts/locales-8.dat
|
||||
OTFCHOP_DIR ?= vendor/otfchop
|
||||
@@ -105,14 +115,14 @@ EMBEDDED_ASSETS_C := $(BUILD_OBJ_DIR)/$(APP_NAME)_embedded_assets.c
|
||||
EMBEDDED_ASSET_FILES := $(LOCALE_FILES) $(IMAGE_FILES) $(SOUND_FILES) $(FONT_OUTPUTS)
|
||||
SRC := $(APP_SRCS) $(EMBEDDED_ASSETS_C)
|
||||
|
||||
APP_INCLUDE := -Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/session -Isrc/storage -Isrc/platform/android -Isrc/third_party
|
||||
APP_INCLUDE := -Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party
|
||||
APP_RAYLIB_CONFIG := $(filter-out -DSUPPORT_MODULE_RAUDIO=0 -DSUPPORT_FILEFORMAT_PNG=0 -DSUPPORT_FILEFORMAT_JPG=0 -DSUPPORT_FILEFORMAT_OGG=0 -DSUPPORT_FILEFORMAT_MP3=0,$(RAY_RAYLIB_CONFIG)) -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1 -DSUPPORT_FILEFORMAT_MP3=1
|
||||
CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1 -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_EMBEDDED_ONLY=1 $(FLINT_RUNTIME_ASSET_CFLAGS)
|
||||
WINDOWS_CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1 -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_EMBEDDED_ONLY=1
|
||||
WEB_CFLAGS := $(filter-out -std=c99,$(CFLAGS)) -std=gnu99
|
||||
LDFLAGS := -Wl,--gc-sections -s
|
||||
WINDOWS_LDFLAGS := -Wl,--gc-sections -static -static-libgcc -mwindows
|
||||
WINDOWS_LDLIBS := -lgdi32 -lwinmm -lopengl32 -luser32 -lshell32 -lole32 -lcomdlg32 -lcomctl32 -luuid -lm
|
||||
WINDOWS_LDLIBS := -lgdi32 -lwinmm -lopengl32 -luser32 -lshell32 -lole32 -lcomdlg32 -lcomctl32 -luuid -lwininet -lm
|
||||
ifneq ($(strip $(MCFGTHREADS)),)
|
||||
WIN64_THREAD_LDFLAGS := -L$(MCFGTHREADS)/lib
|
||||
else
|
||||
@@ -138,8 +148,10 @@ WEB_CC ?= emcc
|
||||
WEB_AR ?= emar
|
||||
WEB_CACHE_BUSTER ?= $(shell git rev-parse --short HEAD 2>/dev/null || date +%s)
|
||||
WEB_TARGET := $(WEB_DIST_DIR)/index.html
|
||||
WEB_DIST_ZIP := $(BUILD_DIST_DIR)/$(APP_NAME)-web.zip
|
||||
WEB_ASSET_FILES := $(shell find web-assets -type f 2>/dev/null)
|
||||
UNPACKAGED_AUDIO_DIR := unpackaged_assets/audio
|
||||
WEB_AUDIO_FILES := $(shell find $(UNPACKAGED_AUDIO_DIR) -type f 2>/dev/null)
|
||||
MEDITATION_AUDIO_ZIP := web-assets/dl/inbe-meditation-audio-v1.zip
|
||||
|
||||
.PHONY: all native run test dist appimage clean clean-linux clean-raylib android-check-keystore android-copy-assets android-debug android-release android-bundle android-install android-install-release android-clean package-unpackaged-assets windows-runtime-assets-check windows windows64 windows32 web
|
||||
@@ -175,13 +187,14 @@ appimage: $(APPIMAGE_TARGET)
|
||||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST)
|
||||
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST)
|
||||
$(STORAGE_IMPORT_TEST)
|
||||
$(FLINT_TEXT_SCALING_TEST)
|
||||
$(LOCALE_KEYS_TEST)
|
||||
|
||||
$(STORAGE_IMPORT_TEST): tests/storage_import_test.c src/storage/storage.c src/storage/storage.h src/screens/habits_screen.c src/screens/habits_screen.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -ffunction-sections -fdata-sections \
|
||||
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/session -Isrc/storage -Isrc/platform/android -Isrc/third_party -Ivendor/raylib/src $(FLINT_INCLUDE) $(SQLITE_INCLUDE) \
|
||||
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party -Ivendor/raylib/src $(FLINT_INCLUDE) $(SQLITE_INCLUDE) \
|
||||
-o $@ \
|
||||
tests/storage_import_test.c src/storage/storage.c src/screens/habits_screen.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
-Wl,--gc-sections -lm -lpthread -ldl
|
||||
@@ -193,6 +206,11 @@ $(FLINT_TEXT_SCALING_TEST): tests/flint_text_scaling_test.c flint/src/flint_text
|
||||
tests/flint_text_scaling_test.c flint/src/flint_text.c flint/src/flint_clip.c flint/src/flint_scaling.c \
|
||||
-Wl,--gc-sections -lm
|
||||
|
||||
$(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE \
|
||||
-o $@ \
|
||||
tests/locale_keys_test.c
|
||||
|
||||
$(BUILD_OBJ_DIR) $(LINUX_BIN_DIR) $(LINUX_DIST_DIR) $(LINUX_APPIMAGE_BUILD_DIR) $(WINDOWS_DIST_DIR) $(ANDROID_BUILD_DIR) $(TEST_BIN_DIR) $(WEB_OBJ_DIR) $(WEB_DIST_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
@@ -372,7 +390,7 @@ $(APPIMAGE_TARGET): $(TARGET) $(LINUX_APPIMAGE_APPRUN) $(LINUX_APPIMAGE_DESKTOP)
|
||||
--output appimage
|
||||
test -f $@
|
||||
|
||||
$(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(WEB_RAYLIB_A) src/web_shell.html manifest.json $(WEB_ASSET_FILES) | $(WEB_DIST_DIR)
|
||||
$(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(WEB_RAYLIB_A) src/web_shell.html manifest.json $(WEB_ASSET_FILES) $(WEB_AUDIO_FILES) | $(WEB_DIST_DIR)
|
||||
$(WEB_CC) $(WEB_CFLAGS) \
|
||||
$(APP_INCLUDE) \
|
||||
$(FLINT_INCLUDE) \
|
||||
@@ -392,6 +410,7 @@ $(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMA
|
||||
-sFORCE_FILESYSTEM=1 \
|
||||
-sFETCH=1 \
|
||||
-sALLOW_MEMORY_GROWTH=1 \
|
||||
--preload-file $(UNPACKAGED_AUDIO_DIR)@$(UNPACKAGED_AUDIO_DIR) \
|
||||
--shell-file src/web_shell.html \
|
||||
-lidbfs.js \
|
||||
-lm
|
||||
@@ -526,9 +545,7 @@ package-unpackaged-assets:
|
||||
cd $(UNPACKAGED_AUDIO_DIR) && find . -mindepth 2 -type f -name '*.ogg' -exec zip -9 -r $(abspath $(MEDITATION_AUDIO_ZIP)) {} + && zip -9 -r $(abspath $(MEDITATION_AUDIO_ZIP)) LICENSE.md MANIFEST.txt
|
||||
|
||||
windows-runtime-assets-check:
|
||||
@echo "Windows runtime asset downloads are not wired into this build yet"; \
|
||||
echo "Refusing to build Windows binaries that cannot download meditation audio."; \
|
||||
exit 1
|
||||
@:
|
||||
|
||||
windows64: windows-runtime-assets-check $(WIN64_TARGET)
|
||||
|
||||
@@ -546,6 +563,8 @@ windows:
|
||||
|
||||
web:
|
||||
$(MAKE) $(WEB_TARGET)
|
||||
rm -f $(WEB_DIST_ZIP)
|
||||
cd $(WEB_DIST_DIR) && zip -9 -r $(abspath $(WEB_DIST_ZIP)) .
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 54 KiB |
@@ -35,8 +35,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdk 19
|
||||
targetSdk 35
|
||||
versionCode 30
|
||||
versionName "1.3.2"
|
||||
versionCode 33
|
||||
versionName "1.3.5"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ file(GLOB INBE_LOCALE_ASSETS RELATIVE "${REPO_ROOT}" CONFIGURE_DEPENDS "${REPO_R
|
||||
file(GLOB INBE_SOUND_ASSETS RELATIVE "${REPO_ROOT}" CONFIGURE_DEPENDS "${REPO_ROOT}/assets/sounds/*.ogg")
|
||||
set(INBE_EMBEDDED_INPUTS
|
||||
${INBE_LOCALE_ASSETS}
|
||||
assets/whm/1.jpg
|
||||
assets/whm/2.jpg
|
||||
assets/practices/whm/1.jpg
|
||||
assets/practices/whm/2.jpg
|
||||
assets/practices/meditation/1.jpg
|
||||
assets/fonts/locales.png
|
||||
assets/fonts/locales.dat
|
||||
assets/fonts/locales-8.png
|
||||
@@ -88,10 +89,19 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/main.c"
|
||||
"${SRC_DIR}/core/breath_engine.c"
|
||||
"${SRC_DIR}/app/app.c"
|
||||
"${SRC_DIR}/app/app_settings.c"
|
||||
"${SRC_DIR}/app/device_preferences.c"
|
||||
"${SRC_DIR}/session/session.c"
|
||||
"${SRC_DIR}/practices/practice_registry.c"
|
||||
"${SRC_DIR}/practices/whm/whm_practice.c"
|
||||
"${SRC_DIR}/practices/whm/whm_session.c"
|
||||
"${SRC_DIR}/practices/whm/whm_manual.c"
|
||||
"${SRC_DIR}/practices/whm/whm_config.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_practice.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_session.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_manual.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_config.c"
|
||||
"${SRC_DIR}/screens/habits_screen.c"
|
||||
"${SRC_DIR}/session/meditation_music.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_music.c"
|
||||
"${SRC_DIR}/core/locale.c"
|
||||
"${SRC_DIR}/core/theme.c"
|
||||
"${SRC_DIR}/storage/data.c"
|
||||
@@ -120,7 +130,9 @@ target_include_directories(main PRIVATE
|
||||
"${SRC_DIR}/core"
|
||||
"${SRC_DIR}/screens"
|
||||
"${SRC_DIR}/screens/settings"
|
||||
"${SRC_DIR}/session"
|
||||
"${SRC_DIR}/practices"
|
||||
"${SRC_DIR}/practices/whm"
|
||||
"${SRC_DIR}/practices/meditation"
|
||||
"${SRC_DIR}/storage"
|
||||
"${SRC_DIR}/platform/android"
|
||||
"${SRC_DIR}/third_party"
|
||||
|
||||
@@ -281,7 +281,8 @@ public class MainActivity extends NativeActivity {
|
||||
"application/x-zip-compressed",
|
||||
"application/vnd.sqlite3",
|
||||
"application/x-sqlite",
|
||||
"application/x-sqlite3"
|
||||
"application/x-sqlite3",
|
||||
"application/octet-stream"
|
||||
});
|
||||
startActivityForResult(intent, REQUEST_IMPORT_ZIP);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
|
||||
@@ -0,0 +1,3 @@
|
||||
### Changed
|
||||
- Reorganized WHM and Meditation into practice-owned modules for cleaner code boundaries.
|
||||
- Split the meditation manual into an image intro page and a shorter music/gong setup page.
|
||||
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
|
||||
@@ -204,13 +204,16 @@ EOF
|
||||
libgbm
|
||||
libglvnd
|
||||
libglvnd.dev
|
||||
alsa-lib
|
||||
appimagetool
|
||||
libpulseaudio
|
||||
linuxdeploy
|
||||
linuxdeployPluginAppImage
|
||||
mesa
|
||||
ncurses
|
||||
ninja
|
||||
pkg-config
|
||||
pipewire
|
||||
rsync
|
||||
zlib
|
||||
zip
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
#define FLINT_MKDIR(path) _mkdir(path)
|
||||
#else
|
||||
#include <errno.h>
|
||||
@@ -208,6 +210,128 @@ fetch_failed(emscripten_fetch_t *fetch)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
typedef struct WindowsDownloadContext {
|
||||
FlintRuntimeAssetDownload *download;
|
||||
} WindowsDownloadContext;
|
||||
|
||||
static void
|
||||
windows_set_last_error(FlintRuntimeAssetDownload *download, const char *prefix)
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
|
||||
if(download == NULL)
|
||||
return;
|
||||
snprintf(download->error, sizeof(download->error), "%s (%lu)",
|
||||
prefix != NULL ? prefix : "Windows download failed",
|
||||
(unsigned long)err);
|
||||
}
|
||||
|
||||
static DWORD WINAPI
|
||||
windows_download_thread_main(void *user_data)
|
||||
{
|
||||
WindowsDownloadContext *ctx = (WindowsDownloadContext *)user_data;
|
||||
FlintRuntimeAssetDownload *download = ctx != NULL ? ctx->download : NULL;
|
||||
HINTERNET internet = NULL;
|
||||
HINTERNET request = NULL;
|
||||
FILE *file = NULL;
|
||||
char status_buf[32];
|
||||
DWORD status_len = sizeof(status_buf);
|
||||
DWORD status_index = 0;
|
||||
char length_buf[64];
|
||||
DWORD length_len = sizeof(length_buf);
|
||||
DWORD length_index = 0;
|
||||
BYTE buffer[32768];
|
||||
DWORD bytes_read = 0;
|
||||
BOOL read_ok;
|
||||
|
||||
free(ctx);
|
||||
if(download == NULL)
|
||||
return 0;
|
||||
|
||||
file = fopen(download->path, "wb");
|
||||
if(file == NULL) {
|
||||
snprintf(download->error, sizeof(download->error), "failed to open %.200s", download->path);
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
internet = InternetOpenA("flint-runtime-assets/1",
|
||||
INTERNET_OPEN_TYPE_PRECONFIG,
|
||||
NULL, NULL, 0);
|
||||
if(internet == NULL) {
|
||||
fclose(file);
|
||||
windows_set_last_error(download, "failed to initialize Windows networking");
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
request = InternetOpenUrlA(internet, download->url, NULL, 0,
|
||||
INTERNET_FLAG_RELOAD |
|
||||
INTERNET_FLAG_NO_CACHE_WRITE |
|
||||
INTERNET_FLAG_PRAGMA_NOCACHE,
|
||||
0);
|
||||
if(request == NULL) {
|
||||
fclose(file);
|
||||
InternetCloseHandle(internet);
|
||||
remove(download->path);
|
||||
windows_set_last_error(download, "Windows download failed");
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(HttpQueryInfoA(request, HTTP_QUERY_STATUS_CODE, status_buf, &status_len, &status_index)) {
|
||||
status_buf[sizeof(status_buf) - 1] = '\0';
|
||||
download->http_status = strtol(status_buf, NULL, 10);
|
||||
}
|
||||
if(download->http_status < 200 || download->http_status >= 300) {
|
||||
snprintf(download->error, sizeof(download->error), "HTTP %ld", download->http_status);
|
||||
fclose(file);
|
||||
InternetCloseHandle(request);
|
||||
InternetCloseHandle(internet);
|
||||
remove(download->path);
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(HttpQueryInfoA(request, HTTP_QUERY_CONTENT_LENGTH, length_buf, &length_len, &length_index)) {
|
||||
length_buf[sizeof(length_buf) - 1] = '\0';
|
||||
download->total_bytes = (size_t)strtoull(length_buf, NULL, 10);
|
||||
}
|
||||
|
||||
while((read_ok = InternetReadFile(request, buffer, sizeof(buffer), &bytes_read)) && bytes_read > 0) {
|
||||
if(fwrite(buffer, 1, bytes_read, file) != bytes_read) {
|
||||
snprintf(download->error, sizeof(download->error), "failed to write %.200s", download->path);
|
||||
fclose(file);
|
||||
InternetCloseHandle(request);
|
||||
InternetCloseHandle(internet);
|
||||
remove(download->path);
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
download->bytes += (size_t)bytes_read;
|
||||
}
|
||||
|
||||
if(!read_ok) {
|
||||
fclose(file);
|
||||
InternetCloseHandle(request);
|
||||
InternetCloseHandle(internet);
|
||||
remove(download->path);
|
||||
windows_set_last_error(download, "Windows download failed");
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
InternetCloseHandle(request);
|
||||
InternetCloseHandle(internet);
|
||||
if(download->total_bytes == 0)
|
||||
download->total_bytes = download->bytes;
|
||||
download->status = FLINT_RUNTIME_ASSET_READY;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FLINT_HAS_LIBCURL) && !defined(__EMSCRIPTEN__)
|
||||
typedef struct NativeDownloadContext {
|
||||
FlintRuntimeAssetDownload *download;
|
||||
@@ -251,7 +375,7 @@ curl_thread_main(void *user_data)
|
||||
|
||||
file = fopen(download->path, "wb");
|
||||
if(file == NULL) {
|
||||
snprintf(download->error, sizeof(download->error), "failed to open %s", download->path);
|
||||
snprintf(download->error, sizeof(download->error), "failed to open %.200s", download->path);
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
@@ -348,6 +472,26 @@ flint_runtime_asset_download(FlintRuntimeAssetDownload *download,
|
||||
emscripten_fetch(&attr, download->url);
|
||||
return 1;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
{
|
||||
HANDLE thread;
|
||||
WindowsDownloadContext *ctx = (WindowsDownloadContext *)calloc(1, sizeof(*ctx));
|
||||
if(ctx == NULL) {
|
||||
snprintf(download->error, sizeof(download->error), "out of memory");
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
ctx->download = download;
|
||||
thread = CreateThread(NULL, 0, windows_download_thread_main, ctx, 0, NULL);
|
||||
if(thread == NULL) {
|
||||
free(ctx);
|
||||
windows_set_last_error(download, "failed to create download thread");
|
||||
download->status = FLINT_RUNTIME_ASSET_ERROR;
|
||||
return 0;
|
||||
}
|
||||
CloseHandle(thread);
|
||||
return 1;
|
||||
}
|
||||
#elif defined(FLINT_HAS_LIBCURL)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
@@ -40,8 +40,11 @@ Meditace
|
||||
[meditation_manual_title]
|
||||
Meditace
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Vyberte hudbu, pokud pomáhá sezení zklidnit, a pohodlně se posaďte. Nechte pozornost spočinout na dechu. Když vás myšlenky odvedou, jasně si toho všimněte a vraťte se bez úsilí. Gong označí začátek i konec.
|
||||
Vyberte hudbu, pokud chcete. Gong oznaci zacatek a konec.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Meditační hudba
|
||||
@@ -303,6 +306,9 @@ Importovat data
|
||||
[import_failed]
|
||||
Import selhal
|
||||
---
|
||||
[imported_data]
|
||||
Data importována
|
||||
---
|
||||
[imported_sessions]
|
||||
Importováno %d sezení
|
||||
---
|
||||
@@ -312,6 +318,18 @@ Neplatný exportní soubor
|
||||
[import_cancelled]
|
||||
Import zrušen
|
||||
---
|
||||
[import_choice_title]
|
||||
Importovat nastavení?
|
||||
---
|
||||
[import_choice_message]
|
||||
Nalezeny data a nastavení.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Data
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Data+Nastavení
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -455,3 +473,24 @@ Smazat toto kolo? Tuto akci nelze vrátit.
|
||||
[delete_button]
|
||||
Smazat
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Hudba od Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
Systém
|
||||
---
|
||||
[orientation_label]
|
||||
Orientace
|
||||
---
|
||||
[orientation_system]
|
||||
Systém
|
||||
---
|
||||
[orientation_portrait]
|
||||
Na výšku
|
||||
---
|
||||
[orientation_landscape]
|
||||
Na šířku
|
||||
---
|
||||
[orientation_sensor]
|
||||
Senzor
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditation
|
||||
[meditation_manual_title]
|
||||
Meditation
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Wähle Musik, wenn sie die Sitzung ruhiger macht, und setze dich bequem hin. Lass die Aufmerksamkeit auf dem Atem ruhen. Wenn Gedanken dich wegziehen, bemerke es klar und kehre ohne Druck zurück. Ein Gong markiert Anfang und Ende.
|
||||
Wahlen Sie Musik, wenn Sie mochten. Ein Gong markiert Anfang und Ende.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Meditationsmusik
|
||||
@@ -303,6 +306,9 @@ Daten importieren
|
||||
[import_failed]
|
||||
Import fehlgeschlagen
|
||||
---
|
||||
[imported_data]
|
||||
Daten importiert
|
||||
---
|
||||
[imported_sessions]
|
||||
%d Sitzungen importiert
|
||||
---
|
||||
@@ -312,6 +318,18 @@ Ungültige Exportdatei
|
||||
[import_cancelled]
|
||||
Import cancelled
|
||||
---
|
||||
[import_choice_title]
|
||||
Einstellungen importieren?
|
||||
---
|
||||
[import_choice_message]
|
||||
Daten und Einstellungen gefunden.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Daten
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Daten+Einstellungen
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -455,3 +473,24 @@ Diese Runde löschen? Das kann nicht rückgängig gemacht werden.
|
||||
[delete_button]
|
||||
Löschen
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Musik von Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
System
|
||||
---
|
||||
[orientation_label]
|
||||
Ausrichtung
|
||||
---
|
||||
[orientation_system]
|
||||
System
|
||||
---
|
||||
[orientation_portrait]
|
||||
Hochformat
|
||||
---
|
||||
[orientation_landscape]
|
||||
Querformat
|
||||
---
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditation
|
||||
[meditation_manual_title]
|
||||
Meditation
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Choose music if it helps the session feel steady, then sit comfortably. Let attention rest on the breath. When thoughts pull you away, notice that clearly and return without force. A gong marks the beginning and end.
|
||||
Choose music if you want it. A gong marks the beginning and end.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Meditation Music
|
||||
@@ -324,6 +327,9 @@ Import Data
|
||||
[import_failed]
|
||||
Import failed
|
||||
---
|
||||
[imported_data]
|
||||
Imported data
|
||||
---
|
||||
[imported_sessions]
|
||||
Imported %d sessions
|
||||
---
|
||||
@@ -333,6 +339,18 @@ Invalid export file
|
||||
[import_cancelled]
|
||||
Import cancelled
|
||||
---
|
||||
[import_choice_title]
|
||||
Import settings?
|
||||
---
|
||||
[import_choice_message]
|
||||
Data and settings found.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Data
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Data+Settings
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
|
||||
@@ -40,8 +40,11 @@ Meditación
|
||||
[meditation_manual_title]
|
||||
Meditación
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Elige música si ayuda a que la sesión se sienta estable y siéntate cómodamente. Deja que la atención descanse en la respiración. Cuando los pensamientos te arrastren, obsérvalo con claridad y vuelve sin forzar. Un gong marca el inicio y el final.
|
||||
Elige musica si quieres. Un gong marca el inicio y el final.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Música de meditación
|
||||
@@ -303,6 +306,9 @@ Importar datos
|
||||
[import_failed]
|
||||
Error al importar
|
||||
---
|
||||
[imported_data]
|
||||
Datos importados
|
||||
---
|
||||
[imported_sessions]
|
||||
%d sesiones importadas
|
||||
---
|
||||
@@ -312,6 +318,18 @@ Archivo de exportación no válido
|
||||
[import_cancelled]
|
||||
Import cancelled
|
||||
---
|
||||
[import_choice_title]
|
||||
¿Importar ajustes?
|
||||
---
|
||||
[import_choice_message]
|
||||
Datos y ajustes encontrados.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Datos
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Datos+Ajustes
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -455,3 +473,24 @@ Recuento de sesiones: %d
|
||||
[delete_button]
|
||||
Eliminar
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Música de Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
Sistema
|
||||
---
|
||||
[orientation_label]
|
||||
Orientación
|
||||
---
|
||||
[orientation_system]
|
||||
Sistema
|
||||
---
|
||||
[orientation_portrait]
|
||||
Vertical
|
||||
---
|
||||
[orientation_landscape]
|
||||
Horizontal
|
||||
---
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Méditation
|
||||
[meditation_manual_title]
|
||||
Méditation
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Choisissez une musique si elle aide la séance à rester stable, puis asseyez-vous confortablement. Laissez l’attention se poser sur le souffle. Quand les pensées vous emportent, voyez-le clairement et revenez sans forcer. Un gong marque le début et la fin.
|
||||
Choisissez de la musique si vous le souhaitez. Un gong marque le debut et la fin.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Musique de méditation
|
||||
@@ -303,6 +306,9 @@ Importer les données
|
||||
[import_failed]
|
||||
Échec de l'import
|
||||
---
|
||||
[imported_data]
|
||||
Données importées
|
||||
---
|
||||
[imported_sessions]
|
||||
%d sessions importées
|
||||
---
|
||||
@@ -312,6 +318,18 @@ Fichier d'export invalide
|
||||
[import_cancelled]
|
||||
Import annulé
|
||||
---
|
||||
[import_choice_title]
|
||||
Importer les réglages ?
|
||||
---
|
||||
[import_choice_message]
|
||||
Données et réglages trouvés.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Données
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Données+Réglages
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -455,3 +473,24 @@ Supprimer ce cycle ? Cette action est irréversible.
|
||||
[delete_button]
|
||||
Supprimer
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Musique par Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
Système
|
||||
---
|
||||
[orientation_label]
|
||||
Orientation
|
||||
---
|
||||
[orientation_system]
|
||||
Système
|
||||
---
|
||||
[orientation_portrait]
|
||||
Portrait
|
||||
---
|
||||
[orientation_landscape]
|
||||
Paysage
|
||||
---
|
||||
[orientation_sensor]
|
||||
Capteur
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditasi
|
||||
[meditation_manual_title]
|
||||
Meditasi
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Pilih musik jika membantu sesi terasa stabil, lalu duduk dengan nyaman. Biarkan perhatian beristirahat pada napas. Saat pikiran menarikmu pergi, sadari dengan jelas dan kembali tanpa memaksa. Gong menandai awal dan akhir.
|
||||
Pilih musik jika Anda mau. Gong menandai awal dan akhir.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Musik meditasi
|
||||
@@ -303,6 +306,9 @@ Impor Data
|
||||
[import_failed]
|
||||
Impor gagal
|
||||
---
|
||||
[imported_data]
|
||||
Data diimpor
|
||||
---
|
||||
[imported_sessions]
|
||||
Mengimpor %d sesi
|
||||
---
|
||||
@@ -312,6 +318,18 @@ File ekspor tidak valid
|
||||
[import_cancelled]
|
||||
Impor dibatalkan
|
||||
---
|
||||
[import_choice_title]
|
||||
Impor pengaturan?
|
||||
---
|
||||
[import_choice_message]
|
||||
Data dan pengaturan ditemukan.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Data
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Data+Pengaturan
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -455,3 +473,24 @@ Hapus ronde ini? Tidak dapat dibatalkan.
|
||||
[delete_button]
|
||||
Hapus
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Musik oleh Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
Sistem
|
||||
---
|
||||
[orientation_label]
|
||||
Orientasi
|
||||
---
|
||||
[orientation_system]
|
||||
Sistem
|
||||
---
|
||||
[orientation_portrait]
|
||||
Potret
|
||||
---
|
||||
[orientation_landscape]
|
||||
Lanskap
|
||||
---
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditazione
|
||||
[meditation_manual_title]
|
||||
Meditazione
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Scegli la musica se aiuta la sessione a sentirsi stabile, poi siediti comodamente. Lascia che l'attenzione riposi sul respiro. Quando i pensieri ti portano via, notalo con chiarezza e torna senza forzare. Un gong segna l'inizio e la fine.
|
||||
Scegli la musica se vuoi. Un gong segna l inizio e la fine.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Musica Meditazione
|
||||
@@ -319,6 +322,9 @@ Importa Dati
|
||||
[import_failed]
|
||||
Importazione fallita
|
||||
---
|
||||
[imported_data]
|
||||
Dati importati
|
||||
---
|
||||
[imported_sessions]
|
||||
Importate %d sessioni
|
||||
---
|
||||
@@ -328,6 +334,18 @@ File di esportazione non valido
|
||||
[import_cancelled]
|
||||
Importazione annullata
|
||||
---
|
||||
[import_choice_title]
|
||||
Importare impostazioni?
|
||||
---
|
||||
[import_choice_message]
|
||||
Dati e impostazioni trovati.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Dati
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Dati+Impostazioni
|
||||
---
|
||||
[export_cancelled]
|
||||
Esportazione annullata
|
||||
---
|
||||
@@ -471,3 +489,6 @@ Eliminare questo round? Questa azione non può essere annullata.
|
||||
[delete_button]
|
||||
Elimina
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Musica di Elijah_K.
|
||||
---
|
||||
@@ -40,8 +40,11 @@
|
||||
[meditation_manual_title]
|
||||
瞑想
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
音楽が集中を支えてくれるなら選び、楽な姿勢で座ります。注意を呼吸に置きます。思考に引かれたら、はっきり気づき、力まず戻ります。ゴングが始まりと終わりを知らせます。
|
||||
必要なら音楽を選んでください。ゴングが始まりと終わりを知らせます。
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
瞑想音楽
|
||||
@@ -303,6 +306,9 @@ In / Out
|
||||
[import_failed]
|
||||
インポートに失敗しました
|
||||
---
|
||||
[imported_data]
|
||||
データをインポートしました
|
||||
---
|
||||
[imported_sessions]
|
||||
%dセッションをインポートしました
|
||||
---
|
||||
@@ -312,6 +318,18 @@ In / Out
|
||||
[import_cancelled]
|
||||
Import cancelled
|
||||
---
|
||||
[import_choice_title]
|
||||
設定もインポートしますか?
|
||||
---
|
||||
[import_choice_message]
|
||||
データと設定があります。
|
||||
---
|
||||
[import_data_only_button]
|
||||
データ
|
||||
---
|
||||
[import_data_settings_button]
|
||||
データ+設定
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -448,3 +466,25 @@ Inner Breeze データ書き出し
|
||||
---
|
||||
[delete_button]
|
||||
削除
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
音楽: Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
システム
|
||||
---
|
||||
[orientation_label]
|
||||
向き
|
||||
---
|
||||
[orientation_system]
|
||||
システム
|
||||
---
|
||||
[orientation_portrait]
|
||||
縦向き
|
||||
---
|
||||
[orientation_landscape]
|
||||
横向き
|
||||
---
|
||||
[orientation_sensor]
|
||||
センサー
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Inner Breeze
|
||||
[meditation_manual_title]
|
||||
명상
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
음악이 세션을 안정되게 해 준다면 선택한 뒤 편안하게 앉으세요. 주의를 호흡에 둡니다. 생각에 끌려가면 분명히 알아차리고 힘주지 말고 돌아오세요. 공 소리가 시작과 끝을 알립니다.
|
||||
원하면 음악을 선택하세요. 징 소리가 시작과 끝을 알립니다.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
명상 음악
|
||||
@@ -319,6 +322,9 @@ In / Out
|
||||
[import_failed]
|
||||
가져오기 실패
|
||||
---
|
||||
[imported_data]
|
||||
데이터를 가져왔습니다
|
||||
---
|
||||
[imported_sessions]
|
||||
%d개 세션을 가져왔습니다
|
||||
---
|
||||
@@ -328,6 +334,18 @@ In / Out
|
||||
[import_cancelled]
|
||||
가져오기 취소됨
|
||||
---
|
||||
[import_choice_title]
|
||||
설정을 가져올까요?
|
||||
---
|
||||
[import_choice_message]
|
||||
데이터와 설정을 찾았습니다.
|
||||
---
|
||||
[import_data_only_button]
|
||||
데이터
|
||||
---
|
||||
[import_data_settings_button]
|
||||
데이터+설정
|
||||
---
|
||||
[export_cancelled]
|
||||
내보내기 취소됨
|
||||
---
|
||||
@@ -470,3 +488,6 @@ Inner Breeze 데이터 내보내기
|
||||
[delete_button]
|
||||
삭제
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
음악: Elijah_K.
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditação
|
||||
[meditation_manual_title]
|
||||
Meditação
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Escolha uma música se ela ajudar a sessão a ficar estável e sente-se confortavelmente. Deixe a atenção repousar na respiração. Quando os pensamentos puxarem você, perceba com clareza e volte sem forçar. Um gongo marca o começo e o fim.
|
||||
Escolha musica se quiser. Um gongo marca o inicio e o fim.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Música de meditação
|
||||
@@ -303,6 +306,9 @@ Importar dados
|
||||
[import_failed]
|
||||
Falha ao importar
|
||||
---
|
||||
[imported_data]
|
||||
Dados importados
|
||||
---
|
||||
[imported_sessions]
|
||||
%d sessões importadas
|
||||
---
|
||||
@@ -312,6 +318,18 @@ Arquivo de exportação inválido
|
||||
[import_cancelled]
|
||||
Importação cancelada
|
||||
---
|
||||
[import_choice_title]
|
||||
Importar configurações?
|
||||
---
|
||||
[import_choice_message]
|
||||
Dados e configurações encontrados.
|
||||
---
|
||||
[import_data_only_button]
|
||||
Dados
|
||||
---
|
||||
[import_data_settings_button]
|
||||
Dados+Config.
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -455,3 +473,24 @@ Excluir esta rodada? Isso não pode ser desfeito.
|
||||
[delete_button]
|
||||
Excluir
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
Música por Elijah_K.
|
||||
---
|
||||
[theme_system]
|
||||
Sistema
|
||||
---
|
||||
[orientation_label]
|
||||
Orientação
|
||||
---
|
||||
[orientation_system]
|
||||
Sistema
|
||||
---
|
||||
[orientation_portrait]
|
||||
Retrato
|
||||
---
|
||||
[orientation_landscape]
|
||||
Paisagem
|
||||
---
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Wim Hof 呼吸
|
||||
[meditation_manual_title]
|
||||
冥想
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
如果音乐能让练习更安稳,就先选择音乐,然后舒适地坐下。把注意力放在呼吸上。被念头带走时,清楚地觉察,再不费力地回来。钟声会提示开始和结束。
|
||||
如果需要,可以选择音乐。锣声会提示开始和结束。
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
冥想音乐
|
||||
@@ -303,6 +306,9 @@ In / Out
|
||||
[import_failed]
|
||||
导入失败
|
||||
---
|
||||
[imported_data]
|
||||
数据已导入
|
||||
---
|
||||
[imported_sessions]
|
||||
已导入 %d 个会话
|
||||
---
|
||||
@@ -312,6 +318,18 @@ In / Out
|
||||
[import_cancelled]
|
||||
Import cancelled
|
||||
---
|
||||
[import_choice_title]
|
||||
导入设置?
|
||||
---
|
||||
[import_choice_message]
|
||||
找到数据和设置。
|
||||
---
|
||||
[import_data_only_button]
|
||||
数据
|
||||
---
|
||||
[import_data_settings_button]
|
||||
数据+设置
|
||||
---
|
||||
[export_cancelled]
|
||||
Export cancelled
|
||||
---
|
||||
@@ -446,3 +464,25 @@ Inner Breeze 数据导出
|
||||
---
|
||||
[delete_button]
|
||||
删除
|
||||
---
|
||||
[meditation_music_attribution]
|
||||
音乐来自 Elijah_K。
|
||||
---
|
||||
[theme_system]
|
||||
系统
|
||||
---
|
||||
[orientation_label]
|
||||
方向
|
||||
---
|
||||
[orientation_system]
|
||||
系统
|
||||
---
|
||||
[orientation_portrait]
|
||||
竖屏
|
||||
---
|
||||
[orientation_landscape]
|
||||
横屏
|
||||
---
|
||||
[orientation_sensor]
|
||||
传感器
|
||||
---
|
||||
@@ -41,8 +41,9 @@ fi
|
||||
mkdir -p build
|
||||
sh flint/scripts/embed-assets.sh build/inbe_embedded_assets.c \
|
||||
locales/*.txt \
|
||||
assets/whm/1.jpg \
|
||||
assets/whm/2.jpg \
|
||||
assets/practices/whm/1.jpg \
|
||||
assets/practices/whm/2.jpg \
|
||||
assets/practices/meditation/1.jpg \
|
||||
assets/fonts/locales.png \
|
||||
assets/fonts/locales.dat \
|
||||
assets/fonts/locales-8.png \
|
||||
|
||||
@@ -5,14 +5,10 @@
|
||||
#include "screens/manual_screen.h"
|
||||
#include "screens/settings/settings_screen.h"
|
||||
#include "screens/practice_screen.h"
|
||||
#include "session.h"
|
||||
#include "practices/practice_registry.h"
|
||||
#include "device_preferences.h"
|
||||
#include "meditation_music.h"
|
||||
#include "storage.h"
|
||||
#include "theme.h"
|
||||
#if defined(LOTUS_BUILD)
|
||||
#include "lotus_settings.h"
|
||||
#endif
|
||||
#include "version.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
@@ -62,9 +58,6 @@ int view_height = INBE_DEFAULT_HEIGHT;
|
||||
#define LOCALE_FONT_8_BASE_SIZE 8
|
||||
|
||||
|
||||
/* Forward declarations for tab callbacks */
|
||||
void reset_settings_preview(InbeApp *app);
|
||||
|
||||
static void
|
||||
app_leave_practice_config(InbeApp *app)
|
||||
{
|
||||
@@ -72,7 +65,11 @@ app_leave_practice_config(InbeApp *app)
|
||||
return;
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
meditation_music_unload(app);
|
||||
{
|
||||
const PracticeDefinition *practice = practice_get(app->exercise_type);
|
||||
if(practice->leave_config != NULL)
|
||||
practice->leave_config(app);
|
||||
}
|
||||
app->settings_scroll = 0;
|
||||
}
|
||||
|
||||
@@ -219,38 +216,6 @@ mark_exercise_manual_seen(InbeApp *app, int exercise_type)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LOTUS_BUILD)
|
||||
static void
|
||||
sync_lotus_settings(InbeApp *app)
|
||||
{
|
||||
const LotusSettings *lotus;
|
||||
unsigned int version;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
version = lotus_settings_version();
|
||||
if(app->lotus_settings_version == version)
|
||||
return;
|
||||
|
||||
lotus = lotus_settings_get();
|
||||
app->theme_id = lotus->theme;
|
||||
app->theme_mode = lotus->dark_mode ? APP_THEME_DARK : APP_THEME_LIGHT;
|
||||
app->dark_mode = app_effective_dark_mode(app);
|
||||
snprintf(app->language, sizeof(app->language), "%.*s",
|
||||
(int)sizeof(app->language) - 1, lotus->language);
|
||||
app->language_selected = 1;
|
||||
if(!locale_set(app->language)) {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
locale_set(app->language);
|
||||
}
|
||||
|
||||
app_refresh_theme(app);
|
||||
refresh_locale_dependent_text(app);
|
||||
app->lotus_settings_version = version;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ================================================================
|
||||
* TAB BAR DEFINITIONS
|
||||
* ================================================================ */
|
||||
@@ -432,33 +397,6 @@ init_web_storage(void)
|
||||
web_storage_ready = ok != 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sync_web_storage(void)
|
||||
{
|
||||
EM_ASM({
|
||||
if(typeof FS !== 'undefined' && typeof FS.syncfs === 'function') {
|
||||
if(Module.inbeSyncfsTimer)
|
||||
clearTimeout(Module.inbeSyncfsTimer);
|
||||
Module.__inbeStorageSyncPending = true;
|
||||
Module.inbeSyncfsTimer = setTimeout(function() {
|
||||
Module.inbeSyncfsTimer = 0;
|
||||
Module.__inbeStorageSyncing = true;
|
||||
try {
|
||||
FS.syncfs(false, function(err) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
if(err) console.error("IDBFS save failed:", err);
|
||||
else console.log("IDBFS synced");
|
||||
});
|
||||
} catch(e) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
console.error("IDBFS sync error:", e);
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
@@ -507,170 +445,25 @@ int_from_count(const char src[CountSize])
|
||||
}
|
||||
|
||||
void
|
||||
apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds)
|
||||
{
|
||||
speed = clampi(speed, SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
inbe->speed_level = speed;
|
||||
inbe->breath_half_ticks = inbe_breath_half_ticks_for_speed(speed);
|
||||
inbe->breath_animation = clampi(inbe->breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
inbe->progressive_start_speed = clampi(inbe->progressive_start_speed, SETTINGS_SPEED_MIN, speed);
|
||||
inbe->max_rounds = clampi(max_rounds, 1, MaxRounds);
|
||||
inbe->pause_seconds = clampi(pause_seconds, SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX);
|
||||
count_from_int(inbe->maxbreaths, clampi(max_breaths, SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX));
|
||||
}
|
||||
|
||||
void
|
||||
reset_settings_preview(InbeApp *app)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
int breath_animation = app->inbe.breath_animation;
|
||||
int content_w;
|
||||
|
||||
inbeinit(&app->settings_preview);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_preview.play_in_background = play_in_background;
|
||||
app->settings_preview.breath_animation = breath_animation;
|
||||
flint_centered_column(CONTENT_MAX_W, CONTENT_SIDE_PAD, NULL, &content_w);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
session_reset_round_breathe(&app->settings_preview);
|
||||
}
|
||||
|
||||
void
|
||||
save_settings(InbeApp *app)
|
||||
app_reload_after_import(InbeApp *app, int reload_settings)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
inbe_storage_settings_begin_write();
|
||||
inbe_storage_set_setting_int("speed", app->inbe.speed_level);
|
||||
inbe_storage_set_setting_int("max_rounds", app->inbe.max_rounds);
|
||||
inbe_storage_set_setting_int("max_breaths", int_from_count(app->inbe.maxbreaths));
|
||||
inbe_storage_set_setting_int("pause_seconds", app->inbe.pause_seconds);
|
||||
inbe_storage_set_setting_int("sound_volume", app->sound_volume);
|
||||
inbe_storage_set_setting_int("tutorial_seen", app->tutorial_seen ? 1 : 0);
|
||||
inbe_storage_set_setting_int("exercise_manual_seen_mask", app->exercise_manual_seen_mask);
|
||||
inbe_storage_set_setting_int("theme", app->theme_id);
|
||||
inbe_storage_set_setting_int("dark_mode", app->dark_mode);
|
||||
inbe_storage_set_setting_int("theme_mode", app->theme_mode);
|
||||
inbe_storage_set_setting_int("orientation_mode", app->orientation_mode);
|
||||
inbe_storage_set_setting_int("main_tab", app->main_tab);
|
||||
inbe_storage_set_setting_int("fullscreen", app->fullscreen_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("on_screen_keyboard", app->on_screen_keyboard_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("progressive_speed", app->inbe.progressive_speed);
|
||||
inbe_storage_set_setting_int("progressive_start_speed", app->inbe.progressive_start_speed);
|
||||
inbe_storage_set_setting_int("breath_animation", app->inbe.breath_animation);
|
||||
inbe_storage_set_setting_int("advanced_session_controls", app->advanced_session_controls ? 1 : 0);
|
||||
inbe_storage_set_setting_int("hold_display_mode", app->hold_display_mode);
|
||||
inbe_storage_set_setting_int("exercise_type", app->exercise_type);
|
||||
inbe_storage_set_setting_int("meditation_music_enabled", app->meditation_music_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("meditation_music_shuffle", app->meditation_music_shuffle ? 1 : 0);
|
||||
inbe_storage_set_setting_int("meditation_music_track", app->meditation_music_track);
|
||||
inbe_storage_set_setting_int("play_in_background", app->inbe.play_in_background);
|
||||
inbe_storage_set_setting_text("language",
|
||||
(app->language_selected && app->language[0] != '\0') ? app->language : "");
|
||||
inbe_storage_set_setting_int("practice_category_tab", app->practice_category_tab);
|
||||
inbe_storage_settings_end_write();
|
||||
#if defined(PLATFORM_WEB)
|
||||
sync_web_storage();
|
||||
#endif
|
||||
app->settings_dirty = 0;
|
||||
app->settings_save_delay_ticks = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
load_settings(InbeApp *app)
|
||||
{
|
||||
int settings_missing = inbe_storage_settings_empty();
|
||||
int speed = inbe_storage_get_setting_int("speed", DefaultSpeedLevel);
|
||||
int max_rounds = inbe_storage_get_setting_int("max_rounds", DefaultMaxRounds);
|
||||
int max_breaths = inbe_storage_get_setting_int("max_breaths", DefaultMaxBreaths);
|
||||
int pause_seconds = inbe_storage_get_setting_int("pause_seconds", DefaultPauseSeconds);
|
||||
int sound_volume = inbe_storage_get_setting_int("sound_volume", 100);
|
||||
int manual_seen_mask;
|
||||
|
||||
app->tutorial_seen = inbe_storage_get_setting_int("tutorial_seen", 0) != 0;
|
||||
manual_seen_mask = inbe_storage_get_setting_int("exercise_manual_seen_mask", -1);
|
||||
if(manual_seen_mask < 0)
|
||||
manual_seen_mask = app->tutorial_seen ? exercise_manual_seen_bit(EXERCISE_WIM_HOF) : 0;
|
||||
app->exercise_manual_seen_mask = manual_seen_mask & ((1 << EXERCISE_COUNT) - 1);
|
||||
app->theme_id = clampi(inbe_storage_get_setting_int("theme", 0), 0, FLINT_THEME_COUNT - 1);
|
||||
app->theme_mode = clampi(inbe_storage_get_setting_int("theme_mode", APP_THEME_SYSTEM),
|
||||
APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
app->dark_mode = inbe_storage_get_setting_int("dark_mode", 0) != 0;
|
||||
app->orientation_mode = clampi(inbe_storage_get_setting_int("orientation_mode", APP_ORIENTATION_SYSTEM),
|
||||
APP_ORIENTATION_SYSTEM, APP_ORIENTATION_SENSOR);
|
||||
app->main_tab = clampi(inbe_storage_get_setting_int("main_tab", APP_MAIN_TAB_PRACTICE),
|
||||
APP_MAIN_TAB_HABITS, APP_MAIN_TAB_PRACTICE);
|
||||
app->fullscreen_enabled = inbe_storage_get_setting_int("fullscreen", 0) != 0;
|
||||
#ifdef __ANDROID__
|
||||
app->on_screen_keyboard_enabled = inbe_storage_get_setting_int("on_screen_keyboard", 1) != 0;
|
||||
#else
|
||||
app->on_screen_keyboard_enabled = inbe_storage_get_setting_int("on_screen_keyboard", 0) != 0;
|
||||
#endif
|
||||
app->sound_volume = clampi(sound_volume, SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX);
|
||||
app->inbe.progressive_speed = inbe_storage_get_setting_int("progressive_speed", 1) != 0;
|
||||
app->inbe.progressive_start_speed = clampi(inbe_storage_get_setting_int("progressive_start_speed", DefaultProgressiveStartSpeed),
|
||||
SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
app->inbe.breath_animation = clampi(inbe_storage_get_setting_int("breath_animation", InbeBreathAnimationLinear),
|
||||
InbeBreathAnimationLinear, InbeBreathAnimationCount - 1);
|
||||
app->advanced_session_controls = inbe_storage_get_setting_int("advanced_session_controls", 0) != 0;
|
||||
app->hold_display_mode = clampi(inbe_storage_get_setting_int("hold_display_mode", HOLD_DISPLAY_CIRCLE),
|
||||
HOLD_DISPLAY_CIRCLE, HOLD_DISPLAY_STOPWATCH);
|
||||
app->exercise_type = clampi(inbe_storage_get_setting_int("exercise_type", EXERCISE_WIM_HOF),
|
||||
EXERCISE_WIM_HOF, EXERCISE_COUNT - 1);
|
||||
app->meditation_music_enabled = inbe_storage_get_setting_int("meditation_music_enabled", 1) != 0;
|
||||
app->meditation_music_shuffle = inbe_storage_get_setting_int("meditation_music_shuffle", 0) != 0;
|
||||
app->meditation_music_track = clampi(inbe_storage_get_setting_int("meditation_music_track", 0),
|
||||
0, MEDITATION_MUSIC_TRACK_COUNT - 1);
|
||||
app->practice_category_tab =
|
||||
clampi(inbe_storage_get_setting_int("practice_category_tab", PRACTICE_CATEGORY_MIND),
|
||||
0, PRACTICE_CATEGORY_COUNT - 1);
|
||||
app->language_needs_save = 0;
|
||||
{
|
||||
const char *language = inbe_storage_get_setting_text("language");
|
||||
if(language != NULL && language[0] != '\0') {
|
||||
snprintf(app->language, sizeof(app->language), "%s", language);
|
||||
app->language_selected = 1;
|
||||
if(!locale_set(app->language)) {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
locale_set(app->language);
|
||||
}
|
||||
} else {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
app->language_selected = settings_missing ? 0 : 1;
|
||||
app->language_needs_save = app->language_selected;
|
||||
locale_set(app->language);
|
||||
}
|
||||
app->language_index = locale_current_index();
|
||||
if(app->language_index < 0)
|
||||
app->language_index = 0;
|
||||
if(reload_settings) {
|
||||
if(app_load_settings(app))
|
||||
save_settings(app);
|
||||
reset_settings_preview(app);
|
||||
practice_update_session_sounds(app);
|
||||
}
|
||||
#if defined(LOTUS_BUILD)
|
||||
sync_lotus_settings(app);
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
app->inbe.play_in_background = inbe_storage_get_setting_int("play_in_background",
|
||||
1 // Default to enabled on Android
|
||||
);
|
||||
TraceLog(LOG_INFO, "INBE: Loaded play_in_background setting = %d", app->inbe.play_in_background);
|
||||
#else
|
||||
app->inbe.play_in_background = 0;
|
||||
#endif
|
||||
app->backgrounded = 0;
|
||||
|
||||
app_device_preferences_init(app);
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
refresh_locale_dependent_text(app);
|
||||
if(settings_missing)
|
||||
save_settings(app);
|
||||
inbe_habits_init(&app->habits);
|
||||
if(app->habit_detail_index >= app->habits.count)
|
||||
app->habit_detail_index = -1;
|
||||
if(app->habits.selected < 0 || app->habits.selected >= app->habits.count)
|
||||
app->habits.selected = app->habits.count > 0 ? 0 : -1;
|
||||
app->habit_session_edit_active = 0;
|
||||
app->habit_edit_active = 0;
|
||||
}
|
||||
|
||||
static Texture2D
|
||||
@@ -707,8 +500,8 @@ load_pixel_texture_from_asset(const char *path)
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Texture2D
|
||||
load_asset_texture(const char *name)
|
||||
Texture2D
|
||||
app_load_asset_texture(const char *name)
|
||||
{
|
||||
char path[64];
|
||||
|
||||
@@ -726,15 +519,23 @@ load_sound_asset(const char *name)
|
||||
|
||||
snprintf(path, sizeof(path), "assets/sounds/%s", name);
|
||||
asset = flint_embedded_asset(path);
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0)
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Missing embedded sound asset: %s", path);
|
||||
return sound;
|
||||
}
|
||||
|
||||
wave = LoadWaveFromMemory(flint_embedded_asset_extension(path), asset->data, (int)asset->size);
|
||||
if(wave.data == NULL)
|
||||
if(wave.data == NULL) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Failed to decode embedded sound asset: %s", path);
|
||||
return sound;
|
||||
}
|
||||
|
||||
sound = LoadSoundFromWave(wave);
|
||||
UnloadWave(wave);
|
||||
if(sound.frameCount == 0)
|
||||
TraceLog(LOG_ERROR, "AUDIO: Failed to create sound from embedded asset: %s", path);
|
||||
else
|
||||
TraceLog(LOG_INFO, "AUDIO: Loaded sound asset %s (%u frames)", path, sound.frameCount);
|
||||
return sound;
|
||||
}
|
||||
|
||||
@@ -743,7 +544,17 @@ app_play_sound(InbeApp *app, Sound sound, float scale)
|
||||
{
|
||||
float volume;
|
||||
|
||||
if(app == NULL || !app->audio_ready || sound.frameCount == 0 || app->sound_volume <= 0)
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!app->audio_ready) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Cannot play sound because audio device is not ready");
|
||||
return;
|
||||
}
|
||||
if(sound.frameCount == 0) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Cannot play sound because sound is not loaded");
|
||||
return;
|
||||
}
|
||||
if(app->sound_volume <= 0)
|
||||
return;
|
||||
|
||||
volume = ((float)app->sound_volume / 100.0f) * scale;
|
||||
@@ -755,6 +566,8 @@ app_play_sound(InbeApp *app, Sound sound, float scale)
|
||||
StopSound(sound);
|
||||
SetSoundVolume(sound, volume);
|
||||
PlaySound(sound);
|
||||
if(!IsSoundPlaying(sound))
|
||||
TraceLog(LOG_ERROR, "AUDIO: PlaySound returned but sound is not playing");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -765,8 +578,11 @@ init_audio(InbeApp *app)
|
||||
|
||||
InitAudioDevice();
|
||||
app->audio_ready = IsAudioDeviceReady();
|
||||
if(!app->audio_ready)
|
||||
if(!app->audio_ready) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Audio device failed to initialize");
|
||||
return;
|
||||
}
|
||||
TraceLog(LOG_INFO, "AUDIO: Audio device initialized");
|
||||
|
||||
app->breath_in_sound = load_sound_asset("breath-in.ogg");
|
||||
app->breath_out_sound = load_sound_asset("breath-out.ogg");
|
||||
@@ -812,16 +628,15 @@ inbe_app_init(void *vapp) {
|
||||
#endif
|
||||
|
||||
inbeinit(&app->inbe);
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + flint_px(80));
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(56) + flint_px(80));
|
||||
data_init();
|
||||
load_settings(app);
|
||||
if(app_load_settings(app))
|
||||
save_settings(app);
|
||||
if(app->language_needs_save) {
|
||||
save_settings(app);
|
||||
app->language_needs_save = 0;
|
||||
}
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + 80);
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(56) + 80);
|
||||
inbe_habits_init(&app->habits);
|
||||
app->habit_detail_index = -1;
|
||||
app->habit_detail_day = 0;
|
||||
@@ -836,7 +651,11 @@ inbe_app_init(void *vapp) {
|
||||
app->pending_bottom_tab = APP_BOTTOM_TAB_NONE;
|
||||
app_open_main_tab(app, app->main_tab, 0);
|
||||
init_audio(app);
|
||||
meditation_music_init(app);
|
||||
for(int i = 0; i < practice_count(); i++) {
|
||||
const PracticeDefinition *practice = practice_get(i);
|
||||
if(practice->init != NULL)
|
||||
practice->init(app);
|
||||
}
|
||||
app->camera = (Camera2D){0};
|
||||
app->cursor_clickable = 0;
|
||||
app->cursor_disabled = 0;
|
||||
@@ -870,7 +689,7 @@ inbe_app_init(void *vapp) {
|
||||
app->backgrounded = 0;
|
||||
app->results_saved = 0;
|
||||
app->results_path[0] = '\0';
|
||||
update_session_sounds(app);
|
||||
practice_update_session_sounds(app);
|
||||
reset_settings_preview(app);
|
||||
inbeinit(&app->start_speed_preview);
|
||||
app->start_speed_preview_speed = 0;
|
||||
@@ -894,354 +713,18 @@ inbe_app_init(void *vapp) {
|
||||
|
||||
ui_set_icons(app->icons[UI_ICON_TYPE_GEAR], app->icons[UI_ICON_TYPE_X]);
|
||||
|
||||
if(app->whm_1_image.id == 0) {
|
||||
app->whm_1_image = load_asset_texture("whm/1.jpg");
|
||||
}
|
||||
if(app->whm_2_image.id == 0) {
|
||||
app->whm_2_image = load_asset_texture("whm/2.jpg");
|
||||
}
|
||||
#if !defined(LOTUS_BUILD)
|
||||
if(!app->language_selected)
|
||||
app->inbe.screen = InbeScreenLanguage;
|
||||
else
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
#else
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
#endif
|
||||
|
||||
/* Reset modal state */
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->modal.selected_button = 0;
|
||||
app->meditation_duration_seconds = 0;
|
||||
app->meditation_remaining_seconds = 0;
|
||||
app->meditation_frame_ticks = 0;
|
||||
}
|
||||
|
||||
static Texture2D
|
||||
sound_icon_for_volume(InbeApp *app)
|
||||
{
|
||||
int vol = app->sound_volume;
|
||||
if(vol <= 0)
|
||||
return app->icons[UI_ICON_TYPE_SOUND0];
|
||||
if(vol <= 25)
|
||||
return app->icons[UI_ICON_TYPE_SOUND1];
|
||||
if(vol <= 75)
|
||||
return app->icons[UI_ICON_TYPE_SOUND2];
|
||||
return app->icons[UI_ICON_TYPE_SOUND3];
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_start(InbeApp *app, int seconds)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
app->meditation_duration_seconds = seconds;
|
||||
app->meditation_remaining_seconds = seconds;
|
||||
app->meditation_frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenMeditation;
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
meditation_music_start_session(app);
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_finish(InbeApp *app)
|
||||
{
|
||||
int duration;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
duration = app->meditation_duration_seconds;
|
||||
if(duration >= 60) {
|
||||
int session_duration = duration;
|
||||
if(data_save_session_path_for_activity(&session_duration, 1, 0, EXERCISE_MEDITATION,
|
||||
NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
}
|
||||
}
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
app->meditation_duration_seconds = 0;
|
||||
app->meditation_remaining_seconds = 0;
|
||||
app->meditation_frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
meditation_music_stop(app);
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_elapsed_seconds(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = app->meditation_duration_seconds - app->meditation_remaining_seconds;
|
||||
if(elapsed < 0)
|
||||
elapsed = 0;
|
||||
if(elapsed > app->meditation_duration_seconds)
|
||||
elapsed = app->meditation_duration_seconds;
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_save_elapsed(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = meditation_elapsed_seconds(app);
|
||||
if(elapsed < 60)
|
||||
return 0;
|
||||
if(data_save_session_path_for_activity(&elapsed, 1, 0, EXERCISE_MEDITATION, NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_exit_to_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
meditation_music_stop(app);
|
||||
app->meditation_duration_seconds = 0;
|
||||
app->meditation_remaining_seconds = 0;
|
||||
app->meditation_frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_request_exit(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmExitSession;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
format_meditation_time(char *dst, size_t dst_size, int seconds)
|
||||
{
|
||||
int hours;
|
||||
int minutes;
|
||||
int secs;
|
||||
|
||||
if(dst == NULL || dst_size == 0)
|
||||
return;
|
||||
if(seconds < 0)
|
||||
seconds = 0;
|
||||
|
||||
hours = seconds / 3600;
|
||||
minutes = (seconds / 60) % 60;
|
||||
secs = seconds % 60;
|
||||
|
||||
if(hours > 0)
|
||||
snprintf(dst, dst_size, "%d:%02d:%02d", hours, minutes, secs);
|
||||
else
|
||||
snprintf(dst, dst_size, "%d:%02d", minutes, secs);
|
||||
}
|
||||
|
||||
static int
|
||||
draw_meditation_duration_button(int x, int y, int w, int h, const char *label)
|
||||
{
|
||||
int hover = 0;
|
||||
return ui_draw_generic_button(x, y, w, h, label, UI_BUTTON_STYLE_PRIMARY, 0, &hover);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_setup_modal(InbeApp *app)
|
||||
{
|
||||
static const int durations[] = {5 * 60, 15 * 60, 30 * 60, 60 * 60, 2 * 60 * 60};
|
||||
const char *labels[] = {
|
||||
locale_get("duration_5m"),
|
||||
locale_get("duration_15m"),
|
||||
locale_get("duration_30m"),
|
||||
locale_get("duration_1h"),
|
||||
locale_get("duration_2h")
|
||||
};
|
||||
int modal_w = flint_px(320);
|
||||
int modal_h = flint_px(236);
|
||||
int modal_x;
|
||||
int modal_y;
|
||||
int title_font = flint_px(18);
|
||||
int title_w;
|
||||
int btn_h = flint_px(38);
|
||||
int gap = flint_px(10);
|
||||
int side = flint_px(18);
|
||||
int row_y;
|
||||
int btn_w;
|
||||
int cancel_w = flint_px(120);
|
||||
int cancel_x;
|
||||
int cancel_y;
|
||||
int cancel_hover = 0;
|
||||
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
|
||||
modal_x = (view_width - modal_w) / 2;
|
||||
modal_y = (view_height - modal_h) / 2;
|
||||
btn_w = (modal_w - side * 2 - gap * 2) / 3;
|
||||
if(btn_w < flint_px(64))
|
||||
btn_w = flint_px(64);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
title_w = flint_text_measure(locale_get("meditation_title"), title_font);
|
||||
flint_text_draw(locale_get("meditation_title"), modal_x + (modal_w - title_w) / 2,
|
||||
modal_y + flint_px(16), title_font, theme_get_text());
|
||||
|
||||
row_y = modal_y + flint_px(62);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int x = modal_x + side + i * (btn_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, btn_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
row_y += btn_h + gap;
|
||||
for(int i = 3; i < 5; i++) {
|
||||
int two_w = (modal_w - side * 2 - gap) / 2;
|
||||
int x = modal_x + side + (i - 3) * (two_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, two_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
cancel_y = modal_y + modal_h - btn_h - flint_px(16);
|
||||
cancel_x = modal_x + (modal_w - cancel_w) / 2;
|
||||
if(ui_draw_generic_button(cancel_x, cancel_y, cancel_w, btn_h,
|
||||
locale_get("cancel_button"), UI_BUTTON_STYLE_SECONDARY,
|
||||
0, &cancel_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_sound_controls(InbeApp *app)
|
||||
{
|
||||
int sound_btn_x = view_width - flint_px(56);
|
||||
int sound_btn_y = flint_px(12);
|
||||
int sound_btn_size = flint_px(24);
|
||||
int sound_btn_padding = flint_px(10);
|
||||
int sound_hover = 0;
|
||||
|
||||
if(ui_draw_icon_btn_padded(sound_btn_x, sound_btn_y, sound_btn_size, sound_btn_padding,
|
||||
sound_icon_for_volume(app), &sound_hover)) {
|
||||
app->volume_popup_active = !app->volume_popup_active;
|
||||
}
|
||||
|
||||
if(app->volume_popup_active) {
|
||||
int popup_w = flint_px(44);
|
||||
int popup_x = sound_btn_x;
|
||||
int popup_y = sound_btn_y + sound_btn_size + sound_btn_padding * 2;
|
||||
int popup_h = flint_px(200);
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) &&
|
||||
(mouse.x < popup_x || mouse.x > popup_x + popup_w ||
|
||||
mouse.y < popup_y || mouse.y > popup_y + popup_h)) {
|
||||
app->volume_popup_active = 0;
|
||||
}
|
||||
|
||||
DrawRectangle(popup_x, popup_y, popup_w, popup_h, theme_get_surface());
|
||||
ui_draw_bevel(popup_x, popup_y, popup_w, popup_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
if(ui_draw_slider_vertical(501, popup_x + popup_w / 2, popup_y + flint_px(10),
|
||||
popup_h - flint_px(20), SETTINGS_VOLUME_MIN,
|
||||
SETTINGS_VOLUME_MAX, &app->sound_volume)) {
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_screen(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
char time_text[32];
|
||||
int return_hover = 0;
|
||||
int font = flint_px(48);
|
||||
int max_w;
|
||||
int text_w;
|
||||
|
||||
if(ui_draw_icon_btn_padded(flint_px(12), flint_px(12), flint_px(24),
|
||||
flint_px(10), app->icons[UI_ICON_TYPE_RETURN], &return_hover)) {
|
||||
meditation_request_exit(app);
|
||||
return;
|
||||
}
|
||||
|
||||
draw_meditation_sound_controls(app);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmExitSession) {
|
||||
int elapsed = meditation_elapsed_seconds(app);
|
||||
int modal_result;
|
||||
|
||||
if(elapsed >= 60) {
|
||||
modal_result = ui_draw_modal_3btn(locale_get("exit_session_title"),
|
||||
locale_get("meditation_save_elapsed_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("save_button"),
|
||||
locale_get("discard_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_save_elapsed(app);
|
||||
meditation_exit_to_start(app);
|
||||
} else if(modal_result == 3) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
} else {
|
||||
modal_result = ui_draw_modal(locale_get("exit_session_title"),
|
||||
locale_get("meditation_under_minute_exit_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("exit_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
format_meditation_time(time_text, sizeof(time_text), app->meditation_remaining_seconds);
|
||||
max_w = view_width - flint_px(48);
|
||||
while(font > flint_px(28) && flint_text_measure(time_text, font) > max_w)
|
||||
font--;
|
||||
text_w = flint_text_measure(time_text, font);
|
||||
flint_text_draw(time_text, center_x - text_w / 2,
|
||||
flint_ui_text_y(time_text, center_y - font, font * 2, font),
|
||||
font, theme_get_text());
|
||||
|
||||
app->meditation_frame_ticks++;
|
||||
if(app->meditation_frame_ticks >= 60) {
|
||||
app->meditation_frame_ticks = 0;
|
||||
if(app->meditation_remaining_seconds > 0)
|
||||
app->meditation_remaining_seconds--;
|
||||
if(app->meditation_remaining_seconds <= 0)
|
||||
meditation_finish(app);
|
||||
}
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1290,7 +773,7 @@ handle_back_button(InbeApp *app)
|
||||
break;
|
||||
|
||||
case InbeScreenResults:
|
||||
session_ensure_results_saved(app);
|
||||
practice_ensure_results_saved(app);
|
||||
inbe_app_init(app);
|
||||
break;
|
||||
|
||||
@@ -1313,7 +796,11 @@ handle_back_button(InbeApp *app)
|
||||
break;
|
||||
|
||||
case InbeScreenMeditation:
|
||||
meditation_request_exit(app);
|
||||
{
|
||||
const PracticeDefinition *practice = practice_get(PRACTICE_MEDITATION);
|
||||
if(practice->request_exit != NULL)
|
||||
practice->request_exit(app);
|
||||
}
|
||||
break;
|
||||
|
||||
case InbeScreenStart:
|
||||
@@ -1350,7 +837,11 @@ updateapp(InbeApp *app)
|
||||
int hover = 0;
|
||||
|
||||
app_apply_pending_bottom_tab(app);
|
||||
meditation_music_update(app);
|
||||
for(int i = 0; i < practice_count(); i++) {
|
||||
const PracticeDefinition *practice = practice_get(i);
|
||||
if(practice->update != NULL)
|
||||
practice->update(app);
|
||||
}
|
||||
if(app->practice_coming_soon_ticks > 0)
|
||||
app->practice_coming_soon_ticks--;
|
||||
|
||||
@@ -1374,7 +865,9 @@ updateapp(InbeApp *app)
|
||||
}
|
||||
|
||||
if(app->inbe.screen == InbeScreenPracticeConfig) {
|
||||
practice_config_screen_draw(app);
|
||||
const PracticeDefinition *practice = practice_get(app->exercise_type);
|
||||
if(practice->draw_config != NULL)
|
||||
practice->draw_config(app);
|
||||
goto finish_frame;
|
||||
}
|
||||
|
||||
@@ -1407,17 +900,16 @@ updateapp(InbeApp *app)
|
||||
}
|
||||
|
||||
if(app->inbe.screen == InbeScreenStart) {
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(58) + flint_px(64));
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(58) + flint_px(64));
|
||||
} else if(app->inbe.screen == InbeScreenSession) {
|
||||
session_update_circle_bounds_for_view(&app->inbe, 0, 84);
|
||||
practice_update_circle_bounds(app, 0, 84);
|
||||
}
|
||||
|
||||
int play_circle_clicked = 0;
|
||||
if(app->inbe.screen == InbeScreenStart)
|
||||
play_circle_clicked = session_draw_start_preview(app, center_x, center_y);
|
||||
play_circle_clicked = practice_draw_start_preview(app, center_x, center_y);
|
||||
else if(app->inbe.screen == InbeScreenSession)
|
||||
session_draw_inbe(app, center_x, center_y);
|
||||
practice_draw_active_breathing(app, center_x, center_y);
|
||||
|
||||
|
||||
switch (app->inbe.screen) {
|
||||
@@ -1489,12 +981,10 @@ updateapp(InbeApp *app)
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenManual;
|
||||
} else if(app->exercise_type == EXERCISE_MEDITATION) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationSetup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
session_start(app);
|
||||
const PracticeDefinition *practice = practice_get(app->exercise_type);
|
||||
if(practice->start != NULL)
|
||||
practice->start(app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1506,20 +996,27 @@ updateapp(InbeApp *app)
|
||||
save_settings(app);
|
||||
}
|
||||
app_draw_bottom_nav(app);
|
||||
if(app->modal.active && app->modal.type == UIModalMeditationSetup)
|
||||
draw_meditation_setup_modal(app);
|
||||
if(app->modal.active && app->modal.type == UIModalMeditationSetup) {
|
||||
const PracticeDefinition *practice = practice_get(PRACTICE_MEDITATION);
|
||||
if(practice->draw_setup_modal != NULL)
|
||||
practice->draw_setup_modal(app);
|
||||
}
|
||||
break;
|
||||
|
||||
case InbeScreenSession:
|
||||
session_update_screen(app, center_x, center_y, &hover);
|
||||
practice_update_active_breathing(app, center_x, center_y, &hover);
|
||||
break;
|
||||
|
||||
case InbeScreenMeditation:
|
||||
draw_meditation_screen(app, center_x, center_y);
|
||||
{
|
||||
const PracticeDefinition *practice = practice_get(PRACTICE_MEDITATION);
|
||||
if(practice->draw_active_session != NULL)
|
||||
practice->draw_active_session(app, center_x, center_y);
|
||||
}
|
||||
break;
|
||||
|
||||
case InbeScreenResults:
|
||||
session_draw_results_screen(app, center_x, center_y, &hover);
|
||||
practice_draw_results(app, center_x, center_y, &hover);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -1544,11 +1041,7 @@ inbe_app_update_draw(void *vapp, Rectangle viewport) {
|
||||
flint_set_view_size(view_width, view_height);
|
||||
|
||||
ui_init(view_width, view_height, flint_dpi_scale());
|
||||
#if defined(LOTUS_BUILD)
|
||||
sync_lotus_settings(app);
|
||||
#endif
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + flint_px(80));
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(56) + flint_px(80));
|
||||
|
||||
app->cursor_clickable = 0;
|
||||
app->cursor_disabled = 0;
|
||||
@@ -1570,7 +1063,8 @@ inbe_app_update_draw(void *vapp, Rectangle viewport) {
|
||||
flint_clip_end();
|
||||
}
|
||||
|
||||
static void SafeUnloadTexture(Texture2D texture) {
|
||||
void
|
||||
app_unload_texture(Texture2D texture) {
|
||||
if (texture.id != 0) {
|
||||
UnloadTexture(texture);
|
||||
}
|
||||
@@ -1593,15 +1087,17 @@ inbe_app_destroy(void *vapp)
|
||||
|
||||
// Unload all icons
|
||||
flint_unload_all_icons(app->icons);
|
||||
SafeUnloadTexture(app->whm_1_image);
|
||||
SafeUnloadTexture(app->whm_2_image);
|
||||
SafeUnloadTexture(app->font_shapes_texture);
|
||||
app_unload_texture(app->font_shapes_texture);
|
||||
unload_locale_font(app);
|
||||
|
||||
SafeUnloadSound(app->breath_in_sound);
|
||||
SafeUnloadSound(app->breath_out_sound);
|
||||
SafeUnloadSound(app->bell_sound);
|
||||
meditation_music_unload(app);
|
||||
for(int i = 0; i < practice_count(); i++) {
|
||||
const PracticeDefinition *practice = practice_get(i);
|
||||
if(practice->destroy != NULL)
|
||||
practice->destroy(app);
|
||||
}
|
||||
|
||||
if (app->audio_ready) {
|
||||
CloseAudioDevice();
|
||||
|
||||
@@ -60,6 +60,7 @@ typedef enum {
|
||||
UIModalConfirmDeleteHabit,
|
||||
UIModalEditProgressiveStartSpeed,
|
||||
UIModalMeditationNetworkError,
|
||||
UIModalConfirmImportDataSettings,
|
||||
} UIModalType;
|
||||
|
||||
typedef struct {
|
||||
@@ -78,15 +79,6 @@ typedef struct InbeConfig {
|
||||
|
||||
extern InbeConfig config;
|
||||
|
||||
typedef struct LotusAppApi {
|
||||
const char *id;
|
||||
void *(*create)(void);
|
||||
void (*init)(void *state);
|
||||
void (*init_args)(void *state, int argc, char **argv);
|
||||
void (*update_draw)(void *state, Rectangle viewport);
|
||||
void (*destroy)(void *state);
|
||||
} LotusAppApi;
|
||||
|
||||
typedef enum HoldDisplayMode {
|
||||
HOLD_DISPLAY_CIRCLE = 0,
|
||||
HOLD_DISPLAY_STOPWATCH = 1,
|
||||
@@ -95,7 +87,7 @@ typedef enum HoldDisplayMode {
|
||||
typedef enum ExerciseType {
|
||||
EXERCISE_WIM_HOF = 0,
|
||||
EXERCISE_MEDITATION = 1,
|
||||
EXERCISE_COUNT
|
||||
EXERCISE_COUNT = 2
|
||||
} ExerciseType;
|
||||
|
||||
typedef enum AppThemeMode {
|
||||
@@ -122,6 +114,30 @@ typedef enum AppMainTab {
|
||||
APP_MAIN_TAB_PRACTICE = 1,
|
||||
} AppMainTab;
|
||||
|
||||
typedef struct WhmPracticeState {
|
||||
Texture2D image_1;
|
||||
Texture2D image_2;
|
||||
} WhmPracticeState;
|
||||
|
||||
typedef struct MeditationPracticeState {
|
||||
Texture2D image_1;
|
||||
int duration_seconds;
|
||||
int remaining_seconds;
|
||||
int frame_ticks;
|
||||
int music_enabled;
|
||||
int music_shuffle;
|
||||
int music_track;
|
||||
int music_loaded;
|
||||
int music_playing;
|
||||
int music_test_playing;
|
||||
int music_archive_extracted;
|
||||
int music_network_error_notified;
|
||||
Music music;
|
||||
FlintRuntimeAssetDownload music_download;
|
||||
char music_cache_dir[FS_PATH_MAX];
|
||||
char music_status[128];
|
||||
} MeditationPracticeState;
|
||||
|
||||
struct InbeApp {
|
||||
Inbe inbe;
|
||||
Inbe settings_preview;
|
||||
@@ -132,8 +148,8 @@ struct InbeApp {
|
||||
int cursor_disabled;
|
||||
Texture2D icons[UI_ICON_TYPE_COUNT];
|
||||
|
||||
Texture2D whm_1_image;
|
||||
Texture2D whm_2_image;
|
||||
WhmPracticeState whm;
|
||||
MeditationPracticeState meditation;
|
||||
Texture2D font_shapes_texture;
|
||||
Font locale_font;
|
||||
Font locale_font_8;
|
||||
@@ -177,9 +193,6 @@ struct InbeApp {
|
||||
int android_orientation;
|
||||
int main_tab;
|
||||
int pending_bottom_tab;
|
||||
#if defined(LOTUS_BUILD)
|
||||
unsigned int lotus_settings_version;
|
||||
#endif
|
||||
InbeHabits habits;
|
||||
int habit_detail_index;
|
||||
int habit_detail_day;
|
||||
@@ -213,21 +226,6 @@ struct InbeApp {
|
||||
char results_path[FS_PATH_MAX];
|
||||
int saved_pause_seconds;
|
||||
int volume_popup_active;
|
||||
int meditation_duration_seconds;
|
||||
int meditation_remaining_seconds;
|
||||
int meditation_frame_ticks;
|
||||
int meditation_music_enabled;
|
||||
int meditation_music_shuffle;
|
||||
int meditation_music_track;
|
||||
int meditation_music_loaded;
|
||||
int meditation_music_playing;
|
||||
int meditation_music_test_playing;
|
||||
int meditation_music_archive_extracted;
|
||||
int meditation_music_network_error_notified;
|
||||
Music meditation_music;
|
||||
FlintRuntimeAssetDownload meditation_music_download;
|
||||
char meditation_music_cache_dir[FS_PATH_MAX];
|
||||
char meditation_music_status[128];
|
||||
UIModal modal;
|
||||
int play_circle_hover;
|
||||
float play_circle_scale;
|
||||
@@ -236,16 +234,15 @@ struct InbeApp {
|
||||
void inbe_app_init(void *app);
|
||||
void inbe_app_update_draw(void *app, Rectangle viewport);
|
||||
void inbe_app_destroy(void *app);
|
||||
void update_session_sounds(InbeApp *app);
|
||||
void app_play_sound(InbeApp *app, Sound sound, float scale);
|
||||
Texture2D app_load_asset_texture(const char *name);
|
||||
void app_unload_texture(Texture2D texture);
|
||||
|
||||
int clampi(int x, int min, int max);
|
||||
int int_from_count(const char src[4]);
|
||||
void count_from_int(char dst[4], int value);
|
||||
void save_settings(InbeApp *app);
|
||||
void reset_settings_preview(InbeApp *app);
|
||||
void app_reload_after_import(InbeApp *app, int reload_settings);
|
||||
void update_preview_bounds(Inbe *inbe, int content_w, int max_h);
|
||||
void apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds);
|
||||
void refresh_theme_colors(int theme_id, int dark_mode);
|
||||
void refresh_locale_dependent_text(InbeApp *app);
|
||||
void apply_language_selection(InbeApp *app, int language_index, int save_now);
|
||||
@@ -253,7 +250,7 @@ int exercise_manual_seen(InbeApp *app, int exercise_type);
|
||||
void mark_exercise_manual_seen(InbeApp *app, int exercise_type);
|
||||
void sync_habits_for_activity(InbeApp *app, int exercise_type);
|
||||
void draw_preview_inbe(Inbe *inbe, int center_x, int center_y);
|
||||
int draw_hold_display_mode_selector(InbeApp *app, int x, int y, int w);
|
||||
void settings_draw_progressive_start_speed_editor(InbeApp *app);
|
||||
|
||||
#include "app_settings.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
#include "app_settings.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "device_preferences.h"
|
||||
#include "locale.h"
|
||||
#include "practices/meditation/meditation_music.h"
|
||||
#include "practices/whm/whm_session.h"
|
||||
#include "storage.h"
|
||||
#include "theme.h"
|
||||
#include "flint_dpi.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
typedef struct IntSetting {
|
||||
const char *key;
|
||||
int value;
|
||||
} IntSetting;
|
||||
|
||||
typedef struct LoadedIntSetting {
|
||||
int *dst;
|
||||
const char *key;
|
||||
int fallback;
|
||||
} LoadedIntSetting;
|
||||
|
||||
typedef struct LoadedBoolSetting {
|
||||
int *dst;
|
||||
const char *key;
|
||||
int fallback;
|
||||
} LoadedBoolSetting;
|
||||
|
||||
typedef struct LoadedClampedSetting {
|
||||
int *dst;
|
||||
const char *key;
|
||||
int fallback;
|
||||
int min_value;
|
||||
int max_value;
|
||||
} LoadedClampedSetting;
|
||||
|
||||
static int
|
||||
exercise_manual_bit(int exercise_type)
|
||||
{
|
||||
if(exercise_type < 0 || exercise_type >= EXERCISE_COUNT)
|
||||
return 0;
|
||||
return 1 << exercise_type;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
static void
|
||||
sync_web_storage(void)
|
||||
{
|
||||
EM_ASM({
|
||||
if(typeof FS !== 'undefined' && typeof FS.syncfs === 'function') {
|
||||
if(Module.inbeSyncfsTimer)
|
||||
clearTimeout(Module.inbeSyncfsTimer);
|
||||
Module.__inbeStorageSyncPending = true;
|
||||
Module.inbeSyncfsTimer = setTimeout(function() {
|
||||
Module.inbeSyncfsTimer = 0;
|
||||
Module.__inbeStorageSyncing = true;
|
||||
try {
|
||||
FS.syncfs(false, function(err) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
if(err) console.error("IDBFS save failed:", err);
|
||||
else console.log("IDBFS synced");
|
||||
});
|
||||
} catch(e) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
console.error("IDBFS sync error:", e);
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
save_int_settings(const IntSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++)
|
||||
inbe_storage_set_setting_int(settings[i].key, settings[i].value);
|
||||
}
|
||||
|
||||
static void
|
||||
load_int_settings(const LoadedIntSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++)
|
||||
*settings[i].dst = inbe_storage_get_setting_int(settings[i].key,
|
||||
settings[i].fallback);
|
||||
}
|
||||
|
||||
static void
|
||||
load_bool_settings(const LoadedBoolSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++)
|
||||
*settings[i].dst = inbe_storage_get_setting_int(settings[i].key,
|
||||
settings[i].fallback) != 0;
|
||||
}
|
||||
|
||||
static void
|
||||
load_clamped_settings(const LoadedClampedSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
int value = inbe_storage_get_setting_int(settings[i].key, settings[i].fallback);
|
||||
*settings[i].dst = clampi(value, settings[i].min_value, settings[i].max_value);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds)
|
||||
{
|
||||
speed = clampi(speed, SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
inbe->speed_level = speed;
|
||||
inbe->breath_half_ticks = inbe_breath_half_ticks_for_speed(speed);
|
||||
inbe->breath_animation = clampi(inbe->breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
inbe->progressive_start_speed = clampi(inbe->progressive_start_speed,
|
||||
SETTINGS_SPEED_MIN, speed);
|
||||
inbe->max_rounds = clampi(max_rounds, 1, MaxRounds);
|
||||
inbe->pause_seconds = clampi(pause_seconds, SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX);
|
||||
count_from_int(inbe->maxbreaths,
|
||||
clampi(max_breaths, SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX));
|
||||
}
|
||||
|
||||
void
|
||||
reset_settings_preview(InbeApp *app)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
int breath_animation = app->inbe.breath_animation;
|
||||
int content_w;
|
||||
|
||||
inbeinit(&app->settings_preview);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_preview.play_in_background = play_in_background;
|
||||
app->settings_preview.breath_animation = breath_animation;
|
||||
flint_centered_column(CONTENT_MAX_W, CONTENT_SIDE_PAD, NULL, &content_w);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
session_reset_round_breathe(&app->settings_preview);
|
||||
}
|
||||
|
||||
void
|
||||
save_settings(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
const IntSetting int_settings[] = {
|
||||
{"speed", app->inbe.speed_level},
|
||||
{"max_rounds", app->inbe.max_rounds},
|
||||
{"max_breaths", int_from_count(app->inbe.maxbreaths)},
|
||||
{"pause_seconds", app->inbe.pause_seconds},
|
||||
{"sound_volume", app->sound_volume},
|
||||
{"tutorial_seen", app->tutorial_seen ? 1 : 0},
|
||||
{"exercise_manual_seen_mask", app->exercise_manual_seen_mask},
|
||||
{"theme", app->theme_id},
|
||||
{"dark_mode", app->dark_mode},
|
||||
{"theme_mode", app->theme_mode},
|
||||
{"orientation_mode", app->orientation_mode},
|
||||
{"main_tab", app->main_tab},
|
||||
{"fullscreen", app->fullscreen_enabled ? 1 : 0},
|
||||
{"on_screen_keyboard", app->on_screen_keyboard_enabled ? 1 : 0},
|
||||
{"progressive_speed", app->inbe.progressive_speed},
|
||||
{"progressive_start_speed", app->inbe.progressive_start_speed},
|
||||
{"breath_animation", app->inbe.breath_animation},
|
||||
{"advanced_session_controls", app->advanced_session_controls ? 1 : 0},
|
||||
{"hold_display_mode", app->hold_display_mode},
|
||||
{"exercise_type", app->exercise_type},
|
||||
{"meditation_music_enabled", app->meditation.music_enabled ? 1 : 0},
|
||||
{"meditation_music_shuffle", app->meditation.music_shuffle ? 1 : 0},
|
||||
{"meditation_music_track", app->meditation.music_track},
|
||||
{"play_in_background", app->inbe.play_in_background},
|
||||
{"practice_category_tab", app->practice_category_tab},
|
||||
};
|
||||
|
||||
inbe_storage_settings_begin_write();
|
||||
save_int_settings(int_settings, sizeof(int_settings) / sizeof(int_settings[0]));
|
||||
inbe_storage_set_setting_text("language",
|
||||
(app->language_selected && app->language[0] != '\0') ?
|
||||
app->language : "");
|
||||
inbe_storage_settings_end_write();
|
||||
#if defined(PLATFORM_WEB)
|
||||
sync_web_storage();
|
||||
#endif
|
||||
app->settings_dirty = 0;
|
||||
app->settings_save_delay_ticks = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
load_language_setting(InbeApp *app, int settings_missing)
|
||||
{
|
||||
const char *language = inbe_storage_get_setting_text("language");
|
||||
|
||||
app->language_needs_save = 0;
|
||||
if(language != NULL && language[0] != '\0') {
|
||||
snprintf(app->language, sizeof(app->language), "%s", language);
|
||||
app->language_selected = 1;
|
||||
if(!locale_set(app->language)) {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
locale_set(app->language);
|
||||
}
|
||||
} else {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
app->language_selected = settings_missing ? 0 : 1;
|
||||
app->language_needs_save = app->language_selected;
|
||||
locale_set(app->language);
|
||||
}
|
||||
|
||||
app->language_index = locale_current_index();
|
||||
if(app->language_index < 0)
|
||||
app->language_index = 0;
|
||||
}
|
||||
|
||||
int
|
||||
app_load_settings(InbeApp *app)
|
||||
{
|
||||
int settings_missing;
|
||||
int speed;
|
||||
int max_rounds;
|
||||
int max_breaths;
|
||||
int pause_seconds;
|
||||
int manual_seen_mask;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
|
||||
settings_missing = inbe_storage_settings_empty();
|
||||
|
||||
{
|
||||
LoadedIntSetting settings[] = {
|
||||
{&speed, "speed", DefaultSpeedLevel},
|
||||
{&max_rounds, "max_rounds", DefaultMaxRounds},
|
||||
{&max_breaths, "max_breaths", DefaultMaxBreaths},
|
||||
{&pause_seconds, "pause_seconds", DefaultPauseSeconds},
|
||||
};
|
||||
load_int_settings(settings, sizeof(settings) / sizeof(settings[0]));
|
||||
}
|
||||
|
||||
{
|
||||
LoadedBoolSetting settings[] = {
|
||||
{&app->tutorial_seen, "tutorial_seen", 0},
|
||||
{&app->dark_mode, "dark_mode", 0},
|
||||
{&app->fullscreen_enabled, "fullscreen", 0},
|
||||
#ifdef __ANDROID__
|
||||
{&app->on_screen_keyboard_enabled, "on_screen_keyboard", 1},
|
||||
#else
|
||||
{&app->on_screen_keyboard_enabled, "on_screen_keyboard", 0},
|
||||
#endif
|
||||
{&app->inbe.progressive_speed, "progressive_speed", 1},
|
||||
{&app->advanced_session_controls, "advanced_session_controls", 0},
|
||||
{&app->meditation.music_enabled, "meditation_music_enabled", 1},
|
||||
{&app->meditation.music_shuffle, "meditation_music_shuffle", 0},
|
||||
};
|
||||
load_bool_settings(settings, sizeof(settings) / sizeof(settings[0]));
|
||||
}
|
||||
|
||||
{
|
||||
LoadedClampedSetting settings[] = {
|
||||
{&app->sound_volume, "sound_volume", 100,
|
||||
SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX},
|
||||
{&app->theme_id, "theme", 0, 0, FLINT_THEME_COUNT - 1},
|
||||
{&app->theme_mode, "theme_mode", APP_THEME_SYSTEM,
|
||||
APP_THEME_SYSTEM, APP_THEME_DARK},
|
||||
{&app->orientation_mode, "orientation_mode", APP_ORIENTATION_SYSTEM,
|
||||
APP_ORIENTATION_SYSTEM, APP_ORIENTATION_SENSOR},
|
||||
{&app->main_tab, "main_tab", APP_MAIN_TAB_PRACTICE,
|
||||
APP_MAIN_TAB_HABITS, APP_MAIN_TAB_PRACTICE},
|
||||
{&app->inbe.progressive_start_speed, "progressive_start_speed",
|
||||
DefaultProgressiveStartSpeed, SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX},
|
||||
{&app->inbe.breath_animation, "breath_animation", InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationLinear, InbeBreathAnimationCount - 1},
|
||||
{&app->hold_display_mode, "hold_display_mode", HOLD_DISPLAY_CIRCLE,
|
||||
HOLD_DISPLAY_CIRCLE, HOLD_DISPLAY_STOPWATCH},
|
||||
{&app->exercise_type, "exercise_type", EXERCISE_WIM_HOF,
|
||||
EXERCISE_WIM_HOF, EXERCISE_COUNT - 1},
|
||||
{&app->meditation.music_track, "meditation_music_track", 0,
|
||||
0, MEDITATION_MUSIC_TRACK_COUNT - 1},
|
||||
{&app->practice_category_tab, "practice_category_tab", PRACTICE_CATEGORY_MIND,
|
||||
0, PRACTICE_CATEGORY_COUNT - 1},
|
||||
};
|
||||
load_clamped_settings(settings, sizeof(settings) / sizeof(settings[0]));
|
||||
}
|
||||
|
||||
manual_seen_mask = inbe_storage_get_setting_int("exercise_manual_seen_mask", -1);
|
||||
if(manual_seen_mask < 0)
|
||||
manual_seen_mask = app->tutorial_seen ? exercise_manual_bit(EXERCISE_WIM_HOF) : 0;
|
||||
app->exercise_manual_seen_mask = manual_seen_mask & ((1 << EXERCISE_COUNT) - 1);
|
||||
|
||||
load_language_setting(app, settings_missing);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
app->inbe.play_in_background =
|
||||
inbe_storage_get_setting_int("play_in_background", 1) != 0;
|
||||
TraceLog(LOG_INFO, "INBE: Loaded play_in_background setting = %d",
|
||||
app->inbe.play_in_background);
|
||||
#else
|
||||
app->inbe.play_in_background = 0;
|
||||
#endif
|
||||
app->backgrounded = 0;
|
||||
|
||||
app_device_preferences_init(app);
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
refresh_locale_dependent_text(app);
|
||||
|
||||
return settings_missing;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef INBE_APP_SETTINGS_H
|
||||
#define INBE_APP_SETTINGS_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
#include "breath_engine.h"
|
||||
|
||||
void save_settings(InbeApp *app);
|
||||
int app_load_settings(InbeApp *app);
|
||||
void reset_settings_preview(InbeApp *app);
|
||||
void apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "device_preferences.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#if defined(LOTUS_BUILD)
|
||||
#include "lotus_settings.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_device.h"
|
||||
#endif
|
||||
@@ -17,18 +14,9 @@ void
|
||||
refresh_theme_colors(int theme_id, int dark_mode)
|
||||
{
|
||||
theme_set_current(theme_id, dark_mode);
|
||||
#if defined(LOTUS_BUILD)
|
||||
(void)theme_id;
|
||||
(void)dark_mode;
|
||||
ui_set_colors(theme_get_text(), theme_get_bg(), theme_get_surface(),
|
||||
theme_get_circle(), theme_get_button(), theme_get_button_hover(),
|
||||
theme_get_icon());
|
||||
return;
|
||||
#else
|
||||
ui_set_colors(theme_get_text(), theme_get_bg(), theme_get_surface(),
|
||||
theme_get_circle(), theme_get_button(), theme_get_button_hover(),
|
||||
theme_get_icon());
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define INBE_VERSION_MAJOR 1
|
||||
#define INBE_VERSION_MINOR 3
|
||||
#define INBE_VERSION_PATCH 2
|
||||
#define INBE_VERSION_STRING "1.3.2"
|
||||
#define INBE_VERSION_PATCH 5
|
||||
#define INBE_VERSION_STRING "1.3.5"
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "android_timer.h"
|
||||
#include "app.h"
|
||||
#include "practices/practice_registry.h"
|
||||
#include <time.h>
|
||||
|
||||
#include <raylib.h>
|
||||
@@ -41,15 +42,15 @@ timer_thread_func(void *arg) {
|
||||
if (should_run) {
|
||||
// Log every 60 frames (1 second)
|
||||
if (frame_count % 60 == 0) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer: Running meditation step + sounds");
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer: Running background practice step + sounds");
|
||||
}
|
||||
frame_count++;
|
||||
|
||||
// Update meditation state and sounds with mutex protection
|
||||
// Update practice state and sounds with mutex protection
|
||||
pthread_mutex_lock(&inbe_state_mutex);
|
||||
InbeApp *app = (InbeApp*)g_app;
|
||||
inbestep(&app->inbe);
|
||||
update_session_sounds(app);
|
||||
practice_update_session_sounds(app);
|
||||
pthread_mutex_unlock(&inbe_state_mutex);
|
||||
|
||||
// Sleep for exact frame time (60fps = ~16.666ms)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "meditation_music.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
static int
|
||||
meditation_config_content_height(InbeApp *app, int content_w)
|
||||
{
|
||||
return meditation_music_measure_settings(app, content_w, 1, 1);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_config_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
int min_content_w = flint_px(320);
|
||||
int scroll_y;
|
||||
int scroll_h;
|
||||
int content_h;
|
||||
int controls_w;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIHeader header;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < min_content_w)
|
||||
responsive_max_w = min_content_w;
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
header = ui_draw_title_header(title_h, locale_get("exercise_meditation"),
|
||||
(Texture2D){0}, app->icons[UI_ICON_TYPE_X]);
|
||||
if(header.right_clicked) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
meditation_practice_leave_config(app);
|
||||
app->settings_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
scroll_y = title_h + flint_px(16);
|
||||
scroll_h = view_height - scroll_y;
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
|
||||
controls_w = content_w;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
FlintUIScrollView measured;
|
||||
content_h = meditation_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == controls_w)
|
||||
break;
|
||||
controls_w = measured.content_w;
|
||||
}
|
||||
|
||||
content_h = meditation_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
{
|
||||
int y = scroll_view.content_y;
|
||||
meditation_music_draw_settings(app, scroll_view.content_x, scroll_view.content_w,
|
||||
&y, 1, 1);
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "meditation_music.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
enum {
|
||||
MEDITATION_MANUAL_PAGES = 2
|
||||
};
|
||||
|
||||
static void
|
||||
meditation_manual_start(InbeApp *app)
|
||||
{
|
||||
mark_exercise_manual_seen(app, EXERCISE_MEDITATION);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
meditation_practice_start(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_manual_close(InbeApp *app, int mark_seen)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(mark_seen)
|
||||
mark_exercise_manual_seen(app, EXERCISE_MEDITATION);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_intro_page(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
int img_h = flint_px(190);
|
||||
FlintUIParagraph paragraph;
|
||||
|
||||
ui_draw_tutorial_image(app->meditation.image_1, "practices/meditation/1.jpg",
|
||||
content_x, *y, content_w, img_h);
|
||||
*y += img_h + flint_px(22);
|
||||
|
||||
paragraph = (FlintUIParagraph){
|
||||
.text = locale_get("meditation_manual_intro_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
flint_ui_paragraph_draw(paragraph, content_x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
intro_page_height(int content_w)
|
||||
{
|
||||
FlintUIParagraph paragraph = {
|
||||
.text = locale_get("meditation_manual_intro_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
|
||||
return flint_px(190) + flint_px(22) + flint_ui_paragraph_height(paragraph) +
|
||||
flint_px(20);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_page_height(InbeApp *app, int content_w)
|
||||
{
|
||||
FlintUIParagraph paragraph = {
|
||||
.text = locale_get("meditation_manual_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
|
||||
return meditation_music_measure_settings(app, content_w, 0, 1) +
|
||||
flint_px(34) + flint_ui_paragraph_height(paragraph) + flint_px(20);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_manual_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int button_h = flint_px(36);
|
||||
int footer_y = view_height - flint_px(42);
|
||||
int content_y = title_h + flint_px(16);
|
||||
int content_h = footer_y - content_y - flint_px(28);
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.90f);
|
||||
int max_content_w = flint_px(520);
|
||||
int page = clampi(app->tutorial_step, 0, MEDITATION_MANUAL_PAGES - 1);
|
||||
int content_total_h;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < flint_px(280))
|
||||
responsive_max_w = flint_px(280);
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
app->tutorial_step = page;
|
||||
if(ui_draw_screen_header(locale_get("meditation_manual_title"), 1))
|
||||
meditation_manual_close(app, 0);
|
||||
|
||||
if(content_h < flint_px(120))
|
||||
content_h = flint_px(120);
|
||||
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
content_total_h = page == 0 ? intro_page_height(content_w)
|
||||
: settings_page_height(app, content_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y, (float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
|
||||
content_total_h = page == 0 ? intro_page_height(content_w)
|
||||
: settings_page_height(app, content_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y, (float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
{
|
||||
int y = scroll_view.content_y;
|
||||
if(page == 0) {
|
||||
draw_intro_page(app, scroll_view.content_x, scroll_view.content_w, &y);
|
||||
} else {
|
||||
FlintUIParagraph paragraph;
|
||||
meditation_music_draw_settings(app, scroll_view.content_x, scroll_view.content_w,
|
||||
&y, 0, 1);
|
||||
y += flint_px(34);
|
||||
paragraph = (FlintUIParagraph){
|
||||
.text = locale_get("meditation_manual_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = scroll_view.content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
flint_ui_paragraph_draw(paragraph, scroll_view.content_x, &y);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
if(page == 1)
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
|
||||
{
|
||||
int gap = flint_px(10);
|
||||
int button_w = (content_w - gap) / 2;
|
||||
int hover = 0;
|
||||
const char *left = page == 0 ? locale_get("tutorial_skip_button")
|
||||
: locale_get("tutorial_back_button");
|
||||
const char *right = page == 0 ? locale_get("tutorial_next_button")
|
||||
: locale_get("tutorial_start_button");
|
||||
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left, UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(page == 0)
|
||||
meditation_manual_start(app);
|
||||
else {
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
if(ui_draw_generic_button(content_x + button_w + gap, footer_y, button_w,
|
||||
button_h, right, UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(page == 0) {
|
||||
app->tutorial_step = 1;
|
||||
app->manual_scroll = 0;
|
||||
} else {
|
||||
meditation_manual_start(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
@@ -143,11 +143,31 @@ set_status(InbeApp *app, const char *message)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
copy_text_checked(app->meditation_music_status,
|
||||
sizeof(app->meditation_music_status),
|
||||
copy_text_checked(app->meditation.music_status,
|
||||
sizeof(app->meditation.music_status),
|
||||
message);
|
||||
}
|
||||
|
||||
static int
|
||||
download_supported(void)
|
||||
{
|
||||
#if defined(PLATFORM_WEB)
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *
|
||||
missing_audio_message(void)
|
||||
{
|
||||
#if defined(PLATFORM_WEB)
|
||||
return "Audio is unavailable";
|
||||
#else
|
||||
return "Download audio before playing music";
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
is_network_download_error(const FlintRuntimeAssetDownload *download)
|
||||
{
|
||||
@@ -207,7 +227,7 @@ draw_download_progress(InbeApp *app, int x, int y, int w)
|
||||
if(app == NULL || w <= 0)
|
||||
return;
|
||||
|
||||
download = &app->meditation_music_download;
|
||||
download = &app->meditation.music_download;
|
||||
if(download->status != FLINT_RUNTIME_ASSET_DOWNLOADING)
|
||||
return;
|
||||
|
||||
@@ -264,7 +284,7 @@ draw_music_attribution(int content_x, int content_w, int *y)
|
||||
static void
|
||||
music_archive_path(InbeApp *app, char *out, size_t out_size)
|
||||
{
|
||||
if(!join_path2(out, out_size, app->meditation_music_cache_dir,
|
||||
if(!join_path2(out, out_size, app->meditation.music_cache_dir,
|
||||
"/inbe-meditation-audio-v1.zip"))
|
||||
set_status(app, "Audio cache path is too long");
|
||||
}
|
||||
@@ -281,7 +301,7 @@ music_track_path(InbeApp *app, int track, char *out, size_t out_size)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if(join_path2(out, out_size, app->meditation_music_cache_dir, "/audio/") &&
|
||||
if(join_path2(out, out_size, app->meditation.music_cache_dir, "/audio/") &&
|
||||
append_text_checked(out, out_size, g_tracks[track].file) &&
|
||||
file_exists(out))
|
||||
return;
|
||||
@@ -302,10 +322,10 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
flint_runtime_asset_ensure_dir(app->meditation_music_cache_dir);
|
||||
flint_runtime_asset_ensure_dir(app->meditation.music_cache_dir);
|
||||
{
|
||||
char audio_dir[FS_PATH_MAX];
|
||||
if(join_path2(audio_dir, sizeof(audio_dir), app->meditation_music_cache_dir, "/audio"))
|
||||
if(join_path2(audio_dir, sizeof(audio_dir), app->meditation.music_cache_dir, "/audio"))
|
||||
flint_runtime_asset_ensure_dir(audio_dir);
|
||||
else
|
||||
set_status(app, "Audio cache path is too long");
|
||||
@@ -325,7 +345,7 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
|
||||
if(!known_track_archive_member(stat.m_filename))
|
||||
continue;
|
||||
|
||||
if(!join_path2(out_path, sizeof(out_path), app->meditation_music_cache_dir, "/audio/") ||
|
||||
if(!join_path2(out_path, sizeof(out_path), app->meditation.music_cache_dir, "/audio/") ||
|
||||
!append_text_checked(out_path, sizeof(out_path), stat.m_filename)) {
|
||||
set_status(app, "Audio file path is too long");
|
||||
continue;
|
||||
@@ -346,7 +366,7 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
|
||||
}
|
||||
|
||||
mz_zip_reader_end(&archive);
|
||||
snprintf(app->meditation_music_status, sizeof(app->meditation_music_status),
|
||||
snprintf(app->meditation.music_status, sizeof(app->meditation.music_status),
|
||||
"Installed %d audio files", extracted);
|
||||
return extracted > 0;
|
||||
}
|
||||
@@ -374,7 +394,7 @@ meditation_music_selected_label(InbeApp *app)
|
||||
int track;
|
||||
if(app == NULL)
|
||||
return "";
|
||||
track = app->meditation_music_track;
|
||||
track = app->meditation.music_track;
|
||||
if(track < 0 || track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
track = 0;
|
||||
return g_tracks[track].title;
|
||||
@@ -387,18 +407,18 @@ meditation_music_init(InbeApp *app)
|
||||
return;
|
||||
|
||||
flint_runtime_assets_init("inbe");
|
||||
if(!flint_runtime_asset_cache_root("inbe", app->meditation_music_cache_dir,
|
||||
sizeof(app->meditation_music_cache_dir))) {
|
||||
snprintf(app->meditation_music_cache_dir, sizeof(app->meditation_music_cache_dir),
|
||||
if(!flint_runtime_asset_cache_root("inbe", app->meditation.music_cache_dir,
|
||||
sizeof(app->meditation.music_cache_dir))) {
|
||||
snprintf(app->meditation.music_cache_dir, sizeof(app->meditation.music_cache_dir),
|
||||
"runtime-assets");
|
||||
flint_runtime_asset_ensure_dir(app->meditation_music_cache_dir);
|
||||
flint_runtime_asset_ensure_dir(app->meditation.music_cache_dir);
|
||||
}
|
||||
|
||||
if(app->meditation_music_track < 0 ||
|
||||
app->meditation_music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation_music_track = 0;
|
||||
if(app->meditation.music_track < 0 ||
|
||||
app->meditation.music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation.music_track = 0;
|
||||
|
||||
if(app->meditation_music_status[0] == '\0') {
|
||||
if(app->meditation.music_status[0] == '\0') {
|
||||
set_status(app, meditation_music_available(app) ? "Audio installed" : "Audio not installed");
|
||||
}
|
||||
}
|
||||
@@ -408,13 +428,13 @@ meditation_music_unload(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_loaded) {
|
||||
StopMusicStream(app->meditation_music);
|
||||
UnloadMusicStream(app->meditation_music);
|
||||
app->meditation_music_loaded = 0;
|
||||
if(app->meditation.music_loaded) {
|
||||
StopMusicStream(app->meditation.music);
|
||||
UnloadMusicStream(app->meditation.music);
|
||||
app->meditation.music_loaded = 0;
|
||||
}
|
||||
app->meditation_music_playing = 0;
|
||||
app->meditation_music_test_playing = 0;
|
||||
app->meditation.music_playing = 0;
|
||||
app->meditation.music_test_playing = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -422,10 +442,10 @@ meditation_music_stop(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_loaded)
|
||||
StopMusicStream(app->meditation_music);
|
||||
app->meditation_music_playing = 0;
|
||||
app->meditation_music_test_playing = 0;
|
||||
if(app->meditation.music_loaded)
|
||||
StopMusicStream(app->meditation.music);
|
||||
app->meditation.music_playing = 0;
|
||||
app->meditation.music_test_playing = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -435,25 +455,27 @@ meditation_music_test_track(InbeApp *app)
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_playing) {
|
||||
if(app->meditation.music_playing) {
|
||||
meditation_music_unload(app);
|
||||
set_status(app, "Test audio stopped");
|
||||
return;
|
||||
}
|
||||
if(!meditation_music_available(app)) {
|
||||
set_status(app, "Download audio before testing");
|
||||
set_status(app, missing_audio_message());
|
||||
return;
|
||||
}
|
||||
|
||||
track = app->meditation_music_track;
|
||||
track = app->meditation.music_track;
|
||||
if(track < 0 || track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
track = 0;
|
||||
if(!load_track(app, track))
|
||||
return;
|
||||
|
||||
PlayMusicStream(app->meditation_music);
|
||||
app->meditation_music_playing = 1;
|
||||
app->meditation_music_test_playing = 1;
|
||||
PlayMusicStream(app->meditation.music);
|
||||
if(!IsMusicStreamPlaying(app->meditation.music))
|
||||
TraceLog(LOG_ERROR, "AUDIO: PlayMusicStream returned but test music is not playing");
|
||||
app->meditation.music_playing = 1;
|
||||
app->meditation.music_test_playing = 1;
|
||||
set_status(app, "Playing test audio");
|
||||
}
|
||||
|
||||
@@ -462,8 +484,13 @@ load_track(InbeApp *app, int track)
|
||||
{
|
||||
char path[FS_PATH_MAX];
|
||||
|
||||
if(app == NULL || !app->audio_ready)
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(!app->audio_ready) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Cannot load meditation music because audio device is not ready");
|
||||
set_status(app, "Audio device is not ready");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(track < 0 || track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
track = 0;
|
||||
@@ -475,16 +502,18 @@ load_track(InbeApp *app, int track)
|
||||
return 0;
|
||||
}
|
||||
|
||||
app->meditation_music = LoadMusicStream(path);
|
||||
if(app->meditation_music.ctxData == NULL) {
|
||||
app->meditation.music = LoadMusicStream(path);
|
||||
if(app->meditation.music.ctxData == NULL) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Could not load meditation track: %s", path);
|
||||
set_status(app, "Could not load track");
|
||||
app->meditation_music_loaded = 0;
|
||||
app->meditation.music_loaded = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
app->meditation_music_loaded = 1;
|
||||
app->meditation_music_track = track;
|
||||
SetMusicVolume(app->meditation_music, (float)app->sound_volume / 100.0f);
|
||||
app->meditation.music_loaded = 1;
|
||||
app->meditation.music_track = track;
|
||||
SetMusicVolume(app->meditation.music, (float)app->sound_volume / 100.0f);
|
||||
TraceLog(LOG_INFO, "AUDIO: Loaded meditation track: %s", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -493,21 +522,23 @@ meditation_music_start_session(InbeApp *app)
|
||||
{
|
||||
int track;
|
||||
|
||||
if(app == NULL || !app->meditation_music_enabled)
|
||||
if(app == NULL || !app->meditation.music_enabled)
|
||||
return;
|
||||
if(!meditation_music_available(app)) {
|
||||
set_status(app, "Download audio before playing music");
|
||||
set_status(app, missing_audio_message());
|
||||
return;
|
||||
}
|
||||
|
||||
track = app->meditation_music_track;
|
||||
if(app->meditation_music_shuffle)
|
||||
track = app->meditation.music_track;
|
||||
if(app->meditation.music_shuffle)
|
||||
track = GetRandomValue(0, MEDITATION_MUSIC_TRACK_COUNT - 1);
|
||||
if(!load_track(app, track))
|
||||
return;
|
||||
PlayMusicStream(app->meditation_music);
|
||||
app->meditation_music_playing = 1;
|
||||
app->meditation_music_test_playing = 0;
|
||||
PlayMusicStream(app->meditation.music);
|
||||
if(!IsMusicStreamPlaying(app->meditation.music))
|
||||
TraceLog(LOG_ERROR, "AUDIO: PlayMusicStream returned but session music is not playing");
|
||||
app->meditation.music_playing = 1;
|
||||
app->meditation.music_test_playing = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -517,7 +548,7 @@ meditation_music_update(InbeApp *app)
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_test_playing &&
|
||||
if(app->meditation.music_test_playing &&
|
||||
(app->exercise_type != EXERCISE_MEDITATION ||
|
||||
(app->inbe.screen != InbeScreenPracticeConfig &&
|
||||
app->inbe.screen != InbeScreenManual))) {
|
||||
@@ -525,29 +556,29 @@ meditation_music_update(InbeApp *app)
|
||||
return;
|
||||
}
|
||||
|
||||
if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_READY &&
|
||||
!app->meditation_music_archive_extracted) {
|
||||
if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_READY &&
|
||||
!app->meditation.music_archive_extracted) {
|
||||
music_archive_path(app, archive_path, sizeof(archive_path));
|
||||
app->meditation_music_archive_extracted = 1;
|
||||
app->meditation.music_archive_extracted = 1;
|
||||
extract_audio_archive(app, archive_path);
|
||||
} else if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_ERROR ||
|
||||
app->meditation_music_download.status == FLINT_RUNTIME_ASSET_UNSUPPORTED) {
|
||||
if(is_network_download_error(&app->meditation_music_download)) {
|
||||
} else if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_ERROR ||
|
||||
app->meditation.music_download.status == FLINT_RUNTIME_ASSET_UNSUPPORTED) {
|
||||
if(is_network_download_error(&app->meditation.music_download)) {
|
||||
set_status(app, locale_get("meditation_music_network_error_title"));
|
||||
if(!app->meditation_music_network_error_notified && !app->modal.active) {
|
||||
if(!app->meditation.music_network_error_notified && !app->modal.active) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationNetworkError;
|
||||
app->modal.selected_button = 0;
|
||||
app->meditation_music_network_error_notified = 1;
|
||||
app->meditation.music_network_error_notified = 1;
|
||||
}
|
||||
} else if(app->meditation_music_download.error[0] != '\0') {
|
||||
set_status(app, app->meditation_music_download.error);
|
||||
} else if(app->meditation.music_download.error[0] != '\0') {
|
||||
set_status(app, app->meditation.music_download.error);
|
||||
}
|
||||
}
|
||||
|
||||
if(app->meditation_music_loaded) {
|
||||
SetMusicVolume(app->meditation_music, (float)app->sound_volume / 100.0f);
|
||||
UpdateMusicStream(app->meditation_music);
|
||||
if(app->meditation.music_loaded) {
|
||||
SetMusicVolume(app->meditation.music, (float)app->sound_volume / 100.0f);
|
||||
UpdateMusicStream(app->meditation.music);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,17 +591,17 @@ start_download(InbeApp *app)
|
||||
return;
|
||||
|
||||
music_archive_path(app, archive_path, sizeof(archive_path));
|
||||
app->meditation_music_archive_extracted = 0;
|
||||
app->meditation_music_network_error_notified = 0;
|
||||
app->meditation.music_archive_extracted = 0;
|
||||
app->meditation.music_network_error_notified = 0;
|
||||
set_status(app, "Downloading audio...");
|
||||
flint_runtime_asset_download(&app->meditation_music_download,
|
||||
flint_runtime_asset_download(&app->meditation.music_download,
|
||||
INBE_MEDITATION_AUDIO_URL,
|
||||
archive_path);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
int show_installed_download, int show_status)
|
||||
void
|
||||
meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y,
|
||||
int show_installed_download, int show_status)
|
||||
{
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
@@ -584,29 +615,29 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
if(app == NULL || y == NULL)
|
||||
return;
|
||||
|
||||
if(app->meditation_music_track < 0 ||
|
||||
app->meditation_music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation_music_track = 0;
|
||||
if(app->meditation.music_track < 0 ||
|
||||
app->meditation.music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation.music_track = 0;
|
||||
|
||||
if(!app->meditation_music_enabled) {
|
||||
app->meditation_music_enabled = 1;
|
||||
if(!app->meditation.music_enabled) {
|
||||
app->meditation.music_enabled = 1;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
|
||||
flint_text_draw(locale_get("meditation_music_shuffle_label"), content_x, *y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, *y + flint_px(26), toggle_w, toggle_h,
|
||||
&app->meditation_music_shuffle,
|
||||
&app->meditation.music_shuffle,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->settings_dirty = 1;
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
*y += flint_px(76);
|
||||
|
||||
if(!app->meditation_music_shuffle) {
|
||||
if(!app->meditation.music_shuffle) {
|
||||
flint_text_draw(locale_get("meditation_music_track_label"), content_x, *y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_dropdown_button(401, content_x, *y + flint_px(24), content_w, flint_px(36),
|
||||
g_track_options, MEDITATION_MUSIC_TRACK_COUNT,
|
||||
&app->meditation_music_track)) {
|
||||
&app->meditation.music_track)) {
|
||||
app->settings_dirty = 1;
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
@@ -615,7 +646,7 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
|
||||
installed = meditation_music_available(app);
|
||||
if(installed) {
|
||||
test_label = app->meditation_music_playing ?
|
||||
test_label = app->meditation.music_playing ?
|
||||
locale_get("meditation_music_stop_test_button") :
|
||||
locale_get("meditation_music_test_button");
|
||||
button_w = flint_text_measure(test_label, flint_ui_font()) + flint_px(24);
|
||||
@@ -628,7 +659,7 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
*y += button_h + flint_px(12);
|
||||
}
|
||||
|
||||
if(!installed || show_installed_download) {
|
||||
if(download_supported() && (!installed || show_installed_download)) {
|
||||
button_w = flint_text_measure(locale_get(installed ? "meditation_music_redownload_button"
|
||||
: "meditation_music_download_button"),
|
||||
flint_ui_font()) + flint_px(24);
|
||||
@@ -642,16 +673,16 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
*y += button_h + flint_px(12);
|
||||
}
|
||||
|
||||
if(show_status && (!installed || app->meditation_music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING) {
|
||||
if(show_status && (!installed || app->meditation.music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING) {
|
||||
format_download_status(download_status, sizeof(download_status),
|
||||
&app->meditation_music_download);
|
||||
&app->meditation.music_download);
|
||||
flint_text_draw(download_status, content_x, *y, flint_ui_font(), theme_get_text());
|
||||
*y += flint_px(28);
|
||||
draw_download_progress(app, content_x, *y, content_w);
|
||||
*y += flint_px(22);
|
||||
} else {
|
||||
flint_text_draw(app->meditation_music_status, content_x, *y, flint_ui_font(), theme_get_text());
|
||||
flint_text_draw(app->meditation.music_status, content_x, *y, flint_ui_font(), theme_get_text());
|
||||
*y += flint_px(34);
|
||||
}
|
||||
}
|
||||
@@ -670,17 +701,17 @@ meditation_music_measure_settings(InbeApp *app, int content_w,
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
|
||||
if(!app->meditation_music_shuffle)
|
||||
if(!app->meditation.music_shuffle)
|
||||
h += flint_px(74);
|
||||
|
||||
installed = meditation_music_available(app);
|
||||
if(installed)
|
||||
h += flint_px(48);
|
||||
if(!installed || show_installed_download)
|
||||
if(download_supported() && (!installed || show_installed_download))
|
||||
h += flint_px(48);
|
||||
|
||||
if(show_status && (!installed || app->meditation_music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING)
|
||||
if(show_status && (!installed || app->meditation.music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING)
|
||||
h += flint_px(50);
|
||||
else
|
||||
h += flint_px(34);
|
||||
@@ -691,18 +722,6 @@ meditation_music_measure_settings(InbeApp *app, int content_w,
|
||||
return h;
|
||||
}
|
||||
|
||||
void
|
||||
meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
draw_music_picker(app, content_x, content_w, y, 1, 1);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_music_draw_guide_settings(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
draw_music_picker(app, content_x, content_w, y, 0, 1);
|
||||
}
|
||||
|
||||
int
|
||||
meditation_music_draw_dropdown_menu(InbeApp *app)
|
||||
{
|
||||
@@ -14,8 +14,8 @@ void meditation_music_start_session(InbeApp *app);
|
||||
void meditation_music_stop(InbeApp *app);
|
||||
int meditation_music_measure_settings(InbeApp *app, int content_w,
|
||||
int show_installed_download, int show_status);
|
||||
void meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y);
|
||||
void meditation_music_draw_guide_settings(InbeApp *app, int content_x, int content_w, int *y);
|
||||
void meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y,
|
||||
int show_installed_download, int show_status);
|
||||
int meditation_music_draw_dropdown_menu(InbeApp *app);
|
||||
int meditation_music_available(InbeApp *app);
|
||||
const char *meditation_music_selected_label(InbeApp *app);
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "meditation_music.h"
|
||||
|
||||
void
|
||||
meditation_practice_init(InbeApp *app)
|
||||
{
|
||||
if(app != NULL && app->meditation.image_1.id == 0)
|
||||
app->meditation.image_1 = app_load_asset_texture("practices/meditation/1.jpg");
|
||||
meditation_music_init(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_destroy(InbeApp *app)
|
||||
{
|
||||
if(app != NULL)
|
||||
app_unload_texture(app->meditation.image_1);
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
mark_exercise_manual_seen(app, EXERCISE_MEDITATION);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationSetup;
|
||||
app->modal.selected_button = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_update(InbeApp *app)
|
||||
{
|
||||
meditation_music_update(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_leave_config(InbeApp *app)
|
||||
{
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef INBE_MEDITATION_PRACTICE_H
|
||||
#define INBE_MEDITATION_PRACTICE_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
void meditation_practice_init(InbeApp *app);
|
||||
void meditation_practice_destroy(InbeApp *app);
|
||||
void meditation_practice_start(InbeApp *app);
|
||||
void meditation_practice_update(InbeApp *app);
|
||||
void meditation_practice_leave_config(InbeApp *app);
|
||||
void meditation_manual_draw(InbeApp *app);
|
||||
void meditation_manual_close(InbeApp *app, int mark_seen);
|
||||
void meditation_config_screen_draw(InbeApp *app);
|
||||
void meditation_draw_setup_modal(InbeApp *app);
|
||||
void meditation_draw_screen(InbeApp *app, int center_x, int center_y);
|
||||
void meditation_request_exit(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,340 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
#include "meditation_music.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
static Texture2D
|
||||
meditation_sound_icon_for_volume(InbeApp *app)
|
||||
{
|
||||
int vol = app->sound_volume;
|
||||
if(vol <= 0)
|
||||
return app->icons[UI_ICON_TYPE_SOUND0];
|
||||
if(vol <= 25)
|
||||
return app->icons[UI_ICON_TYPE_SOUND1];
|
||||
if(vol <= 75)
|
||||
return app->icons[UI_ICON_TYPE_SOUND2];
|
||||
return app->icons[UI_ICON_TYPE_SOUND3];
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_start(InbeApp *app, int seconds)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
app->meditation.duration_seconds = seconds;
|
||||
app->meditation.remaining_seconds = seconds;
|
||||
app->meditation.frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenMeditation;
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
meditation_music_start_session(app);
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_finish(InbeApp *app)
|
||||
{
|
||||
int duration;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
duration = app->meditation.duration_seconds;
|
||||
if(duration >= 60) {
|
||||
int session_duration = duration;
|
||||
if(data_save_session_path_for_activity(&session_duration, 1, 0, EXERCISE_MEDITATION,
|
||||
NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
}
|
||||
}
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
meditation_music_stop(app);
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_elapsed_seconds(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = app->meditation.duration_seconds - app->meditation.remaining_seconds;
|
||||
if(elapsed < 0)
|
||||
elapsed = 0;
|
||||
if(elapsed > app->meditation.duration_seconds)
|
||||
elapsed = app->meditation.duration_seconds;
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_save_elapsed(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = meditation_elapsed_seconds(app);
|
||||
if(elapsed < 60)
|
||||
return 0;
|
||||
if(data_save_session_path_for_activity(&elapsed, 1, 0, EXERCISE_MEDITATION, NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_exit_to_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
meditation_music_stop(app);
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
void
|
||||
meditation_request_exit(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmExitSession;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
format_meditation_time(char *dst, size_t dst_size, int seconds)
|
||||
{
|
||||
int hours;
|
||||
int minutes;
|
||||
int secs;
|
||||
|
||||
if(dst == NULL || dst_size == 0)
|
||||
return;
|
||||
if(seconds < 0)
|
||||
seconds = 0;
|
||||
|
||||
hours = seconds / 3600;
|
||||
minutes = (seconds / 60) % 60;
|
||||
secs = seconds % 60;
|
||||
|
||||
if(hours > 0)
|
||||
snprintf(dst, dst_size, "%d:%02d:%02d", hours, minutes, secs);
|
||||
else
|
||||
snprintf(dst, dst_size, "%d:%02d", minutes, secs);
|
||||
}
|
||||
|
||||
static int
|
||||
draw_meditation_duration_button(int x, int y, int w, int h, const char *label)
|
||||
{
|
||||
int hover = 0;
|
||||
return ui_draw_generic_button(x, y, w, h, label, UI_BUTTON_STYLE_PRIMARY, 0, &hover);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_draw_setup_modal(InbeApp *app)
|
||||
{
|
||||
static const int durations[] = {5 * 60, 15 * 60, 30 * 60, 60 * 60, 2 * 60 * 60};
|
||||
const char *labels[] = {
|
||||
locale_get("duration_5m"),
|
||||
locale_get("duration_15m"),
|
||||
locale_get("duration_30m"),
|
||||
locale_get("duration_1h"),
|
||||
locale_get("duration_2h")
|
||||
};
|
||||
int modal_w = flint_px(320);
|
||||
int modal_h = flint_px(236);
|
||||
int modal_x;
|
||||
int modal_y;
|
||||
int title_font = flint_px(18);
|
||||
int title_w;
|
||||
int btn_h = flint_px(38);
|
||||
int gap = flint_px(10);
|
||||
int side = flint_px(18);
|
||||
int row_y;
|
||||
int btn_w;
|
||||
int cancel_w = flint_px(120);
|
||||
int cancel_x;
|
||||
int cancel_y;
|
||||
int cancel_hover = 0;
|
||||
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
|
||||
modal_x = (view_width - modal_w) / 2;
|
||||
modal_y = (view_height - modal_h) / 2;
|
||||
btn_w = (modal_w - side * 2 - gap * 2) / 3;
|
||||
if(btn_w < flint_px(64))
|
||||
btn_w = flint_px(64);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
title_w = flint_text_measure(locale_get("meditation_title"), title_font);
|
||||
flint_text_draw(locale_get("meditation_title"), modal_x + (modal_w - title_w) / 2,
|
||||
modal_y + flint_px(16), title_font, theme_get_text());
|
||||
|
||||
row_y = modal_y + flint_px(62);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int x = modal_x + side + i * (btn_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, btn_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
row_y += btn_h + gap;
|
||||
for(int i = 3; i < 5; i++) {
|
||||
int two_w = (modal_w - side * 2 - gap) / 2;
|
||||
int x = modal_x + side + (i - 3) * (two_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, two_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
cancel_y = modal_y + modal_h - btn_h - flint_px(16);
|
||||
cancel_x = modal_x + (modal_w - cancel_w) / 2;
|
||||
if(ui_draw_generic_button(cancel_x, cancel_y, cancel_w, btn_h,
|
||||
locale_get("cancel_button"), UI_BUTTON_STYLE_SECONDARY,
|
||||
0, &cancel_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_sound_controls(InbeApp *app)
|
||||
{
|
||||
int sound_btn_x = view_width - flint_px(56);
|
||||
int sound_btn_y = flint_px(12);
|
||||
int sound_btn_size = flint_px(24);
|
||||
int sound_btn_padding = flint_px(10);
|
||||
int sound_hover = 0;
|
||||
|
||||
if(ui_draw_icon_btn_padded(sound_btn_x, sound_btn_y, sound_btn_size, sound_btn_padding,
|
||||
meditation_sound_icon_for_volume(app), &sound_hover)) {
|
||||
app->volume_popup_active = !app->volume_popup_active;
|
||||
}
|
||||
|
||||
if(app->volume_popup_active) {
|
||||
int popup_w = flint_px(44);
|
||||
int popup_x = sound_btn_x;
|
||||
int popup_y = sound_btn_y + sound_btn_size + sound_btn_padding * 2;
|
||||
int popup_h = flint_px(200);
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) &&
|
||||
(mouse.x < popup_x || mouse.x > popup_x + popup_w ||
|
||||
mouse.y < popup_y || mouse.y > popup_y + popup_h)) {
|
||||
app->volume_popup_active = 0;
|
||||
}
|
||||
|
||||
DrawRectangle(popup_x, popup_y, popup_w, popup_h, theme_get_surface());
|
||||
ui_draw_bevel(popup_x, popup_y, popup_w, popup_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
if(ui_draw_slider_vertical(501, popup_x + popup_w / 2, popup_y + flint_px(10),
|
||||
popup_h - flint_px(20), SETTINGS_VOLUME_MIN,
|
||||
SETTINGS_VOLUME_MAX, &app->sound_volume)) {
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
meditation_draw_screen(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
char time_text[32];
|
||||
int return_hover = 0;
|
||||
int font = flint_px(48);
|
||||
int max_w;
|
||||
int text_w;
|
||||
|
||||
if(ui_draw_icon_btn_padded(flint_px(12), flint_px(12), flint_px(24),
|
||||
flint_px(10), app->icons[UI_ICON_TYPE_RETURN], &return_hover)) {
|
||||
meditation_request_exit(app);
|
||||
return;
|
||||
}
|
||||
|
||||
draw_meditation_sound_controls(app);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmExitSession) {
|
||||
int elapsed = meditation_elapsed_seconds(app);
|
||||
int modal_result;
|
||||
|
||||
if(elapsed >= 60) {
|
||||
modal_result = ui_draw_modal_3btn(locale_get("exit_session_title"),
|
||||
locale_get("meditation_save_elapsed_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("save_button"),
|
||||
locale_get("discard_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_save_elapsed(app);
|
||||
meditation_exit_to_start(app);
|
||||
} else if(modal_result == 3) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
} else {
|
||||
modal_result = ui_draw_modal(locale_get("exit_session_title"),
|
||||
locale_get("meditation_under_minute_exit_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("exit_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
format_meditation_time(time_text, sizeof(time_text), app->meditation.remaining_seconds);
|
||||
max_w = view_width - flint_px(48);
|
||||
while(font > flint_px(28) && flint_text_measure(time_text, font) > max_w)
|
||||
font--;
|
||||
text_w = flint_text_measure(time_text, font);
|
||||
flint_text_draw(time_text, center_x - text_w / 2,
|
||||
flint_ui_text_y(time_text, center_y - font, font * 2, font),
|
||||
font, theme_get_text());
|
||||
|
||||
app->meditation.frame_ticks++;
|
||||
if(app->meditation.frame_ticks >= 60) {
|
||||
app->meditation.frame_ticks = 0;
|
||||
if(app->meditation.remaining_seconds > 0)
|
||||
app->meditation.remaining_seconds--;
|
||||
if(app->meditation.remaining_seconds <= 0)
|
||||
meditation_finish(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "practice_registry.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "practices/whm/whm_practice.h"
|
||||
#include "practices/whm/whm_session.h"
|
||||
#include "practices/meditation/meditation_practice.h"
|
||||
|
||||
static const PracticeDefinition g_practices[PRACTICE_COUNT] = {
|
||||
{
|
||||
.id = PRACTICE_WHM,
|
||||
.label_key = "exercise_wim_hof",
|
||||
.init = whm_practice_init,
|
||||
.destroy = whm_practice_destroy,
|
||||
.start = whm_practice_start,
|
||||
.draw_manual = whm_manual_draw,
|
||||
.close_manual = whm_manual_close,
|
||||
.draw_config = whm_config_screen_draw,
|
||||
.leave_config = whm_practice_leave_config,
|
||||
.update = NULL,
|
||||
.draw_setup_modal = NULL,
|
||||
.draw_active_session = NULL,
|
||||
.request_exit = NULL,
|
||||
},
|
||||
{
|
||||
.id = PRACTICE_MEDITATION,
|
||||
.label_key = "exercise_meditation",
|
||||
.init = meditation_practice_init,
|
||||
.destroy = meditation_practice_destroy,
|
||||
.start = meditation_practice_start,
|
||||
.draw_manual = meditation_manual_draw,
|
||||
.close_manual = meditation_manual_close,
|
||||
.draw_config = meditation_config_screen_draw,
|
||||
.leave_config = meditation_practice_leave_config,
|
||||
.update = meditation_practice_update,
|
||||
.draw_setup_modal = meditation_draw_setup_modal,
|
||||
.draw_active_session = meditation_draw_screen,
|
||||
.request_exit = meditation_request_exit,
|
||||
},
|
||||
};
|
||||
|
||||
const PracticeDefinition *
|
||||
practice_get(int id)
|
||||
{
|
||||
id = practice_clamp_id(id);
|
||||
return &g_practices[id];
|
||||
}
|
||||
|
||||
int
|
||||
practice_count(void)
|
||||
{
|
||||
return PRACTICE_COUNT;
|
||||
}
|
||||
|
||||
int
|
||||
practice_clamp_id(int id)
|
||||
{
|
||||
if(id < 0 || id >= PRACTICE_COUNT)
|
||||
return PRACTICE_WHM;
|
||||
return id;
|
||||
}
|
||||
|
||||
const char *
|
||||
practice_label(int id)
|
||||
{
|
||||
return locale_get(practice_get(id)->label_key);
|
||||
}
|
||||
|
||||
void
|
||||
practice_update_circle_bounds(InbeApp *app, int top_reserve, int bottom_reserve)
|
||||
{
|
||||
if(app != NULL)
|
||||
session_update_circle_bounds_for_view(&app->inbe, top_reserve, bottom_reserve);
|
||||
}
|
||||
|
||||
void
|
||||
practice_update_session_sounds(InbeApp *app)
|
||||
{
|
||||
update_session_sounds(app);
|
||||
}
|
||||
|
||||
int
|
||||
practice_ensure_results_saved(InbeApp *app)
|
||||
{
|
||||
return session_ensure_results_saved(app);
|
||||
}
|
||||
|
||||
int
|
||||
practice_draw_start_preview(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
return session_draw_start_preview(app, center_x, center_y);
|
||||
}
|
||||
|
||||
void
|
||||
practice_draw_active_breathing(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
session_draw_inbe(app, center_x, center_y);
|
||||
}
|
||||
|
||||
void
|
||||
practice_update_active_breathing(InbeApp *app, int center_x, int center_y, int *hover)
|
||||
{
|
||||
session_update_screen(app, center_x, center_y, hover);
|
||||
}
|
||||
|
||||
void
|
||||
practice_draw_results(InbeApp *app, int center_x, int center_y, int *hover)
|
||||
{
|
||||
session_draw_results_screen(app, center_x, center_y, hover);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef INBE_PRACTICE_REGISTRY_H
|
||||
#define INBE_PRACTICE_REGISTRY_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef enum PracticeId {
|
||||
PRACTICE_WHM = 0,
|
||||
PRACTICE_MEDITATION = 1,
|
||||
PRACTICE_COUNT = 2
|
||||
} PracticeId;
|
||||
|
||||
typedef struct PracticeDefinition {
|
||||
PracticeId id;
|
||||
const char *label_key;
|
||||
void (*init)(InbeApp *app);
|
||||
void (*destroy)(InbeApp *app);
|
||||
void (*start)(InbeApp *app);
|
||||
void (*draw_manual)(InbeApp *app);
|
||||
void (*close_manual)(InbeApp *app, int mark_seen);
|
||||
void (*draw_config)(InbeApp *app);
|
||||
void (*leave_config)(InbeApp *app);
|
||||
void (*update)(InbeApp *app);
|
||||
void (*draw_setup_modal)(InbeApp *app);
|
||||
void (*draw_active_session)(InbeApp *app, int center_x, int center_y);
|
||||
void (*request_exit)(InbeApp *app);
|
||||
} PracticeDefinition;
|
||||
|
||||
const PracticeDefinition *practice_get(int id);
|
||||
int practice_count(void);
|
||||
int practice_clamp_id(int id);
|
||||
const char *practice_label(int id);
|
||||
void practice_update_circle_bounds(InbeApp *app, int top_reserve, int bottom_reserve);
|
||||
void practice_update_session_sounds(InbeApp *app);
|
||||
int practice_ensure_results_saved(InbeApp *app);
|
||||
int practice_draw_start_preview(InbeApp *app, int center_x, int center_y);
|
||||
void practice_draw_active_breathing(InbeApp *app, int center_x, int center_y);
|
||||
void practice_update_active_breathing(InbeApp *app, int center_x, int center_y, int *hover);
|
||||
void practice_draw_results(InbeApp *app, int center_x, int center_y, int *hover);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,418 @@
|
||||
#include "whm_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "whm_session.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
static void
|
||||
whm_draw_exact_speed_preview(Inbe *preview, int *preview_speed,
|
||||
int speed, int max_rounds, int max_breaths,
|
||||
int pause_seconds, int content_w, int content_h,
|
||||
int center_x, int center_y)
|
||||
{
|
||||
if(preview == NULL || preview_speed == NULL)
|
||||
return;
|
||||
|
||||
if(preview->phase != InbePhaseBreathe) {
|
||||
inbeinit(preview);
|
||||
apply_settings(preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
preview->progressive_speed = 0;
|
||||
session_reset_round_breathe(preview);
|
||||
} else if(*preview_speed != speed) {
|
||||
apply_settings(preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
preview->progressive_speed = 0;
|
||||
}
|
||||
|
||||
if(*preview_speed != speed)
|
||||
*preview_speed = speed;
|
||||
|
||||
update_preview_bounds(preview, content_w, content_h);
|
||||
inbestep(preview);
|
||||
draw_preview_inbe(preview, center_x, center_y);
|
||||
}
|
||||
|
||||
static void
|
||||
whm_draw_progressive_start_speed_editor(InbeApp *app)
|
||||
{
|
||||
int modal_w = flint_px(340);
|
||||
int modal_h = flint_px(360);
|
||||
int modal_x;
|
||||
int modal_y;
|
||||
int title_font = flint_ui_font();
|
||||
int title_y;
|
||||
int close_size = flint_px(22);
|
||||
int close_padding = flint_px(8);
|
||||
int close_w = close_size + close_padding * 2;
|
||||
int close_hover = 0;
|
||||
int max_speed = app->inbe.speed_level;
|
||||
int start_speed = clampi(app->inbe.progressive_start_speed, SETTINGS_SPEED_MIN, max_speed);
|
||||
const char *title;
|
||||
int title_w;
|
||||
int title_max_w;
|
||||
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
modal_x = (view_width - modal_w) / 2;
|
||||
modal_y = (view_height - modal_h) / 2;
|
||||
title_y = modal_y + flint_px(14);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
title = locale_get("progressive_start_speed_editor_title");
|
||||
title_w = flint_text_measure(title, title_font);
|
||||
title_max_w = modal_w - close_w * 2 - flint_px(24);
|
||||
while(title_font > flint_px(12) && title_w > title_max_w) {
|
||||
title_font--;
|
||||
title_w = flint_text_measure(title, title_font);
|
||||
}
|
||||
flint_text_draw(title, modal_x + (modal_w - title_w) / 2, title_y, title_font, theme_get_text());
|
||||
|
||||
if(ui_draw_icon_btn_padded(modal_x + modal_w - close_w - flint_px(6), modal_y + flint_px(6),
|
||||
close_size, close_padding, app->icons[UI_ICON_TYPE_X], &close_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
return;
|
||||
}
|
||||
|
||||
whm_draw_exact_speed_preview(&app->start_speed_preview,
|
||||
&app->start_speed_preview_speed,
|
||||
start_speed,
|
||||
app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths),
|
||||
app->inbe.pause_seconds,
|
||||
modal_w - flint_px(48),
|
||||
flint_px(210),
|
||||
modal_x + modal_w / 2,
|
||||
modal_y + flint_px(150));
|
||||
|
||||
if(ui_draw_slider(12, modal_x + flint_px(24), modal_y + flint_px(250),
|
||||
modal_w - flint_px(48), locale_get("progressive_start_speed_label"),
|
||||
SETTINGS_SPEED_MIN, max_speed, &start_speed, "")) {
|
||||
app->inbe.progressive_start_speed = start_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
whm_draw_subtab_bar(int y, int h, const char **tab_names, int tab_count,
|
||||
int selected_tab)
|
||||
{
|
||||
enum { WHM_SUBTAB_RENDER_MAX = 8 };
|
||||
FlintUISubtab tabs[WHM_SUBTAB_RENDER_MAX];
|
||||
|
||||
if(tab_count <= 0 || tab_count > WHM_SUBTAB_RENDER_MAX)
|
||||
return -1;
|
||||
for(int i = 0; i < tab_count; i++) {
|
||||
tabs[i].label = tab_names[i];
|
||||
tabs[i].disabled = 0;
|
||||
}
|
||||
return ui_draw_subtab_bar((FlintUISubtabBar){
|
||||
.bounds = {0, (float)y, (float)view_width, (float)h},
|
||||
.tabs = tabs,
|
||||
.count = tab_count,
|
||||
.selected_index = selected_tab,
|
||||
.font = flint_ui_font()
|
||||
});
|
||||
}
|
||||
|
||||
static int
|
||||
whm_config_draw_breathing_tab(InbeApp *app, int content_x, int content_w, int y,
|
||||
int *draw_breath_animation_menu)
|
||||
{
|
||||
static const char *animation_options[InbeBreathAnimationCount];
|
||||
int preview_h = flint_px(240);
|
||||
int preview_radius;
|
||||
int preview_padding = flint_px(12);
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int progressive_start_speed = app->inbe.progressive_start_speed;
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
animation_options[InbeBreathAnimationLinear] = locale_get("breath_animation_linear");
|
||||
animation_options[InbeBreathAnimationInOut] = locale_get("breath_animation_in_out");
|
||||
app->inbe.breath_animation = clampi(app->inbe.breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
|
||||
flint_text_draw(locale_get("breath_animation_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(104, content_x, y + flint_px(26), content_w, flint_px(36),
|
||||
animation_options, InbeBreathAnimationCount,
|
||||
&app->inbe.breath_animation);
|
||||
if(draw_breath_animation_menu != NULL)
|
||||
*draw_breath_animation_menu = 1;
|
||||
y += flint_px(76);
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, preview_h);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, preview_h);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
|
||||
preview_radius = (int)((float)app->settings_preview.rmax * 0.72f + 1.0f);
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2,
|
||||
y + preview_padding + preview_radius);
|
||||
if(ui_draw_slider(1, content_x, y + preview_padding + preview_radius * 2 + flint_px(28),
|
||||
content_w, locale_get("speed_label"),
|
||||
SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += preview_padding + preview_radius * 2 + flint_px(102);
|
||||
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, y + flint_px(26), toggle_w, toggle_h, &progressive_speed,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
|
||||
if(app->inbe.progressive_speed) {
|
||||
int modify_w = flint_text_measure(locale_get("modify_start_speed_button"), flint_ui_font()) + flint_px(24);
|
||||
int modify_hover = 0;
|
||||
if(modify_w > content_w)
|
||||
modify_w = content_w;
|
||||
if(progressive_start_speed != clampi(progressive_start_speed, SETTINGS_SPEED_MIN, speed)) {
|
||||
app->inbe.progressive_start_speed = clampi(progressive_start_speed, SETTINGS_SPEED_MIN, speed);
|
||||
app->settings_preview.progressive_start_speed = app->inbe.progressive_start_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
if(ui_draw_generic_button(content_x, y, modify_w, flint_px(36),
|
||||
locale_get("modify_start_speed_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &modify_hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalEditProgressiveStartSpeed;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
y += flint_px(58);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
whm_config_draw_session_tab(InbeApp *app, int content_x, int content_w, int y)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int advanced_session_controls = app->advanced_session_controls;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
int reset_w = flint_text_measure(locale_get("reset_to_defaults_label"), flint_ui_font()) + flint_px(24);
|
||||
int reset_h = flint_px(36);
|
||||
int reset_hover = 0;
|
||||
|
||||
if(ui_draw_slider(2, content_x, y, content_w, locale_get("max_rounds_label"),
|
||||
1, MaxRounds, &max_rounds, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
if(ui_draw_slider(3, content_x, y, content_w, locale_get("max_breaths_label"),
|
||||
SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX, &max_breaths, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
if(ui_draw_slider(4, content_x, y, content_w, locale_get("pause_after_round_label"),
|
||||
SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX, &pause_seconds, "s")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(52);
|
||||
flint_text_draw(locale_get("advanced_session_controls_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, y + flint_px(26), toggle_w, toggle_h, &advanced_session_controls,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->advanced_session_controls = advanced_session_controls;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(76);
|
||||
if(reset_w > content_w)
|
||||
reset_w = content_w;
|
||||
if(ui_draw_generic_button(content_x + content_w - reset_w, y, reset_w, reset_h,
|
||||
locale_get("reset_to_defaults_label"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &reset_hover)) {
|
||||
speed = DefaultSpeedLevel;
|
||||
max_rounds = DefaultMaxRounds;
|
||||
max_breaths = DefaultMaxBreaths;
|
||||
pause_seconds = DefaultPauseSeconds;
|
||||
app->inbe.progressive_start_speed = DefaultProgressiveStartSpeed;
|
||||
app->settings_preview.progressive_start_speed = DefaultProgressiveStartSpeed;
|
||||
app->inbe.breath_animation = InbeBreathAnimationLinear;
|
||||
app->settings_preview.breath_animation = InbeBreathAnimationLinear;
|
||||
app->advanced_session_controls = 0;
|
||||
app->hold_display_mode = HOLD_DISPLAY_CIRCLE;
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += reset_h + flint_px(28);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
whm_config_content_height(InbeApp *app, int content_w)
|
||||
{
|
||||
if(app->practice_config_tab == 0) {
|
||||
int span = content_w < flint_px(240) ? content_w : flint_px(240);
|
||||
int preview_radius = span / 2;
|
||||
int h;
|
||||
if(preview_radius < flint_px(60))
|
||||
preview_radius = flint_px(60);
|
||||
if(preview_radius > flint_px(120))
|
||||
preview_radius = flint_px(120);
|
||||
preview_radius = (int)((float)preview_radius * 0.72f + 1.0f);
|
||||
h = flint_px(12) + preview_radius * 2 + flint_px(102);
|
||||
h += flint_px(66);
|
||||
if(app->inbe.progressive_speed)
|
||||
h += flint_px(58);
|
||||
h += flint_px(76);
|
||||
return h;
|
||||
}
|
||||
|
||||
return flint_px(66) * 3 +
|
||||
flint_px(26) + flint_px(52) +
|
||||
flint_px(76) +
|
||||
flint_px(36) + flint_px(28);
|
||||
}
|
||||
|
||||
void
|
||||
whm_config_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int config_tab_h = flint_px(40);
|
||||
int config_tab_gap = flint_px(14);
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
int min_content_w = flint_px(320);
|
||||
int scroll_y;
|
||||
int scroll_h;
|
||||
int content_h;
|
||||
int controls_w;
|
||||
int draw_breath_animation_menu = 0;
|
||||
int clicked_config_tab = -1;
|
||||
const char *config_tabs[] = {
|
||||
locale_get("settings_section_breathing"),
|
||||
locale_get("settings_section_session"),
|
||||
};
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIHeader header;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < min_content_w)
|
||||
responsive_max_w = min_content_w;
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
||||
app->settings_drag_slider = 0;
|
||||
if(app->practice_config_tab < 0 || app->practice_config_tab > 1)
|
||||
app->practice_config_tab = 0;
|
||||
|
||||
header = ui_draw_title_header(title_h, locale_get("exercise_wim_hof"),
|
||||
(Texture2D){0}, app->icons[UI_ICON_TYPE_X]);
|
||||
if(header.right_clicked) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
app->settings_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
clicked_config_tab = whm_draw_subtab_bar(title_h, config_tab_h, config_tabs, 2,
|
||||
app->practice_config_tab);
|
||||
if(clicked_config_tab >= 0 && clicked_config_tab != app->practice_config_tab) {
|
||||
app->practice_config_tab = clicked_config_tab;
|
||||
app->settings_scroll = 0;
|
||||
}
|
||||
scroll_y = title_h + config_tab_h + config_tab_gap;
|
||||
scroll_h = view_height - scroll_y;
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
|
||||
controls_w = content_w;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
FlintUIScrollView measured;
|
||||
content_h = whm_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == controls_w)
|
||||
break;
|
||||
controls_w = measured.content_w;
|
||||
}
|
||||
|
||||
content_h = whm_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
if(app->practice_config_tab == 0) {
|
||||
whm_config_draw_breathing_tab(app, scroll_view.content_x, scroll_view.content_w,
|
||||
scroll_view.content_y, &draw_breath_animation_menu);
|
||||
} else {
|
||||
whm_config_draw_session_tab(app, scroll_view.content_x, scroll_view.content_w,
|
||||
scroll_view.content_y);
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
if(draw_breath_animation_menu && ui_draw_dropdown_menu(104)) {
|
||||
app->inbe.breath_animation = clampi(app->inbe.breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
app->settings_preview.breath_animation = app->inbe.breath_animation;
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalEditProgressiveStartSpeed)
|
||||
whm_draw_progressive_start_speed_editor(app);
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
#include "whm_practice.h"
|
||||
#include "app.h"
|
||||
#include "whm_session.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define CONTENT_MAX_W 800 /* Responsive width for tutorial text reflow */
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
/* Tutorial text content ordered by step */
|
||||
static const char *const TUTORIAL_KEYS[] = {
|
||||
"tutorial_step_intro",
|
||||
"tutorial_step_method",
|
||||
"tutorial_step_progressive_speed",
|
||||
"tutorial_step_breathe",
|
||||
"tutorial_step_exhale_hold",
|
||||
"tutorial_step_inhale_hold"
|
||||
};
|
||||
|
||||
#define TUTORIAL_STEPS_COUNT (sizeof(TUTORIAL_KEYS) / sizeof(TUTORIAL_KEYS[0]))
|
||||
#define TUTORIAL_LINE_SPACING flint_px(8) /* Normal readable line spacing */
|
||||
|
||||
static Color
|
||||
manual_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_hold_preview(InbeApp *app, int center_x, int center_y, int radius)
|
||||
{
|
||||
int seconds = (app->inbe.frame / 60) % 60;
|
||||
char text[CountSize];
|
||||
int font = flint_px(16);
|
||||
int thickness = flint_px(5);
|
||||
Color text_color = theme_get_text();
|
||||
|
||||
count_from_int(text, seconds);
|
||||
if(thickness < 3)
|
||||
thickness = 3;
|
||||
|
||||
if(app->hold_display_mode == HOLD_DISPLAY_CIRCLE) {
|
||||
float sweep = 360.0f * (float)((app->inbe.frame % (60 * 60))) / (float)(60 * 60);
|
||||
|
||||
DrawRing((Vector2){center_x, center_y},
|
||||
(float)(radius + flint_px(8) - thickness / 2),
|
||||
(float)(radius + flint_px(8) + thickness / 2),
|
||||
-90.0f, -90.0f + sweep, 96, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_bg());
|
||||
} else {
|
||||
DrawCircle(center_x, center_y, radius, theme_get_circle());
|
||||
DrawCircleLines(center_x, center_y, radius, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_circle());
|
||||
}
|
||||
|
||||
flint_ui_draw_text_centered(text, center_x, center_y, font, text_color);
|
||||
}
|
||||
|
||||
static FlintUIParagraph
|
||||
tutorial_paragraph(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int has_icon = step == 1;
|
||||
return (FlintUIParagraph){
|
||||
.text = locale_get(TUTORIAL_KEYS[step]),
|
||||
.icon = has_icon ? app->icons[UI_ICON_TYPE_WRENCH] : (Texture2D){0},
|
||||
.icon_type = has_icon ? UI_ICON_TYPE_WRENCH : UI_ICON_TYPE_NONE,
|
||||
.icon_size = has_icon ? flint_px(14) : 0,
|
||||
.width = content_w,
|
||||
.font = body_font,
|
||||
.line_gap = TUTORIAL_LINE_SPACING,
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
tutorial_paragraph_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
return flint_ui_paragraph_height(tutorial_paragraph(app, step, content_w, body_font));
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_paragraph(InbeApp *app, int step, int content_x, int *y, int content_w, int body_font)
|
||||
{
|
||||
flint_ui_paragraph_draw(tutorial_paragraph(app, step, content_w, body_font), content_x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
manual_tutorial_content_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int actual_content_h = 0;
|
||||
|
||||
if(step == 0) {
|
||||
actual_content_h += flint_px(170) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 0, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 1, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 2, content_w, body_font) + flint_px(68);
|
||||
if(app->inbe.progressive_speed)
|
||||
actual_content_h += flint_px(66);
|
||||
} else if(step == 3) {
|
||||
int preview_span;
|
||||
int preview_rmax;
|
||||
int slider_h = flint_px(40);
|
||||
|
||||
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font) + flint_px(20);
|
||||
preview_span = (content_w < flint_px(132)) ? content_w : flint_px(132);
|
||||
preview_rmax = preview_span / 2;
|
||||
if(preview_rmax < flint_px(60)) preview_rmax = flint_px(60);
|
||||
if(preview_rmax > flint_px(120)) preview_rmax = flint_px(120);
|
||||
actual_content_h += flint_px(40) + (int)((float)preview_rmax * 0.72f) + flint_px(14);
|
||||
actual_content_h += slider_h + flint_px(8);
|
||||
} else if(step == 4) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
|
||||
actual_content_h += flint_px(26) + flint_px(36) + flint_px(20);
|
||||
actual_content_h += hold_preview_extent * 2 + flint_px(24);
|
||||
actual_content_h += tutorial_paragraph_height(app, 4, content_w, body_font);
|
||||
} else {
|
||||
actual_content_h += flint_px(200) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 5, content_w, body_font);
|
||||
}
|
||||
|
||||
return actual_content_h;
|
||||
}
|
||||
|
||||
void
|
||||
whm_manual_close(InbeApp *app, int mark_seen)
|
||||
{
|
||||
if(mark_seen)
|
||||
mark_exercise_manual_seen(app, EXERCISE_WIM_HOF);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static void
|
||||
manual_screen_start_exercise(InbeApp *app)
|
||||
{
|
||||
mark_exercise_manual_seen(app, EXERCISE_WIM_HOF);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
session_start(app);
|
||||
}
|
||||
|
||||
void
|
||||
whm_manual_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int tab_h = flint_px(56);
|
||||
int viewport_h = view_height - title_h - tab_h;
|
||||
int body_font = flint_ui_font();
|
||||
int footer_content_pad = flint_ui_font() / 2;
|
||||
int content_area_h = viewport_h - footer_content_pad; /* For scissor mode and scroll calculations */
|
||||
int previous_step;
|
||||
int content_x;
|
||||
int content_w;
|
||||
const char *title = locale_get("tutorial_title");
|
||||
char page_label[32];
|
||||
int close_clicked = 0;
|
||||
int step = app->tutorial_step;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
|
||||
step = clampi(step, 0, (int)TUTORIAL_STEPS_COUNT - 1);
|
||||
app->tutorial_step = step;
|
||||
previous_step = step;
|
||||
|
||||
if(IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_ENTER)) {
|
||||
if(step < (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
app->tutorial_step++;
|
||||
else
|
||||
manual_screen_start_exercise(app);
|
||||
}
|
||||
if(IsKeyPressed(KEY_LEFT) && step > 0)
|
||||
app->tutorial_step--;
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
whm_manual_close(app, 0);
|
||||
|
||||
step = app->tutorial_step;
|
||||
if(previous_step != step) {
|
||||
app->manual_scroll = 0;
|
||||
previous_step = step;
|
||||
}
|
||||
|
||||
switch(step) {
|
||||
case 1: title = locale_get("tutorial_method_title"); break;
|
||||
case 2: title = locale_get("tutorial_progressive_speed_title"); break;
|
||||
case 3: title = locale_get("tutorial_step1_title"); break;
|
||||
case 4: title = locale_get("tutorial_step2_title"); break;
|
||||
case 5: title = locale_get("tutorial_step3_title"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* Calculate responsive content width */
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
int min_width = flint_px(280);
|
||||
if(responsive_max_w < min_width)
|
||||
responsive_max_w = min_width;
|
||||
|
||||
int side_padding = flint_page_side_padding();
|
||||
flint_centered_column(responsive_max_w, side_padding, &content_x, &content_w);
|
||||
|
||||
close_clicked = ui_draw_screen_header(title, 1);
|
||||
if(close_clicked)
|
||||
whm_manual_close(app, 0);
|
||||
|
||||
{
|
||||
int top_padding = flint_px(16);
|
||||
int total_content_h;
|
||||
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
total_content_h = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding;
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = total_content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
}
|
||||
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
content_x = scroll_view.content_x;
|
||||
content_w = scroll_view.content_w;
|
||||
{
|
||||
int y = scroll_view.content_y + flint_px(16);
|
||||
if(step == 0) {
|
||||
int img_h = flint_px(170);
|
||||
ui_draw_tutorial_image(app->whm.image_1, "practices/whm/1.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
|
||||
draw_tutorial_paragraph(app, 0, content_x, &y, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
draw_tutorial_paragraph(app, 1, content_x, &y, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
draw_tutorial_paragraph(app, 2, content_x, &y, content_w, body_font);
|
||||
y += flint_px(18);
|
||||
{
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
if(ui_draw_toggle_switch(content_x, y, toggle_w, toggle_h,
|
||||
&progressive_speed, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = progressive_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += toggle_h + flint_px(20);
|
||||
}
|
||||
} else if(step == 3) {
|
||||
int speed = app->inbe.speed_level;
|
||||
draw_tutorial_paragraph(app, 3, content_x, &y, content_w, body_font);
|
||||
y += flint_px(20); /* Increased spacing between text and circle */
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2, y + flint_px(40));
|
||||
y += (int)(app->settings_preview.rmax * 0.72f) + flint_px(54);
|
||||
|
||||
if(ui_draw_slider(10, content_x, y, content_w, locale_get("speed_label"), SETTINGS_SPEED_MIN,
|
||||
SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
} else if(step == 4) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(36) + flint_px(20) + hold_preview_extent;
|
||||
draw_tutorial_hold_preview(app, content_x + content_w / 2, y, hold_preview_radius);
|
||||
y += hold_preview_extent + flint_px(24);
|
||||
draw_tutorial_paragraph(app, 4, content_x, &y, content_w, body_font);
|
||||
} else {
|
||||
int img_h = flint_px(200);
|
||||
ui_draw_tutorial_image(app->whm.image_2, "practices/whm/2.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
draw_tutorial_paragraph(app, 5, content_x, &y, content_w, body_font);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
locale_format(page_label, sizeof(page_label), "tutorial_page_label",
|
||||
step + 1, (int)TUTORIAL_STEPS_COUNT);
|
||||
|
||||
int left_hover = 0;
|
||||
int right_hover = 0;
|
||||
const char *left_label = step == 0 ? locale_get("tutorial_skip_button") : locale_get("tutorial_back_button");
|
||||
const char *right_label = step == (int)TUTORIAL_STEPS_COUNT - 1 ? locale_get("tutorial_start_button") : locale_get("tutorial_next_button");
|
||||
int footer_gap = flint_px(10);
|
||||
int page_font = flint_ui_font();
|
||||
int button_h = flint_px(34);
|
||||
int button_w = (content_w - footer_gap) / 2;
|
||||
int footer_y = view_height - flint_px(38);
|
||||
int counter_gap = flint_px(6);
|
||||
|
||||
|
||||
flint_text_draw(page_label,
|
||||
view_width / 2 - flint_text_measure(page_label, page_font) / 2,
|
||||
footer_y - page_font - counter_gap, page_font, theme_get_text());
|
||||
|
||||
if(step == 0) {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover))
|
||||
manual_screen_start_exercise(app);
|
||||
} else {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover)) {
|
||||
app->tutorial_step--;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(ui_draw_generic_button(content_x + button_w + footer_gap, footer_y, button_w, button_h,
|
||||
right_label, UI_BUTTON_STYLE_PRIMARY, 0, &right_hover)) {
|
||||
if(step == (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
manual_screen_start_exercise(app);
|
||||
else {
|
||||
app->tutorial_step++;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
app->settings_drag_slider = 0;
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "whm_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "whm_session.h"
|
||||
|
||||
void
|
||||
whm_practice_init(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->whm.image_1.id == 0)
|
||||
app->whm.image_1 = app_load_asset_texture("practices/whm/1.jpg");
|
||||
if(app->whm.image_2.id == 0)
|
||||
app->whm.image_2 = app_load_asset_texture("practices/whm/2.jpg");
|
||||
}
|
||||
|
||||
void
|
||||
whm_practice_destroy(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
app_unload_texture(app->whm.image_1);
|
||||
app_unload_texture(app->whm.image_2);
|
||||
}
|
||||
|
||||
void
|
||||
whm_practice_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
mark_exercise_manual_seen(app, EXERCISE_WIM_HOF);
|
||||
session_start(app);
|
||||
}
|
||||
|
||||
void
|
||||
whm_practice_leave_config(InbeApp *app)
|
||||
{
|
||||
(void)app;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_WHM_PRACTICE_H
|
||||
#define INBE_WHM_PRACTICE_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
void whm_practice_init(InbeApp *app);
|
||||
void whm_practice_destroy(InbeApp *app);
|
||||
void whm_practice_start(InbeApp *app);
|
||||
void whm_practice_leave_config(InbeApp *app);
|
||||
void whm_manual_draw(InbeApp *app);
|
||||
void whm_manual_close(InbeApp *app, int mark_seen);
|
||||
void whm_config_screen_draw(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "session.h"
|
||||
#include "whm_session.h"
|
||||
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
@@ -156,25 +156,6 @@ remember_sound_state(InbeApp *app)
|
||||
cpcount(app->sound_last_count, app->inbe.count);
|
||||
}
|
||||
|
||||
static void
|
||||
play_app_sound(InbeApp *app, Sound sound, float scale)
|
||||
{
|
||||
float volume;
|
||||
|
||||
if(app == NULL || !app->audio_ready || sound.frameCount == 0 || app->sound_volume <= 0)
|
||||
return;
|
||||
|
||||
volume = ((float)app->sound_volume / 100.0f) * scale;
|
||||
if(volume < 0.0f)
|
||||
volume = 0.0f;
|
||||
if(volume > 1.0f)
|
||||
volume = 1.0f;
|
||||
|
||||
StopSound(sound);
|
||||
SetSoundVolume(sound, volume);
|
||||
PlaySound(sound);
|
||||
}
|
||||
|
||||
void
|
||||
update_session_sounds(InbeApp *app)
|
||||
{
|
||||
@@ -197,17 +178,17 @@ update_session_sounds(InbeApp *app)
|
||||
if(app->inbe.phase == InbePhaseBreathe) {
|
||||
if(screen_changed || phase_changed || dir_changed) {
|
||||
Sound breath_snd = app->inbe.dir == 0 ? app->breath_in_sound : app->breath_out_sound;
|
||||
play_app_sound(app, breath_snd, 1.0f);
|
||||
app_play_sound(app, breath_snd, 1.0f);
|
||||
}
|
||||
if(count_changed) {
|
||||
int count_value = int_from_count(app->inbe.count);
|
||||
int maxbreaths_value = int_from_count(app->inbe.maxbreaths);
|
||||
if(count_value == maxbreaths_value - 1)
|
||||
play_app_sound(app, app->bell_sound, 0.8f);
|
||||
app_play_sound(app, app->bell_sound, 0.8f);
|
||||
}
|
||||
} else if(phase_changed) {
|
||||
if(app->inbe.phase == InbePhaseNext && app->sound_last_phase == InbePhaseRecover)
|
||||
play_app_sound(app, app->breath_out_sound, 1.0f);
|
||||
app_play_sound(app, app->breath_out_sound, 1.0f);
|
||||
}
|
||||
|
||||
remember_sound_state(app);
|
||||
@@ -338,7 +319,7 @@ finish_hold(InbeApp *app)
|
||||
app->inbe.breath_frame = 0;
|
||||
app->inbe.breathtick = 0;
|
||||
app->inbe.sectick = 0;
|
||||
play_app_sound(app, app->breath_in_sound, 1.0f);
|
||||
app_play_sound(app, app->breath_in_sound, 1.0f);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef INBE_APP_SESSION_H
|
||||
#define INBE_APP_SESSION_H
|
||||
#ifndef INBE_WHM_SESSION_H
|
||||
#define INBE_WHM_SESSION_H
|
||||
|
||||
#include "app.h"
|
||||
|
||||
@@ -21,8 +21,9 @@ extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
enum {
|
||||
HABIT_WEEKLY_INITIAL_DAYS = 7,
|
||||
HABIT_WEEKLY_LOAD_DAYS = 7,
|
||||
HABIT_WEEKLY_MONTH_DAYS = 31,
|
||||
HABIT_WEEKLY_INITIAL_DAYS = HABIT_WEEKLY_MONTH_DAYS,
|
||||
HABIT_WEEKLY_LOAD_DAYS = HABIT_WEEKLY_MONTH_DAYS,
|
||||
HABIT_WEEKLY_MAX_DAYS = INBE_HABIT_MAX_DAYS
|
||||
};
|
||||
|
||||
@@ -771,6 +772,26 @@ draw_habit_link_dot(int x, int y, int w, Color color)
|
||||
flint_px(3), color);
|
||||
}
|
||||
|
||||
static Color
|
||||
habit_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
habit_weekly_draw_text_line(const char *text, int x, int y, int w, int h,
|
||||
int text_size, Color color)
|
||||
{
|
||||
int font_size;
|
||||
|
||||
if(text == NULL || text[0] == '\0' || w <= 0 || h <= 0)
|
||||
return;
|
||||
font_size = flint_px(text_size);
|
||||
flint_text_draw(text, x, flint_text_y(text, y, h, font_size), font_size, color);
|
||||
}
|
||||
|
||||
static int
|
||||
habit_weekly_summary(const HabitLinkedContext *ctx, int day_index,
|
||||
char *primary, size_t primary_size,
|
||||
@@ -821,8 +842,9 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
|
||||
int hovered;
|
||||
Color fill = completed ? theme_get_button() : flint_darken(theme_get_bg(), 10);
|
||||
Color text = disabled ? flint_darken(theme_get_text(), 35) : theme_get_text();
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_px(FLINT_TEXT_8);
|
||||
int pad = flint_px(9);
|
||||
int text_x;
|
||||
int text_w;
|
||||
const char *line1 = primary != NULL ? primary : "";
|
||||
const char *line2 = secondary != NULL ? secondary : "";
|
||||
|
||||
@@ -841,25 +863,28 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
|
||||
|
||||
if(hovered)
|
||||
fill = theme_get_button_hover();
|
||||
if(!disabled && completed)
|
||||
text = habit_text_color_for_background(fill);
|
||||
DrawRectangle(x, y, w, h, fill);
|
||||
ui_draw_bevel(x, y, w, h, flint_lighten(fill, 36), flint_darken(fill, 42));
|
||||
|
||||
text_x = x + pad;
|
||||
text_w = w - pad * 2;
|
||||
|
||||
if(line1[0] != '\0') {
|
||||
if(line2[0] != '\0') {
|
||||
flint_text_draw_fitted_in_rect(line1,
|
||||
(Rectangle){x + flint_px(8), y + flint_px(5),
|
||||
w - flint_px(16), flint_px(18)},
|
||||
font, FLINT_TEXT_12, text);
|
||||
flint_text_draw_fitted_in_rect(line2,
|
||||
(Rectangle){x + flint_px(8), y + flint_px(24),
|
||||
w - flint_px(16), flint_px(12)},
|
||||
small_font, FLINT_TEXT_8,
|
||||
flint_darken(text, 16));
|
||||
int line1_h = flint_px(24);
|
||||
int line2_h = flint_px(16);
|
||||
int block_h = line1_h + line2_h;
|
||||
int block_y = y + (h - block_h) / 2;
|
||||
habit_weekly_draw_text_line(line1, text_x, block_y, text_w, line1_h,
|
||||
FLINT_TEXT_16, text);
|
||||
habit_weekly_draw_text_line(line2, text_x, block_y + line1_h, text_w, line2_h,
|
||||
FLINT_TEXT_8, flint_darken(text, 16));
|
||||
} else {
|
||||
flint_text_draw_fitted_in_rect(line1,
|
||||
(Rectangle){x + flint_px(8), y,
|
||||
w - flint_px(16), h},
|
||||
font, FLINT_TEXT_16, text);
|
||||
habit_weekly_draw_text_line(line1, text_x, y + flint_px(3),
|
||||
text_w, h - flint_px(6),
|
||||
FLINT_TEXT_16, text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -883,7 +908,7 @@ habit_weekly_visible_days(InbeHabits *habits)
|
||||
static int
|
||||
habit_weekly_content_height(int visible_days)
|
||||
{
|
||||
int row_h = flint_px(40);
|
||||
int row_h = flint_px(44);
|
||||
int row_gap = flint_px(6);
|
||||
int load_h = flint_px(38);
|
||||
|
||||
@@ -908,7 +933,7 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
int gap = flint_px(8);
|
||||
int button_x;
|
||||
int button_w;
|
||||
int row_h = flint_px(40);
|
||||
int row_h = flint_px(44);
|
||||
int row_gap = flint_px(6);
|
||||
int day_font = flint_px(16);
|
||||
int date_font = flint_px(FLINT_TEXT_8);
|
||||
|
||||
@@ -87,9 +87,6 @@ typedef struct HabitLinkedContext {
|
||||
int best_seconds;
|
||||
} HabitLinkedContext;
|
||||
|
||||
/* External functions */
|
||||
void save_settings(InbeApp *app);
|
||||
|
||||
/* Core habits functions */
|
||||
void inbe_habits_init(InbeHabits *habits);
|
||||
void inbe_habits_save(const InbeHabits *habits);
|
||||
|
||||
@@ -1,510 +1,36 @@
|
||||
#include "manual_screen.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "session.h"
|
||||
#include "locale.h"
|
||||
#include "meditation_music.h"
|
||||
#include "theme.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define CONTENT_MAX_W 800 /* Responsive width for tutorial text reflow */
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
/* Tutorial text content ordered by step */
|
||||
static const char *const TUTORIAL_KEYS[] = {
|
||||
"tutorial_step_intro",
|
||||
"tutorial_step_method",
|
||||
"tutorial_step_progressive_speed",
|
||||
"tutorial_step_breathe",
|
||||
"tutorial_step_exhale_hold",
|
||||
"tutorial_step_inhale_hold"
|
||||
};
|
||||
|
||||
#define TUTORIAL_STEPS_COUNT (sizeof(TUTORIAL_KEYS) / sizeof(TUTORIAL_KEYS[0]))
|
||||
#define TUTORIAL_LINE_SPACING flint_px(8) /* Normal readable line spacing */
|
||||
|
||||
static Color
|
||||
manual_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_hold_preview(InbeApp *app, int center_x, int center_y, int radius)
|
||||
{
|
||||
int seconds = (app->inbe.frame / 60) % 60;
|
||||
char text[CountSize];
|
||||
int font = flint_px(16);
|
||||
int thickness = flint_px(5);
|
||||
Color text_color = theme_get_text();
|
||||
|
||||
count_from_int(text, seconds);
|
||||
if(thickness < 3)
|
||||
thickness = 3;
|
||||
|
||||
if(app->hold_display_mode == HOLD_DISPLAY_CIRCLE) {
|
||||
float sweep = 360.0f * (float)((app->inbe.frame % (60 * 60))) / (float)(60 * 60);
|
||||
|
||||
DrawRing((Vector2){center_x, center_y},
|
||||
(float)(radius + flint_px(8) - thickness / 2),
|
||||
(float)(radius + flint_px(8) + thickness / 2),
|
||||
-90.0f, -90.0f + sweep, 96, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_bg());
|
||||
} else {
|
||||
DrawCircle(center_x, center_y, radius, theme_get_circle());
|
||||
DrawCircleLines(center_x, center_y, radius, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_circle());
|
||||
}
|
||||
|
||||
flint_ui_draw_text_centered(text, center_x, center_y, font, text_color);
|
||||
}
|
||||
|
||||
static FlintUIParagraph
|
||||
tutorial_paragraph(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int has_icon = step == 1;
|
||||
return (FlintUIParagraph){
|
||||
.text = locale_get(TUTORIAL_KEYS[step]),
|
||||
.icon = has_icon ? app->icons[UI_ICON_TYPE_WRENCH] : (Texture2D){0},
|
||||
.icon_type = has_icon ? UI_ICON_TYPE_WRENCH : UI_ICON_TYPE_NONE,
|
||||
.icon_size = has_icon ? flint_px(14) : 0,
|
||||
.width = content_w,
|
||||
.font = body_font,
|
||||
.line_gap = TUTORIAL_LINE_SPACING,
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
tutorial_paragraph_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
return flint_ui_paragraph_height(tutorial_paragraph(app, step, content_w, body_font));
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_paragraph(InbeApp *app, int step, int content_x, int *y, int content_w, int body_font)
|
||||
{
|
||||
flint_ui_paragraph_draw(tutorial_paragraph(app, step, content_w, body_font), content_x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
manual_tutorial_content_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int actual_content_h = 0;
|
||||
|
||||
if(step == 0) {
|
||||
actual_content_h += flint_px(170) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 0, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 1, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 2, content_w, body_font) + flint_px(68);
|
||||
if(app->inbe.progressive_speed)
|
||||
actual_content_h += flint_px(66);
|
||||
} else if(step == 3) {
|
||||
int preview_span;
|
||||
int preview_rmax;
|
||||
int slider_h = flint_px(40);
|
||||
|
||||
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font) + flint_px(20);
|
||||
preview_span = (content_w < flint_px(132)) ? content_w : flint_px(132);
|
||||
preview_rmax = preview_span / 2;
|
||||
if(preview_rmax < flint_px(60)) preview_rmax = flint_px(60);
|
||||
if(preview_rmax > flint_px(120)) preview_rmax = flint_px(120);
|
||||
actual_content_h += flint_px(40) + (int)((float)preview_rmax * 0.72f) + flint_px(14);
|
||||
actual_content_h += slider_h + flint_px(8);
|
||||
} else if(step == 4) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
|
||||
actual_content_h += flint_px(26) + flint_px(36) + flint_px(20);
|
||||
actual_content_h += hold_preview_extent * 2 + flint_px(24);
|
||||
actual_content_h += tutorial_paragraph_height(app, 4, content_w, body_font);
|
||||
} else {
|
||||
actual_content_h += flint_px(200) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 5, content_w, body_font);
|
||||
}
|
||||
|
||||
return actual_content_h;
|
||||
}
|
||||
#include "practices/practice_registry.h"
|
||||
|
||||
void
|
||||
manual_screen_reset_layouts(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
|
||||
void
|
||||
manual_screen_close_tutorial(InbeApp *app, int mark_seen)
|
||||
{
|
||||
if(mark_seen)
|
||||
mark_exercise_manual_seen(app, app->exercise_type);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
const PracticeDefinition *practice;
|
||||
|
||||
static void
|
||||
manual_screen_start_exercise(InbeApp *app)
|
||||
{
|
||||
mark_exercise_manual_seen(app, app->exercise_type);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
|
||||
if(app->exercise_type == EXERCISE_MEDITATION) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationSetup;
|
||||
app->modal.selected_button = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
if(app == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
session_start(app);
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_manual_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int body_font = flint_ui_font();
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.90f);
|
||||
int max_content_w = flint_px(520);
|
||||
int y;
|
||||
int button_w;
|
||||
int button_h = flint_px(36);
|
||||
int button_y = view_height - flint_px(52);
|
||||
int content_y = title_h + flint_px(20);
|
||||
int content_h = button_y - content_y - flint_px(16);
|
||||
int content_total_h;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIParagraph paragraph;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < flint_px(280))
|
||||
responsive_max_w = flint_px(280);
|
||||
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
if(ui_draw_screen_header(locale_get("meditation_manual_title"), 1))
|
||||
manual_screen_close_tutorial(app, 0);
|
||||
|
||||
if(content_h < flint_px(120))
|
||||
content_h = flint_px(120);
|
||||
|
||||
paragraph = (FlintUIParagraph){
|
||||
.text = locale_get("meditation_manual_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = body_font,
|
||||
.line_gap = TUTORIAL_LINE_SPACING,
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
paragraph.width = content_w;
|
||||
content_total_h = meditation_music_measure_settings(app, content_w, 0, 1) +
|
||||
flint_px(34) +
|
||||
flint_ui_paragraph_height(paragraph) +
|
||||
flint_px(20);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y,
|
||||
(float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
paragraph.width = content_w;
|
||||
content_total_h = meditation_music_measure_settings(app, content_w, 0, 1) +
|
||||
flint_px(34) +
|
||||
flint_ui_paragraph_height(paragraph) +
|
||||
flint_px(20);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y,
|
||||
(float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
y = scroll_view.content_y;
|
||||
meditation_music_draw_guide_settings(app, scroll_view.content_x, scroll_view.content_w, &y);
|
||||
y += flint_px(34);
|
||||
paragraph.width = scroll_view.content_w;
|
||||
flint_ui_paragraph_draw(paragraph, scroll_view.content_x, &y);
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
|
||||
{
|
||||
int hover = 0;
|
||||
|
||||
button_w = content_w;
|
||||
if(button_w > flint_px(260))
|
||||
button_w = flint_px(260);
|
||||
|
||||
if(ui_draw_generic_button(content_x + (content_w - button_w) / 2, button_y,
|
||||
button_w, button_h, locale_get("tutorial_start_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
manual_screen_start_exercise(app);
|
||||
}
|
||||
practice = practice_get(app->exercise_type);
|
||||
if(practice->close_manual != NULL)
|
||||
practice->close_manual(app, mark_seen);
|
||||
}
|
||||
|
||||
void
|
||||
manual_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int tab_h = flint_px(56);
|
||||
int viewport_h = view_height - title_h - tab_h;
|
||||
int body_font = flint_ui_font();
|
||||
int footer_content_pad = flint_ui_font() / 2;
|
||||
int content_area_h = viewport_h - footer_content_pad; /* For scissor mode and scroll calculations */
|
||||
int previous_step;
|
||||
int content_x;
|
||||
int content_w;
|
||||
const char *title = locale_get("tutorial_title");
|
||||
char page_label[32];
|
||||
int close_clicked = 0;
|
||||
int step = app->tutorial_step;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
const PracticeDefinition *practice;
|
||||
|
||||
if(app->exercise_type == EXERCISE_MEDITATION) {
|
||||
meditation_manual_draw(app);
|
||||
if(app == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
step = clampi(step, 0, (int)TUTORIAL_STEPS_COUNT - 1);
|
||||
app->tutorial_step = step;
|
||||
previous_step = step;
|
||||
|
||||
if(IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_ENTER)) {
|
||||
if(step < (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
app->tutorial_step++;
|
||||
else
|
||||
manual_screen_start_exercise(app);
|
||||
}
|
||||
if(IsKeyPressed(KEY_LEFT) && step > 0)
|
||||
app->tutorial_step--;
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
manual_screen_close_tutorial(app, 0);
|
||||
|
||||
step = app->tutorial_step;
|
||||
if(previous_step != step) {
|
||||
app->manual_scroll = 0;
|
||||
previous_step = step;
|
||||
}
|
||||
|
||||
switch(step) {
|
||||
case 1: title = locale_get("tutorial_method_title"); break;
|
||||
case 2: title = locale_get("tutorial_progressive_speed_title"); break;
|
||||
case 3: title = locale_get("tutorial_step1_title"); break;
|
||||
case 4: title = locale_get("tutorial_step2_title"); break;
|
||||
case 5: title = locale_get("tutorial_step3_title"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* Calculate responsive content width */
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
int min_width = flint_px(280);
|
||||
if(responsive_max_w < min_width)
|
||||
responsive_max_w = min_width;
|
||||
|
||||
int side_padding = flint_page_side_padding();
|
||||
flint_centered_column(responsive_max_w, side_padding, &content_x, &content_w);
|
||||
|
||||
close_clicked = ui_draw_screen_header(title, 1);
|
||||
if(close_clicked)
|
||||
manual_screen_close_tutorial(app, 0);
|
||||
|
||||
{
|
||||
int top_padding = flint_px(16);
|
||||
int total_content_h;
|
||||
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
total_content_h = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding;
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = total_content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
}
|
||||
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
content_x = scroll_view.content_x;
|
||||
content_w = scroll_view.content_w;
|
||||
{
|
||||
int y = scroll_view.content_y + flint_px(16);
|
||||
if(step == 0) {
|
||||
int img_h = flint_px(170);
|
||||
ui_draw_tutorial_image(app->whm_1_image, "whm/1.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
|
||||
draw_tutorial_paragraph(app, 0, content_x, &y, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
draw_tutorial_paragraph(app, 1, content_x, &y, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
draw_tutorial_paragraph(app, 2, content_x, &y, content_w, body_font);
|
||||
y += flint_px(18);
|
||||
{
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
if(ui_draw_toggle_switch(content_x, y, toggle_w, toggle_h,
|
||||
&progressive_speed, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = progressive_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += toggle_h + flint_px(20);
|
||||
}
|
||||
} else if(step == 3) {
|
||||
int speed = app->inbe.speed_level;
|
||||
draw_tutorial_paragraph(app, 3, content_x, &y, content_w, body_font);
|
||||
y += flint_px(20); /* Increased spacing between text and circle */
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2, y + flint_px(40));
|
||||
y += (int)(app->settings_preview.rmax * 0.72f) + flint_px(54);
|
||||
|
||||
if(ui_draw_slider(10, content_x, y, content_w, locale_get("speed_label"), SETTINGS_SPEED_MIN,
|
||||
SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
} else if(step == 4) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(36) + flint_px(20) + hold_preview_extent;
|
||||
draw_tutorial_hold_preview(app, content_x + content_w / 2, y, hold_preview_radius);
|
||||
y += hold_preview_extent + flint_px(24);
|
||||
draw_tutorial_paragraph(app, 4, content_x, &y, content_w, body_font);
|
||||
} else {
|
||||
int img_h = flint_px(200);
|
||||
ui_draw_tutorial_image(app->whm_2_image, "whm/2.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
draw_tutorial_paragraph(app, 5, content_x, &y, content_w, body_font);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
locale_format(page_label, sizeof(page_label), "tutorial_page_label",
|
||||
step + 1, (int)TUTORIAL_STEPS_COUNT);
|
||||
|
||||
int left_hover = 0;
|
||||
int right_hover = 0;
|
||||
const char *left_label = step == 0 ? locale_get("tutorial_skip_button") : locale_get("tutorial_back_button");
|
||||
const char *right_label = step == (int)TUTORIAL_STEPS_COUNT - 1 ? locale_get("tutorial_start_button") : locale_get("tutorial_next_button");
|
||||
int footer_gap = flint_px(10);
|
||||
int page_font = flint_ui_font();
|
||||
int button_h = flint_px(34);
|
||||
int button_w = (content_w - footer_gap) / 2;
|
||||
int footer_y = view_height - flint_px(38);
|
||||
int counter_gap = flint_px(6);
|
||||
|
||||
|
||||
flint_text_draw(page_label,
|
||||
view_width / 2 - flint_text_measure(page_label, page_font) / 2,
|
||||
footer_y - page_font - counter_gap, page_font, theme_get_text());
|
||||
|
||||
if(step == 0) {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover))
|
||||
manual_screen_start_exercise(app);
|
||||
} else {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover)) {
|
||||
app->tutorial_step--;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(ui_draw_generic_button(content_x + button_w + footer_gap, footer_y, button_w, button_h,
|
||||
right_label, UI_BUTTON_STYLE_PRIMARY, 0, &right_hover)) {
|
||||
if(step == (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
manual_screen_start_exercise(app);
|
||||
else {
|
||||
app->tutorial_step++;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
app->settings_drag_slider = 0;
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
practice = practice_get(app->exercise_type);
|
||||
if(practice->draw_manual != NULL)
|
||||
practice->draw_manual(app);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "practice_screen.h"
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "practices/practice_registry.h"
|
||||
|
||||
void
|
||||
on_practice_tab_click(void *user_data)
|
||||
@@ -15,7 +15,7 @@ int
|
||||
practice_activity_count_for_tab(int tab)
|
||||
{
|
||||
(void)tab;
|
||||
return EXERCISE_COUNT;
|
||||
return practice_count();
|
||||
}
|
||||
|
||||
int
|
||||
@@ -24,30 +24,22 @@ practice_activity_for_tab(int tab, int index)
|
||||
(void)tab;
|
||||
if(index < 0)
|
||||
return EXERCISE_WIM_HOF;
|
||||
if(index >= EXERCISE_COUNT)
|
||||
return EXERCISE_COUNT - 1;
|
||||
if(index >= practice_count())
|
||||
return practice_count() - 1;
|
||||
return index;
|
||||
}
|
||||
|
||||
const char *
|
||||
practice_activity_label(int exercise)
|
||||
{
|
||||
switch(exercise) {
|
||||
case EXERCISE_MEDITATION:
|
||||
return locale_get("exercise_meditation");
|
||||
case EXERCISE_WIM_HOF:
|
||||
default:
|
||||
return locale_get("exercise_wim_hof");
|
||||
}
|
||||
return practice_label(exercise);
|
||||
}
|
||||
|
||||
int
|
||||
practice_activity_index_for_tab(int tab, int exercise)
|
||||
{
|
||||
(void)tab;
|
||||
if(exercise < 0 || exercise >= EXERCISE_COUNT)
|
||||
return EXERCISE_WIM_HOF;
|
||||
return exercise;
|
||||
return practice_clamp_id(exercise);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -55,6 +47,5 @@ practice_clamp_activity_to_tab(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->exercise_type < 0 || app->exercise_type >= EXERCISE_COUNT)
|
||||
app->exercise_type = EXERCISE_WIM_HOF;
|
||||
app->exercise_type = practice_clamp_id(app->exercise_type);
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "settings_screen.h"
|
||||
#include "app.h"
|
||||
#include "device_preferences.h"
|
||||
#include "session.h"
|
||||
#include "language_screen.h"
|
||||
#include "meditation_music.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_theme_meta.h"
|
||||
@@ -16,6 +14,9 @@
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_import.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
#include "version.h"
|
||||
#include "data.h"
|
||||
#include "raylib.h"
|
||||
@@ -61,98 +62,12 @@ settings_draw_subtab_bar(int y, int h, const char **tab_names, int tab_count,
|
||||
});
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_exact_speed_preview(Inbe *preview, int *preview_speed,
|
||||
int speed, int max_rounds, int max_breaths,
|
||||
int pause_seconds, int content_w, int content_h,
|
||||
int center_x, int center_y)
|
||||
{
|
||||
if(preview == NULL || preview_speed == NULL)
|
||||
return;
|
||||
|
||||
if(preview->phase != InbePhaseBreathe) {
|
||||
inbeinit(preview);
|
||||
apply_settings(preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
preview->progressive_speed = 0;
|
||||
session_reset_round_breathe(preview);
|
||||
} else if(*preview_speed != speed) {
|
||||
apply_settings(preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
preview->progressive_speed = 0;
|
||||
}
|
||||
|
||||
if(*preview_speed != speed) {
|
||||
*preview_speed = speed;
|
||||
}
|
||||
|
||||
update_preview_bounds(preview, content_w, content_h);
|
||||
inbestep(preview);
|
||||
draw_preview_inbe(preview, center_x, center_y);
|
||||
}
|
||||
|
||||
void
|
||||
settings_draw_progressive_start_speed_editor(InbeApp *app)
|
||||
{
|
||||
int modal_w = flint_px(340);
|
||||
int modal_h = flint_px(360);
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
int modal_x = (view_width - modal_w) / 2;
|
||||
int modal_y = (view_height - modal_h) / 2;
|
||||
int title_font = flint_ui_font();
|
||||
int title_y = modal_y + flint_px(14);
|
||||
int close_size = flint_px(22);
|
||||
int close_padding = flint_px(8);
|
||||
int close_w = close_size + close_padding * 2;
|
||||
int close_hover = 0;
|
||||
int max_speed = app->inbe.speed_level;
|
||||
int start_speed = clampi(app->inbe.progressive_start_speed, SETTINGS_SPEED_MIN, max_speed);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
const char *title = locale_get("progressive_start_speed_editor_title");
|
||||
int title_w = flint_text_measure(title, title_font);
|
||||
int title_max_w = modal_w - close_w * 2 - flint_px(24);
|
||||
while(title_font > flint_px(12) && title_w > title_max_w) {
|
||||
title_font--;
|
||||
title_w = flint_text_measure(title, title_font);
|
||||
}
|
||||
flint_text_draw(title, modal_x + (modal_w - title_w) / 2, title_y, title_font, theme_get_text());
|
||||
|
||||
if(ui_draw_icon_btn_padded(modal_x + modal_w - close_w - flint_px(6), modal_y + flint_px(6),
|
||||
close_size, close_padding, app->icons[UI_ICON_TYPE_X], &close_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
return;
|
||||
}
|
||||
|
||||
settings_draw_exact_speed_preview(&app->start_speed_preview,
|
||||
&app->start_speed_preview_speed,
|
||||
start_speed,
|
||||
app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths),
|
||||
app->inbe.pause_seconds,
|
||||
modal_w - flint_px(48),
|
||||
flint_px(210),
|
||||
modal_x + modal_w / 2,
|
||||
modal_y + flint_px(150));
|
||||
|
||||
if(ui_draw_slider(12, modal_x + flint_px(24), modal_y + flint_px(250),
|
||||
modal_w - flint_px(48), locale_get("progressive_start_speed_label"),
|
||||
SETTINGS_SPEED_MIN, max_speed, &start_speed, "")) {
|
||||
app->inbe.progressive_start_speed = start_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unified status system variables */
|
||||
static char unified_status[256] = "";
|
||||
static char unified_detail[256] = "";
|
||||
static int unified_status_type = 0;
|
||||
static char pending_import_path[FS_PATH_MAX] = "";
|
||||
static DataImportInfo pending_import_info;
|
||||
|
||||
/* Helper functions for unified status system */
|
||||
void settings_screen_set_status_success(const char *message, const char *detail) {
|
||||
@@ -190,6 +105,109 @@ settings_screen_clear_status(void)
|
||||
unified_status_type = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_clear_pending_import(void)
|
||||
{
|
||||
pending_import_path[0] = '\0';
|
||||
memset(&pending_import_info, 0, sizeof(pending_import_info));
|
||||
}
|
||||
|
||||
static void
|
||||
settings_import_success(InbeApp *app, int imported_settings)
|
||||
{
|
||||
app_reload_after_import(app, imported_settings);
|
||||
settings_screen_set_status_success(locale_get("imported_data"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Import successful");
|
||||
}
|
||||
|
||||
static int
|
||||
settings_perform_import(InbeApp *app, const char *path, DataImportMode mode)
|
||||
{
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(data_import_with_mode(path, mode)) {
|
||||
settings_import_success(app, mode == DATA_IMPORT_DATA_AND_SETTINGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Import failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_begin_import_for_path(InbeApp *app, const char *path)
|
||||
{
|
||||
DataImportInfo info;
|
||||
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
if(!data_inspect_import(path, &info) || !info.valid) {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: Invalid import file selected");
|
||||
return;
|
||||
}
|
||||
|
||||
if((info.has_sessions || info.has_habits) && info.has_settings) {
|
||||
snprintf(pending_import_path, sizeof(pending_import_path), "%s", path);
|
||||
pending_import_info = info;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmImportDataSettings;
|
||||
app->modal.selected_button = 0;
|
||||
settings_screen_clear_status();
|
||||
return;
|
||||
}
|
||||
|
||||
settings_perform_import(app, path, DATA_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_draw_import_choice_modal(InbeApp *app)
|
||||
{
|
||||
FlintUIPanelFrame frame;
|
||||
int font = flint_ui_font();
|
||||
int msg_y;
|
||||
int msg_x;
|
||||
const char *message = locale_get("import_choice_message");
|
||||
int row_gap = flint_px(10);
|
||||
int btn_h = flint_px(36);
|
||||
int btn_y;
|
||||
int btn_w;
|
||||
int hover = 0;
|
||||
|
||||
(void)app;
|
||||
frame = ui_draw_modal_frame(flint_px(320), flint_px(232),
|
||||
locale_get("import_choice_title"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
msg_x = frame.content_x;
|
||||
msg_y = frame.content_y;
|
||||
flint_text_draw(message, msg_x, msg_y, font, theme_get_text());
|
||||
|
||||
btn_y = frame.y + frame.h - flint_px(24) - btn_h * 2 - row_gap;
|
||||
btn_w = (frame.content_w - row_gap) / 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y, btn_w, btn_h,
|
||||
locale_get("cancel_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover))
|
||||
return 1;
|
||||
if(ui_draw_generic_button(frame.content_x + btn_w + row_gap, btn_y, btn_w, btn_h,
|
||||
locale_get("import_data_only_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y + btn_h + row_gap,
|
||||
frame.content_w, btn_h,
|
||||
locale_get("import_data_settings_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_status(int x, int *y)
|
||||
{
|
||||
@@ -362,7 +380,7 @@ settings_apply_file_dialog_theme(InbeApp *app)
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
static void
|
||||
settings_screen_handle_android_import(void)
|
||||
settings_screen_handle_android_import(InbeApp *app)
|
||||
{
|
||||
char import_path[FS_PATH_MAX];
|
||||
int import_result = android_import_poll_result(import_path, sizeof(import_path));
|
||||
@@ -380,15 +398,74 @@ settings_screen_handle_android_import(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if(data_import(import_path)) {
|
||||
char import_message[128];
|
||||
locale_format(import_message, sizeof(import_message), "imported_sessions", data_get_session_count());
|
||||
settings_screen_set_status_success(import_message, NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Android import successful");
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Android import failed");
|
||||
settings_begin_import_for_path(app, import_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#define SETTINGS_WEB_IMPORT_PATH "/tmp/inbe-web-import.zip"
|
||||
|
||||
static void
|
||||
settings_web_import_open_picker(void)
|
||||
{
|
||||
EM_ASM({
|
||||
const importPath = UTF8ToString($0);
|
||||
Module.__inbeImportResult = 0;
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".zip,.db,application/zip,application/x-sqlite3,application/octet-stream";
|
||||
input.style.display = "none";
|
||||
|
||||
input.onchange = async function() {
|
||||
try {
|
||||
if(!input.files || input.files.length === 0) {
|
||||
Module.__inbeImportResult = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
const file = input.files[0];
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
try {
|
||||
FS.mkdir("/tmp");
|
||||
} catch(e) {}
|
||||
FS.writeFile(importPath, bytes);
|
||||
Module.__inbeImportResult = 1;
|
||||
} catch(e) {
|
||||
console.error("Inbe web import failed:", e);
|
||||
Module.__inbeImportResult = 3;
|
||||
} finally {
|
||||
input.remove();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
}, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_screen_handle_web_import(InbeApp *app)
|
||||
{
|
||||
int import_result = EM_ASM_INT({
|
||||
const result = Module.__inbeImportResult || 0;
|
||||
if(result !== 0)
|
||||
Module.__inbeImportResult = 0;
|
||||
return result;
|
||||
});
|
||||
|
||||
if(import_result == 0)
|
||||
return;
|
||||
if(import_result == 2) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
if(import_result != 1) {
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
settings_begin_import_for_path(app, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -400,6 +477,10 @@ settings_import_data(InbeApp *app)
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
else
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#elif defined(PLATFORM_WEB)
|
||||
(void)app;
|
||||
settings_web_import_open_picker();
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_load(&import_dlg, locale_get("import_data_dialog_title"));
|
||||
@@ -472,16 +553,7 @@ settings_draw_pending_file_dialog(InbeApp *app)
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&import_dlg);
|
||||
if(path != NULL && path[0] != '\0') {
|
||||
if(data_import(path)) {
|
||||
char import_message[128];
|
||||
locale_format(import_message, sizeof(import_message),
|
||||
"imported_sessions", data_get_session_count());
|
||||
settings_screen_set_status_success(import_message, NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Import successful");
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Import failed");
|
||||
}
|
||||
settings_begin_import_for_path(app, path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: No file selected for import");
|
||||
@@ -510,356 +582,6 @@ settings_draw_pending_file_dialog(InbeApp *app)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
wim_hof_config_draw_breathing_tab(InbeApp *app, int content_x, int content_w, int y,
|
||||
int *draw_breath_animation_menu)
|
||||
{
|
||||
static const char *animation_options[InbeBreathAnimationCount];
|
||||
int preview_h = flint_px(240);
|
||||
int preview_radius;
|
||||
int preview_padding = flint_px(12);
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int progressive_start_speed = app->inbe.progressive_start_speed;
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
animation_options[InbeBreathAnimationLinear] = locale_get("breath_animation_linear");
|
||||
animation_options[InbeBreathAnimationInOut] = locale_get("breath_animation_in_out");
|
||||
app->inbe.breath_animation = clampi(app->inbe.breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
|
||||
flint_text_draw(locale_get("breath_animation_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(104, content_x, y + flint_px(26), content_w, flint_px(36),
|
||||
animation_options, InbeBreathAnimationCount,
|
||||
&app->inbe.breath_animation);
|
||||
if(draw_breath_animation_menu != NULL)
|
||||
*draw_breath_animation_menu = 1;
|
||||
y += flint_px(76);
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, preview_h);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, preview_h);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
|
||||
preview_radius = (int)((float)app->settings_preview.rmax * 0.72f + 1.0f);
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2,
|
||||
y + preview_padding + preview_radius);
|
||||
if(ui_draw_slider(1, content_x, y + preview_padding + preview_radius * 2 + flint_px(28),
|
||||
content_w, locale_get("speed_label"),
|
||||
SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += preview_padding + preview_radius * 2 + flint_px(102);
|
||||
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, y + flint_px(26), toggle_w, toggle_h, &progressive_speed,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
|
||||
if(app->inbe.progressive_speed) {
|
||||
int modify_w = flint_text_measure(locale_get("modify_start_speed_button"), flint_ui_font()) + flint_px(24);
|
||||
int modify_hover = 0;
|
||||
if(modify_w > content_w)
|
||||
modify_w = content_w;
|
||||
if(progressive_start_speed != clampi(progressive_start_speed, SETTINGS_SPEED_MIN, speed)) {
|
||||
app->inbe.progressive_start_speed = clampi(progressive_start_speed, SETTINGS_SPEED_MIN, speed);
|
||||
app->settings_preview.progressive_start_speed = app->inbe.progressive_start_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
if(ui_draw_generic_button(content_x, y, modify_w, flint_px(36),
|
||||
locale_get("modify_start_speed_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &modify_hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalEditProgressiveStartSpeed;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
y += flint_px(58);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
wim_hof_config_draw_session_tab(InbeApp *app, int content_x, int content_w, int y)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int advanced_session_controls = app->advanced_session_controls;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
int reset_w = flint_text_measure(locale_get("reset_to_defaults_label"), flint_ui_font()) + flint_px(24);
|
||||
int reset_h = flint_px(36);
|
||||
int reset_hover = 0;
|
||||
|
||||
if(ui_draw_slider(2, content_x, y, content_w, locale_get("max_rounds_label"),
|
||||
1, MaxRounds, &max_rounds, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
if(ui_draw_slider(3, content_x, y, content_w, locale_get("max_breaths_label"),
|
||||
SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX, &max_breaths, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
if(ui_draw_slider(4, content_x, y, content_w, locale_get("pause_after_round_label"),
|
||||
SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX, &pause_seconds, "s")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(52);
|
||||
flint_text_draw(locale_get("advanced_session_controls_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, y + flint_px(26), toggle_w, toggle_h, &advanced_session_controls,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->advanced_session_controls = advanced_session_controls;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(76);
|
||||
if(reset_w > content_w)
|
||||
reset_w = content_w;
|
||||
if(ui_draw_generic_button(content_x + content_w - reset_w, y, reset_w, reset_h,
|
||||
locale_get("reset_to_defaults_label"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &reset_hover)) {
|
||||
speed = DefaultSpeedLevel;
|
||||
max_rounds = DefaultMaxRounds;
|
||||
max_breaths = DefaultMaxBreaths;
|
||||
pause_seconds = DefaultPauseSeconds;
|
||||
app->inbe.progressive_start_speed = DefaultProgressiveStartSpeed;
|
||||
app->settings_preview.progressive_start_speed = DefaultProgressiveStartSpeed;
|
||||
app->inbe.breath_animation = InbeBreathAnimationLinear;
|
||||
app->settings_preview.breath_animation = InbeBreathAnimationLinear;
|
||||
app->advanced_session_controls = 0;
|
||||
app->hold_display_mode = HOLD_DISPLAY_CIRCLE;
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += reset_h + flint_px(28);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
wim_hof_config_draw_content(InbeApp *app, int content_x, int content_w, int y,
|
||||
int *draw_breath_animation_menu)
|
||||
{
|
||||
if(app->practice_config_tab == 0)
|
||||
return wim_hof_config_draw_breathing_tab(app, content_x, content_w, y,
|
||||
draw_breath_animation_menu);
|
||||
return wim_hof_config_draw_session_tab(app, content_x, content_w, y);
|
||||
}
|
||||
|
||||
static int
|
||||
wim_hof_preview_radius(int content_w, int preview_h)
|
||||
{
|
||||
int span = content_w;
|
||||
int rmax;
|
||||
|
||||
if(preview_h > 0 && preview_h < span)
|
||||
span = preview_h;
|
||||
rmax = span / 2;
|
||||
if(rmax < flint_px(60))
|
||||
rmax = flint_px(60);
|
||||
if(rmax > flint_px(120))
|
||||
rmax = flint_px(120);
|
||||
return (int)((float)rmax * 0.72f + 1.0f);
|
||||
}
|
||||
|
||||
static int
|
||||
wim_hof_config_content_height(InbeApp *app, int content_w)
|
||||
{
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(app->practice_config_tab == 0) {
|
||||
int preview_radius = wim_hof_preview_radius(content_w, flint_px(240));
|
||||
int h = flint_px(12) + preview_radius * 2 + flint_px(102);
|
||||
h += flint_px(66);
|
||||
if(app->inbe.progressive_speed)
|
||||
h += flint_px(58);
|
||||
h += flint_px(76);
|
||||
return h;
|
||||
}
|
||||
|
||||
return flint_px(66) * 3 +
|
||||
flint_px(26) + flint_px(52) +
|
||||
flint_px(76) +
|
||||
flint_px(36) + flint_px(28);
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_config_draw_content(InbeApp *app, int content_x, int content_w, int y,
|
||||
int *draw_meditation_music_menu)
|
||||
{
|
||||
meditation_music_draw_settings(app, content_x, content_w, &y);
|
||||
if(draw_meditation_music_menu != NULL)
|
||||
*draw_meditation_music_menu = 1;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
practice_config_content_height(InbeApp *app, int content_w)
|
||||
{
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(app->exercise_type == EXERCISE_MEDITATION)
|
||||
return meditation_music_measure_settings(app, content_w, 1, 1);
|
||||
return wim_hof_config_content_height(app, content_w);
|
||||
}
|
||||
|
||||
void
|
||||
practice_config_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int config_tab_h = flint_px(40);
|
||||
int config_tab_gap = flint_px(14);
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
int min_content_w = flint_px(320);
|
||||
int scroll_y;
|
||||
int scroll_h;
|
||||
int content_h;
|
||||
int scrollbar_x;
|
||||
int controls_w;
|
||||
int y;
|
||||
int draw_meditation_music_menu = 0;
|
||||
int draw_breath_animation_menu = 0;
|
||||
int has_config_tabs = app->exercise_type == EXERCISE_WIM_HOF;
|
||||
int clicked_config_tab = -1;
|
||||
const char *config_tabs[] = {
|
||||
locale_get("settings_section_breathing"),
|
||||
locale_get("settings_section_session"),
|
||||
};
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIHeader header;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < min_content_w)
|
||||
responsive_max_w = min_content_w;
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
||||
app->settings_drag_slider = 0;
|
||||
|
||||
if(app->practice_config_tab < 0 || app->practice_config_tab > 1)
|
||||
app->practice_config_tab = 0;
|
||||
|
||||
header = ui_draw_title_header(title_h, locale_get(app->exercise_type == EXERCISE_MEDITATION
|
||||
? "exercise_meditation"
|
||||
: "exercise_wim_hof"),
|
||||
(Texture2D){0}, app->icons[UI_ICON_TYPE_X]);
|
||||
if(header.right_clicked) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
meditation_music_unload(app);
|
||||
app->settings_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
if(has_config_tabs) {
|
||||
clicked_config_tab = settings_draw_subtab_bar(title_h, config_tab_h, config_tabs, 2,
|
||||
app->practice_config_tab);
|
||||
if(clicked_config_tab >= 0 && clicked_config_tab != app->practice_config_tab) {
|
||||
app->practice_config_tab = clicked_config_tab;
|
||||
app->settings_scroll = 0;
|
||||
}
|
||||
scroll_y = title_h + config_tab_h + config_tab_gap;
|
||||
} else {
|
||||
scroll_y = title_h + flint_px(16);
|
||||
}
|
||||
scroll_h = view_height - scroll_y;
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
scrollbar_x = view_width - flint_px(8);
|
||||
controls_w = content_w;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
content_h = practice_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = scrollbar_x
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == controls_w)
|
||||
break;
|
||||
controls_w = measured.content_w;
|
||||
}
|
||||
content_h = practice_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = scrollbar_x
|
||||
};
|
||||
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
if(app->exercise_type == EXERCISE_MEDITATION)
|
||||
y = meditation_config_draw_content(app, scroll_view.content_x, scroll_view.content_w,
|
||||
scroll_view.content_y,
|
||||
&draw_meditation_music_menu);
|
||||
else
|
||||
y = wim_hof_config_draw_content(app, scroll_view.content_x, scroll_view.content_w,
|
||||
scroll_view.content_y,
|
||||
&draw_breath_animation_menu);
|
||||
(void)y;
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
if(draw_meditation_music_menu)
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
if(draw_breath_animation_menu && ui_draw_dropdown_menu(104)) {
|
||||
app->inbe.breath_animation = clampi(app->inbe.breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
app->settings_preview.breath_animation = app->inbe.breath_animation;
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalEditProgressiveStartSpeed)
|
||||
settings_draw_progressive_start_speed_editor(app);
|
||||
}
|
||||
|
||||
int
|
||||
settings_screen_draw(InbeApp *app)
|
||||
{
|
||||
@@ -924,7 +646,9 @@ settings_screen_draw(InbeApp *app)
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
settings_screen_handle_android_import();
|
||||
settings_screen_handle_android_import(app);
|
||||
#elif defined(PLATFORM_WEB)
|
||||
settings_screen_handle_web_import(app);
|
||||
#endif
|
||||
|
||||
if(content_viewport_h < 0)
|
||||
@@ -1008,13 +732,9 @@ settings_screen_draw(InbeApp *app)
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
#if defined(LOTUS_BUILD)
|
||||
flint_text_draw(locale_current_code(), draw_x, y, flint_ui_font(), theme_get_text());
|
||||
#else
|
||||
if(language_dropdown_button(app, 101, draw_x, y, draw_w, flint_px(36), &app->language_index))
|
||||
language_menu_changed = 1;
|
||||
draw_language_menu = 1;
|
||||
#endif
|
||||
y += flint_px(74);
|
||||
|
||||
if(ui_draw_slider(6, draw_x, y, draw_w, locale_get("volume_label"),
|
||||
@@ -1128,6 +848,26 @@ settings_screen_draw(InbeApp *app)
|
||||
}
|
||||
ui_set_dropdown_clip_top(0);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmImportDataSettings) {
|
||||
int modal_result = settings_draw_import_choice_modal(app);
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
} else if(modal_result == 2 || modal_result == 3) {
|
||||
char import_path[FS_PATH_MAX];
|
||||
DataImportMode mode = modal_result == 3
|
||||
? DATA_IMPORT_DATA_AND_SETTINGS
|
||||
: DATA_IMPORT_DATA_ONLY;
|
||||
snprintf(import_path, sizeof(import_path), "%s", pending_import_path);
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_perform_import(app, import_path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmDeleteData) {
|
||||
int modal_result = ui_draw_modal(locale_get("delete_all_data_title"),
|
||||
locale_get("delete_all_data_message"),
|
||||
@@ -1161,10 +901,6 @@ settings_screen_draw(InbeApp *app)
|
||||
}
|
||||
}
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalEditProgressiveStartSpeed) {
|
||||
settings_draw_progressive_start_speed_editor(app);
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
/* Draw the settings screen. Returns non-zero when it consumed the whole frame. */
|
||||
int settings_screen_draw(InbeApp *app);
|
||||
void practice_config_screen_draw(InbeApp *app);
|
||||
void settings_screen_clear_status(void);
|
||||
void settings_screen_set_status_success(const char *message, const char *detail);
|
||||
void settings_screen_set_status_error(const char *message);
|
||||
|
||||
@@ -235,9 +235,41 @@ data_validate_import_file(const char *path)
|
||||
|
||||
int
|
||||
data_import(const char *path)
|
||||
{
|
||||
return data_import_with_mode(path, DATA_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
int
|
||||
data_import_with_mode(const char *path, DataImportMode mode)
|
||||
{
|
||||
data_init();
|
||||
return inbe_storage_import_zip(path);
|
||||
return inbe_storage_import_zip_ex(
|
||||
path,
|
||||
mode == DATA_IMPORT_DATA_AND_SETTINGS
|
||||
? INBE_STORAGE_IMPORT_DATA_AND_SETTINGS
|
||||
: INBE_STORAGE_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
int
|
||||
data_inspect_import(const char *path, DataImportInfo *info)
|
||||
{
|
||||
InbeStorageImportInfo storage_info;
|
||||
|
||||
data_init();
|
||||
if(info != NULL)
|
||||
memset(info, 0, sizeof(*info));
|
||||
if(!inbe_storage_inspect_import(path, &storage_info))
|
||||
return 0;
|
||||
if(info != NULL) {
|
||||
info->valid = storage_info.valid;
|
||||
info->has_sessions = storage_info.has_sessions;
|
||||
info->has_habits = storage_info.has_habits;
|
||||
info->has_settings = storage_info.has_settings;
|
||||
info->session_count = storage_info.session_count;
|
||||
info->habit_count = storage_info.habit_count;
|
||||
info->setting_count = storage_info.setting_count;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef struct DbListSessionContext {
|
||||
|
||||
@@ -4,6 +4,21 @@
|
||||
#include <stddef.h>
|
||||
#include "breath_engine.h"
|
||||
|
||||
typedef enum DataImportMode {
|
||||
DATA_IMPORT_DATA_ONLY = 0,
|
||||
DATA_IMPORT_DATA_AND_SETTINGS = 1
|
||||
} DataImportMode;
|
||||
|
||||
typedef struct DataImportInfo {
|
||||
int valid;
|
||||
int has_sessions;
|
||||
int has_habits;
|
||||
int has_settings;
|
||||
int session_count;
|
||||
int habit_count;
|
||||
int setting_count;
|
||||
} DataImportInfo;
|
||||
|
||||
void data_init(void);
|
||||
const char *data_root(void);
|
||||
const char *data_today_dir(void);
|
||||
@@ -22,6 +37,8 @@ long long data_delete_all(void);
|
||||
void data_default_export_filename(char *out, size_t out_size);
|
||||
int data_export(const char *path);
|
||||
int data_import(const char *path);
|
||||
int data_import_with_mode(const char *path, DataImportMode mode);
|
||||
int data_inspect_import(const char *path, DataImportInfo *info);
|
||||
int data_validate_import_file(const char *path);
|
||||
typedef void (*data_session_callback)(const char *date, const char *time,
|
||||
int rounds, int best, void *user);
|
||||
|
||||
@@ -198,6 +198,100 @@ source_table_has_column(sqlite3 *db, const char *table, const char *column)
|
||||
return found;
|
||||
}
|
||||
|
||||
static int
|
||||
source_table_exists(sqlite3 *db, const char *table)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int found = 0;
|
||||
|
||||
if(db == NULL || table == NULL)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(db,
|
||||
"SELECT 1 FROM sqlite_master WHERE type='table' AND name=?1 LIMIT 1",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
sqlite3_bind_text(stmt, 1, table, -1, SQLITE_TRANSIENT);
|
||||
found = sqlite3_step(stmt) == SQLITE_ROW;
|
||||
sqlite3_finalize(stmt);
|
||||
return found;
|
||||
}
|
||||
|
||||
static int
|
||||
source_count_rows(sqlite3 *db, const char *sql)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = 0;
|
||||
|
||||
if(db == NULL || sql == NULL)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count;
|
||||
}
|
||||
|
||||
static const char *const importable_setting_keys[] = {
|
||||
"speed",
|
||||
"max_rounds",
|
||||
"max_breaths",
|
||||
"pause_seconds",
|
||||
"sound_volume",
|
||||
"tutorial_seen",
|
||||
"exercise_manual_seen_mask",
|
||||
"theme",
|
||||
"dark_mode",
|
||||
"theme_mode",
|
||||
"orientation_mode",
|
||||
"main_tab",
|
||||
"fullscreen",
|
||||
"on_screen_keyboard",
|
||||
"progressive_speed",
|
||||
"progressive_start_speed",
|
||||
"breath_animation",
|
||||
"advanced_session_controls",
|
||||
"hold_display_mode",
|
||||
"exercise_type",
|
||||
"meditation_music_enabled",
|
||||
"meditation_music_shuffle",
|
||||
"meditation_music_track",
|
||||
"play_in_background",
|
||||
"language",
|
||||
"practice_category_tab"
|
||||
};
|
||||
|
||||
static int
|
||||
setting_key_importable(const char *key)
|
||||
{
|
||||
if(key == NULL || key[0] == '\0')
|
||||
return 0;
|
||||
for(size_t i = 0; i < sizeof(importable_setting_keys) / sizeof(importable_setting_keys[0]); i++) {
|
||||
if(strcmp(key, importable_setting_keys[i]) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
source_count_importable_settings(sqlite3 *db)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = 0;
|
||||
|
||||
if(db == NULL || !source_table_exists(db, "settings"))
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(db, "SELECT DISTINCT key FROM settings", -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *key = (const char *)sqlite3_column_text(stmt, 0);
|
||||
if(setting_key_importable(key))
|
||||
count++;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return count;
|
||||
}
|
||||
|
||||
static long long
|
||||
now_seconds(void)
|
||||
{
|
||||
@@ -1428,8 +1522,11 @@ import_tickmate_db(sqlite3 *src)
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,1,?3)",
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,1,?3) "
|
||||
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
|
||||
"completed=CASE WHEN habit_days.completed!=0 THEN habit_days.completed ELSE excluded.completed END,"
|
||||
"updated_at=CASE WHEN habit_days.completed!=0 THEN habit_days.updated_at ELSE excluded.updated_at END",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(write_stmt, 1, local_habit_id);
|
||||
@@ -1448,12 +1545,96 @@ import_tickmate_db(sqlite3 *src)
|
||||
}
|
||||
|
||||
static int
|
||||
import_sqlite_db_file(const char *db_path)
|
||||
import_settings_from_source(sqlite3 *src)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
sqlite3_stmt *write_stmt = NULL;
|
||||
int imported = 0;
|
||||
long long imported_at = now_seconds();
|
||||
|
||||
if(src == NULL || g_storage.db == NULL || !source_table_exists(src, "settings"))
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(src, "SELECT key,value FROM settings", -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *key = (const char *)sqlite3_column_text(stmt, 0);
|
||||
const char *value = (const char *)sqlite3_column_text(stmt, 1);
|
||||
|
||||
if(!setting_key_importable(key))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO settings(user_id,key,value,updated_at) VALUES(?1,?2,?3,?4) "
|
||||
"ON CONFLICT(user_id,key) DO UPDATE SET "
|
||||
"value=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.value ELSE settings.value END,"
|
||||
"updated_at=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.updated_at ELSE settings.updated_at END",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(write_stmt, 1, g_storage.user_id);
|
||||
bind_text(write_stmt, 2, key);
|
||||
bind_text(write_stmt, 3, value != NULL ? value : "");
|
||||
sqlite3_bind_int64(write_stmt, 4, imported_at);
|
||||
if(sqlite3_step(write_stmt) == SQLITE_DONE)
|
||||
imported++;
|
||||
sqlite3_finalize(write_stmt);
|
||||
write_stmt = NULL;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_finalize(write_stmt);
|
||||
exec_sql("COMMIT");
|
||||
return imported;
|
||||
}
|
||||
|
||||
static int
|
||||
inspect_sqlite_db_file(const char *db_path, InbeStorageImportInfo *info)
|
||||
{
|
||||
sqlite3 *src = NULL;
|
||||
int ok = 0;
|
||||
|
||||
if(info != NULL)
|
||||
memset(info, 0, sizeof(*info));
|
||||
if(db_path == NULL || db_path[0] == '\0' || info == NULL)
|
||||
return 0;
|
||||
if(sqlite3_open(db_path, &src) != SQLITE_OK)
|
||||
goto done;
|
||||
|
||||
if(source_table_exists(src, "sessions") && source_table_exists(src, "session_rounds")) {
|
||||
info->session_count = source_count_rows(src, "SELECT COUNT(*) FROM sessions WHERE deleted_at=0");
|
||||
info->habit_count = source_table_exists(src, "habits")
|
||||
? source_count_rows(src, "SELECT COUNT(*) FROM habits WHERE deleted_at=0")
|
||||
: 0;
|
||||
info->setting_count = source_count_importable_settings(src);
|
||||
info->has_sessions = info->session_count > 0;
|
||||
info->has_habits = info->habit_count > 0;
|
||||
info->has_settings = info->setting_count > 0;
|
||||
info->valid = info->has_sessions || info->has_habits || info->has_settings;
|
||||
ok = info->valid;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if(source_table_has_column(src, "tracks", "name") &&
|
||||
source_table_has_column(src, "ticks", "_track_id")) {
|
||||
info->habit_count = source_count_rows(src, "SELECT COUNT(*) FROM tracks WHERE enabled!=0");
|
||||
info->has_habits = info->habit_count > 0;
|
||||
info->valid = info->has_habits;
|
||||
ok = info->valid;
|
||||
}
|
||||
|
||||
done:
|
||||
if(src != NULL)
|
||||
sqlite3_close(src);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int
|
||||
import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
{
|
||||
sqlite3 *src = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
sqlite3_stmt *hstmt = NULL;
|
||||
int ok = 0;
|
||||
int imported_settings = 0;
|
||||
|
||||
if(db_path == NULL || db_path[0] == '\0')
|
||||
return 0;
|
||||
@@ -1494,15 +1675,21 @@ import_sqlite_db_file(const char *db_path)
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order "
|
||||
"FROM habits WHERE deleted_at=0 ORDER BY sort_order,id",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
if(source_table_exists(src, "habits")) {
|
||||
int has_sync_activity = source_table_has_column(src, "habits", "sync_activity");
|
||||
const char *habit_sql =
|
||||
has_sync_activity
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: "SELECT id,name,color_r,color_g,color_b,sync_mode,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id";
|
||||
if(sqlite3_prepare_v2(src, habit_sql, -1, &stmt, NULL) != SQLITE_OK)
|
||||
goto after_habits;
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *import_habit_id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
const char *name = (const char *)sqlite3_column_text(stmt, 1);
|
||||
char local_habit_id[INBE_STORAGE_ID_SIZE];
|
||||
int sync_activity = has_sync_activity ? sqlite3_column_int(stmt, 6) : 0;
|
||||
int sort_order = has_sync_activity ? sqlite3_column_int(stmt, 7) : sqlite3_column_int(stmt, 6);
|
||||
|
||||
if(import_habit_id == NULL || import_habit_id[0] == '\0' ||
|
||||
name == NULL || name[0] == '\0')
|
||||
@@ -1522,8 +1709,8 @@ import_sqlite_db_file(const char *db_path)
|
||||
sqlite3_bind_int(hstmt, 5, sqlite3_column_int(stmt, 3));
|
||||
sqlite3_bind_int(hstmt, 6, sqlite3_column_int(stmt, 4));
|
||||
sqlite3_bind_int(hstmt, 7, sqlite3_column_int(stmt, 5));
|
||||
sqlite3_bind_int(hstmt, 8, sqlite3_column_int(stmt, 6));
|
||||
sqlite3_bind_int(hstmt, 9, sqlite3_column_int(stmt, 7));
|
||||
sqlite3_bind_int(hstmt, 8, sync_activity);
|
||||
sqlite3_bind_int(hstmt, 9, sort_order);
|
||||
if(sqlite3_step(hstmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(hstmt);
|
||||
@@ -1536,8 +1723,11 @@ import_sqlite_db_file(const char *db_path)
|
||||
while(sqlite3_step(hstmt) == SQLITE_ROW) {
|
||||
sqlite3_stmt *day_stmt = NULL;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4)",
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4) "
|
||||
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
|
||||
"completed=CASE WHEN habit_days.completed!=0 THEN habit_days.completed ELSE excluded.completed END,"
|
||||
"updated_at=CASE WHEN habit_days.completed!=0 THEN habit_days.updated_at ELSE excluded.updated_at END",
|
||||
-1, &day_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(day_stmt, 1, local_habit_id);
|
||||
@@ -1553,6 +1743,12 @@ import_sqlite_db_file(const char *db_path)
|
||||
}
|
||||
exec_sql("COMMIT");
|
||||
}
|
||||
after_habits:
|
||||
|
||||
if(mode == INBE_STORAGE_IMPORT_DATA_AND_SETTINGS)
|
||||
imported_settings = import_settings_from_source(src);
|
||||
if(imported_settings > 0)
|
||||
ok = 1;
|
||||
|
||||
goto done;
|
||||
|
||||
@@ -1575,6 +1771,12 @@ done:
|
||||
|
||||
int
|
||||
inbe_storage_import_zip(const char *path)
|
||||
{
|
||||
return inbe_storage_import_zip_ex(path, INBE_STORAGE_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_storage_import_zip_ex(const char *path, InbeStorageImportMode mode)
|
||||
{
|
||||
mz_zip_archive archive;
|
||||
int ok = 0;
|
||||
@@ -1589,7 +1791,7 @@ inbe_storage_import_zip(const char *path)
|
||||
}
|
||||
memset(&archive, 0, sizeof(archive));
|
||||
if(!mz_zip_reader_init_file(&archive, path, 0)) {
|
||||
return import_sqlite_db_file(path);
|
||||
return import_sqlite_db_file(path, mode);
|
||||
}
|
||||
if(mz_zip_reader_locate_file(&archive, "inbe-data/inbe.db", NULL, 0) >= 0) {
|
||||
char *db_bytes;
|
||||
@@ -1602,7 +1804,7 @@ inbe_storage_import_zip(const char *path)
|
||||
if(db_bytes != NULL && fp != NULL && fwrite(db_bytes, 1, db_size, fp) == db_size) {
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
ok = import_sqlite_db_file(temp_path);
|
||||
ok = import_sqlite_db_file(temp_path, mode);
|
||||
remove(temp_path);
|
||||
if(!ok)
|
||||
TraceLog(LOG_ERROR, "DATA: archive contained inbe-data/inbe.db but sqlite import failed");
|
||||
@@ -1621,6 +1823,63 @@ inbe_storage_import_zip(const char *path)
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
inbe_storage_inspect_import(const char *path, InbeStorageImportInfo *info)
|
||||
{
|
||||
mz_zip_archive archive;
|
||||
int ok = 0;
|
||||
|
||||
if(info != NULL)
|
||||
memset(info, 0, sizeof(*info));
|
||||
if(path == NULL || path[0] == '\0' || info == NULL || !path_exists(path))
|
||||
return 0;
|
||||
|
||||
memset(&archive, 0, sizeof(archive));
|
||||
if(!mz_zip_reader_init_file(&archive, path, 0))
|
||||
return inspect_sqlite_db_file(path, info);
|
||||
|
||||
if(mz_zip_reader_locate_file(&archive, "inbe-data/inbe.db", NULL, 0) >= 0) {
|
||||
char *db_bytes;
|
||||
size_t db_size = 0;
|
||||
char temp_path[INBE_STORAGE_PATH_SIZE];
|
||||
FILE *fp;
|
||||
db_bytes = mz_zip_reader_extract_file_to_heap(&archive, "inbe-data/inbe.db", &db_size, 0);
|
||||
snprintf(temp_path, sizeof(temp_path), "%s/import-inspect-inbe.db", g_storage.root);
|
||||
fp = fopen(temp_path, "wb");
|
||||
if(db_bytes != NULL && fp != NULL && fwrite(db_bytes, 1, db_size, fp) == db_size) {
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
ok = inspect_sqlite_db_file(temp_path, info);
|
||||
remove(temp_path);
|
||||
}
|
||||
if(fp != NULL)
|
||||
fclose(fp);
|
||||
free(db_bytes);
|
||||
} else {
|
||||
mz_uint file_count = mz_zip_reader_get_num_files(&archive);
|
||||
for(mz_uint i = 0; i < file_count; i++) {
|
||||
mz_zip_archive_file_stat stat;
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
int hour;
|
||||
int minute;
|
||||
int second;
|
||||
|
||||
if(!mz_zip_reader_file_stat(&archive, i, &stat) || stat.m_is_directory)
|
||||
continue;
|
||||
if(parse_legacy_session_filename(stat.m_filename, &year, &month, &day,
|
||||
&hour, &minute, &second))
|
||||
info->session_count++;
|
||||
}
|
||||
info->has_sessions = info->session_count > 0;
|
||||
info->valid = info->has_sessions;
|
||||
ok = info->valid;
|
||||
}
|
||||
mz_zip_reader_end(&archive);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
inbe_storage_init(const char *root)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,21 @@ typedef void (*InbeStorageSessionRecordCallback)(const char *id,
|
||||
const int *rounds, int round_count,
|
||||
void *user);
|
||||
|
||||
typedef enum InbeStorageImportMode {
|
||||
INBE_STORAGE_IMPORT_DATA_ONLY = 0,
|
||||
INBE_STORAGE_IMPORT_DATA_AND_SETTINGS = 1
|
||||
} InbeStorageImportMode;
|
||||
|
||||
typedef struct InbeStorageImportInfo {
|
||||
int valid;
|
||||
int has_sessions;
|
||||
int has_habits;
|
||||
int has_settings;
|
||||
int session_count;
|
||||
int habit_count;
|
||||
int setting_count;
|
||||
} InbeStorageImportInfo;
|
||||
|
||||
int inbe_storage_init(const char *root);
|
||||
void inbe_storage_close(void);
|
||||
const char *inbe_storage_db_path(void);
|
||||
@@ -53,5 +68,7 @@ void inbe_storage_mark_habits_initialized(void);
|
||||
|
||||
int inbe_storage_export_zip(const char *path);
|
||||
int inbe_storage_import_zip(const char *path);
|
||||
int inbe_storage_import_zip_ex(const char *path, InbeStorageImportMode mode);
|
||||
int inbe_storage_inspect_import(const char *path, InbeStorageImportInfo *info);
|
||||
|
||||
#endif
|
||||
@@ -8,12 +8,12 @@
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://inbe.waozi.xyz/">
|
||||
<meta property="og:title" content="Inner Breeze">
|
||||
<meta property="og:description" content="guided breathing meditation based on the Wim Hof method">
|
||||
<meta property="og:description" content="guided breathing, meditation, and habit tracking">
|
||||
<meta property="og:image" content="https://inbe.waozi.xyz/og.jpg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:url" content="https://inbe.waozi.xyz/">
|
||||
<meta name="twitter:title" content="Inner Breeze">
|
||||
<meta name="twitter:description" content="guided breathing meditation based on the Wim Hof method">
|
||||
<meta name="twitter:description" content="guided breathing, meditation, and habit tracking">
|
||||
<meta name="twitter:image" content="https://inbe.waozi.xyz/og.jpg">
|
||||
<meta name="twitter:site" content="@waozixyz">
|
||||
<meta name="twitter:creator" content="@waozixyz">
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
MAX_KEYS = 1024,
|
||||
MAX_KEY_LEN = 128,
|
||||
MAX_PATH_LEN = 512
|
||||
};
|
||||
|
||||
typedef struct LocaleKeys {
|
||||
char keys[MAX_KEYS][MAX_KEY_LEN];
|
||||
int count;
|
||||
} LocaleKeys;
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void
|
||||
trim_newline(char *text)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(text == NULL)
|
||||
return;
|
||||
len = strlen(text);
|
||||
while(len > 0 && (text[len - 1] == '\n' || text[len - 1] == '\r')) {
|
||||
text[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
parse_key_line(const char *line, char *out, size_t out_size)
|
||||
{
|
||||
const char *end;
|
||||
size_t len;
|
||||
|
||||
if(line == NULL || out == NULL || out_size == 0 || line[0] != '[')
|
||||
return 0;
|
||||
end = strchr(line, ']');
|
||||
if(end == NULL || end == line + 1)
|
||||
return 0;
|
||||
len = (size_t)(end - line - 1);
|
||||
if(len >= out_size)
|
||||
len = out_size - 1;
|
||||
memcpy(out, line + 1, len);
|
||||
out[len] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
keys_contains(const LocaleKeys *keys, const char *key)
|
||||
{
|
||||
if(keys == NULL || key == NULL)
|
||||
return 0;
|
||||
for(int i = 0; i < keys->count; i++) {
|
||||
if(strcmp(keys->keys[i], key) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
keys_add(LocaleKeys *keys, const char *key)
|
||||
{
|
||||
if(keys == NULL || key == NULL || key[0] == '\0')
|
||||
return;
|
||||
if(keys_contains(keys, key))
|
||||
return;
|
||||
if(keys->count >= MAX_KEYS) {
|
||||
fprintf(stderr, "FAIL too many locale keys\n");
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
snprintf(keys->keys[keys->count], sizeof(keys->keys[keys->count]), "%s", key);
|
||||
keys->count++;
|
||||
}
|
||||
|
||||
static int
|
||||
line_has_value(const char *line)
|
||||
{
|
||||
if(line == NULL)
|
||||
return 0;
|
||||
while(*line == ' ' || *line == '\t')
|
||||
line++;
|
||||
return line[0] != '\0' && strcmp(line, "---") != 0;
|
||||
}
|
||||
|
||||
static int
|
||||
load_locale_keys(const char *path, LocaleKeys *keys)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[512];
|
||||
char pending_key[MAX_KEY_LEN] = "";
|
||||
int ok = 1;
|
||||
|
||||
if(keys == NULL)
|
||||
return 0;
|
||||
memset(keys, 0, sizeof(*keys));
|
||||
fp = fopen(path, "rb");
|
||||
if(fp == NULL) {
|
||||
fprintf(stderr, "FAIL open %s\n", path);
|
||||
failures++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(fgets(line, sizeof(line), fp) != NULL) {
|
||||
char key[MAX_KEY_LEN];
|
||||
trim_newline(line);
|
||||
if(parse_key_line(line, key, sizeof(key))) {
|
||||
if(pending_key[0] != '\0') {
|
||||
fprintf(stderr, "FAIL %s key [%s] has no value\n", path, pending_key);
|
||||
failures++;
|
||||
ok = 0;
|
||||
}
|
||||
keys_add(keys, key);
|
||||
snprintf(pending_key, sizeof(pending_key), "%s", key);
|
||||
} else if(pending_key[0] != '\0' && line_has_value(line)) {
|
||||
pending_key[0] = '\0';
|
||||
}
|
||||
}
|
||||
if(pending_key[0] != '\0') {
|
||||
fprintf(stderr, "FAIL %s key [%s] has no value\n", path, pending_key);
|
||||
failures++;
|
||||
ok = 0;
|
||||
}
|
||||
fclose(fp);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void
|
||||
check_locale_file(const LocaleKeys *english, const char *path)
|
||||
{
|
||||
LocaleKeys translated;
|
||||
|
||||
load_locale_keys(path, &translated);
|
||||
for(int i = 0; i < english->count; i++) {
|
||||
if(!keys_contains(&translated, english->keys[i])) {
|
||||
fprintf(stderr, "FAIL %s missing [%s]\n", path, english->keys[i]);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
LocaleKeys english;
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
if(!load_locale_keys("locales/en.txt", &english))
|
||||
return 1;
|
||||
|
||||
dir = opendir("locales");
|
||||
if(dir == NULL) {
|
||||
fprintf(stderr, "FAIL open locales directory\n");
|
||||
return 1;
|
||||
}
|
||||
while((entry = readdir(dir)) != NULL) {
|
||||
char path[MAX_PATH_LEN];
|
||||
const char *name = entry->d_name;
|
||||
size_t len = strlen(name);
|
||||
|
||||
if(len <= 4 || strcmp(name + len - 4, ".txt") != 0)
|
||||
continue;
|
||||
if(strcmp(name, "en.txt") == 0 || strcmp(name, "index.txt") == 0)
|
||||
continue;
|
||||
snprintf(path, sizeof(path), "locales/%s", name);
|
||||
check_locale_file(&english, path);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
if(failures != 0) {
|
||||
fprintf(stderr, "%d locale key test failure(s)\n", failures);
|
||||
return 1;
|
||||
}
|
||||
printf("locale key tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -42,6 +42,18 @@ check_true(const char *label, int ok)
|
||||
g_failures++;
|
||||
}
|
||||
|
||||
static void
|
||||
check_str(const char *label, const char *got, const char *want)
|
||||
{
|
||||
if(got == NULL && want == NULL)
|
||||
return;
|
||||
if(got != NULL && want != NULL && strcmp(got, want) == 0)
|
||||
return;
|
||||
fprintf(stderr, "FAIL %s: got %s, want %s\n",
|
||||
label, got != NULL ? got : "(null)", want != NULL ? want : "(null)");
|
||||
g_failures++;
|
||||
}
|
||||
|
||||
static int
|
||||
ascii_equal_ci(const char *a, const char *b)
|
||||
{
|
||||
@@ -147,6 +159,32 @@ write_source_database(const char *root)
|
||||
inbe_storage_close();
|
||||
}
|
||||
|
||||
static void
|
||||
insert_raw_habit_day(const char *root, const char *habit_id, int local_date, int completed)
|
||||
{
|
||||
char db_path[512];
|
||||
sqlite3 *db = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
|
||||
make_path(db_path, sizeof(db_path), root, "inbe.db");
|
||||
check_true("open raw habit day db", sqlite3_open(db_path, &db) == SQLITE_OK);
|
||||
if(db == NULL)
|
||||
return;
|
||||
if(sqlite3_prepare_v2(db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(stmt, 1, habit_id, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(stmt, 2, local_date);
|
||||
sqlite3_bind_int(stmt, 3, completed ? 1 : 0);
|
||||
check_true("insert raw habit day", sqlite3_step(stmt) == SQLITE_DONE);
|
||||
} else {
|
||||
check_true("prepare raw habit day", 0);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
static void
|
||||
metadata_history_callback(const char *id, int year, int month, int day,
|
||||
int hour, int minute, int second,
|
||||
@@ -326,6 +364,163 @@ test_habit_name_merge_import(void)
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_import_conflict_prefers_data_over_empty(void)
|
||||
{
|
||||
char source[512], dest[512], zip_path[512];
|
||||
InbeHabits habits;
|
||||
InbeHabit *habit;
|
||||
|
||||
make_clean_root(source, sizeof(source), "conflict-source");
|
||||
make_clean_root(dest, sizeof(dest), "conflict-dest");
|
||||
make_path(zip_path, sizeof(zip_path), source, "conflict-export.zip");
|
||||
|
||||
check_true("init conflict source", inbe_storage_init(source));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add conflict source habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){224, 124, 104, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_storage_set_setting_text("language", "");
|
||||
inbe_storage_close();
|
||||
insert_raw_habit_day(source, "habit-1", 20260618, 0);
|
||||
check_true("reopen conflict source", inbe_storage_init(source));
|
||||
check_true("conflict source export", inbe_storage_export_zip(zip_path));
|
||||
inbe_storage_close();
|
||||
|
||||
check_true("init conflict dest", inbe_storage_init(dest));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add conflict dest habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){126, 183, 230, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20260618, 1);
|
||||
inbe_storage_set_setting_text("language", "en");
|
||||
check_true("conflict import",
|
||||
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("conflict habits load", inbe_storage_habits_load(&habits));
|
||||
habit = find_habit_ci(&habits, "Meditation");
|
||||
check_true("conflict keeps completed day",
|
||||
habit != NULL && inbe_habit_completed_day(habit, 20260618));
|
||||
check_str("conflict keeps non-empty setting",
|
||||
inbe_storage_get_setting_text("language"), "en");
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
write_multi_habit_source_database(const char *root, const char *zip_path)
|
||||
{
|
||||
int rounds[] = {77};
|
||||
InbeHabits habits;
|
||||
|
||||
check_true("init multi habit source", inbe_storage_init(root));
|
||||
check_true("save multi habit source session",
|
||||
inbe_storage_save_session_for_activity(rounds, 1, 0, 1, NULL, 0));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add meditation habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){224, 124, 104, 255},
|
||||
INBE_HABIT_SYNC_ACTIVITIES,
|
||||
(1 << 0) | (1 << 1)),
|
||||
0);
|
||||
check_int("add push ups habit",
|
||||
inbe_habits_add_custom(&habits, "Push ups",
|
||||
(Color){180, 132, 220, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
1);
|
||||
check_int("add cold shower habit",
|
||||
inbe_habits_add_custom(&habits, "Cold Shower",
|
||||
(Color){99, 196, 165, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
2);
|
||||
inbe_habit_set_day(&habits, 0, 20260617, 1);
|
||||
inbe_habit_set_day(&habits, 1, 20260617, 1);
|
||||
inbe_habit_set_day(&habits, 2, 20260617, 1);
|
||||
inbe_storage_set_setting_int("speed", 7);
|
||||
inbe_storage_set_setting_text("language", "en");
|
||||
inbe_storage_set_setting_text("future_unknown_key", "ignore-me");
|
||||
check_true("export multi habit source", inbe_storage_export_zip(zip_path));
|
||||
inbe_storage_close();
|
||||
}
|
||||
|
||||
static void
|
||||
assert_multi_habits_imported(const char *root, int want_speed)
|
||||
{
|
||||
InbeHabits habits;
|
||||
InbeHabit *habit;
|
||||
|
||||
check_true("init multi habit import db", inbe_storage_init(root));
|
||||
check_int("multi habit imported sessions", inbe_storage_session_count(), 1);
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("multi habit load", inbe_storage_habits_load(&habits));
|
||||
check_int("multi habit count", habits.count, 3);
|
||||
habit = find_habit_ci(&habits, "Meditation");
|
||||
check_true("multi meditation exists", habit != NULL);
|
||||
check_int("multi meditation sync mode",
|
||||
habit != NULL ? habit->sync_mode : -1,
|
||||
INBE_HABIT_SYNC_ACTIVITIES);
|
||||
check_int("multi meditation sync activity",
|
||||
habit != NULL ? habit->sync_activity : -1,
|
||||
(1 << 0) | (1 << 1));
|
||||
check_true("multi meditation day",
|
||||
habit != NULL && inbe_habit_completed_day(habit, 20260617));
|
||||
habit = find_habit_ci(&habits, "Push ups");
|
||||
check_true("multi push ups day",
|
||||
habit != NULL && inbe_habit_completed_day(habit, 20260617));
|
||||
habit = find_habit_ci(&habits, "Cold Shower");
|
||||
check_true("multi cold shower day",
|
||||
habit != NULL && inbe_habit_completed_day(habit, 20260617));
|
||||
check_int("multi import speed setting",
|
||||
inbe_storage_get_setting_int("speed", -1), want_speed);
|
||||
check_str("multi import unknown setting",
|
||||
inbe_storage_get_setting_text("future_unknown_key"), NULL);
|
||||
inbe_storage_close();
|
||||
}
|
||||
|
||||
static void
|
||||
test_import_modes_preserve_habits_and_settings_choice(void)
|
||||
{
|
||||
char source[512], dest_data[512], dest_settings[512], zip_path[512];
|
||||
InbeStorageImportInfo info;
|
||||
|
||||
make_clean_root(source, sizeof(source), "multi-source");
|
||||
make_clean_root(dest_data, sizeof(dest_data), "multi-dest-data");
|
||||
make_clean_root(dest_settings, sizeof(dest_settings), "multi-dest-settings");
|
||||
make_path(zip_path, sizeof(zip_path), source, "multi-export.zip");
|
||||
write_multi_habit_source_database(source, zip_path);
|
||||
|
||||
check_true("init inspect dest", inbe_storage_init(dest_data));
|
||||
memset(&info, 0, sizeof(info));
|
||||
check_true("inspect multi export", inbe_storage_inspect_import(zip_path, &info));
|
||||
check_true("inspect valid", info.valid);
|
||||
check_true("inspect sessions", info.has_sessions);
|
||||
check_true("inspect habits", info.has_habits);
|
||||
check_true("inspect settings", info.has_settings);
|
||||
check_int("inspect habit count", info.habit_count, 3);
|
||||
inbe_storage_set_setting_int("speed", 1);
|
||||
check_true("multi data only import",
|
||||
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_ONLY));
|
||||
inbe_storage_close();
|
||||
assert_multi_habits_imported(dest_data, 1);
|
||||
|
||||
check_true("init settings import dest", inbe_storage_init(dest_settings));
|
||||
inbe_storage_set_setting_int("speed", 1);
|
||||
check_true("multi data settings import",
|
||||
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
|
||||
inbe_storage_close();
|
||||
assert_multi_habits_imported(dest_settings, 7);
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest_data);
|
||||
remove_tree(dest_settings);
|
||||
}
|
||||
|
||||
static void
|
||||
write_legacy_zip(const char *path, const char *prefix)
|
||||
{
|
||||
@@ -463,15 +658,44 @@ test_tickmate_db_import(void)
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_external_tickmate_db_import(void)
|
||||
{
|
||||
const char *db_path = getenv("INBE_TICKMATE_IMPORT_FIXTURE");
|
||||
char dest[512];
|
||||
InbeStorageImportInfo info;
|
||||
InbeHabits habits;
|
||||
|
||||
if(db_path == NULL || db_path[0] == '\0')
|
||||
return;
|
||||
|
||||
make_clean_root(dest, sizeof(dest), "external-tickmate-dest");
|
||||
check_true("init external tickmate import dest", inbe_storage_init(dest));
|
||||
memset(&info, 0, sizeof(info));
|
||||
check_true("inspect external tickmate db", inbe_storage_inspect_import(db_path, &info));
|
||||
check_true("external tickmate db valid", info.valid);
|
||||
check_true("external tickmate db has habits", info.has_habits);
|
||||
check_true("external tickmate db import", inbe_storage_import_zip(db_path));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("external tickmate habits load", inbe_storage_habits_load(&habits));
|
||||
check_true("external tickmate habit count", habits.count > 0);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
test_raw_db_import();
|
||||
test_zip_db_import();
|
||||
test_habit_name_merge_import();
|
||||
test_import_conflict_prefers_data_over_empty();
|
||||
test_import_modes_preserve_habits_and_settings_choice();
|
||||
test_legacy_zip_import();
|
||||
test_legacy_file_startup_migration();
|
||||
test_tickmate_db_import();
|
||||
test_external_tickmate_db_import();
|
||||
test_session_metadata();
|
||||
|
||||
if(g_failures != 0) {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
IDI_APP_ICON ICON "inbe.ico"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,3,2,0
|
||||
PRODUCTVERSION 1,3,2,0
|
||||
FILEVERSION 1,3,5,0
|
||||
PRODUCTVERSION 1,3,5,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -21,11 +21,11 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "waozi"
|
||||
VALUE "FileDescription", "Inner Breeze"
|
||||
VALUE "FileVersion", "1.3.2"
|
||||
VALUE "FileVersion", "1.3.5"
|
||||
VALUE "InternalName", "inbe"
|
||||
VALUE "OriginalFilename", "inbe-windows-x86_64.exe"
|
||||
VALUE "ProductName", "Inner Breeze"
|
||||
VALUE "ProductVersion", "1.3.2"
|
||||
VALUE "ProductVersion", "1.3.5"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||