Implement dummy items and scrollablewindowcomponent setup

pull/28/head
sigonasr2 1 year ago
parent e3d0283fcb
commit 1c4ec84d75
  1. 21
      Crawler/Crawler.cpp
  2. 1
      Crawler/Crawler.vcxproj
  3. 3
      Crawler/Crawler.vcxproj.filters
  4. 21
      Crawler/InventoryWindow.cpp
  5. 20
      Crawler/Menu.cpp
  6. 4
      Crawler/MenuComponent.h
  7. 2
      Crawler/MenuItemButton.h
  8. 68
      Crawler/ScrollableWindowComponent.h
  9. 2
      Crawler/Version.h
  10. 100
      Crawler/assets/config/items/ItemDatabase.txt
  11. BIN
      Crawler/assets/items/Dummy Item 1.png
  12. BIN
      Crawler/assets/items/Dummy Item 10.png
  13. BIN
      Crawler/assets/items/Dummy Item 11.png
  14. BIN
      Crawler/assets/items/Dummy Item 12.png
  15. BIN
      Crawler/assets/items/Dummy Item 13.png
  16. BIN
      Crawler/assets/items/Dummy Item 14.png
  17. BIN
      Crawler/assets/items/Dummy Item 15.png
  18. BIN
      Crawler/assets/items/Dummy Item 16.png
  19. BIN
      Crawler/assets/items/Dummy Item 17.png
  20. BIN
      Crawler/assets/items/Dummy Item 18.png
  21. BIN
      Crawler/assets/items/Dummy Item 19.png
  22. BIN
      Crawler/assets/items/Dummy Item 2.png
  23. BIN
      Crawler/assets/items/Dummy Item 20.png
  24. BIN
      Crawler/assets/items/Dummy Item 3.png
  25. BIN
      Crawler/assets/items/Dummy Item 4.png
  26. BIN
      Crawler/assets/items/Dummy Item 5.png
  27. BIN
      Crawler/assets/items/Dummy Item 6.png
  28. BIN
      Crawler/assets/items/Dummy Item 7.png
  29. BIN
      Crawler/assets/items/Dummy Item 8.png
  30. BIN
      Crawler/assets/items/Dummy Item 9.png

