ScummVM API documentation
icon_list.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_ICON_LIST_H_INCLUDED
28 #define ICB_ICON_LIST_H_INCLUDED
29 
30 // Include headers needed by this class.
31 #include "engines/icb/common/px_string.h"
32 #include "engines/icb/common/px_clu_api.h"
33 #include "engines/icb/p4.h"
34 #include "engines/icb/debug.h"
35 #include "engines/icb/string_vest.h"
36 
37 namespace ICB {
38 
39 extern const char *global_deleted_list;
40 
41 // This is used as a placeholder for deleted lists to save reallocating.
42 #define ICON_LIST_DELETED_PLACEHOLDER global_deleted_list
43 
44 // This defines the available values for the scope of these lists.
45 enum IconListScope { CURRENT_LOGIC = 0, SESSION_WIDE, MISSION_WIDE, GAME_WIDE };
46 
47 // This defines the maximum number of icons that can be in the menu.
48 #define ICON_LIST_MAX_ICONS 16 // This defines an array size, so must be a multiple of 4!
49 
50 // And this defines the maximum number that can be displayed at one time.
51 #define ICON_LIST_MAX_DISPLAYED 10
52 
53 // This defines how many of each icon are allowed (only meaningful when the list is handling duplicates).
54 #define ICON_MAX_DUPLICATE_COUNT 99
55 
56 // This means there is no current selection.
57 #define ICON_LIST_NO_SELECTION (-1)
58 
59 // This defines the name of the 'empty' icon.
60 
61 extern const char *iconListEmptyIcon;
62 #define ICON_LIST_EMPTY_ICON iconListEmptyIcon
63 
64 // Class to manage the lists of icons used in the game. the inventory, Remora and speech system all use these lists.
65 class _icon_list {
66 public:
67  // Default constructor and destructor.
68  _icon_list();
69  ~_icon_list() {}
70 
71  // Alternative constructor, which takes the list name.
72  inline _icon_list(const char *pcListName);
73 
74  // Copy constructor and assignment operator.
75  inline _icon_list(const _icon_list &oX);
76  inline const _icon_list &operator=(const _icon_list &oOpB);
77 
78  // This resets the list to its newly-created state.
79  void Reset();
80 
81  // Gets and sets.
82  const char *GetListName() const { return (m_pcListName); }
83  void SetListName(const char *pcListName) { m_pcListName = pcListName; }
84 
85  uint8 GetIconCount() const { return (m_nItemCount); }
86 
87  IconListScope GetScope() const { return (m_eScope); }
88  void SetScope(IconListScope eScope) { m_eScope = eScope; }
89 
90  inline const char *GetIcon(uint32 nIndex) const;
91  inline uint32 GetIconHash(uint32 nIndex) const;
92  uint8 GetDuplicateCount(const char *pcIconName) const;
93  uint8 GetDuplicateCount(uint32 nIndex) const;
94 
95  void SetAbsoluteIconCount(const char *pcIconName, uint32 nCount);
96 
97  // This returns the index position of an icon in the list.
98  int32 GetIconPosition(const char *pcIconName) const;
99 
100  // These add and remove items from the list.
101  void AddIcon(const char *pcIconName, const uint32 nIconNameHash);
102  void RemoveIcon(const char *pcIconName, bool8 bForceRemove);
103 
104 private:
105  const char *m_pcListName; // The name of the list.
106  IconListScope m_eScope; // Scope of the list (determines when it is allowed to be destroyed).
107  uint32 m_pnIconListHash[ICON_LIST_MAX_ICONS]; // The hash number of items currently in the inventory.
108  uint8 m_pnDuplicateCount[ICON_LIST_MAX_ICONS]; // The list of items currently in the inventory.
109  char m_ppcIconList[ICON_LIST_MAX_ICONS][MAXLEN_ICON_NAME]; // The list of items currently in the inventory.
110  uint8 m_nItemCount; // My own count of the number of items currently in the inventory.
111  bool8 m_bAllowDuplicates; // If true, a count is incremented when a duplicate is added.
112  uint8 m_nPad1;
113  uint8 m_nPad2;
114 
115  // Private functions used only in this class.
116  void Clone(const _icon_list &oSource);
117 };
118 
119 inline _icon_list::_icon_list(const _icon_list &oX) { Clone(oX); }
120 
121 inline const _icon_list &_icon_list::operator=(const _icon_list &oOpB) {
122  Clone(oOpB);
123 
124  return (*this);
125 }
126 
127 inline void _icon_list::Reset() {
128  memset((uint8 *)m_pnIconListHash, 0, ICON_LIST_MAX_ICONS * sizeof(uint32));
129  memset((uint8 *)m_pnDuplicateCount, 0, ICON_LIST_MAX_ICONS * sizeof(uint8));
130  memset((uint8 *)m_ppcIconList, 0, ICON_LIST_MAX_ICONS * MAXLEN_ICON_NAME * sizeof(char));
131  m_nItemCount = 0;
132 }
133 
134 inline const char *_icon_list::GetIcon(uint32 nIndex) const { return (m_ppcIconList[nIndex]); }
135 
136 inline uint32 _icon_list::GetIconHash(uint32 nIndex) const {
137  if (nIndex >= m_nItemCount) {
138  Fatal_error("_icon_list::GetIconHash( %d ) called - list has %d items", nIndex, m_nItemCount);
139  }
140 
141  return (m_pnIconListHash[nIndex]);
142 }
143 
144 } // End of namespace ICB
145 
146 #endif // #if !defined( ICON_LIST_H_INCLUDED )
Definition: actor.h:32
Definition: icon_list.h:65