Change scrollable window component's offset to be an attribute instead.
This commit is contained in:
parent
472e8eceda
commit
be0225aa97
@ -1066,6 +1066,8 @@ void Crawler::RenderHud(){
|
|||||||
if("debug_player_info"_I){
|
if("debug_player_info"_I){
|
||||||
DrawShadowStringDecal({0,128},player->GetPos().str());
|
DrawShadowStringDecal({0,128},player->GetPos().str());
|
||||||
DrawShadowStringDecal({0,136},"Spd: "+std::to_string(player->GetMoveSpdMult()));
|
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
|
INCLUDE_GFX
|
||||||
extern vi2d WINDOW_SIZE;
|
extern vi2d WINDOW_SIZE;
|
||||||
|
|
||||||
|
typedef Attribute A;
|
||||||
|
|
||||||
Menu::Menu(){}
|
Menu::Menu(){}
|
||||||
|
|
||||||
Menu::Menu(vf2d pos,vf2d size)
|
Menu::Menu(vf2d pos,vf2d size)
|
||||||
@ -80,7 +82,7 @@ void Menu::MenuSelect(Crawler*game){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Menu::Update(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();
|
buttonHoldTime+=game->GetElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +100,7 @@ void Menu::Update(Crawler*game){
|
|||||||
if(!MOUSE_NAVIGATION){
|
if(!MOUSE_NAVIGATION){
|
||||||
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true;
|
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true;
|
||||||
}else{
|
}else{
|
||||||
|
selection={-1,-1};
|
||||||
for(auto&key:buttons){
|
for(auto&key:buttons){
|
||||||
int index=0;
|
int index=0;
|
||||||
for(auto&button:key.second){
|
for(auto&button:key.second){
|
||||||
@ -201,7 +204,11 @@ void Menu::Draw(Crawler*game){
|
|||||||
vf2d offsetPos=draggingComponent->rect.pos;
|
vf2d offsetPos=draggingComponent->rect.pos;
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!MOUSE_NAVIGATION){
|
||||||
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
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{
|
}else{
|
||||||
draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
|
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());
|
game->DrawDecal({0,0},overlay.Decal());
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!MOUSE_NAVIGATION){
|
||||||
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
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{
|
}else{
|
||||||
draggingComponent->DrawDecal(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
|
draggingComponent->DrawDecal(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
|
||||||
}
|
}
|
||||||
@ -340,9 +351,11 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
for(auto&key:buttons){
|
for(auto&key:buttons){
|
||||||
int index=0;
|
int index=0;
|
||||||
for(auto&button:key.second){
|
for(auto&button:key.second){
|
||||||
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){
|
if(!button->disabled){
|
||||||
selection={index,key.first};
|
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){
|
||||||
break;
|
selection={index,key.first};
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
|
||||||
class MenuComponent{
|
class MenuComponent:IAttributable{
|
||||||
friend class Menu;
|
friend class Menu;
|
||||||
friend class MenuItemButton;
|
friend class MenuItemButton;
|
||||||
friend class ScrollableWindowComponent;
|
friend class ScrollableWindowComponent;
|
||||||
|
@ -28,4 +28,5 @@ enum class Attribute{
|
|||||||
JUMP_TOWARDS_PLAYER,
|
JUMP_TOWARDS_PLAYER,
|
||||||
HITS_UNTIL_DEATH, //When this is set, it is reduced by 1 each time the monster is hit.
|
HITS_UNTIL_DEATH, //When this is set, it is reduced by 1 each time the monster is hit.
|
||||||
INDEXED_THEME,
|
INDEXED_THEME,
|
||||||
|
SCROLL_OFFSET,
|
||||||
};
|
};
|
@ -3,15 +3,16 @@
|
|||||||
#include "MenuComponent.h"
|
#include "MenuComponent.h"
|
||||||
#include "Crawler.h"
|
#include "Crawler.h"
|
||||||
|
|
||||||
|
typedef Attribute A;
|
||||||
|
|
||||||
class ScrollableWindowComponent:public MenuComponent{
|
class ScrollableWindowComponent:public MenuComponent{
|
||||||
protected:
|
protected:
|
||||||
Renderable r;
|
Renderable r;
|
||||||
std::vector<MenuComponent*>components;
|
std::vector<MenuComponent*>components;
|
||||||
vf2d scrollOffset{};
|
|
||||||
geom2d::rect<float>bounds; //It's for the scrollbar.
|
geom2d::rect<float>bounds; //It's for the scrollbar.
|
||||||
private:
|
private:
|
||||||
inline bool OnScreen(MenuComponent*component){
|
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:
|
public:
|
||||||
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
|
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){
|
||||||
if(game->GetMouseWheel()>0){
|
if(game->GetMouseWheel()>0){
|
||||||
scrollOffset.y+="ThemeGlobal.MenuScrollWheelSpeed"_I;
|
V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuScrollWheelSpeed"_I;
|
||||||
}else{
|
}else{
|
||||||
scrollOffset.y-="ThemeGlobal.MenuScrollWheelSpeed"_I;
|
V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuScrollWheelSpeed"_I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ protected:
|
|||||||
game->SetDrawTarget(r.Sprite());
|
game->SetDrawTarget(r.Sprite());
|
||||||
game->Clear(BLANK);
|
game->Clear(BLANK);
|
||||||
for(MenuComponent*component:components){
|
for(MenuComponent*component:components){
|
||||||
component->_Draw(game,scrollOffset,focused);
|
component->_Draw(game,V(A::SCROLL_OFFSET),focused);
|
||||||
}
|
}
|
||||||
game->SetDrawTarget(prevDrawTarget);
|
game->SetDrawTarget(prevDrawTarget);
|
||||||
game->DrawSprite(parentPos,r.Sprite());
|
game->DrawSprite(parentPos,r.Sprite());
|
||||||
@ -50,11 +51,11 @@ protected:
|
|||||||
MenuComponent::DrawDecal(game,parentPos,focused);
|
MenuComponent::DrawDecal(game,parentPos,focused);
|
||||||
game->DrawRectDecal(parentPos,rect.size);
|
game->DrawRectDecal(parentPos,rect.size);
|
||||||
for(MenuComponent*component:components){
|
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{
|
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:
|
public:
|
||||||
void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){
|
void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_BUILD 2007
|
#define VERSION_BUILD 2026
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user