diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index ccc8dab2..ec011f37 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -72,6 +72,14 @@ Crawler::Crawler() std::string THEMES_CONFIG = CONFIG_PATH + "themes_config"_S; utils::datafile::Read(DATA,THEMES_CONFIG); + std::string ITEM_CONFIG = CONFIG_PATH + "item_config"_S; + utils::datafile::Read(DATA,ITEM_CONFIG); + + for(auto&key:DATA.GetProperty("ItemConfiguration").GetKeys()){ + std::string config = DATA["ItemConfiguration"][key.first].GetString(); + utils::datafile::Read(DATA,CONFIG_PATH + "item_directory"_S + config); + } + DEBUG_PATHFINDING="debug_pathfinding"_I; for(std::string&cl:DATA.GetProperty("class_list").GetValues()){ diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 59d053da..4ed301a3 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -272,6 +272,8 @@ + + @@ -314,6 +316,7 @@ + @@ -359,6 +362,10 @@ + + + + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 372ed3b2..61e9dd84 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -52,6 +52,9 @@ {f36af2ba-e884-4e50-b7bd-7e6aa9a8528c} + + {09fc0cbe-06f7-4fdf-944c-9833066bb9c8} + @@ -177,6 +180,12 @@ Header Files\Game States + + Header Files\Interface + + + Configurations + @@ -308,6 +317,9 @@ Source Files\Game States + + Source Files + @@ -362,6 +374,18 @@ Configurations\GFX + + Configurations\Items + + + Configurations\Items + + + Configurations\Items + + + Configurations\Items + diff --git a/Crawler/DEFINES.h b/Crawler/DEFINES.h index 2cb61f1a..e22db22f 100644 --- a/Crawler/DEFINES.h +++ b/Crawler/DEFINES.h @@ -13,6 +13,7 @@ #define INCLUDE_STRATEGY_ID_DATA extern safemapSTRATEGY_ID_DATA; #define INCLUDE_TILE_ANIMATION_DATA extern std::map>>TILE_ANIMATION_DATA; #define INCLUDE_GFX extern safemapGFX; +#define INCLUDE_ITEM_DATA extern safemapITEM_DATA; #define ACCESS_PLAYER Player*p=game->GetPlayer(); diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp new file mode 100644 index 00000000..29286244 --- /dev/null +++ b/Crawler/Item.cpp @@ -0,0 +1,38 @@ +#pragma once +#include "Item.h" +#include "safemap.h" +#include "DEFINES.h" +#include "Crawler.h" + +INCLUDE_game +INCLUDE_DATA + +safemapITEM_DATA; + +typedef std::string IT; + +void ItemInfo::InitializeItems(){ + for(auto&key:DATA["ItemDatabase"].GetKeys()){ + std::cout< +#include +#include +#include "olcPixelGameEngine.h" + +class Crawler; +class ItemInfo; + +class Item{ +private: + int amt; + ItemInfo*it; +}; + +class Inventory{ +public: + void AddItem(std::string it,int amt=1); + void GetItemCount(std::string it); + void UseItem(std::string it,int amt=1); + void RemoveItem(std::string it,int amt=1); +private: + static std::mapinventory; +}; + +class ItemInfo{ + std::string name; + std::string displayName; + Decal*img; + //Returns true if the item can be used, false otherwise + std::functionuseFunc; +public: + static void InitializeItems(); + /* + For the useFunc, return true if the item can be used, false otherwise. + */ + ItemInfo(std::string name,std::string displayName,Decal*img,std::functionuseFunc); +}; \ No newline at end of file diff --git a/Crawler/ItemComponent.h b/Crawler/ItemComponent.h new file mode 100644 index 00000000..9d387950 --- /dev/null +++ b/Crawler/ItemComponent.h @@ -0,0 +1,19 @@ +#pragma once +#include "MenuIconButton.h" +#include "Item.h" + +INCLUDE_game + +class ItemComponent:public MenuIconButton{ + Item::ItemName item; +public: + inline ItemComponent(geom2d::rectrect,Item::ItemName*item,MenuFunc onClick) + :MenuIconButton(rect,,onClick){} +protected: + virtual void inline Update(Crawler*game)override{ + MenuIconButton::Update(game); + } + virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ + MenuIconButton::Draw(game,parentPos,focused); + } +}; \ No newline at end of file diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index 8491b677..fc799a0e 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -45,6 +45,23 @@ void Menu::AddComponent(std::string key,MenuComponent*button){ components[key]=button; } +void Menu::CheckClickAndPerformMenuSelect(Crawler*game){ + if(game->GetMouse(Mouse::LEFT).bReleased||game->GetKey(SPACE).bReleased||game->GetKey(ENTER).bReleased){ + MenuSelect(game); + } +} + +void Menu::HoverMenuSelect(Crawler*game){ + if(selection==vi2d{-1,-1})return; + if(buttons[selection.y][selection.x]->draggable) + if(buttonHoldTime<0.3)CheckClickAndPerformMenuSelect(game); + else{ + draggingComponent=buttons[selection.y][selection.x]; + buttons[selection.y].erase(buttons[selection.y].begin()+selection.x); + } + else CheckClickAndPerformMenuSelect(game); +} + void Menu::MenuSelect(Crawler*game){ if(selection==vi2d{-1,-1})return; buttons[selection.y][selection.x]->onClick(*this,game); @@ -60,6 +77,10 @@ void Menu::MenuSelect(Crawler*game){ void Menu::Update(Crawler*game){ + buttonHoldTime+=game->GetElapsedTime(); + + HoverMenuSelect(game); + for(auto&key:buttons){ for(auto&button:key.second){ button->hovered=false; @@ -207,7 +228,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ if(game->GetMouse(0).bPressed||game->GetKey(ENTER).bPressed||game->GetKey(SPACE).bPressed){ MOUSE_NAVIGATION=game->GetMouse(0).bPressed; //If a click occurs we use mouse controls. if(!MOUSE_NAVIGATION){ - MenuSelect(game); + buttonHoldTime=0; //Key presses automatically highlight the first button if it's not highlighted. if(selection==vi2d{-1,-1}&&buttons.size()>0){ //Find the first possible button entry in the map... @@ -234,7 +255,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ index++; } } - MenuSelect(game); + buttonHoldTime=0; } } } diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 164ab4e0..ebf806f8 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -14,12 +14,16 @@ class Menu:IAttributable{ static bool MOUSE_NAVIGATION; static std::mapmenus; + float buttonHoldTime=0; std::map>buttons; //Buttons are stored in rows followed by their column order. + std::map>newButtonArrangement; //The new setup that the buttons will be at if a drag operation completes. std::vectordisplayComponents; //Components that are only for displaying purposes. safemapcomponents; //A friendly way to interrogate any component we are interested in. vi2d selection={-1,-1}; vf2d pos; //Specify the upper-left corner of the window. Using CENTERED will always put this where the upper-left corner would center the window. vf2d size; //Size in tiles (24x24), every menu will be tile-based + + MenuComponent*draggingComponent=nullptr; public: Menu(); Menu(vf2d pos,vf2d size); @@ -33,7 +37,9 @@ public: static safeunorderedmapthemes; static const vf2d CENTERED; private: + void HoverMenuSelect(Crawler*game); void MenuSelect(Crawler*game); + void CheckClickAndPerformMenuSelect(Crawler*game); static const Menu InitializeTestMenu(); static const Menu InitializeTestSubMenu(); //X (0-3), Y (0-2) for specific 9-patch tile (tiled version). diff --git a/Crawler/Version.h b/Crawler/Version.h index c9730cb2..f560b929 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1782 +#define VERSION_BUILD 1796 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/configuration.txt b/Crawler/assets/config/configuration.txt index aef3b484..9d2ce96e 100644 --- a/Crawler/assets/config/configuration.txt +++ b/Crawler/assets/config/configuration.txt @@ -39,6 +39,12 @@ class_directory = classes/ # Class list to be loaded into the game. class_list = Warrior, Thief, Ranger, Trapper, Wizard, Witch +# Items Config +item_config = items/items.txt + +# Path to items configuration +item_directory = items/ + # Whether or not to show individual data accesses from config data structure. debug_access_options = 0 diff --git a/Crawler/assets/config/gfx/themes.txt b/Crawler/assets/config/gfx/themes.txt index 7852f762..ee3f6674 100644 --- a/Crawler/assets/config/gfx/themes.txt +++ b/Crawler/assets/config/gfx/themes.txt @@ -4,6 +4,8 @@ ThemeGlobal HighlightTime = 0.2 # How much the R,G,B color components of a menu are multiplied to unfocused windows. MenuUnfocusedColorMult = 0.4 + # Amount of time to hold down an element before a press becomes a drag. + MenuHoldTime = 0.3 } Themes diff --git a/Crawler/assets/config/items/ItemCategory.txt b/Crawler/assets/config/items/ItemCategory.txt new file mode 100644 index 00000000..bcbc3ddf --- /dev/null +++ b/Crawler/assets/config/items/ItemCategory.txt @@ -0,0 +1,19 @@ +ItemCategory +{ + Consumables + { + Description = Items that will be consumed after a single use. + } + Equipment + { + Description = Gear that can be placed onto a player. + } + Accesories + { + Description = Items worn as extra items on the player. + } + Materials + { + Description = Items used as crafting materials for the forge. + } +} \ No newline at end of file diff --git a/Crawler/assets/config/items/ItemDatabase.txt b/Crawler/assets/config/items/ItemDatabase.txt new file mode 100644 index 00000000..78080fb8 --- /dev/null +++ b/Crawler/assets/config/items/ItemDatabase.txt @@ -0,0 +1,67 @@ +ItemDatabase +{ + Small Health Potion + { + ItemScript = Restore + Description = Restores 40 health points. + HP Restore = 40 + ItemCategory = Consumables + } + Medium Health Potion + { + ItemScript = Restore + Description = Restores 100 health points. + HP Restore = 100 + ItemCategory = Consumables + } + Large Health Potion + { + ItemScript = Restore + Description = Restores 320 health points. + HP Restore = 320 + ItemCategory = Consumables + } + Small Mana Potion + { + ItemScript = Restore + Description = Restores 40 mana points. + MP Restore = 40 + ItemCategory = Consumables + } + Medium Mana Potion + { + ItemScript = Restore + Description = Restores 100 mana points. + MP Restore = 100 + ItemCategory = Consumables + } + Large Mana Potion + { + ItemScript = Restore + Description = Restores 320 mana points. + MP Restore = 320 + ItemCategory = Consumables + } + Bandages + { + ItemScript = Restore + Description = Restores 10% health points. + HP % Restore = 10% + ItemCategory = Consumables + } + Green Slime Remains + { + Description = The remains of a green slime. It stares at you intently. + ItemCategory = Materials + } + Blue Slime Remains + { + Description = The remains of a blue slime. It stares at you intently. + ItemCategory = Materials + } + Red Slime Remains + { + Description = The remains of a red slime. It stares at you intently. + ItemCategory = Materials + } +} \ No newline at end of file diff --git a/Crawler/assets/config/items/ItemScript.txt b/Crawler/assets/config/items/ItemScript.txt new file mode 100644 index 00000000..1d0b7726 --- /dev/null +++ b/Crawler/assets/config/items/ItemScript.txt @@ -0,0 +1,14 @@ +ItemScript +{ + # Used with the Item Database. + # Any of these properties can be overwritten by specifying them in the main item. + + # Restores stats. + Restore + { + HP Restore = 0 + HP % Restore = 0 + MP Restore = 0 + MP % Restore = 0 + } +} \ No newline at end of file diff --git a/Crawler/assets/config/items/items.txt b/Crawler/assets/config/items/items.txt new file mode 100644 index 00000000..345e9e05 --- /dev/null +++ b/Crawler/assets/config/items/items.txt @@ -0,0 +1,6 @@ +ItemConfiguration +{ + Item Database = "ItemDatabase.txt" + Item Scripts = "ItemScript.txt" + Item Categories = "ItemCategory.txt" +} \ No newline at end of file diff --git a/Crawler/assets/items/Bandages.png b/Crawler/assets/items/Bandages.png new file mode 100644 index 00000000..59e39a98 Binary files /dev/null and b/Crawler/assets/items/Bandages.png differ diff --git a/Crawler/assets/items/Blue Slime Remains.png b/Crawler/assets/items/Blue Slime Remains.png new file mode 100644 index 00000000..6e0e3ee2 Binary files /dev/null and b/Crawler/assets/items/Blue Slime Remains.png differ diff --git a/Crawler/assets/items/Green Slime Remains.png b/Crawler/assets/items/Green Slime Remains.png new file mode 100644 index 00000000..e9f3e8a1 Binary files /dev/null and b/Crawler/assets/items/Green Slime Remains.png differ diff --git a/Crawler/assets/items/Large Health Potion.png b/Crawler/assets/items/Large Health Potion.png new file mode 100644 index 00000000..d1c87ddb Binary files /dev/null and b/Crawler/assets/items/Large Health Potion.png differ diff --git a/Crawler/assets/items/Large Mana Potion.png b/Crawler/assets/items/Large Mana Potion.png new file mode 100644 index 00000000..e99c0792 Binary files /dev/null and b/Crawler/assets/items/Large Mana Potion.png differ diff --git a/Crawler/assets/items/Medium Health Potion.png b/Crawler/assets/items/Medium Health Potion.png new file mode 100644 index 00000000..ef34e452 Binary files /dev/null and b/Crawler/assets/items/Medium Health Potion.png differ diff --git a/Crawler/assets/items/Medium Mana Potion.png b/Crawler/assets/items/Medium Mana Potion.png new file mode 100644 index 00000000..84c4cdc2 Binary files /dev/null and b/Crawler/assets/items/Medium Mana Potion.png differ diff --git a/Crawler/assets/items/Red Slime Remains.png b/Crawler/assets/items/Red Slime Remains.png new file mode 100644 index 00000000..84edf9d5 Binary files /dev/null and b/Crawler/assets/items/Red Slime Remains.png differ diff --git a/Crawler/assets/items/Small Health Potion.png b/Crawler/assets/items/Small Health Potion.png new file mode 100644 index 00000000..3d23c17c Binary files /dev/null and b/Crawler/assets/items/Small Health Potion.png differ diff --git a/Crawler/assets/items/Small Mana Potion.png b/Crawler/assets/items/Small Mana Potion.png new file mode 100644 index 00000000..605a4dd2 Binary files /dev/null and b/Crawler/assets/items/Small Mana Potion.png differ diff --git a/Crawler/safemap.h b/Crawler/safemap.h index cde6f16e..4e99745d 100644 --- a/Crawler/safemap.h +++ b/Crawler/safemap.h @@ -1,5 +1,4 @@ #pragma once -#include "olcPixelGameEngine.h" //A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection. template