diff options
author | Eric Fry | 2018-06-27 23:12:40 +1000 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | 608f2f1f1ae524fd6ffc656dfcef3985988adaa9 (patch) | |
tree | 57859b99a9b507065cc90e3e1affcbbdd4415fb6 | |
parent | 9ad048f8a6c6380fe8ca6534afcae30d3b1ada37 (diff) | |
download | scummvm-rg350-608f2f1f1ae524fd6ffc656dfcef3985988adaa9.tar.gz scummvm-rg350-608f2f1f1ae524fd6ffc656dfcef3985988adaa9.tar.bz2 scummvm-rg350-608f2f1f1ae524fd6ffc656dfcef3985988adaa9.zip |
ILLUSIONS: Refactor duckman inventory code to remove verbose init logic
Replaced Common::String with c string array in slider menu init logic
-rw-r--r-- | engines/illusions/duckman/duckman_inventory.cpp | 84 | ||||
-rw-r--r-- | engines/illusions/duckman/duckman_inventory.h | 5 | ||||
-rw-r--r-- | engines/illusions/duckman/menusystem_duckman.cpp | 4 |
3 files changed, 41 insertions, 52 deletions
diff --git a/engines/illusions/duckman/duckman_inventory.cpp b/engines/illusions/duckman/duckman_inventory.cpp index 2196826417..1f863b5869 100644 --- a/engines/illusions/duckman/duckman_inventory.cpp +++ b/engines/illusions/duckman/duckman_inventory.cpp @@ -40,48 +40,40 @@ DuckmanInventory::DuckmanInventory(IllusionsEngine_Duckman *vm) DuckmanInventory::~DuckmanInventory() { } +static const struct DMInventoryItem kInventoryItems[21] = { + {0x40011, 0xE005B}, + {0x40099, 0xE001B}, + {0x4000F, 0xE000C}, + {0x40042, 0xE0012}, + {0x40044, 0xE000F}, + {0x40029, 0xE000D}, + {0x400A7, 0xE005D}, + {0x40096, 0xE001C}, + {0x40077, 0xE0010}, + {0x4008A, 0xE0033}, + {0x4004B, 0xE0045}, + {0x40054, 0xE0021}, + {0x400C6, 0xE005A}, + {0x4000B, 0xE005E}, + {0x4005F, 0xE0016}, + {0x40072, 0xE0017}, + {0x400AA, 0xE005F}, + {0x400B8, 0xE0050}, + {0x4001F, 0xE001A}, + {0x40095, 0xE0060}, + {0x40041, 0xE0053} +}; + void DuckmanInventory::initInventory() { - _inventorySlots.push_back(DMInventorySlot( 64, 52)); - _inventorySlots.push_back(DMInventorySlot(112, 52)); - _inventorySlots.push_back(DMInventorySlot(160, 52)); - _inventorySlots.push_back(DMInventorySlot(208, 52)); - _inventorySlots.push_back(DMInventorySlot(255, 52)); - _inventorySlots.push_back(DMInventorySlot( 64, 84)); - _inventorySlots.push_back(DMInventorySlot(112, 84)); - _inventorySlots.push_back(DMInventorySlot(160, 84)); - _inventorySlots.push_back(DMInventorySlot(208, 84)); - _inventorySlots.push_back(DMInventorySlot(255, 84)); - _inventorySlots.push_back(DMInventorySlot( 64, 116)); - _inventorySlots.push_back(DMInventorySlot(112, 116)); - _inventorySlots.push_back(DMInventorySlot(160, 116)); - _inventorySlots.push_back(DMInventorySlot(208, 116)); - _inventorySlots.push_back(DMInventorySlot(255, 116)); - _inventorySlots.push_back(DMInventorySlot( 64, 148)); - _inventorySlots.push_back(DMInventorySlot(112, 148)); - _inventorySlots.push_back(DMInventorySlot(160, 148)); - _inventorySlots.push_back(DMInventorySlot(208, 148)); - _inventorySlots.push_back(DMInventorySlot(255, 148)); - _inventoyItems.push_back(DMInventoryItem(0x40011, 0xE005B)); - _inventoyItems.push_back(DMInventoryItem(0x40099, 0xE001B)); - _inventoyItems.push_back(DMInventoryItem(0x4000F, 0xE000C)); - _inventoyItems.push_back(DMInventoryItem(0x40042, 0xE0012)); - _inventoyItems.push_back(DMInventoryItem(0x40044, 0xE000F)); - _inventoyItems.push_back(DMInventoryItem(0x40029, 0xE000D)); - _inventoyItems.push_back(DMInventoryItem(0x400A7, 0xE005D)); - _inventoyItems.push_back(DMInventoryItem(0x40096, 0xE001C)); - _inventoyItems.push_back(DMInventoryItem(0x40077, 0xE0010)); - _inventoyItems.push_back(DMInventoryItem(0x4008A, 0xE0033)); - _inventoyItems.push_back(DMInventoryItem(0x4004B, 0xE0045)); - _inventoyItems.push_back(DMInventoryItem(0x40054, 0xE0021)); - _inventoyItems.push_back(DMInventoryItem(0x400C6, 0xE005A)); - _inventoyItems.push_back(DMInventoryItem(0x4000B, 0xE005E)); - _inventoyItems.push_back(DMInventoryItem(0x4005F, 0xE0016)); - _inventoyItems.push_back(DMInventoryItem(0x40072, 0xE0017)); - _inventoyItems.push_back(DMInventoryItem(0x400AA, 0xE005F)); - _inventoyItems.push_back(DMInventoryItem(0x400B8, 0xE0050)); - _inventoyItems.push_back(DMInventoryItem(0x4001F, 0xE001A)); - _inventoyItems.push_back(DMInventoryItem(0x40095, 0xE0060)); - _inventoyItems.push_back(DMInventoryItem(0x40041, 0xE0053)); + for (int y = 0; y < 4; y++) { + for (int x = 0; x < 5; x++) { + _inventorySlots.push_back(DMInventorySlot( 64 + x * 48, 52 + y * 32)); + } + } + + for (int i = 0; i < 21; i++) { + _inventoryItems.push_back(kInventoryItems[i]); + } } void DuckmanInventory::openInventory() { @@ -95,8 +87,8 @@ void DuckmanInventory::openInventory() { } } - for (uint i = 0; i < _inventoyItems.size(); ++i) { - DMInventoryItem *inventoryItem = &_inventoyItems[i]; + for (uint i = 0; i < _inventoryItems.size(); ++i) { + DMInventoryItem *inventoryItem = &_inventoryItems[i]; if (_vm->_scriptResource->_properties.get(inventoryItem->_propertyId)) { DMInventorySlot *inventorySlot = findInventorySlot(inventoryItem->_objectId); if (inventorySlot) { @@ -155,9 +147,9 @@ DMInventorySlot *DuckmanInventory::findInventorySlot(uint32 objectId) { } DMInventoryItem *DuckmanInventory::findInventoryItem(uint32 objectId) { - for (uint i = 0; i < _inventoyItems.size(); ++i) - if (_inventoyItems[i]._objectId == objectId) - return &_inventoyItems[i]; + for (uint i = 0; i < _inventoryItems.size(); ++i) + if (_inventoryItems[i]._objectId == objectId) + return &_inventoryItems[i]; return 0; } diff --git a/engines/illusions/duckman/duckman_inventory.h b/engines/illusions/duckman/duckman_inventory.h index 05048f4eac..f8faf5d4bc 100644 --- a/engines/illusions/duckman/duckman_inventory.h +++ b/engines/illusions/duckman/duckman_inventory.h @@ -37,9 +37,6 @@ struct DMInventorySlot { struct DMInventoryItem { uint32 _objectId; uint32 _propertyId; - DMInventoryItem() : _objectId(0) {} - DMInventoryItem(uint32 objectId, uint32 propertyId) - : _objectId(objectId), _propertyId(propertyId) {} }; class DuckmanInventory { @@ -49,7 +46,7 @@ public: public: IllusionsEngine_Duckman *_vm; Common::Array<DMInventorySlot> _inventorySlots; - Common::Array<DMInventoryItem> _inventoyItems; + Common::Array<DMInventoryItem> _inventoryItems; void initInventory(); void openInventory(); void addInventoryItem(uint32 objectId); diff --git a/engines/illusions/duckman/menusystem_duckman.cpp b/engines/illusions/duckman/menusystem_duckman.cpp index b4ccee903d..3a10ec3f0a 100644 --- a/engines/illusions/duckman/menusystem_duckman.cpp +++ b/engines/illusions/duckman/menusystem_duckman.cpp @@ -120,7 +120,7 @@ BaseMenu *DuckmanMenuSystem::createLoadGameFailedMenu() { MenuItem *DuckmanMenuSystem::createOptionsSliderMenuItem(MenuActionUpdateSlider **action, const Common::String &text, SliderActionType type, BaseMenu *baseMenu) { int sliderValue = 0; - Common::String sliderText = "{~~~~~~~~~~~~~~~~}"; + char sliderText[] = "{~~~~~~~~~~~~~~~~}"; switch (type) { case SFX : sliderValue = _vm->_soundMan->getSfxVolume()/(256/15); break; case MUSIC : sliderValue = _vm->_soundMan->getMusicVolume()/(256/15); break; @@ -129,7 +129,7 @@ MenuItem *DuckmanMenuSystem::createOptionsSliderMenuItem(MenuActionUpdateSlider default: break; } - sliderText.setChar('|', sliderValue + 1); + sliderText[sliderValue + 1] = '|'; *action = new MenuActionUpdateSlider(this, baseMenu, type, _vm); MenuItem *menuItem = new MenuItem(text + sliderText, *action); |