diff options
author | iainp5 <iain.pearce.ip@gmail.com> | 2024-10-06 19:43:29 +0100 |
---|---|---|
committer | iainp5 <iain.pearce.ip@gmail.com> | 2024-10-06 19:43:29 +0100 |
commit | b05884c4412a403a8fde4e58d30d96da14a9eee9 (patch) | |
tree | 68f746ae098b5562b85f66d19ff4ae46c0e1d83a /play.js | |
parent | b283e3c47b5235dd99291612600014c72f35032e (diff) | |
download | 1989-dawn-of-freedom-b05884c4412a403a8fde4e58d30d96da14a9eee9.tar.gz |
Working on popup
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 105 |
1 files changed, 99 insertions, 6 deletions
@@ -162,6 +162,84 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi }
}
+// POP UP CARD MENU
+
+var card_action_menu = Array.from(document.getElementById("popup").querySelectorAll("li[data-action]")).map(e => e.dataset.action)
+
+console.log('card_action_menu', card_action_menu)
+
+function show_popup_menu(evt, menu_id, target_id, title) {
+ let menu = document.getElementById(menu_id)
+ console.log('show_popup_menu called with evt',evt, 'menu_id',menu_id, 'target_id', target_id, 'title', title)
+
+ let show = false
+ for (let item of menu.querySelectorAll("li")) {
+ let action = item.dataset.action
+ console.log('item', item, 'action', action)
+ if (action) {
+ console.log('in if action')
+ if (is_card_action(action, target_id)) {
+ console.log('in is_card_action')
+ show = true
+ item.classList.add("action")
+ item.classList.remove("disabled")
+ item.onclick = function () {
+ send_action(action, target_id)
+ hide_popup_menu()
+ evt.stopPropagation()
+ }
+ } else {
+ item.classList.remove("action")
+ item.classList.add("disabled")
+ item.onclick = null
+ }
+ }
+ }
+
+ if (show) {
+ menu.onmouseleave = hide_popup_menu
+ menu.style.display = "block"
+ if (title) {
+ let item = menu.querySelector("li.title")
+ if (item) {
+ item.onclick = hide_popup_menu
+ item.textContent = title
+ }
+ }
+
+ let w = menu.clientWidth
+ let h = menu.clientHeight
+ let x = Math.max(5, Math.min(evt.clientX - w / 2, window.innerWidth - w - 5))
+ let y = Math.max(5, Math.min(evt.clientY - 12, window.innerHeight - h - 40))
+ menu.style.left = x + "px"
+ menu.style.top = y + "px"
+
+ evt.stopPropagation()
+ } else {
+ menu.style.display = "none"
+ }
+}
+
+function hide_popup_menu() {
+ document.getElementById("popup").style.display = "none"
+ document.getElementById("popup_select_card").style.display = "none"
+}
+
+
+function is_card_enabled(card) {
+ if (view.actions) {
+ if (card_action_menu.some(a => view.actions[a] && view.actions[a].includes(card)))
+ return true
+ if (view.actions.card_select && view.actions.card_select.includes(card))
+ return true
+ if (view.actions.card && view.actions.card.includes(card))
+ return true
+ }
+ return false
+}
+
+// SUPPORTING FUNCTIONS
+
function on_click_space(evt) {
if (evt.button === 0) {
const space = evt.target.my_space;
@@ -182,10 +260,17 @@ function on_click_card(evt) { //console.log('on_click_card')
if (evt.button === 0) {
const card = evt.target.my_card;
- // console.log('on_click_card_called with card:', card);
- if (send_action('card', card)) {
- evt.stopPropagation();
- } else {
+ console.log('on_click_card_called with card:', card);
+ if (is_action('card', card)) {
+ console.log('in action card')
+ if (send_action('card', card)) {
+ evt.stopPropagation();
+ }
+ } else if (is_action('card_select', card)) {
+ console.log('in action card_select')
+ show_popup_menu(evt, "popup_select_card", card, cards[card].name)
+ }
+ else {
// console.log('send_action failed for card:', card);
}
}
@@ -193,11 +278,19 @@ function on_click_card(evt) { function is_action(action) {
//console.log('is_action called with: ', action)
+ //console.log('view.actions', view.actions)
if (view.actions && view.actions[action])
return true
return false
}
+function is_card_action(action, card) {
+ console.log('is_card_action called with action', action, 'card', card)
+ console.log('view.actions', view.actions, 'view.actions[action]', view.actions[action])
+ if (view.actions && view.actions[action] && view.actions[action].includes(card))
+ return true
+ return false
+}
function on_log(text) { // eslint-disable-line no-unused-vars
@@ -631,8 +724,8 @@ if (view.persistent_events.includes(97)) { action_button("bulgaria", "Bulgaria")
action_button("extra", "Take action round")
action_button("pass", "Pass")
- action_button("remove", "Remove influence")
- action_button("add", "Add influence")
+ action_button("remove", "Remove SPs")
+ action_button("add", "Add SPs")
action_button("ops", "Operations")
action_button("discard", "Discard")
action_button("strike", "Strike")
|