OpenXcom  1.0
Open-source clone of the original X-Com
Inventory.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "../Engine/InteractiveSurface.h"
21 #include <map>
22 #include <string>
23 
24 namespace OpenXcom
25 {
26 
27 class RuleInventory;
28 class Game;
29 class WarningMessage;
30 class BattleItem;
31 class BattleUnit;
32 class NumberText;
33 class Timer;
34 
40 {
41 private:
42  Game *_game;
43  Surface *_grid, *_items, *_selection;
44  WarningMessage *_warning;
45  BattleUnit *_selUnit;
46  BattleItem *_selItem;
47  bool _tu, _base;
48  BattleItem *_mouseOverItem;
49  int _groundOffset, _animFrame;
50  std::map<int, std::map<int, int> > _stackLevel;
51  std::vector<std::pair<int, int> > _grenadeIndicators;
52  NumberText *_stackNumber;
53  Timer *_animTimer;
54  int _depth;
56  void moveItem(BattleItem *item, RuleInventory *slot, int x, int y);
58  RuleInventory *getSlotInPosition(int *x, int *y) const;
59 public:
61  Inventory(Game *game, int width, int height, int x = 0, int y = 0, bool base = false);
63  ~Inventory();
65  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
67  void setTuMode(bool tu);
69  void setSelectedUnit(BattleUnit *unit);
71  void draw();
73  void drawGrid();
75  void drawItems();
77  BattleItem *getSelectedItem() const;
79  void setSelectedItem(BattleItem *item);
83  void setMouseOverItem(BattleItem *item);
85  void think();
87  void blit(Surface *surface);
89  void mouseOver(Action *action, State *state);
91  void mouseClick(Action *action, State *state);
93  bool unload();
95  void arrangeGround(bool alterOffset = true);
97  bool fitItem(RuleInventory *newSlot, BattleItem *item, std::string &warning);
99  bool canBeStacked(BattleItem *itemA, BattleItem *itemB);
101  static bool overlapItems(BattleUnit *unit, BattleItem *item, RuleInventory *slot, int x = 0, int y = 0);
103  void showWarning(const std::string &msg);
105  void drawPrimers();
106 };
107 
108 }
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
BattleItem * getSelectedItem() const
Gets the currently selected item.
Definition: Inventory.cpp:402
void showWarning(const std::string &msg)
Shows a warning message.
Definition: Inventory.cpp:1019
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Timer used to run code in fixed intervals.
Definition: Timer.h:35
static bool overlapItems(BattleUnit *unit, BattleItem *item, RuleInventory *slot, int x=0, int y=0)
Checks for item overlap.
Definition: Inventory.cpp:355
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
void arrangeGround(bool alterOffset=true)
Arranges items on the ground.
Definition: Inventory.cpp:857
void drawPrimers()
Show priming warnings on grenades.
Definition: Inventory.cpp:1027
void setTuMode(bool tu)
Sets the inventory&#39;s Time Unit mode.
Definition: Inventory.cpp:111
Interactive view of an inventory.
Definition: Inventory.h:39
void drawGrid()
Draws the inventory grid.
Definition: Inventory.cpp:139
Represents a single item in the battlescape.
Definition: BattleItem.h:37
void setSelectedUnit(BattleUnit *unit)
Sets the inventory&#39;s selected unit.
Definition: Inventory.cpp:120
Coloured box with text inside that fades out after it is displayed.
Definition: WarningMessage.h:33
bool canBeStacked(BattleItem *itemA, BattleItem *itemB)
Checks if two items can be stacked on one another.
Definition: Inventory.cpp:990
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
bool unload()
Unloads the selected weapon.
Definition: Inventory.cpp:805
Inventory(Game *game, int width, int height, int x=0, int y=0, bool base=false)
Creates a new inventory view at the specified position and size.
Definition: Inventory.cpp:57
void drawItems()
Draws the inventory items.
Definition: Inventory.cpp:219
void think()
Handles timers.
Definition: Inventory.cpp:450
BattleItem * getMouseOverItem() const
Gets the mouse over item.
Definition: Inventory.cpp:433
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the inventory&#39;s palette.
Definition: Inventory.cpp:95
The core of the game engine, manages the game&#39;s entire contents and structure.
Definition: Game.h:41
~Inventory()
Cleans up the inventory.
Definition: Inventory.cpp:79
Number digits displayed on the screen.
Definition: NumberText.h:29
void blit(Surface *surface)
Blits the inventory onto another surface.
Definition: Inventory.cpp:460
void setMouseOverItem(BattleItem *item)
Sets the mouse over item.
Definition: Inventory.cpp:442
void setSelectedItem(BattleItem *item)
Sets the currently selected item.
Definition: Inventory.cpp:411
void mouseClick(Action *action, State *state)
Special handling for mouse clicks.
Definition: Inventory.cpp:509
void draw()
Draws the inventory.
Definition: Inventory.cpp:130
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
Definition: BaseInfoState.cpp:40
bool fitItem(RuleInventory *newSlot, BattleItem *item, std::string &warning)
Attempts to place an item in an inventory slot.
Definition: Inventory.cpp:951
void mouseOver(Action *action, State *state)
Special handling for mouse hovers.
Definition: Inventory.cpp:475
Represents a specific section of the inventory, containing information like available slots and scree...
Definition: RuleInventory.h:42