Commit graph

435 commits

Author SHA1 Message Date
Gleb Mazovetskiy
cb0dae8590 🚚 Rename CelOutputBuf to Surface and extract 2021-07-03 05:33:32 -07:00
Anders Jenbo
50aa3dce0d Fix GCC warning in inv.cpp 2021-07-02 21:01:25 +02:00
qndel
fd3893190f inv cleanup 2021-07-02 05:00:31 -07:00
qndel
a1710ff51e
pass item to CelDrawItem (#2265)
pass item to CelDrawItem
2021-06-29 18:09:54 +02:00
Juliano Leal Goncalves
cbb84199c2 ♻️ Replace Point addition with 'Point + Displacement' 2021-06-28 20:37:44 -07:00
Juliano Leal Goncalves
fd9f2099d0 ♻️ Leverage 'Point' to represent mouse position 2021-06-27 16:37:59 +02:00
Anders Jenbo
790f42d078 Clang-tidy: readability-inconsistent-declaration-parameter-name 2021-06-27 01:06:00 +02:00
Andrew James
60a47caf1b
Refactor Draw* functions to use Rectangle and Point types
Added overload for DrawString taking a Point to avoid creating a rect for callers which only use position. This also documents the way DrawString operates when passed a clipping rectangle with a dimension of 0.
As part of this overload removed the logic for 0 width regions from DrawString. This does change the behaviour of the Rectangle version if called with a rect with width 0, all callers using that behaviour have been updated in this commit.

Using Rectangle/Size allowed simplifying the logic for certain calls where they could use DrawText alignment flags, previously this was manually aligning by calculating dimensions and offsetting the position. This also fixes #2169

Also includes a few instances where a temporary buffer was used to set the text to be drawn with unbounded sprintf calls, replaced those with snprintf as is recommended in modern C applications. Moving to C++ strings would be good in a future refactor.
2021-06-24 01:36:06 +02:00
Anders Jenbo
ee7b32d8f6 Player by reference part 3 2021-06-24 00:53:09 +02:00
Anders Jenbo
e670faac99 🔥 Remove unused code DrawInvMsg 2021-06-23 14:42:19 -07:00
Gleb Mazovetskiy
f98148484f
🐞 Fix inventory manipulation (#2216)
Fixes #2214
Co-authored-by: staphen <staphen@gmail.com>
2021-06-23 08:05:19 +02:00
Gleb Mazovetskiy
5cefb4a365 Fix -Wswitch in UseInvItem
Fixes a giant non-exhaustive switch warning in `UseInvItem`:

```
../Source/inv.cpp: In function ‘bool devilution::UseInvItem(int, int)’:
../Source/inv.cpp:2131:9: warning: enumeration value ‘IDI_GOLD’ not handled in switch [-Wswitch]
 2131 |  switch (item->IDidx) {
      |         ^
../Source/inv.cpp:2131:9: warning: enumeration value ‘IDI_WARRIOR’ not handled in switch [-Wswitch]
../Source/inv.cpp:2131:9: warning: enumeration value ‘IDI_WARRSHLD’ not handled in switch [-Wswitch]
../Source/inv.cpp:2131:9: warning: enumeration value ‘IDI_WARRCLUB’ not handled in switch [-Wswitch]
...
```
2021-06-21 01:37:26 -07:00
Gleb Mazovetskiy
e40b1963f9 🚚 engine.h: Extract CelSprite and file loading 2021-06-21 01:36:20 -07:00
Gleb Mazovetskiy
aa54675d83 🚚 engine.h: Extract Size 2021-06-21 01:36:20 -07:00
Juliano Leal Goncalves
a983792880 ♻️ Replace 'pair<int, int>' with 'Size' in 'GetItemSizeOnSlot' and 'GetInvItemSize' 2021-06-20 18:27:45 -07:00
Juliano Leal Goncalves
572c3e632e ♻️ Leverage 'Point' in 'InvDrawSlotBack' implementation 2021-06-20 18:27:45 -07:00
Juliano Leal Goncalves
07a049f667 ♻️ Replace 'INV_SLOT_SIZE_PX' macro with Size-based constexpr 2021-06-20 18:27:45 -07:00
Juliano Leal Goncalves
0e2d734bbb ♻️ Leverage 'Size' in 'CheckInvPaste' implementation 2021-06-20 18:27:45 -07:00
Juliano Leal Goncalves
4ab80d25f4 ♻️ Leverage 'Size' in 'AddItemToInvGrid' function 2021-06-20 18:27:45 -07:00
Gleb Mazovetskiy
43bc08bd63 Hardware Cursor: Fall back to software on failure 2021-06-19 12:36:39 +01:00
Gleb Mazovetskiy
523d838bd4 Hardware Cursor: Use item hotpoint
For a hardware item cursor, set the hotpoint to the center
instead of manually setting the cursor position.
2021-06-19 12:36:39 +01:00
Gleb Mazovetskiy
432fdacd81 Clip InvDrawSlotBack draw call 2021-06-16 03:12:54 +02:00
qndel
816b244689 HasItem/RemoveInvItem combo refactor 2021-06-13 05:18:08 +02:00
qndel
0c39656c91 fix reconstructed note 2021-06-13 05:18:08 +02:00
Juliano Leal Goncalves
1328c9ea93 🎨 Make 'Size' fields camelCase 2021-06-12 19:47:52 +02:00
Vladimir Olteanu
512fcdb790 Use WalkingDistance in PutItem 2021-06-02 13:36:17 +02:00
Juliano Leal Goncalves
8622130966 ♻️ Add '==' and '!=' operators to 'Size' struct 2021-05-31 06:13:24 +02:00
Juliano Leal Goncalves
ff3dee8d45 ♻️ Replace poor usages of 'Size' with 'Point's 2021-05-31 06:05:13 +02:00
Juliano Leal Goncalves
abee4fe6fe ♻️ Repurpose the 'InvXY' struct as a new 'Size' struct 2021-05-31 06:05:13 +02:00
Juliano Leal Goncalves
21ecaa225f
♻️ Leverage 'Point' struct on inventory functions (#2094) 2021-05-30 23:44:38 +02:00
Kalebe Alves
118efe8e6d
Use Point/SDL_Rect for control functions coordinate system 2021-05-28 19:57:16 +02:00
Gleb Mazovetskiy
dd3ea66fa2 ♻️ Split getTextColor(bool) into 2 functions
This is a bit more readable than using a bool argument.
2021-05-28 13:38:36 +02:00
qndel
2f3cf65b27 cleanup getTextColor 2021-05-26 15:58:14 +02:00
Anders Jenbo
8a7ec56d3a Player by reference part 2
This mostly change player to be by reference instead of by index.
But additionally it does stript checks for gold in the belt, move some
value types to the initialization and short circute a few functiongs.
2021-05-24 21:00:32 +02:00
Anders Jenbo
6ce8f13751 Apply clang-tidy to more code and do some related cleanups 2021-05-24 05:27:06 +02:00
Juliano Leal Goncalves
21fdb0dcd9 ♻️ Replace manual direction displacement logic with 'Point' add operator 2021-05-24 04:46:08 +02:00
Juliano Leal Goncalves
d55cd99dd5 🚚 Rename 'direction' enum to 'Direction' 2021-05-24 04:46:08 +02:00
Juliano Leal Goncalves
15c46b9eb0 💬 Rename HeroSpeech members to improve discoverability 2021-05-23 22:01:47 +02:00
Juliano Leal Goncalves
5350250a76 🚚 Rename speech functions to 'Say' variations 2021-05-23 05:32:34 +02:00
Juliano Leal Goncalves
8c620ce29e ♻️ Extract 'HeroSpeech' enum class for hero sounds instead of using raw ints 2021-05-23 05:32:34 +02:00
Jmgr
0e7ada15fc Apply new format to ngexttext translations 2021-05-21 01:02:45 +02:00
Anders Jenbo
34744c068f ♻️Consitantly use %i and not %d 2021-05-15 14:17:52 +02:00
Stefan Mielke
30bfe45781 One pixel was not being calculated on the X axis when trying to find for an inventory slot to put the item. 2021-05-15 12:27:48 +02:00
qndel
89c40eaa7b
inventory items rendering cleanup (#1938) 2021-05-14 12:46:16 +02:00
Anders Jenbo
0c2042fa52 ♻️ Player by reference
Update Source/items.cpp
Update Source/lighting.cpp
Update Source/pack.cpp
asd


ads


as
2021-05-13 01:47:46 +02:00
Anders Jenbo
68e73c0dfe 🐛 Fix infopanel text color 2021-05-12 11:40:31 +02:00
Anders Jenbo
ad97ebe980 🔥 Remove redundant code from towners.cpp
This changes one bavious. Previously walking away from the dead guy
would interupt the "Your death shall be reveanged", the interuption
seamed un natural and the code didn't seam to have been specifically
made for this case (TownCtrlMsg).

Fix several edge cases in quests where the incorrect state could be reached
2021-05-10 23:17:43 +02:00
Stefan Mielke
dfece830ad
Controller Inventory Improvements (#1885)
- controller: Move inventory coordinates logic to outside of the method to ease visibility and changes; Fix cursor offset when holding items on the inventory; Move cursor between edges of the inventory to ease movement inside.
- Renamed InvGetCoord to InvGetSlotCoord.
- adding more SLOTXY_xxx options to improve controls code
- changed inventory slots comment to improve legibility
- fixing bugs and centering sprite on the slot
- fix belt item movement
- slots 9 and 10 move to belt 8 when moving down using a controller
- creating function to return correct mousePos slot to remove code duplication
- create BeltGetSlotCoord to get coords for belts and remove duplicates; code cleanup.
- adding INV_ROW_SLOT_SIZE to hold the amount of slots on an inv row
- improve code for moving item to the belt when it's the last 2 slots.
- fix bug that would not update the cursor position when going up on certain conditions.
- equip equipment when pressing [use] on the controller
- moving items in the inventory as a single instance, and blocking them from moving accordingly.
- move item to belt when clicking the spell button (Y)
- resetting the cursor takes into consideration if the current slot has an item that is bigger than 1x1
- change whitespace to tabs on inv.h changes
- fixing plrctrls.cpp formatting
2021-05-09 17:00:48 +02:00
Aneurin
2365b5f440
Improve inventory filling algorithm (#1876)
* Extract loop body into GoldAutoPlaceInInventorySlot()
* Improve placement of gold in inventory

When adding gold to the inventory, this now finds a free slot as
follows:

1) Start at X, and work left until row 3 is full
2) Start at Y, and work up until column 9 is full
3) Move one column left, start at row 2 and work up
4) Repeat step 3 until there is no free space

| |0|1|2|3|4|5|6|7|8|9|
|-|-|-|-|-|-|-|-|-|-|-|
|0| | | | | | | | | | |
|1| | | | | | | | | | |
|2| | | | | | | | | |Y|
|3| | | | | | | | | |X|

* Improve inventory placement for single-height items

When adding single-height items (which in practice are all 1x1) to the
inventory, this now finds a free slot as follows:

1) Start at X, and work right until row 3 is full
2) Start at Y, and work up until column 9 is full
3) Move one column left, start at row 2 and work up
4) Repeat step 3 until there is no free space

