Profectus-Demo/src/components/Layer.vue

210 lines
5 KiB
Vue
Raw Normal View History

2022-01-13 22:25:47 -06:00
<template>
<div class="layer-container" :style="{ '--layer-color': unref(color) }">
2022-12-23 23:34:49 -06:00
<button v-if="showGoBack" class="goBack" @click="goBack"></button>
2022-12-24 08:38:36 -06:00
<button
class="layer-tab minimized"
v-if="unref(minimized)"
@click="$emit('setMinimized', false)"
>
2022-12-12 23:50:35 -06:00
<component v-if="minimizedComponent" :is="minimizedComponent" />
<div v-else>{{ unref(name) }}</div>
2022-01-13 22:25:47 -06:00
</button>
2022-05-03 21:10:24 -05:00
<div class="layer-tab" :class="{ showGoBack }" v-else>
<Context @update-nodes="updateNodes">
2022-01-13 22:25:47 -06:00
<component :is="component" />
</Context>
2022-01-13 22:25:47 -06:00
</div>
2022-12-24 08:38:36 -06:00
<button v-if="unref(minimizable)" class="minimize" @click="$emit('setMinimized', true)">
2022-01-24 22:25:34 -06:00
</button>
2022-01-13 22:25:47 -06:00
</div>
</template>
2022-01-24 22:25:34 -06:00
<script lang="ts">
2022-03-03 21:39:48 -06:00
import projInfo from "data/projInfo.json";
2022-06-26 19:17:22 -05:00
import type { CoercableComponent } from "features/feature";
import type { FeatureNode } from "game/layers";
2022-03-03 21:39:48 -06:00
import player from "game/player";
import { computeComponent, computeOptionalComponent, processedPropType, unwrapRef } from "util/vue";
2022-06-26 19:17:22 -05:00
import type { PropType, Ref } from "vue";
import { computed, defineComponent, toRefs, unref } from "vue";
import Context from "./Context.vue";
2022-01-13 22:25:47 -06:00
2022-01-24 22:25:34 -06:00
export default defineComponent({
components: { Context },
2022-01-24 22:25:34 -06:00
props: {
index: {
type: Number,
required: true
},
display: {
type: processedPropType<CoercableComponent>(Object, String, Function),
2022-01-24 22:25:34 -06:00
required: true
},
2022-12-12 23:50:35 -06:00
minimizedDisplay: processedPropType<CoercableComponent>(Object, String, Function),
2022-01-24 22:25:34 -06:00
minimized: {
2022-12-24 08:38:36 -06:00
type: Object as PropType<Ref<boolean>>,
2022-01-24 22:25:34 -06:00
required: true
},
name: {
type: processedPropType<string>(String),
2022-01-24 22:25:34 -06:00
required: true
},
color: processedPropType<string>(String),
minimizable: processedPropType<boolean>(Boolean),
nodes: {
type: Object as PropType<Ref<Record<string, FeatureNode | undefined>>>,
required: true
}
2022-01-24 22:25:34 -06:00
},
2022-12-24 08:38:36 -06:00
emits: ["setMinimized"],
2022-01-24 22:25:34 -06:00
setup(props) {
2022-12-23 23:34:49 -06:00
const { display, index, minimized, minimizedDisplay } = toRefs(props);
2022-01-13 22:25:47 -06:00
2022-01-24 22:25:34 -06:00
const component = computeComponent(display);
2022-12-12 23:50:35 -06:00
const minimizedComponent = computeOptionalComponent(minimizedDisplay);
2022-01-24 22:25:34 -06:00
const showGoBack = computed(
() => projInfo.allowGoBack && index.value > 0 && !unwrapRef(minimized)
2022-01-24 22:25:34 -06:00
);
2022-01-13 22:25:47 -06:00
2022-01-24 22:25:34 -06:00
function goBack() {
player.tabs.splice(unref(props.index), Infinity);
2022-01-24 22:25:34 -06:00
}
2022-01-13 22:25:47 -06:00
2023-02-15 22:43:44 -06:00
function setMinimized(min: boolean) {
minimized.value = min;
}
function updateNodes(nodes: Record<string, FeatureNode | undefined>) {
props.nodes.value = nodes;
}
2022-01-24 22:25:34 -06:00
return {
component,
2022-12-12 23:50:35 -06:00
minimizedComponent,
2022-01-24 22:25:34 -06:00
showGoBack,
updateNodes,
2022-01-24 22:25:34 -06:00
unref,
2022-12-24 08:38:36 -06:00
goBack
2022-01-24 22:25:34 -06:00
};
2022-01-13 22:25:47 -06:00
}
2022-01-24 22:25:34 -06:00
});
2022-01-13 22:25:47 -06:00
</script>
<style scoped>
2023-02-15 22:43:44 -06:00
.layer-container {
min-width: 100%;
min-height: 100%;
margin: 0;
flex-grow: 1;
display: flex;
isolation: isolate;
}
2022-01-13 22:25:47 -06:00
.layer-tab:not(.minimized) {
padding-top: 20px;
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;
}
.layer-tab.minimized {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
padding: 0;
padding-top: 55px;
margin: 0;
cursor: pointer;
font-size: 40px;
color: var(--foreground);
border: none;
background-color: transparent;
}
2022-12-12 23:50:35 -06:00
.layer-tab.minimized > * {
2022-01-13 22:25:47 -06:00
margin: 0;
writing-mode: vertical-rl;
2023-02-15 22:43:44 -06:00
text-align: left;
2022-01-13 22:25:47 -06:00
padding-left: 10px;
width: 50px;
}
.inner-tab > .layer-container > .layer-tab:not(.minimized) {
margin: -50px -10px;
padding: 50px 10px;
}
.modal-body .layer-tab {
padding-bottom: 0;
}
.modal-body .layer-tab:not(.hasSubtabs) {
padding-top: 0;
}
.minimize {
position: sticky;
top: 6px;
right: 9px;
z-index: 7;
line-height: 30px;
border: none;
background: var(--background);
box-shadow: var(--background) 0 2px 3px 5px;
border-radius: 50%;
color: var(--foreground);
font-size: 40px;
cursor: pointer;
margin-top: -44px;
margin-right: -30px;
}
.minimized + .minimize {
transform: rotate(-90deg);
top: 10px;
right: 18px;
pointer-events: none;
2022-01-13 22:25:47 -06:00
}
.goBack {
position: sticky;
2023-02-15 22:43:44 -06:00
top: 10px;
left: 10px;
line-height: 30px;
margin-top: -50px;
margin-left: -35px;
border: none;
background: var(--background);
box-shadow: var(--background) 0 2px 3px 5px;
border-radius: 50%;
2022-01-13 22:25:47 -06:00
color: var(--foreground);
2023-02-15 22:43:44 -06:00
font-size: 30px;
2022-01-13 22:25:47 -06:00
cursor: pointer;
z-index: 7;
}
.goBack:hover {
transform: scale(1.1, 1.1);
text-shadow: 0 0 7px var(--foreground);
}
</style>
2023-02-15 22:43:44 -06:00
<style>
.layer-tab.minimized > * > .desc {
color: var(--accent1);
font-size: 30px;
}
</style>