@ -108,6 +108,27 @@ bool Crawler::OnUserCreate(){
Inventory::AddItem("Small Health Potion",16);
Inventory::AddItem("Large Health Potion",3);
Inventory::AddItem("Medium Mana Potion",1);
Inventory::AddItem("Dummy Item 1",78);
Inventory::AddItem("Dummy Item 2",3);
Inventory::AddItem("Dummy Item 3",5);
Inventory::AddItem("Dummy Item 4",8);
Inventory::AddItem("Dummy Item 5",6);
Inventory::AddItem("Dummy Item 6",3);
Inventory::AddItem("Dummy Item 7",5);
Inventory::AddItem("Dummy Item 8",8);
Inventory::AddItem("Dummy Item 9",3);
Inventory::AddItem("Dummy Item 10",4);
Inventory::AddItem("Dummy Item 11",8);
Inventory::AddItem("Dummy Item 12",3);
Inventory::AddItem("Dummy Item 13",6);
Inventory::AddItem("Dummy Item 14",192);
Inventory::AddItem("Dummy Item 15",35);
Inventory::AddItem("Dummy Item 16",6);
Inventory::AddItem("Dummy Item 17",3);
Inventory::AddItem("Dummy Item 18",1);
Inventory::AddItem("Dummy Item 19",8);
Inventory::AddItem("Dummy Item 20",4);
Inventory::AddItem("Bandages",10);
Inventory::AddItem("Blue Slime Remains",22);
InitializeGraphics();

@ -295,6 +295,7 @@
<ClInclude Include="resource.h" />
<ClInclude Include="resource1.h" />
<ClInclude Include="safemap.h" />
<ClInclude Include="ScrollableWindowComponent.h" />
<ClInclude Include="State.h" />
<ClInclude Include="Theme.h" />
<ClInclude Include="TMXParser.h" />

@ -186,6 +186,9 @@
<ClInclude Include="olcPGEX_Graphics2D.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScrollableWindowComponent.h">
<Filter>Header Files\Interface</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">

@ -6,39 +6,42 @@
#include "Item.h"
#include "MenuItemButton.h"
#include "MenuLabel.h"
#include "ScrollableWindowComponent.h"
INCLUDE_GFX
typedef Attribute A;
Menu*Menu::InitializeInventoryWindow(){
constexpr int invWidth=5;
constexpr int invHeight=3;
constexpr int totalItemSlots=invWidth*invHeight;
constexpr int initialInvHeight=3;
constexpr int itemSpacing=8;
constexpr int buttonSize=24;
constexpr int totalSpacing=buttonSize+itemSpacing;
vf2d windowSize={totalSpacing*invWidth-itemSpacing+1,totalSpacing*(invHeight+1)-itemSpacing+24};
vf2d windowSize={totalSpacing*invWidth-itemSpacing+1,totalSpacing*(3+1)-itemSpacing+24};
Menu*inventoryWindow=new Menu(CENTERED,windowSize);
ScrollableWindowComponent*inventory=new ScrollableWindowComponent(INVENTORY,{{0,0},{windowSize.x,totalSpacing*3-itemSpacing}},nullptr,[](MenuFuncData data){});
inventoryWindow->AddComponent("inventory",inventory);
MenuFunc useItemFunc=[](MenuFuncData data){
MenuItemButton*button=(MenuItemButton*)data.component;
button->UseItem();
};
for(int y=0;y<invHeight;y++){
for(int x=0;x<invWidth;x++){
for(int i=0;i<Inventory::get("Consumables").size();i++){
int x=i%invWidth;
int y=i/invWidth;
int itemIndex=y*invWidth+x;
MenuItemButton*button=new MenuItemButton{INVENTORY,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc};
inventoryWindow->AddComponent("item"+std::to_string(itemIndex),button);
}
inventory->AddComponent(inventoryWindow,"item"+std::to_string(itemIndex),button);
}
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,invHeight*totalSpacing-4},windowSize),"",false,true};
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,initialInvHeight*totalSpacing-4},windowSize),"",false,true};
inventoryWindow->AddComponent("itemName",itemNameLabel);
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,invHeight*totalSpacing+itemSpacing},{windowSize.x-4,windowSize.y-108}),"",true,true};
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,initialInvHeight*totalSpacing+itemSpacing},{windowSize.x-4,windowSize.y-108}),"",true,true};
inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel);
return inventoryWindow;