| |0|1|2|3|4|5|6|7|8|9|
|-|-|-|-|-|-|-|-|-|-|-|
|0| | | | | | | | | | |
|1| | | | | | | | | | |
|2| | | | | | | | | |Y|
|3|X| | | | | | | | | |

* Improve inventory placement for two-height items

When adding 1x2 items to the inventory, this now finds a free slot as
follows:

1) Start at X, and work down until column 9 is full
2) Move one column left, start at row 0 and work down
3) Repeat step 2 until there is no free space

| |0|1|2|3|4|5|6|7|8|9|
|-|-|-|-|-|-|-|-|-|-|-|
|0| | | | | | | |Z|Y|X|
|1| | | | | | | | | | |
|2| | | | | | | | | | |
|3| | | | | | | | | | |

When adding 2x2 items, it first tries to place them in even columns,
then goes to odd columns of no space was found:

1) Start at Y, and work down until columns 8/9 are full
2) Move two columns left, start at row 0 and work down
3) Repeat step 2 until there is no free space in columns 0/1
4) Go to Z, and work down until columns 7/8 are full
5) Move two columns left, start at row 0 and work down
3) Repeat step 5 until there is no free space
2021-05-09 06:34:57 +02:00
Anders Jenbo
8361e70087 ♻️Use DrawString in error.cpp 2021-05-08 18:48:19 +02:00