Change scrollable window component's offset to be an attribute instead.

pull/28/head
sigonasr2 1 year ago
parent 472e8eceda
commit be0225aa97
  1. 2
      Crawler/Crawler.cpp
  2. 19
      Crawler/Menu.cpp
  3. 2
      Crawler/MenuComponent.h
  4. 1
      Crawler/MonsterAttribute.h
  5. 15
      Crawler/ScrollableWindowComponent.h
  6. 2
      Crawler/Version.h

@ -1066,6 +1066,8 @@ void Crawler::RenderHud(){
if("debug_player_info"_I){
DrawShadowStringDecal({0,128},player->GetPos().str());
DrawShadowStringDecal({0,136},"Spd: "+std::to_string(player->GetMoveSpdMult()));
DrawShadowStringDecal({0,4},"Selection: "+Menu::menus[INVENTORY]->selection.str());
DrawShadowStringDecal({0,12},"Button Hold Time: "+std::to_string(Menu::menus[INVENTORY]->buttonHoldTime));
}
}

@ -13,6 +13,8 @@ const vf2d Menu::CENTERED = {-456,-456};
INCLUDE_GFX
extern vi2d WINDOW_SIZE;
typedef Attribute A;
Menu::Menu(){}
Menu::Menu(vf2d pos,vf2d size)
@ -80,7 +82,7 @@ void Menu::MenuSelect(Crawler*game){
}
void Menu::Update(Crawler*game){
if(draggingComponent==nullptr&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){
if(draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){
buttonHoldTime+=game->GetElapsedTime();
}
@ -98,6 +100,7 @@ void Menu::Update(Crawler*game){
if(!MOUSE_NAVIGATION){
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true;
}else{
selection={-1,-1};
for(auto&key:buttons){
int index=0;
for(auto&button:key.second){
@ -201,7 +204,11 @@ void Menu::Draw(Crawler*game){
vf2d offsetPos=draggingComponent->rect.pos;
if(!MOUSE_NAVIGATION){
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
draggingComponent->Draw(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
vf2d drawOffset{};
if(selectedComponent->parentComponent!=nullptr){
drawOffset+=selectedComponent->parentComponent->V(A::SCROLL_OFFSET);
}
draggingComponent->Draw(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
}else{
draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
}
@ -211,7 +218,11 @@ void Menu::Draw(Crawler*game){
game->DrawDecal({0,0},overlay.Decal());
if(!MOUSE_NAVIGATION){
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
draggingComponent->DrawDecal(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
vf2d drawOffset{};
if(selectedComponent->parentComponent!=nullptr){
drawOffset+=selectedComponent->parentComponent->V(A::SCROLL_OFFSET);
}
draggingComponent->DrawDecal(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
}else{
draggingComponent->DrawDecal(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
}
@ -340,10 +351,12 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
for(auto&key:buttons){
int index=0;
for(auto&button:key.second){
if(!button->disabled){
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){
selection={index,key.first};
break;
}
}
index++;
}
}

@ -1,7 +1,7 @@
#pragma once
#include "Menu.h"
class MenuComponent{
class MenuComponent:IAttributable{
friend class Menu;
friend class MenuItemButton;
friend class ScrollableWindowComponent;

@ -28,4 +28,5 @@ enum class Attribute{
JUMP_TOWARDS_PLAYER,
HITS_UNTIL_DEATH, //When this is set, it is reduced by 1 each time the monster is hit.
INDEXED_THEME,
SCROLL_OFFSET,
};

@ -3,15 +3,16 @@
#include "MenuComponent.h"
#include "Crawler.h"
typedef Attribute A;
class ScrollableWindowComponent:public MenuComponent{
protected:
Renderable r;
std::vector<MenuComponent*>components;
vf2d scrollOffset{};
geom2d::rect<float>bounds; //It's for the scrollbar.
private:
inline bool OnScreen(MenuComponent*component){
return geom2d::overlaps(rect,geom2d::rect<float>{component->rect.pos+scrollOffset,component->rect.size});
return geom2d::overlaps(rect,geom2d::rect<float>{component->rect.pos+V(A::SCROLL_OFFSET),component->rect.size});
}
public:
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
@ -24,9 +25,9 @@ protected:
if(game->GetMouseWheel()!=0){
if(game->GetMouseWheel()>0){
scrollOffset.y+="ThemeGlobal.MenuScrollWheelSpeed"_I;
V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuScrollWheelSpeed"_I;
}else{
scrollOffset.y-="ThemeGlobal.MenuScrollWheelSpeed"_I;
V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuScrollWheelSpeed"_I;
}
}
@ -41,7 +42,7 @@ protected:
game->SetDrawTarget(r.Sprite());
game->Clear(BLANK);
for(MenuComponent*component:components){
component->_Draw(game,scrollOffset,focused);
component->_Draw(game,V(A::SCROLL_OFFSET),focused);
}
game->SetDrawTarget(prevDrawTarget);
game->DrawSprite(parentPos,r.Sprite());
@ -50,11 +51,11 @@ protected:
MenuComponent::DrawDecal(game,parentPos,focused);
game->DrawRectDecal(parentPos,rect.size);
for(MenuComponent*component:components){
component->_DrawDecal(game,parentPos+scrollOffset,focused);
component->_DrawDecal(game,parentPos+V(A::SCROLL_OFFSET),focused);
}
}
virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+child->rect.pos+scrollOffset,child->rect.size},game->GetMousePos());
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+child->rect.pos+V(A::SCROLL_OFFSET),child->rect.size},game->GetMousePos());
}
public:
void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){

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

Loading…
Cancel
Save