Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection menu #377

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
382a606
Dragging pieces with mouse
samomania21 Nov 17, 2024
a2522b1
Don't start dragging pieces if the board is moving.
samomania21 Nov 19, 2024
c9453f6
Dragging pieces with touchscreen
samomania21 Nov 20, 2024
de371c6
Skip animation on dragged pieces
samomania21 Nov 25, 2024
1f1343d
Moved `draganimation` to its own file.
samomania21 Nov 25, 2024
0f6b8d8
Merge branch 'main' of https://github.com/Infinite-Chess/infiniteches…
samomania21 Nov 25, 2024
8166b66
Improved animation to implement point 4. See #22.
BF5258 Nov 27, 2024
2b291dc
Testing shadow under dragged piece.
BF5258 Nov 27, 2024
aeb699e
Decluttering selection.update
BF5258 Nov 28, 2024
2723cbf
Sound is no longer played when toggling selection.
BF5258 Nov 28, 2024
bd3f481
Opponent pieces no longer selectable by dragging
BF5258 Nov 29, 2024
1304422
Replaced `hidden` with `perspective.isLookingUp()`.
BF5258 Dec 3, 2024
5624dd9
Improved variable names and comments.
BF5258 Dec 3, 2024
a4f870a
Moved pieceModel and transparentModel to function scope.
BF5258 Dec 3, 2024
0f7a076
Separated pickUpPiece from dragPiece
BF5258 Dec 4, 2024
c0bdafb
Fixed getPointerClickedTile
BF5258 Dec 4, 2024
c968c71
No ghost pieces when using touchscreen
BF5258 Dec 4, 2024
e790808
Never use mouseClickedTile when dragging
BF5258 Dec 4, 2024
ceaf034
Box outline
BF5258 Dec 5, 2024
d899798
Merge branch 'Infinite-Chess:main' into dragging-pieces
BF5258 Dec 5, 2024
5f56dc7
boxOutlineColor added to themes
BF5258 Dec 5, 2024
526020d
Outline rank and file on touchscreen
BF5258 Dec 5, 2024
e417481
Merge branch 'dragging-pieces' of https://github.com/BF5258/infinitec…
BF5258 Dec 5, 2024
d47daa6
Correct sound played on en passant
BF5258 Dec 6, 2024
d21d753
Merge branch 'Infinite-Chess:main' into dragging-pieces
BF5258 Dec 10, 2024
8227729
Various minor bug fixes
BF5258 Dec 11, 2024
16202b4
Drag continues working when zoomed far out.
BF5258 Dec 15, 2024
3435ba7
Merge branch 'main' of https://github.com/Infinite-Chess/infiniteches…
BF5258 Dec 15, 2024
68c9092
Merge branch 'main' of https://github.com/Infinite-Chess/infiniteches…
BF5258 Dec 16, 2024
5b535af
Added comments
BF5258 Dec 16, 2024
23fbff4
Removed unused import and fixed mistakes
BF5258 Dec 16, 2024
0a8f127
Added selection menu
BF5258 Dec 16, 2024
b25148a
Selection dropdown closes when clicking away
BF5258 Dec 16, 2024
601aceb
Decreased width of toggle switch
BF5258 Dec 17, 2024
366ef99
Premoves default to false until they are implemented
BF5258 Dec 17, 2024
469ec16
Animation and color change
BF5258 Dec 18, 2024
d0edfa3
Added border
BF5258 Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions src/client/css/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
--CBC-out: cubic-bezier(.54,0,1,.97); /* Settings dropdown OUT curve */
--CBC-CM-in: cubic-bezier(.09,1.61,.36,1); /* Checkmark IN curve */
--CBC-CM-out: cubic-bezier(0,1.1,1,1); /* Checkmark OUT curve */
--CBC-switch-slider: cubic-bezier(0,1.05,.47,1); /* Toggle switch curve */
--CBC-switch-color: cubic-bezier(.54,0,1,.97);
}