@ -131,12 +131,16 @@ void Menu::Update(Crawler*game){
KeyboardButtonNavigation(game,pos);
for(auto&key:buttons){
for(auto&button:key.second){
if(button->renderInMain){
button->Update(game);
}
}
}
for(auto&component:displayComponents){
if(component->renderInMain){
component->Update(game);
}
}
};
void Menu::Draw(Crawler*game){
@ -152,23 +156,31 @@ void Menu::Draw(Crawler*game){
game->Clear(BLANK);
for(auto&key:buttons){
for(auto&button:key.second){
if(button->renderInMain){
button->Draw(game,{0,0},this==Menu::stack.back());
}
}
}
for(auto&component:displayComponents){
if(component->renderInMain){
component->Draw(game,{0,0},this==Menu::stack.back());
}
}
game->SetPixelMode(prevMode);
game->SetDrawTarget(nullptr);
r.Decal()->Update();
game->DrawDecal(pos,r.Decal());
for(auto&key:buttons){
for(auto&button:key.second){
button->DrawDecal(game,{0,0},this==Menu::stack.back());
if(button->renderInMain){
button->DrawDecal(game,pos,this==Menu::stack.back());
}
}
}
for(auto&component:displayComponents){
component->DrawDecal(game,{0,0},this==Menu::stack.back());
if(component->renderInMain){
component->DrawDecal(game,pos,this==Menu::stack.back());
}
}
if(GetCurrentTheme().IsScaled()){
@ -195,9 +207,9 @@ void Menu::Draw(Crawler*game){
game->DrawDecal({0,0},overlay.Decal());
if(!MOUSE_NAVIGATION){
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
draggingComponent->DrawDecal(game,-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
draggingComponent->DrawDecal(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
}else{
draggingComponent->DrawDecal(game,-pos-offsetPos+game->GetMousePos(),this==Menu::stack.back());
draggingComponent->DrawDecal(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
}
}
};

@ -4,8 +4,8 @@
class MenuComponent{
friend class Menu;
friend class MenuItemButton;
friend class ScrollableWindowComponent;
MenuType menuDest;
bool selectable=true;
private:
float hoverEffect=0;
protected:
@ -16,6 +16,8 @@ protected:
MenuFunc onClick;
MenuType parentMenu=MenuType::ENUM_END;
bool hovered=false;
bool selectable=true;
bool renderInMain=true; //If set to false, this component is the responsibility of some other windowing system and won't be rendered or updated via the main window loop.
public:
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuFunc onClick,bool selectable=true);
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true);

@ -63,7 +63,7 @@ protected:
if(valid){
std::string quantityText="x"+std::to_string(Inventory::GetItemCount(invRef.at(inventoryIndex)));
vf2d textSize=vf2d(game->GetTextSizeProp(quantityText))*0.5;
game->DrawShadowStringDecal(Menu::menus[parentMenu]->pos+parentPos+rect.pos+rect.size-textSize,quantityText,WHITE,BLACK,{0.5,0.5},0.5);
game->DrawShadowStringDecal(parentPos+rect.pos+rect.size-textSize,quantityText,WHITE,BLACK,{0.5,0.5},0.5);
}
}
virtual inline MenuComponent*PickUpDraggableItem()override{

@ -0,0 +1,68 @@
#pragma once
#include "Menu.h"
#include "MenuComponent.h"
#include "Crawler.h"
class ScrollableWindowComponent:public MenuComponent{
protected:
Renderable r;
std::vector<MenuComponent*>components;
vf2d scrollOffset{};
geom2d::rect<float>bounds;
public:
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
:MenuComponent(parent,rect,"",onClick,false){
r.Create(rect.size.x,rect.size.y);
}
protected:
virtual inline void Update(Crawler*game)override{
MenuComponent::Update(game);
for(MenuComponent*component:components){
component->Update(game);
}
}
virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{
MenuComponent::Draw(game,parentPos,focused);
Sprite*prevDrawTarget=game->GetDrawTarget();
game->SetDrawTarget(r.Sprite());
game->Clear(BLANK);
for(MenuComponent*component:components){
component->Draw(game,scrollOffset,focused);
}
game->SetDrawTarget(prevDrawTarget);
game->DrawSprite(parentPos,r.Sprite());
}
virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{
MenuComponent::DrawDecal(game,parentPos,focused);
game->DrawRectDecal(parentPos,rect.size);
for(MenuComponent*component:components){
component->DrawDecal(game,parentPos+scrollOffset,focused);
}
}
public:
void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){
components.push_back(button);
button->renderInMain=false; //Now we are in control!
if(button->rect.pos.x<bounds.pos.x){
float sizeIncrease=bounds.pos.x-button->rect.pos.x;
bounds.size.x+=sizeIncrease;
bounds.pos.x=button->rect.pos.x;
}
if(button->rect.right().start.x>bounds.right().start.x){
float sizeIncrease=button->rect.right().start.x-bounds.right().start.x;
bounds.size.x+=sizeIncrease;
}
if(button->rect.pos.y<bounds.pos.y){
float sizeIncrease=bounds.pos.y-button->rect.pos.y;
bounds.size.y+=sizeIncrease;
bounds.pos.y=button->rect.pos.y;
}
if(button->rect.bottom().start.y>bounds.bottom().start.y){
float sizeIncrease=button->rect.bottom().start.y-bounds.bottom().start.y;
bounds.size.y+=sizeIncrease;
}
parentMenu->AddComponent(key,button);
}
};

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 1954
#define VERSION_BUILD 1972
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -42,6 +42,106 @@ ItemDatabase
MP Restore = 320
ItemCategory = Consumables
}
Dummy Item 1
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 2
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 3
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 4
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 5
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 6
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 7
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 8
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 9
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 10
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 11
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 12
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 13
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 14
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 15
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 16
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 17
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 18
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 19
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Dummy Item 20
{
Description = Does nothing apparently.
ItemCategory = Consumables
}
Bandages
{
ItemScript = Restore

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

Loading…
Cancel
Save