-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathARCH_character.vue
77 lines (65 loc) · 3.23 KB
/
ARCH_character.vue
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
<script setup>
import { ref, defineProps } from 'vue';
import useDragAndDrop from '../../drag_drop.js';
import ObjectNode from './types/object.vue'; // Import the ItemNode component
const props = defineProps({
id:Number,
node_type:"Room",
output_handle:Boolean,
input_handle:Boolean,
items: { type: Array, default: () => [] }, // Define items as an array prop with a default empty array
name:String// gotta have a name!
})
const emit = defineEmits(['showContextMenu']);//showcontext menu emit interacts with toolbox screen
const { onDragStart } = useDragAndDrop();//uses the same drag and drop functionality as the "prompt". I still won't lie I don't know exactly what prompts are meant to be, even though its been explained
const isDropdownOpen = ref(false);//tracks whether the rooms dropdown is open in the toolbar
const selectedItemId = ref(null); // Reactive reference to store the selected item ID
const selectedRoomId = ref(null); // Reactive reference to store the selected room ID
const toggleDropdown = () => { isDropdownOpen.value = !isDropdownOpen.value; };//toggles dropdown menu for the room
const handleRightClick = (event) => { //when right clicked, shows the context menu of the room
event.preventDefault();
console.log('Right-click detected on room node'); // Debugging
emit('showContextMenu', { id: props.id, type: 'room', x: event.clientX, y: event.clientY }); //emits showcontextmeny, used below
};
const handleRoomRightClick = ({ id, type, x, y }) => {
console.log('Right-clicked on room node:', { id, type, x, y });
if (type === 'room') {
contextMenuPosition.value = { x, y };
contextMenuType.value = 'room';
selectedRoomId.value = id;
contextMenuVisible.value = true;
}
};
const handleItemRightClick = (item, event) => {
event.preventDefault();
event.stopPropagation(); // Prevent propagation to the room's context menu
selectedItemId.value = item.id;
selectedRoomId.value = item.roomId; // Store the room ID of the item for later
console.log('Right-click detected on item in handleItemRightClick in item.vue:', item); // Debugging
emit('showItemContextMenu', { id: item.id, type: 'item', x: event.clientX, y: event.clientY });//emits item context menu event
};
</script>
<template>
<div class="component_container" :draggable="true" @dragstart="onDragStart($event, 'output')" @contextmenu="handleRightClick">
<div class="component_title" @click="toggleDropdown">
{{ props.name }}
</div>
<ul v-if="isDropdownOpen"> <!---if the dropdown is open, displays the child items-->
<li v-for="item in props.items" :key="item.id" @contextmenu="handleItemRightClick(item, $event)">
<ItemNode :id="item.id" :name="item.name" :description="item.description" :roomId="props.id" />
</li>
</ul>
<input>
</div>
</template>
<style>
.component_container{
padding:10px;
background:rgb(255, 255, 255);
outline: 2px solid black;
height:fit-content;
width:fit-content;
}
.component_container > input { background: rgb(186, 186, 186); }
.component_title { padding: 3px; cursor: pointer; }
</style>