Fission FSN
Loading...
Searching...
No Matches
gfCLetterGrid.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: gfCLetterGrid.h
4*
5* Purpose: Grid of letter tiles shared by the word games: lays
6* out the tiles, drag-through selection, finding a word
7* in the grid and drawing selection lines
8*
9*********************************************************************/
10
11#ifndef gfCLetterGridhdr
12#define gfCLetterGridhdr
13
14#include <memory>
15#include <vector>
16
17#include <fsCore/fsStr.h>
18#include <fsCore/fsPoint.h>
19#include <fsCore/fsGrid.h>
20#include <fsCore/fsSColour.h>
21
22class fsCEntity;
23class fsCResourceName;
25
26
28{
29public:
30
32 {
33 fsStr mWord = {""};
34 std::vector<fsCEntity*> mLines;
35 std::vector<gfCMinigameLetterTileComponent*> mTiles;
36
37 fsBool empty() const;
38 void tilesTint(fsSColour4B const& pTint);
39 void linesDestroy();
40 void clear();
41 };
42
43 static const fsSColour4B mTileTint;
45
46 static fsBool verticalGet(fsPoint const& pSize);
47 static fsStr spellGet(const std::vector<gfCMinigameLetterTileComponent*>& pTiles, fsBool pBackward);
48
49 // Tiles and selection lines are children of pOwner.
50 explicit gfCLetterGrid(fsCEntity* pOwner);
52
53 void hilightsSet(const fsStr& pHilight, const fsStr& pHilight2, const fsStr& pHilight2End);
54 // pLetters is rows of columns; a zero origin centres the grid on the owner.
55 void init(const fsStr& pTileSet, const std::vector<std::vector<fsStr>>& pLetters, fsPoint const& pOrigin);
56
57 // Off leaves the letters untinted while dragging, so only the selection line shows.
58 void dragTintSet(fsBool pDragTint) { mDragTint = pDragTint; }
59
61 const fsGrid<gfCMinigameLetterTileComponent*>& tilesGet() const { return mTiles; }
62
63 // Drag through adjacent tiles; straight unless pSnake, which may turn as it goes.
64 void dragTo(sSelection& pSelection, fsPoint const& pPos, fsBool pSnake);
65
66 // Lays pSelection.mWord out in the grid: straight first, then bending if pSnake. A tile may hold
67 // several letters ("qu").
68 fsBool wordFind(sSelection& pSelection, fsBool pSnake);
69
70 // The first tile, every tile the path turns at, and the last.
71 std::vector<gfCMinigameLetterTileComponent*> cornerTilesGet(const sSelection& pSelection) const;
72 // A vertex wherever the path turns.
73 std::vector<fsPoint> lineVertsGet(const sSelection& pSelection) const;
74 void lineCreate(sSelection& pSelection, fsSColour4B const& pTint);
75 void segmentCreate(sSelection& pSelection, fsPoint const& pStart, fsPoint const& pEnd, fsSColour4B const& pTint);
76 fsBool diagonalGet(fsPoint const& pSize) const;
77
78 // "WORD|x,y;x,y..." so a bent word restores the path the player traced, not just any path.
79 fsStr pathSaveStrGet(const sSelection& pSelection) const;
80 fsBool pathRestore(sSelection& pSelection, const fsStr& pPath);
81
82private:
83
84 gfCMinigameLetterTileComponent* tileCreate(fsPoint const& pGridPos, const std::vector<std::vector<fsStr>>& pLetters);
85
86 void tileAdd(sSelection& pSelection, gfCMinigameLetterTileComponent* pTile) const;
87 void tileRemoveLast(sSelection& pSelection) const;
88 void lineRefresh(sSelection& pSelection);
89 // A bent path as one stroke: end caps only at its ends, rounded at each bend.
90 void pathCreate(sSelection& pSelection, const std::vector<fsPoint>& pVerts, fsSColour4B const& pTint);
91
92 fsCEntity* spriteCreate(sSelection& pSelection, const fsCResourceName& pBrushName, fsSColour4B const& pTint);
93 void spriteAdjust(fsCEntity* pSprite, fsPoint const& pStart, fsPoint const& pEnd) const;
94 void capAdjust(fsCEntity* pCap, fsPoint const& pPos, fsF32 pAngle) const;
95 fsPoint capOffsetGet(fsCEntity* pCap, fsPoint const& pStart, fsPoint const& pEnd) const;
96 fsF32 angleGet(fsPoint const& pStart, fsPoint const& pEnd) const;
97 fsBool hilight2Available() const;
98
99 fsCEntity* const mOwner;
100 fsStr mTileSet = {""};
101 fsGrid<gfCMinigameLetterTileComponent*> mTiles;
102 fsBool mDragTint = true;
103
104 std::unique_ptr<fsCResourceName> mHilight;
105 std::unique_ptr<fsCResourceName> mHilight2;
106 std::unique_ptr<fsCResourceName> mHilight2End;
107};
108
109#endif
Definition fsCEntity.h:39
Definition fsCResourceName.h:32
Definition fsGrid.h:22
Definition fsStr.h:23
void lineCreate(sSelection &pSelection, fsSColour4B const &pTint)
Definition gfCLetterGrid.cpp:276
void dragTo(sSelection &pSelection, fsPoint const &pPos, fsBool pSnake)
Definition gfCLetterGrid.cpp:148
void hilightsSet(const fsStr &pHilight, const fsStr &pHilight2, const fsStr &pHilight2End)
Definition gfCLetterGrid.cpp:77
void dragTintSet(fsBool pDragTint)
Definition gfCLetterGrid.h:58
std::vector< gfCMinigameLetterTileComponent * > cornerTilesGet(const sSelection &pSelection) const
Definition gfCLetterGrid.cpp:246
static const fsSColour4B mSelectionTint
Definition gfCLetterGrid.h:44
fsStr pathSaveStrGet(const sSelection &pSelection) const
Definition gfCLetterGrid.cpp:481
fsGrid< gfCMinigameLetterTileComponent * > & tilesGet()
Definition gfCLetterGrid.h:60
void init(const fsStr &pTileSet, const std::vector< std::vector< fsStr > > &pLetters, fsPoint const &pOrigin)
Definition gfCLetterGrid.cpp:84
~gfCLetterGrid()
Definition gfCLetterGrid.cpp:523
static fsBool verticalGet(fsPoint const &pSize)
Definition gfCLetterGrid.cpp:57
gfCLetterGrid(fsCEntity *pOwner)
Definition gfCLetterGrid.cpp:518
fsBool wordFind(sSelection &pSelection, fsBool pSnake)
Definition gfCLetterGrid.cpp:228
fsBool pathRestore(sSelection &pSelection, const fsStr &pPath)
Definition gfCLetterGrid.cpp:492
static fsStr spellGet(const std::vector< gfCMinigameLetterTileComponent * > &pTiles, fsBool pBackward)
Definition gfCLetterGrid.cpp:62
std::vector< fsPoint > lineVertsGet(const sSelection &pSelection) const
Definition gfCLetterGrid.cpp:266
void segmentCreate(sSelection &pSelection, fsPoint const &pStart, fsPoint const &pEnd, fsSColour4B const &pTint)
Definition gfCLetterGrid.cpp:355
const fsGrid< gfCMinigameLetterTileComponent * > & tilesGet() const
Definition gfCLetterGrid.h:61
fsBool diagonalGet(fsPoint const &pSize) const
Definition gfCLetterGrid.cpp:420
static const fsSColour4B mTileTint
Definition gfCLetterGrid.h:43
Definition gfCMinigameLetterTileComponent.h:20
bool fsBool
Definition fsBaseTypes.h:26
float fsF32
Definition fsBaseTypes.h:28
Definition fsPoint.h:17
Definition fsSColour.h:54
Definition gfCLetterGrid.h:32
std::vector< fsCEntity * > mLines
Definition gfCLetterGrid.h:34
void clear()
Definition gfCLetterGrid.cpp:49
fsStr mWord
Definition gfCLetterGrid.h:33
std::vector< gfCMinigameLetterTileComponent * > mTiles
Definition gfCLetterGrid.h:35
void tilesTint(fsSColour4B const &pTint)
Definition gfCLetterGrid.cpp:30
fsBool empty() const
Definition gfCLetterGrid.cpp:25
void linesDestroy()
Definition gfCLetterGrid.cpp:39