aboutsummaryrefslogtreecommitdiff
path: root/src/components/TutorialPane.vue
blob: 88e1c66d03ed673b65524e0d1477269dca854bfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
<div :style="styles" class="p-2 flex flex-col justify-between">
	<div class="flex">
		<h2 class="text-center mb-2 mx-auto">{{stage == 0 ? 'Welcome' : 'Tutorial'}}</h2>
		<close-icon @click.stop="onClose"
			class="block w-6 h-6 hover:cursor-pointer"/>
	</div>
	<template v-if="stage == 0">
		<div :style="contentStyles">
			This page provides a visualisation of the biological Tree of Life.
			It was made using data from OTOL, EOL, and Wikipedia.
			For more project information, click here.
		</div>
		<div class="w-full flex justify-evenly mt-2">
			<s-button :style="buttonStyles" @click="onStartTutorial">Start Tutorial</s-button>
			<s-button :style="buttonStyles" @click="onSkipTutorial">Skip</s-button>
		</div>
	</template>
	<template v-else>
		<div v-if="stage == 1" :style="contentStyles">
			Clicking/touching a tile expands it and shows it's children.
		</div>
		<div v-else-if="stage == 2" :style="contentStyles">
			Clicking on an expanded tile's header shrinks it back.
		</div>
		<div v-else-if="stage == 3" :style="contentStyles">
			Clicking and holding on a tile makes it fill the view, and moves it's
				ancestors to a sidebar. The same thing applies for an expanded tile's header.
		</div>
		<div v-else-if="stage == 4" :style="contentStyles">
			Clicking on a tile in the sidebar brings it back into the main view.
		</div>
		<div v-else-if="stage == 5" :style="contentStyles">
			Clicking on the icon at a tile's bottom-right, or at the right of
				an expanded tile's header, brings up more information.
		</div>
		<div v-else-if="stage == 6" :style="contentStyles">
			You can search using the icon at the top-right. Alternatively, press Ctrl-F.
		</div>
		<div v-else-if="stage == 7" :style="contentStyles">
			You can use the play icon to enable 'Auto Mode'.
		</div>
		<div v-else-if="stage == 8" :style="contentStyles">
			The settings icon allows adjusting the layout, animation speed, etc.
		</div>
		<div v-else-if="stage == 9" :style="contentStyles">
			And finally, the help icon provides more information.
		</div>
		<!-- Buttons -->
		<div class="w-full flex justify-evenly mt-2">
			<s-button :disabled="stage == 1" :style="buttonStyles" @click="onPrevClick">
				Prev
			</s-button>
			<s-button :style="buttonStyles" @click="(stage != lastStage) ? onNextClick() : onClose()">
				{{stage != lastStage ? 'Next' : 'Finish'}}
			</s-button>
		</div>
	</template>
</div>
</template>

<script lang="ts">
import {defineComponent, PropType} from 'vue';
import SButton from './SButton.vue';
import CloseIcon from './icon/CloseIcon.vue';
import {Action, UiOptions} from '../lib';

export default defineComponent({
	props: {
		skipWelcome: {type: Boolean, default: false},
		triggerFlag: {type: Boolean, required: true},
			// Used to indicate that a tutorial-requested 'trigger' action has been done
		uiOpts: {type: Object as PropType<UiOptions>, required: true},
	},
	data(){
		return {
			stage: 0, // Indicates the current step of the tutorial (stage 0 is the welcome message)
			lastStage: 9,
			stageActions: [ // Specifies, for stages 1+, when actions are introduced (null means none)
				'expand', 'collapse', 'expandToView', 'unhideAncestor',
				'tileInfo', 'search', 'autoMode', 'settings', 'help',
			] as (Action | null)[],
		};
	},
	computed: {
		 styles(): Record<string,string> {
			return {
				backgroundColor: this.uiOpts.bgColorDark,
				color: this.uiOpts.textColor,
			};
		 },
		 contentStyles(): Record<string,string> {
			return {
				padding: '0 0.5cm',
				maxWidth: '15cm',
				margin: '0 auto',
				overflow: 'auto',
			};
		 },
		 buttonStyles(): Record<string,string> {
			return {
				color: this.uiOpts.textColor,
				backgroundColor: this.uiOpts.bgColor,
			};
		 },
	},
	watch: {
		stage(newVal, oldVal){
			// Update disabled actions
			let disabledActions = this.uiOpts.disabledActions;
			if (this.stage == 0){
				disabledActions.clear();
				return;
			}
			let currentAction = null as null | Action;
			for (let i = 0; i < this.lastStage; i++){
				let action = this.stageActions[i];
				if (action != null){
					if (i < this.stage){
						currentAction = action;
						disabledActions.delete(action);
					} else {
						disabledActions.add(action);
					}
				}
			}
			// Notify of new trigger-action
			this.$emit('stage-chg', currentAction);
		},
		// Called when a trigger-action is done, and advances to the next stage
		triggerFlag(){
			if (this.stage < this.lastStage){
				this.onNextClick();
			} else {
				this.onClose();
			}
		},
	},
	methods: {
		onStartTutorial(){
			this.stage = 1;
		},
		onSkipTutorial(){
			this.$emit('skip');
			this.$emit('close');
		},
		onPrevClick(){
			this.stage = Math.max(1, this.stage - 1);
		},
		onNextClick(){
			this.stage = Math.min(this.stage + 1, this.lastStage);
		},
		onClose(){
			this.$emit('close');
		},
	},
	created(){
		if (this.skipWelcome){
			this.stage += 1;
		}
	},
	components: {CloseIcon, SButton, },
	emits: ['close', 'stage-chg', 'skip', ],
});
</script>