Documentation and launching much nicer now when using the yad interface.
This commit is contained in:
@@ -83,6 +83,82 @@ agm_menu() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Specialized game launcher menu with "Read Documentation" button
|
||||
# Usage: agm_game_menu "title" "backtitle" "text" option1 "description1" option2 "description2" ...
|
||||
# Returns: exit code 0=Launch, 1=Cancel, 2/3=Documentation (yad/dialog)
|
||||
agm_game_menu() {
|
||||
local title="$1"
|
||||
local backTitle="$2"
|
||||
local text="$3"
|
||||
shift 3
|
||||
|
||||
if [[ "$dialogType" == "yad" ]]; then
|
||||
# Use custom buttons to match dialog behavior (launch/doc/cancel)
|
||||
local yadList=""
|
||||
declare -A valueMap
|
||||
while [[ $# -gt 0 ]]; do
|
||||
local option="$1"
|
||||
local description="$2"
|
||||
valueMap["$description"]="$option"
|
||||
if [[ -n "$yadList" ]]; then
|
||||
yadList="$yadList\n"
|
||||
fi
|
||||
yadList="${yadList}${description}"
|
||||
shift 2
|
||||
done
|
||||
|
||||
local selectedDescription
|
||||
selectedDescription=$(echo -e "$yadList" | yad --list \
|
||||
--title="$title" \
|
||||
--text="$text" \
|
||||
--column="Option" \
|
||||
--no-headers \
|
||||
--selectable-labels \
|
||||
--search-column=1 \
|
||||
--height=400 \
|
||||
--width=600 \
|
||||
--button="Launch:0" \
|
||||
--button="Read Documentation:2" \
|
||||
--button="Cancel:1")
|
||||
local menuCode=$?
|
||||
|
||||
# Strip trailing pipes and return the mapped value
|
||||
if [[ -n "$selectedDescription" ]]; then
|
||||
selectedDescription="${selectedDescription%|}"
|
||||
echo "${valueMap["$selectedDescription"]}"
|
||||
fi
|
||||
return $menuCode
|
||||
else
|
||||
# Build dialog menu format with mapping (same approach as yad)
|
||||
local dialogArgs=()
|
||||
declare -A valueMap
|
||||
while [[ $# -gt 0 ]]; do
|
||||
local option="$1"
|
||||
local description="$2"
|
||||
valueMap["$description"]="$option"
|
||||
dialogArgs+=("$description" "$description")
|
||||
shift 2
|
||||
done
|
||||
|
||||
local selectedDescription
|
||||
selectedDescription=$(dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--extra-button \
|
||||
--extra-label "Read Documentation" \
|
||||
--no-tags \
|
||||
--menu "$text" 0 0 0 \
|
||||
"${dialogArgs[@]}" \
|
||||
--stdout)
|
||||
local menuCode=$?
|
||||
|
||||
# Return the mapped value
|
||||
if [[ -n "$selectedDescription" ]]; then
|
||||
echo "${valueMap["$selectedDescription"]}"
|
||||
fi
|
||||
return $menuCode
|
||||
fi
|
||||
}
|
||||
|
||||
# Wrapper function for checklist selection
|
||||
# Usage: agm_checklist "title" "backtitle" "text" option1 "description1" "status1" option2 "description2" "status2" ...
|
||||
agm_checklist() {
|
||||
@@ -181,24 +257,41 @@ agm_msgbox() {
|
||||
}
|
||||
|
||||
# Wrapper function for yes/no dialog
|
||||
# Usage: agm_yesno "title" "backtitle" "text"
|
||||
# Usage: agm_yesno "title" "backtitle" "text" ["yes_label"] ["no_label"]
|
||||
agm_yesno() {
|
||||
local title="$1"
|
||||
local backTitle="$2"
|
||||
local text="$3"
|
||||
|
||||
local yesLabel="${4:-Yes}"
|
||||
local noLabel="${5:-No}"
|
||||
|
||||
if [[ "$dialogType" == "yad" ]]; then
|
||||
echo -e "$text" | yad --text-info \
|
||||
--title="$title" \
|
||||
--show-cursor \
|
||||
--button="Yes:0" \
|
||||
--button="No:1" \
|
||||
--button="$yesLabel:0" \
|
||||
--button="$noLabel:1" \
|
||||
--width=600 \
|
||||
--height=400
|
||||
else
|
||||
dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--yesno "$text" 0 0
|
||||
# dialog --yesno doesn't support custom labels, use menu instead
|
||||
if [[ "$yesLabel" != "Yes" ]] || [[ "$noLabel" != "No" ]]; then
|
||||
# Custom labels requested, use menu
|
||||
local choice
|
||||
choice=$(dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--no-tags \
|
||||
--menu "$text" 0 0 0 \
|
||||
"1" "$yesLabel" \
|
||||
"2" "$noLabel" \
|
||||
--stdout)
|
||||
[[ "$choice" == "1" ]]
|
||||
else
|
||||
# Default Yes/No
|
||||
dialog --backtitle "$backTitle" \
|
||||
--title "$title" \
|
||||
--yesno "$text" 0 0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -441,4 +534,4 @@ agm_dselect() {
|
||||
--dselect "$defaultPath" 0 0 \
|
||||
--stdout
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,21 @@ documentation() {
|
||||
if [[ "$2" == "Donate" ]]; then
|
||||
return
|
||||
fi
|
||||
if ! command -v w3m &> /dev/null ; then
|
||||
echo "This feature of audiogame-manager requires w3m. Please install it before continuing."
|
||||
exit 1
|
||||
fi
|
||||
get_bottle "$1"
|
||||
echo "Loading documentation, please wait..."
|
||||
|
||||
# Extract architecture from first parameter (format: "win64|path")
|
||||
local wineArch="${1%%|*}"
|
||||
get_bottle "$wineArch"
|
||||
|
||||
echo "Loading documentation, please wait..."
|
||||
|
||||
# Try to find documentation based on common naming conventions.
|
||||
local gamePath="$(winepath -u "$2" 2> /dev/null)"
|
||||
local gamePath
|
||||
gamePath="$(winepath -u "$2" 2> /dev/null)"
|
||||
gamePath="${gamePath%/*}"
|
||||
local gameDoc="$(find "$gamePath" -type f -iname 'user_manual.htm*' -or -iname 'user manual.htm*' -or -iname '*user guide.htm*' | head -1)"
|
||||
local gameDoc=""
|
||||
local isUrl="false"
|
||||
|
||||
gameDoc="$(find "$gamePath" -type f -iname 'user_manual.htm*' -or -iname 'user manual.htm*' -or -iname '*user guide.htm*' | head -1)"
|
||||
# Game name specific docs, add the name to the for loop.
|
||||
if [[ -z "$gameDoc" ]]; then
|
||||
for i in "troopanum.txt" "superdeekout.txt" scw.html ; do
|
||||
@@ -46,12 +51,47 @@ echo "Loading documentation, please wait..."
|
||||
gameDoc="$(find "$gamePath" -type f -iname '*.url' -exec grep -i 'url=' {} \; | grep -iv 'score' | head -1)"
|
||||
gameDoc="${gameDoc#*=}"
|
||||
gameDoc="${gameDoc//[[:cntrl:]]/}"
|
||||
[[ -n "$gameDoc" ]] && isUrl="true"
|
||||
fi
|
||||
# Display documentation if available.
|
||||
|
||||
# Display documentation if available
|
||||
if [[ -n "$gameDoc" ]]; then
|
||||
w3m "$gameDoc"
|
||||
if [[ "$isUrl" == "true" ]]; then
|
||||
# URL extracted from .url file - open in browser
|
||||
open_url "$gameDoc"
|
||||
elif [[ "$dialogType" == "yad" ]]; then
|
||||
# GUI mode: use appropriate viewer
|
||||
if [[ "${gameDoc,,}" =~ \.(html?)$ ]]; then
|
||||
# HTML files: use xdg-open for default browser
|
||||
xdg-open "$gameDoc" 2>/dev/null &
|
||||
else
|
||||
# Text files: use yad text-info for accessibility
|
||||
yad --text-info \
|
||||
--title="Game Documentation" \
|
||||
--filename="$gameDoc" \
|
||||
--width=800 \
|
||||
--height=600 \
|
||||
--button="Close:0"
|
||||
fi
|
||||
else
|
||||
# Console mode: use w3m or fallback
|
||||
if command -v w3m &> /dev/null; then
|
||||
w3m "$gameDoc"
|
||||
elif [[ "${gameDoc,,}" =~ \.(html?)$ ]]; then
|
||||
echo "Install w3m to view HTML documentation in console mode."
|
||||
echo "Documentation location: $gameDoc"
|
||||
read -rp "Press Enter to continue..."
|
||||
else
|
||||
less "$gameDoc"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "No documentation found."
|
||||
if [[ "$dialogType" == "yad" ]]; then
|
||||
agm_msgbox "Documentation" "" "No documentation found for this game."
|
||||
else
|
||||
echo "No documentation found."
|
||||
read -rp "Press Enter to continue..."
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user