Profectus/src/components/Options.vue

168 lines
4.9 KiB
Vue
Raw Normal View History

2021-05-22 20:29:06 +00:00
<template>
2022-01-14 04:25:47 +00:00
<Modal v-model="isOpen">
<template v-slot:header>
<div class="header">
2023-02-16 03:58:06 +00:00
<h2>Settings</h2>
<div class="option-tabs">
<button :class="{selected: isTab('behaviour')}" @click="setTab('behaviour')">Behaviour</button>
<button :class="{selected: isTab('appearance')}" @click="setTab('appearance')">Appearance</button>
</div>
</div>
</template>
<template v-slot:body>
2023-02-16 03:58:06 +00:00
<div v-if="isTab('behaviour')">
<Toggle :title="unthrottledTitle" v-model="unthrottled" />
<Toggle v-if="projInfo.enablePausing" :title="isPausedTitle" v-model="isPaused" />
<Toggle :title="offlineProdTitle" v-model="offlineProd" />
<Toggle :title="autosaveTitle" v-model="autosave" />
<FeedbackButton v-if="!autosave" class="button save-button" @click="save()">Manually save</FeedbackButton>
</div>
<div v-if="isTab('appearance')">
<Select :title="themeTitle" :options="themes" v-model="theme" />
<component :is="settingFieldsComponent" />
<Toggle :title="showTPSTitle" v-model="showTPS" />
<Toggle :title="alignModifierUnitsTitle" v-model="alignUnits" />
</div>
</template>
</Modal>
2021-05-22 20:29:06 +00:00
</template>
2022-01-25 04:25:34 +00:00
<script setup lang="tsx">
2022-03-04 03:39:48 +00:00
import Modal from "components/Modal.vue";
2022-03-11 22:58:11 +00:00
import projInfo from "data/projInfo.json";
2023-02-16 03:58:06 +00:00
import { save } from "util/save";
2022-03-04 03:39:48 +00:00
import rawThemes from "data/themes";
2022-03-11 22:58:11 +00:00
import { jsx } from "features/feature";
2022-06-27 00:17:22 +00:00
import Tooltip from "features/tooltips/Tooltip.vue";
2022-03-04 03:39:48 +00:00
import player from "game/player";
import settings, { settingFields } from "game/settings";
2023-02-16 03:58:06 +00:00
import { camelToTitle, Direction } from "util/common";
2022-03-11 22:58:11 +00:00
import { coerceComponent, render } from "util/vue";
import { computed, ref, toRefs } from "vue";
2022-02-27 22:04:56 +00:00
import Select from "./fields/Select.vue";
2022-03-11 22:58:11 +00:00
import Toggle from "./fields/Toggle.vue";
2023-02-16 03:58:06 +00:00
import FeedbackButton from "./fields/FeedbackButton.vue";
2021-05-22 20:29:06 +00:00
2022-01-14 04:25:47 +00:00
const isOpen = ref(false);
2023-02-16 03:58:06 +00:00
const currentTab = ref("behaviour");
function isTab(tab: string): boolean {
return tab == currentTab.value;
}
function setTab(tab: string) {
currentTab.value = tab;
}
2022-01-14 04:25:47 +00:00
defineExpose({
2023-02-16 03:58:06 +00:00
isTab,
setTab,
save,
2022-01-14 04:25:47 +00:00
open() {
isOpen.value = true;
}
});
const themes = Object.keys(rawThemes).map(theme => ({
label: camelToTitle(theme),
value: theme
}));
const settingFieldsComponent = computed(() => {
return coerceComponent(jsx(() => (<>{settingFields.map(render)}</>)));
});
2022-01-14 04:25:47 +00:00
2023-02-16 03:58:06 +00:00
const { showTPS, theme, unthrottled, alignUnits } = toRefs(settings);
2022-01-25 04:25:34 +00:00
const { autosave, offlineProd } = toRefs(player);
2022-01-14 04:25:47 +00:00
const isPaused = computed({
get() {
return player.devSpeed === 0;
},
2022-01-14 04:25:47 +00:00
set(value: boolean) {
player.devSpeed = value ? 0 : null;
}
});
2022-01-25 04:25:34 +00:00
2023-02-16 03:58:06 +00:00
const unthrottledTitle = jsx(() => (
<span class="option-title">
Unthrottled
<desc>Allow the game to run as fast as possible. Not battery friendly.</desc>
</span>
));
const offlineProdTitle = jsx(() => (
2023-02-16 03:58:06 +00:00
<span class="option-title">
Offline Production<Tooltip display="Save-specific" direction={Direction.Right}>*</Tooltip>
<desc>Simulate production that occurs while the game is closed.</desc>
</span>
));
const autosaveTitle = jsx(() => (
2023-02-16 03:58:06 +00:00
<span class="option-title">
Autosave<Tooltip display="Save-specific" direction={Direction.Right}>*</Tooltip>
<desc>Automatically save the game every second or when the game is closed.</desc>
</span>
));
const isPausedTitle = jsx(() => (
2023-02-16 03:58:06 +00:00
<span class="option-title">
Pause game<Tooltip display="Save-specific" direction={Direction.Right}>*</Tooltip>
<desc>Stop everything from moving.</desc>
</span>
));
const themeTitle = jsx(() => (
<span class="option-title">
Theme
<desc>How the game looks.</desc>
</span>
));
const showTPSTitle = jsx(() => (
<span class="option-title">
Show TPS
<desc>Show TPS meter at the bottom-left corner of the page.</desc>
</span>
));
const alignModifierUnitsTitle = jsx(() => (
<span class="option-title">
Align modifier units
<desc>Align numbers to the beginning of the unit in modifier view.</desc>
</span>
));
2021-05-22 20:29:06 +00:00
</script>
2023-02-16 03:58:06 +00:00
<style>
.option-tabs {
border-bottom: 2px solid var(--outline);
margin-top: 10px;
margin-bottom: -10px;
2021-05-22 20:29:06 +00:00
}
2023-02-16 03:58:06 +00:00
.option-tabs button {
background-color: transparent;
color: var(--foreground);
margin-bottom: -2px;
font-size: 14px;
cursor: pointer;
padding: 5px 20px;
border: none;
border-bottom: 2px solid var(--foreground);
}
.option-tabs button:not(.selected) {
border-bottom-color: transparent;
}
.option-title .tooltip-container {
display: inline;
margin-left: 5px;
}
2023-02-16 03:58:06 +00:00
.option-title desc {
display: block;
opacity: 0.6;
font-size: small;
width: 300px;
margin-left: 0;
}
.save-button {
text-align: right;
}
2021-05-22 20:29:06 +00:00
</style>