header {
Expand Down Expand Up @@ -59,7 +61,7 @@ header a {
animation: spin 0.65s linear infinite; /* Spin animation with continuous loop */
}

.svg-language, .svg-board, .svg-legalmove, .svg-perspective,
.svg-language, .svg-board, .svg-legalmove, .svg-perspective, .svg-selection,
.svg-squares, .svg-mouse, .svg-camera,
.checkmark {
width: 19px;
Expand Down Expand Up @@ -273,7 +275,7 @@ nav.compact-3 #svg-logout {
border-bottom: 1px solid grey;
}

.dropdown-title:hover, .settings-dropdown-item:hover, .language-dropdown-item:hover, .legalmove-option:hover {
.dropdown-title:hover, .settings-dropdown-item:hover, .language-dropdown-item:hover, .legalmove-option:hover, .selection-option:hover {
background-color: var(--header-link-hover-color);
}

Expand Down Expand Up @@ -320,11 +322,47 @@ span.arrow-head-left {
transform: scale(0);
}

.switch {
position: relative;
--switch-on-color: #737373; /* Default value */
}

.switch input {
visibility: none;
width: 0;
height: 0;
}

.switch > input + * {
position: absolute;
inset: 0;
border-radius: 14px;
background-color: #0000008c;
outline: 2px solid rgb(97, 97, 97);
transition: background-color 0.2s var(--CBC-switch-color);
}

.switch > input + ::before {
content: '';
display: inline-block;
border-radius: 14px;
background-color: #000000c4;
width: 50%;
height: 100%;
transition: transform 0.2s var(--CBC-switch-slider), background-color 0.2s linear;
}

.switch input:checked + ::before {
transform: translateX(100%);
}
.switch input:checked + * {
background-color: var(--switch-on-color);
}


/* Language nested dropdown */

.language-dropdown-item, .legalmove-option {
.language-dropdown-item, .legalmove-option, .selection-option {
display:flex;
align-items: center;
cursor: pointer;
Expand Down Expand Up @@ -386,7 +424,24 @@ span.arrow-head-left {
padding: 0 15px 0 8px;
}

/* Selection dropdown */

.selection-option-title {
display: flex;
justify-content: center;
align-items: center;
height: 35px;
}

.selection-option {
height: 43px;
padding: 0 8px 0 8px;
}

.selection-option .switch {
width: 40px;
height: 40%;
}

/* Perspective dropdown */

Expand Down
5 changes: 3 additions & 2 deletions src/client/scripts/esm/chess/logic/movepiece.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ import game from '../../game/chess/game.js';
* - `doGameOverChecks`: Whether to perform game-over checks, such as checkmate or other win conditions.
* - `concludeGameIfOver`: If true, and `doGameOverChecks` is true, then if this move ends the game, we will not stop the clocks, darken the board, display who won, or play a sound effect.
* - `animate`: Whether to animate this move.
* - `animateSecondary`: Animate the pieces affected by the move without the piece that made the move. Used after dragging the king to castle. Has no effect if `animate` is true.
* - `updateData`: Whether to modify the mesh of all the pieces. Should be false for simulated moves, or if you're planning on regenerating the mesh after this.
* - `updateProperties`: Whether to update gamefile properties that game-over algorithms rely on, such as the 50-move-rule's status, or 3-Check's check counter.
* - `simulated`: Whether you plan on undo'ing this move. If true, the `rewindInfo` property will be added to the `move` for easy restoring of the gamefile's properties when undo'ing the move.
*/
function makeMove(gamefile, move, { flipTurn = true, recordMove = true, pushClock = true, doGameOverChecks = true, concludeGameIfOver = true, animate = true, updateData = true, updateProperties = true, simulated = false } = {}) {
function makeMove(gamefile, move, { flipTurn = true, recordMove = true, pushClock = true, doGameOverChecks = true, concludeGameIfOver = true, animate = true, animateSecondary = false, updateData = true, updateProperties = true, simulated = false } = {}) {
const piece = gamefileutility.getPieceAtCoords(gamefile, move.startCoords);
if (!piece) throw new Error(`Cannot make move because no piece exists at coords ${move.startCoords}.`);
move.type = piece.type;
Expand All @@ -75,7 +76,7 @@ function makeMove(gamefile, move, { flipTurn = true, recordMove = true, pushCloc
if (recordMove || updateProperties) deleteEnpassantAndSpecialRightsProperties(gamefile, move.startCoords, move.endCoords);

let specialMoveMade;
if (gamefile.specialMoves[trimmedType]) specialMoveMade = gamefile.specialMoves[trimmedType](gamefile, piece, move, { updateData, animate, updateProperties, simulated });
if (gamefile.specialMoves[trimmedType]) specialMoveMade = gamefile.specialMoves[trimmedType](gamefile, piece, move, { updateData, animate, animateSecondary, updateProperties, simulated });
if (!specialMoveMade) movePiece_NoSpecial(gamefile, piece, move, { updateData, recordMove, animate, simulated }); // Move piece regularly (no special tag)
const wasACapture = move.captured != null;

Expand Down
6 changes: 3 additions & 3 deletions src/client/scripts/esm/chess/logic/specialmove.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getFunctions() {
// Called when the piece moved is a king.
// Tests if the move contains "castle" special move, if so it executes it!
// RETURNS FALSE if special move was not executed!
function kings(gamefile, piece, move, { updateData = true, animate = true, updateProperties = true, simulated = false } = {}) {
function kings(gamefile, piece, move, { updateData = true, animate = true, animateSecondary = false, updateProperties = true, simulated = false } = {}) {

const specialTag = move.castle; // { dir: -1/1, coord }
if (!specialTag) return false; // No special move to execute, return false to signify we didn't move the piece.
Expand All @@ -55,8 +55,8 @@ function kings(gamefile, piece, move, { updateData = true, animate = true, updat
delete gamefile.specialRights[key];
movepiece.movePiece(gamefile, pieceToCastleWith, landSquare, { updateData }); // Make normal move

if (animate) {
animation.animatePiece(piece.type, piece.coords, move.endCoords); // King
if (animate) animation.animatePiece(piece.type, piece.coords, move.endCoords); // King
if (animate || animateSecondary) {
const resetAnimations = false;
animation.animatePiece(pieceToCastleWith.type, pieceToCastleWith.coords, landSquare, undefined, resetAnimations); // Castled piece
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

// This script allows us to enable or disable premoves and dragging pieces

import preferences from "../preferences.js";
import statustext from "../../../game/gui/statustext.js";

// Document Elements -------------------------------------------------------------------------

const settingsDropdown = document.querySelector('.settings-dropdown');

const selectionDropdown = document.querySelector('.selection-dropdown');
const selectionDropdownTitle = document.querySelector('.selection-dropdown .dropdown-title');

const dragCheckbox = document.querySelector('.selection-option.drag input');
const premoveCheckbox = document.querySelector('.selection-option.premove input');

// Functions ---------------------------------------------------------------------------------

(function init() {

showCheckmarkOnSelectedOptions();

})();

function showCheckmarkOnSelectedOptions() {
dragCheckbox.checked = preferences.getDragEnabled();
premoveCheckbox.checked = preferences.getPremoveMode();
}

function open() {
selectionDropdown.classList.remove('visibility-hidden');
initListeners();
settingsDropdown.classList.add('transparent');
}
function close() {
selectionDropdown.classList.add('visibility-hidden');
closeListeners();
settingsDropdown.classList.remove('transparent');
}

function initListeners() {
selectionDropdownTitle.addEventListener('click', close);
dragCheckbox.addEventListener("click", toggleDrag);
premoveCheckbox.addEventListener("click", togglePremove);
}
function closeListeners() {
selectionDropdownTitle.removeEventListener('click', close);
dragCheckbox.removeEventListener("click", toggleDrag);
premoveCheckbox.removeEventListener("click", togglePremove);
}

function toggleDrag() {
preferences.setDragEnabled(dragCheckbox.checked);
}
function togglePremove() {
statustext.showStatus(translations.planned_feature);
// If the checkbox is disabled it stops sending onclick events.
// Uncheck the box
premoveCheckbox.checked = false;

//preferences.setPremoveMode(premoveCheckbox.checked);
}

export default {
initListeners,
closeListeners,
close,
open,
};
27 changes: 26 additions & 1 deletion src/client/scripts/esm/components/header/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ let preferences; // { theme, legal_moves }

// The legal moves shape preference
const default_legal_moves = 'squares'; // dots/squares
const default_drag_enabled = true;
const default_premove_mode = false; // Change this to true when premoves are implemented.
const default_perspective_sensitivity = 100;
const default_perspective_fov = 90;

/** Prefs that do NOT get saved on the server side */
const clientSidePrefs = ['perspective_sensitivity', 'perspective_fov'];
const clientSidePrefs = ['perspective_sensitivity', 'perspective_fov', 'drag_enabled', 'premove_mode'];

/**
* Whether a change was made to the preferences since the last time we sent them over to the server.
Expand Down Expand Up @@ -132,6 +134,25 @@ function setLegalMovesShape(legal_moves) {
savePreferences();
}

function getDragEnabled() {
return preferences.drag_enabled ?? default_drag_enabled;
}
function setDragEnabled(drag_enabled) {
if (typeof drag_enabled !== 'boolean') throw new Error('Cannot set preference drag_enabled when it is not a boolean.');
preferences.drag_enabled = drag_enabled;
onChangeMade();
savePreferences();
}
function getPremoveMode() {
return preferences.premove_mode ?? default_premove_mode;
}
function setPremoveMode(premove_mode) {
if (typeof premove_mode !== 'boolean') throw new Error('Cannot set preference premove_mode when it is not a string.');
preferences.premove_mode = premove_mode;
onChangeMade();
savePreferences();
}

function getPerspectiveSensitivity() {
return preferences.perspective_sensitivity || default_perspective_sensitivity;
}
Expand Down Expand Up @@ -160,6 +181,10 @@ export default {
setTheme,
getLegalMovesShape,
setLegalMovesShape,
getDragEnabled,
setDragEnabled,
getPremoveMode,
setPremoveMode,
getPerspectiveSensitivity,
setPerspectiveSensitivity,
getPerspectiveFOV,
Expand Down
10 changes: 9 additions & 1 deletion src/client/scripts/esm/components/header/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import languagedropdown from "./dropdowns/languagedropdown.js";
import boarddropdown from "./dropdowns/boarddropdown.js";
import legalmovedropdown from "./dropdowns/legalmovedropdown.js";
import perspectivedropdown from "./dropdowns/perspectivedropdown.js";
import selectiondropdown from "./dropdowns/selectiondropdown.js";
// Only imported so its code runs
import pingmeter from "./pingmeter.js";
import preferences from "./preferences.js";
Expand All @@ -22,13 +23,15 @@ const languageDropdownSelection = document.getElementById('language-settings-dro
const boardDropdownSelection = document.getElementById('board-settings-dropdown-item');
const legalmoveDropdownSelection = document.getElementById('legalmove-settings-dropdown-item');
const mouseDropdownSelection = document.getElementById('perspective-settings-dropdown-item');
const selectionDropdownSelection = document.getElementById('selection-settings-dropdown-item');

// All nested dropdowns
const languageDropdown = document.querySelector('.language-dropdown');
const boardDropdown = document.querySelector('.board-dropdown');
const legalmoveDropdown = document.querySelector('.legalmove-dropdown');
const perspectiveDropdown = document.querySelector('.perspective-dropdown');
const allSettingsDropdownsExceptMainOne = [languageDropdown, boardDropdown, legalmoveDropdown, perspectiveDropdown];
const selectionDropdown = document.querySelector('.selection-dropdown');
const allSettingsDropdownsExceptMainOne = [languageDropdown, boardDropdown, legalmoveDropdown, perspectiveDropdown, selectionDropdown];


// Variables ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -80,6 +83,7 @@ function closeAllSettingsDropdownsExceptMainOne() {
languagedropdown.close();
boarddropdown.close();
legalmovedropdown.close();
selectiondropdown.close();
perspectivedropdown.close();
}

Expand All @@ -93,6 +97,8 @@ function initSettingsListeners() {
legalmoveDropdownSelection.addEventListener('click', legalmovedropdown.open);
mouseDropdownSelection.addEventListener('click', closeAllSettingsDropdownsExceptMainOne);
mouseDropdownSelection.addEventListener('click', perspectivedropdown.open);
selectionDropdownSelection.addEventListener('click', closeAllSettingsDropdownsExceptMainOne);
selectionDropdownSelection.addEventListener('click', selectiondropdown.open);
}
function closeSettingsListeners() {
languageDropdownSelection.removeEventListener('click', closeAllSettingsDropdownsExceptMainOne);
Expand All @@ -103,6 +109,8 @@ function closeSettingsListeners() {
legalmoveDropdownSelection.removeEventListener('click', legalmovedropdown.open);
mouseDropdownSelection.removeEventListener('click', closeAllSettingsDropdownsExceptMainOne);
mouseDropdownSelection.removeEventListener('click', perspectivedropdown.open);
mouseDropdownSelection.addEventListener('click', closeAllSettingsDropdownsExceptMainOne);
mouseDropdownSelection.addEventListener('click', perspectivedropdown.open);
}


Expand Down
2 changes: 2 additions & 0 deletions src/client/scripts/esm/components/header/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const legalMovesHighlightColor_Opponent = "legalMovesHighlightColor_Opponent";
const legalMovesHighlightColor_Premove = "legalMovesHighlightColor_Premove";
const lastMoveHighlightColor = "lastMoveHighlightColor";
const checkHighlightColor = "checkHighlightColor";
const boxOutlineColor = "boxOutlineColor";

/**
* Fallback properties for a themes properties
Expand All @@ -24,6 +25,7 @@ const checkHighlightColor = "checkHighlightColor";
const defaults = {
[lastMoveHighlightColor]: [0.72, 1, 0, 0.28],
[checkHighlightColor]: /* checkHighlightColor */ [1, 0, 0, 0.7],
[boxOutlineColor]: [0.5, 0.5, 0.5, 1],
// If this is false, we will render them white,
// utilizing the more efficient color-less shader program!
useColoredPieces: false,
Expand Down
5 changes: 4 additions & 1 deletion src/client/scripts/esm/game/chess/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import loadingscreen from '../gui/loadingscreen.js';
import movepiece from '../../chess/logic/movepiece.js';
import frametracker from '../rendering/frametracker.js';
import area from '../rendering/area.js';
import dragAnimation from '../rendering/draganimation.js';
// Import End

/**
Expand Down Expand Up @@ -190,12 +191,14 @@ function renderEverythingInGame() {
});

animation.renderTransparentSquares();
dragAnimation.renderTransparentSquare();
pieces.renderPiecesInGame(gamefile);
animation.renderPieces();
webgl.executeWithDepthFunc_ALWAYS(() => {
promotionlines.render();
selection.renderGhostPiece(); // If not after pieces.renderPiecesInGame(), wont render on top of existing pieces
dragAnimation.renderPiece();
arrows.renderThem();
perspective.renderCrosshair();
});
Expand Down
Loading
Loading