profectus-template/src/components/system/LayerTab.vue

302 lines
6.5 KiB
Vue
Raw Normal View History

2021-05-26 01:57:02 +00:00
<template>
<LayerProvider :layer="layer" :index="index">
2021-06-13 08:56:42 +00:00
<div class="layer-container">
<button v-if="index > 0 && allowGoBack && !minimized" class="goBack" @click="goBack(index)"></button>
<button class="layer-tab minimized" v-if="minimized" @click="toggleMinimized"><div>{{ name }}</div></button>
<div class="layer-tab" :style="style" :class="{ hasSubtabs: subtabs }" v-else>
<branches>
2021-07-02 09:50:44 +00:00
<sticky v-if="subtabs" class="subtabs-container" :class="{ floating, firstTab: firstTab || !allowGoBack }">
<div class="subtabs">
<tab-button v-for="(subtab, id) in subtabs" @selectTab="selectSubtab(id)" :key="id"
:activeTab="id === activeSubtab" :options="subtab" :text="id" />
</div>
2021-06-13 08:56:42 +00:00
</sticky>
<component v-if="display" :is="display" />
<default-layer-tab v-else />
</branches>
</div>
<button v-if="minimizable" class="minimize" @click="toggleMinimized"></button>
2021-05-26 01:57:02 +00:00
</div>
</LayerProvider>
</template>
<script>
import { layers } from '../../store/layers';
import { player } from '../../store/proxies';
2021-06-12 04:38:16 +00:00
import { coerceComponent } from '../../util/vue';
import { isPlainObject } from '../../util/common';
import modInfo from '../../data/modInfo.json';
2021-06-12 04:38:16 +00:00
import themes from '../../data/themes';
2021-05-26 01:57:02 +00:00
export default {
name: 'layer-tab',
props: {
layer: String,
2021-06-12 04:38:16 +00:00
index: Number,
2021-06-13 08:56:42 +00:00
forceFirstTab: Boolean,
minimizable: Boolean,
2021-06-13 08:56:42 +00:00
tab: Function
2021-05-26 01:57:02 +00:00
},
data() {
return { allowGoBack: modInfo.allowGoBack };
},
computed: {
2021-06-13 08:56:42 +00:00
minimized() {
return this.minimizable && player.minimized[this.layer];
2021-06-13 08:56:42 +00:00
},
name() {
return layers[this.layer].name;
},
2021-06-12 04:38:16 +00:00
floating() {
return themes[player.theme].floatingTabs;
},
style() {
const style = [];
if (layers[this.layer].style) {
2021-06-12 04:38:16 +00:00
style.push(layers[this.layer].style);
}
if (layers[this.layer].activeSubtab?.style) {
2021-06-12 04:38:16 +00:00
style.push(layers[this.layer].activeSubtab.style);
}
2021-06-12 04:38:16 +00:00
return style;
},
2021-06-12 04:38:16 +00:00
display() {
if (layers[this.layer].activeSubtab?.display) {
return coerceComponent(layers[this.layer].activeSubtab.display);
}
if (layers[this.layer].display) {
return coerceComponent(layers[this.layer].display);
}
return null;
},
subtabs() {
if (layers[this.layer].subtabs) {
return Object.entries(layers[this.layer].subtabs)
2021-06-12 04:38:16 +00:00
.filter(subtab => isPlainObject(subtab[1]) && subtab[1].unlocked !== false)
.reduce((acc, curr) => {
acc[curr[0]] = curr[1];
return acc;
}, {});
}
return null;
},
activeSubtab() {
2021-06-12 04:38:16 +00:00
return layers[this.layer].activeSubtab.id;
},
firstTab() {
if (this.forceFirstTab != undefined) {
return this.forceFirstTab;
}
return this.index === 0;
}
},
2021-06-13 08:56:42 +00:00
watch: {
minimized(newValue) {
if (this.tab == undefined) {
return;
}
2021-06-13 08:56:42 +00:00
const tab = this.tab();
if (tab != undefined) {
if (newValue) {
tab.style.flexGrow = 0;
tab.style.flexShrink = 0;
tab.style.width = "60px";
2021-06-22 08:34:59 +00:00
tab.style.minWidth = null;
2021-06-13 08:56:42 +00:00
tab.style.margin = 0;
} else {
tab.style.flexGrow = null;
tab.style.flexShrink = null;
tab.style.width = null;
2021-06-22 08:34:59 +00:00
tab.style.minWidth = `${layers[this.layer].minWidth}px`;
2021-06-13 08:56:42 +00:00
tab.style.margin = null;
}
}
}
},
mounted() {
if (this.tab == undefined) {
return;
}
2021-06-13 08:56:42 +00:00
const tab = this.tab();
if (tab != undefined) {
if (this.minimized) {
tab.style.flexGrow = 0;
tab.style.flexShrink = 0;
tab.style.width = "60px";
2021-06-22 08:34:59 +00:00
tab.style.minWidth = null;
2021-06-13 08:56:42 +00:00
tab.style.margin = 0;
} else {
tab.style.flexGrow = null;
tab.style.flexShrink = null;
tab.style.width = null;
2021-06-22 08:34:59 +00:00
tab.style.minWidth = `${layers[this.layer].minWidth}px`;
2021-06-13 08:56:42 +00:00
tab.style.margin = null;
}
} else {
this.$nextTick(this.mounted);
}
},
methods: {
selectSubtab(subtab) {
2021-06-12 04:38:16 +00:00
player.subtabs[this.layer].mainTabs = subtab;
2021-06-13 08:56:42 +00:00
},
toggleMinimized() {
player.minimized[this.layer] = !player.minimized[this.layer];
},
goBack(index) {
player.tabs = player.tabs.slice(0, index);
}
2021-05-26 01:57:02 +00:00
}
};
</script>
<style scoped>
2021-06-13 08:56:42 +00:00
.layer-container {
min-width: 100%;
min-height: 100%;
margin: 0;
flex-grow: 1;
display: flex;
2021-06-13 08:56:42 +00:00
}
.layer-tab:not(.minimized) {
padding-top: 20px;
2021-06-12 04:38:16 +00:00
padding-bottom: 20px;
min-height: 100%;
flex-grow: 1;
text-align: center;
position: relative;
}
.inner-tab > .layer-container > .layer-tab:not(.minimized) {
padding-top: 50px;
}
2021-06-13 08:56:42 +00:00
.layer-tab.minimized {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
padding: 0;
padding-top: 50px;
margin: 0;
cursor: pointer;
font-size: 40px;
color: var(--color);
border: none;
background-color: transparent;
}
.layer-tab.minimized div {
margin: 0;
writing-mode: vertical-rl;
padding-left: 10px;
width: 50px;
}
.inner-tab > .layer-container > .layer-tab:not(.minimized) {
2021-06-12 04:38:16 +00:00
margin: -50px -10px;
padding: 50px 10px;
}
.layer-tab .subtabs {
margin-bottom: 24px;
2021-07-02 09:50:44 +00:00
display: flex;
flex-flow: wrap;
padding-right: 60px;
2021-06-12 04:38:16 +00:00
z-index: 4;
}
2021-07-02 09:50:44 +00:00
.subtabs-container:not(.floating) {
2021-06-12 04:38:16 +00:00
border-top: solid 4px var(--separator);
border-bottom: solid 4px var(--separator);
2021-07-02 09:50:44 +00:00
}
.subtabs-container:not(.floating) .subtabs {
width: calc(100% + 14px);
2021-06-12 04:38:16 +00:00
margin-left: -7px;
margin-right: -7px;
box-sizing: border-box;
text-align: left;
padding-left: 14px;
2021-07-02 09:50:44 +00:00
margin-bottom: -4px;
2021-06-12 04:38:16 +00:00
}
2021-07-02 09:50:44 +00:00
.subtabs-container.floating .subtabs {
justify-content: center;
margin-top: -25px;
}
2021-06-12 04:38:16 +00:00
.modal-body .layer-tab {
padding-bottom: 0;
}
.modal-body .layer-tab:not(.hasSubtabs) {
padding-top: 0;
}
.modal-body .subtabs {
width: 100%;
margin-left: 0;
margin-right: 0;
padding-left: 0;
}
2021-07-02 09:50:44 +00:00
.subtabs-container:not(.floating).firstTab .subtabs {
padding-left: 0;
padding-right: 0;
}
2021-07-02 09:50:44 +00:00
.subtabs-container:not(.floating):first-child {
2021-06-12 04:38:16 +00:00
border-top: 0;
}
2021-07-02 09:50:44 +00:00
.subtabs-container:not(.floating):first-child .subtabs {
margin-top: -50px;
}
.subtabs-container:not(.floating):not(.firstTab) .subtabs {
2021-06-12 04:38:16 +00:00
padding-left: 70px;
}
2021-06-13 08:56:42 +00:00
.minimize {
position: absolute;
top: 0;
2021-07-02 09:50:44 +00:00
right: 0;
2021-06-13 08:56:42 +00:00
background-color: transparent;
border: 1px solid transparent;
color: var(--color);
font-size: 40px;
cursor: pointer;
line-height: 40px;
z-index: 7;
2021-07-02 09:50:44 +00:00
width: 60px;
background: var(--background);
2021-06-13 08:56:42 +00:00
}
.minimized + .minimize {
transform: rotate(-90deg);
top: 3px;
}
.goBack {
position: absolute;
top: 0;
left: 20px;
background-color: transparent;
border: 1px solid transparent;
color: var(--color);
font-size: 40px;
cursor: pointer;
line-height: 40px;
z-index: 7;
}
.goBack:hover {
transform: scale(1.1, 1.1);
text-shadow: 0 0 7px var(--color);
}
2021-05-26 01:57:02 +00:00
</style>