|
| 1 | +<template> |
| 2 | + <PageHeader :title="instance.name"> |
| 3 | + <template #leading> |
| 4 | + <Avatar :src="iconSrc" :alt="instance.name" size="64px" :tint-by="instance.id" /> |
| 5 | + </template> |
| 6 | + |
| 7 | + <template #metadata> |
| 8 | + <InstanceHeaderServerMetadata |
| 9 | + v-if="isServerInstance" |
| 10 | + :loading-server-ping="loadingServerPing" |
| 11 | + :players-online="playersOnline" |
| 12 | + :status-online="statusOnline" |
| 13 | + :recent-plays="recentPlays" |
| 14 | + :ping="ping" |
| 15 | + :minecraft-server="minecraftServer" |
| 16 | + :linked-project-v3="linkedProjectV3" |
| 17 | + :instance-id="instance.id" |
| 18 | + /> |
| 19 | + <PageHeaderMetadata v-else> |
| 20 | + <PageHeaderMetadataItem :icon="Gamepad2Icon" tooltip="Minecraft version"> |
| 21 | + Minecraft {{ instance.game_version }} |
| 22 | + </PageHeaderMetadataItem> |
| 23 | + <PageHeaderMetadataItem |
| 24 | + :icon="ServerLoaderIcon" |
| 25 | + :icon-props="{ loader: loaderDisplayName }" |
| 26 | + tooltip="Mod loader" |
| 27 | + > |
| 28 | + {{ loaderLabel }} |
| 29 | + </PageHeaderMetadataItem> |
| 30 | + <PageHeaderMetadataItem |
| 31 | + v-if="showInstancePlayTime" |
| 32 | + :icon="TimerIcon" |
| 33 | + tooltip="Total playtime" |
| 34 | + > |
| 35 | + {{ playtimeLabel }} |
| 36 | + </PageHeaderMetadataItem> |
| 37 | + </PageHeaderMetadata> |
| 38 | + </template> |
| 39 | + |
| 40 | + <template #actions> |
| 41 | + <PageHeaderActions> |
| 42 | + <ButtonStyled v-if="isInstalling" color="brand" size="large"> |
| 43 | + <button type="button" disabled> |
| 44 | + {{ formatMessage(commonMessages.installingLabel) }} |
| 45 | + </button> |
| 46 | + </ButtonStyled> |
| 47 | + <ButtonStyled v-else-if="instance.install_stage !== 'installed'" color="brand" size="large"> |
| 48 | + <button type="button" @click="emit('repair')"> |
| 49 | + <DownloadIcon /> |
| 50 | + {{ formatMessage(messages.repair) }} |
| 51 | + </button> |
| 52 | + </ButtonStyled> |
| 53 | + <ButtonStyled v-else-if="playing" color="red" size="large"> |
| 54 | + <button type="button" :disabled="stopping" @click="emit('stop')"> |
| 55 | + <StopCircleIcon /> |
| 56 | + {{ |
| 57 | + stopping ? formatMessage(messages.stopping) : formatMessage(commonMessages.stopButton) |
| 58 | + }} |
| 59 | + </button> |
| 60 | + </ButtonStyled> |
| 61 | + <JoinedButtons |
| 62 | + v-else-if="!loading && isServerInstance" |
| 63 | + :actions="serverPlayActions" |
| 64 | + color="brand" |
| 65 | + size="large" |
| 66 | + /> |
| 67 | + <ButtonStyled v-else-if="!loading" color="brand" size="large"> |
| 68 | + <button type="button" @click="emit('play')"> |
| 69 | + <PlayIcon /> |
| 70 | + {{ formatMessage(commonMessages.playButton) }} |
| 71 | + </button> |
| 72 | + </ButtonStyled> |
| 73 | + <ButtonStyled v-else color="brand" size="large"> |
| 74 | + <button type="button" disabled>{{ formatMessage(messages.starting) }}</button> |
| 75 | + </ButtonStyled> |
| 76 | + |
| 77 | + <ButtonStyled circular size="large"> |
| 78 | + <button |
| 79 | + v-tooltip="formatMessage(messages.instanceSettings)" |
| 80 | + type="button" |
| 81 | + :aria-label="formatMessage(messages.instanceSettings)" |
| 82 | + @click="emit('settings')" |
| 83 | + > |
| 84 | + <SettingsIcon /> |
| 85 | + </button> |
| 86 | + </ButtonStyled> |
| 87 | + <ButtonStyled circular size="large" type="transparent"> |
| 88 | + <TeleportOverflowMenu |
| 89 | + :options="moreActions" |
| 90 | + :tooltip="formatMessage(messages.moreActions)" |
| 91 | + :aria-label="formatMessage(messages.moreActions)" |
| 92 | + > |
| 93 | + <MoreVerticalIcon /> |
| 94 | + </TeleportOverflowMenu> |
| 95 | + </ButtonStyled> |
| 96 | + </PageHeaderActions> |
| 97 | + </template> |
| 98 | + </PageHeader> |
| 99 | +</template> |
| 100 | + |
| 101 | +<script setup lang="ts"> |
| 102 | +import type { Labrinth } from '@modrinth/api-client' |
| 103 | +import { |
| 104 | + DownloadIcon, |
| 105 | + ExternalIcon, |
| 106 | + FolderOpenIcon, |
| 107 | + MoreVerticalIcon, |
| 108 | + PackageIcon, |
| 109 | + PlayIcon, |
| 110 | + SettingsIcon, |
| 111 | + StopCircleIcon, |
| 112 | + TagCategoryGamepad2Icon as Gamepad2Icon, |
| 113 | + TimerIcon, |
| 114 | +} from '@modrinth/assets' |
| 115 | +import { |
| 116 | + Avatar, |
| 117 | + ButtonStyled, |
| 118 | + commonMessages, |
| 119 | + defineMessages, |
| 120 | + formatLoaderLabel, |
| 121 | + type JoinedButtonAction, |
| 122 | + JoinedButtons, |
| 123 | + LoaderIcon as ServerLoaderIcon, |
| 124 | + PageHeader, |
| 125 | + PageHeaderActions, |
| 126 | + PageHeaderMetadata, |
| 127 | + PageHeaderMetadataItem, |
| 128 | + type ServerLoader, |
| 129 | + TeleportOverflowMenu, |
| 130 | + type TeleportOverflowMenuItem, |
| 131 | + useVIntl, |
| 132 | +} from '@modrinth/ui' |
| 133 | +import { computed } from 'vue' |
| 134 | +
|
| 135 | +import type { GameInstance } from '@/helpers/types' |
| 136 | +
|
| 137 | +import InstanceHeaderServerMetadata from './instance-page-header-server-metadata.vue' |
| 138 | +
|
| 139 | +const messages = defineMessages({ |
| 140 | + createShortcut: { |
| 141 | + id: 'instance.action.create-shortcut', |
| 142 | + defaultMessage: 'Create shortcut', |
| 143 | + }, |
| 144 | + exportModpack: { |
| 145 | + id: 'instance.action.export-modpack', |
| 146 | + defaultMessage: 'Export modpack', |
| 147 | + }, |
| 148 | + instanceSettings: { |
| 149 | + id: 'instance.action.settings', |
| 150 | + defaultMessage: 'Instance settings', |
| 151 | + }, |
| 152 | + launchInstance: { |
| 153 | + id: 'instance.action.launch-instance', |
| 154 | + defaultMessage: 'Launch instance', |
| 155 | + }, |
| 156 | + moreActions: { |
| 157 | + id: 'instance.action.more-actions', |
| 158 | + defaultMessage: 'More actions', |
| 159 | + }, |
| 160 | + neverPlayed: { |
| 161 | + id: 'instance.playtime.never-played', |
| 162 | + defaultMessage: 'Never played', |
| 163 | + }, |
| 164 | + openFolder: { |
| 165 | + id: 'instance.action.open-folder', |
| 166 | + defaultMessage: 'Open folder', |
| 167 | + }, |
| 168 | + repair: { |
| 169 | + id: 'instance.action.repair', |
| 170 | + defaultMessage: 'Repair', |
| 171 | + }, |
| 172 | + starting: { |
| 173 | + id: 'instance.action.starting', |
| 174 | + defaultMessage: 'Starting...', |
| 175 | + }, |
| 176 | + stopping: { |
| 177 | + id: 'instance.action.stopping', |
| 178 | + defaultMessage: 'Stopping...', |
| 179 | + }, |
| 180 | +}) |
| 181 | +
|
| 182 | +const props = withDefaults( |
| 183 | + defineProps<{ |
| 184 | + instance: GameInstance |
| 185 | + iconSrc?: string | null |
| 186 | + isServerInstance?: boolean |
| 187 | + showInstancePlayTime?: boolean |
| 188 | + timePlayed?: number |
| 189 | + playing?: boolean |
| 190 | + loading?: boolean |
| 191 | + stopping?: boolean |
| 192 | + loadingServerPing?: boolean |
| 193 | + playersOnline?: number |
| 194 | + statusOnline?: boolean |
| 195 | + recentPlays?: number |
| 196 | + ping?: number |
| 197 | + minecraftServer?: Labrinth.Projects.v3.Project['minecraft_server'] |
| 198 | + linkedProjectV3?: Labrinth.Projects.v3.Project |
| 199 | + }>(), |
| 200 | + { |
| 201 | + iconSrc: null, |
| 202 | + isServerInstance: false, |
| 203 | + showInstancePlayTime: false, |
| 204 | + timePlayed: 0, |
| 205 | + playing: false, |
| 206 | + loading: false, |
| 207 | + stopping: false, |
| 208 | + loadingServerPing: false, |
| 209 | + playersOnline: undefined, |
| 210 | + statusOnline: false, |
| 211 | + recentPlays: undefined, |
| 212 | + ping: undefined, |
| 213 | + minecraftServer: undefined, |
| 214 | + linkedProjectV3: undefined, |
| 215 | + }, |
| 216 | +) |
| 217 | +
|
| 218 | +const emit = defineEmits<{ |
| 219 | + repair: [] |
| 220 | + stop: [] |
| 221 | + play: [] |
| 222 | + playServer: [] |
| 223 | + settings: [] |
| 224 | + openFolder: [] |
| 225 | + export: [] |
| 226 | + createShortcut: [] |
| 227 | +}>() |
| 228 | +
|
| 229 | +const installingStages = [ |
| 230 | + 'installing', |
| 231 | + 'pack_installing', |
| 232 | + 'pack_installed', |
| 233 | + 'not_installed', |
| 234 | + 'minecraft_installing', |
| 235 | +] |
| 236 | +
|
| 237 | +const { formatMessage } = useVIntl() |
| 238 | +
|
| 239 | +const isInstalling = computed(() => installingStages.includes(props.instance.install_stage)) |
| 240 | +const loaderDisplayName = computed(() => formatLoaderLabel(props.instance.loader) as ServerLoader) |
| 241 | +const loaderLabel = computed(() => |
| 242 | + [loaderDisplayName.value, props.instance.loader_version].filter(Boolean).join(' '), |
| 243 | +) |
| 244 | +const playtimeLabel = computed(() => { |
| 245 | + if (props.timePlayed <= 0) return formatMessage(messages.neverPlayed) |
| 246 | +
|
| 247 | + const hours = Math.floor(props.timePlayed / 3600) |
| 248 | + if (hours >= 1) { |
| 249 | + return `${hours} hour${hours > 1 ? 's' : ''}` |
| 250 | + } |
| 251 | +
|
| 252 | + const minutes = Math.floor(props.timePlayed / 60) |
| 253 | + if (minutes >= 1) { |
| 254 | + return `${minutes} minute${minutes > 1 ? 's' : ''}` |
| 255 | + } |
| 256 | +
|
| 257 | + const seconds = Math.floor(props.timePlayed) |
| 258 | + return `${seconds} second${seconds > 1 ? 's' : ''}` |
| 259 | +}) |
| 260 | +const serverPlayActions = computed<JoinedButtonAction[]>(() => [ |
| 261 | + { |
| 262 | + id: 'join_server', |
| 263 | + label: formatMessage(commonMessages.playButton), |
| 264 | + icon: PlayIcon, |
| 265 | + action: () => emit('playServer'), |
| 266 | + }, |
| 267 | + { |
| 268 | + id: 'launch_instance', |
| 269 | + label: formatMessage(messages.launchInstance), |
| 270 | + icon: PlayIcon, |
| 271 | + action: () => emit('play'), |
| 272 | + }, |
| 273 | +]) |
| 274 | +const moreActions = computed<TeleportOverflowMenuItem[]>(() => [ |
| 275 | + { |
| 276 | + id: 'open-folder', |
| 277 | + label: formatMessage(messages.openFolder), |
| 278 | + icon: FolderOpenIcon, |
| 279 | + action: () => emit('openFolder'), |
| 280 | + }, |
| 281 | + { |
| 282 | + id: 'export-mrpack', |
| 283 | + label: formatMessage(messages.exportModpack), |
| 284 | + icon: PackageIcon, |
| 285 | + action: () => emit('export'), |
| 286 | + }, |
| 287 | + { |
| 288 | + id: 'create-shortcut', |
| 289 | + label: formatMessage(messages.createShortcut), |
| 290 | + icon: ExternalIcon, |
| 291 | + action: () => emit('createShortcut'), |
| 292 | + }, |
| 293 | +]) |
| 294 | +</script> |
0 commit comments