9-patch interface code added
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
3723835cc7
commit
17838ffb8b
@ -98,7 +98,7 @@ bool Crawler::OnUserCreate(){
|
||||
std::string imgFile=DATA["Images"][key].GetString();
|
||||
std::cout<<"Loading image "+imgFile+"..."<<std::endl;
|
||||
GFX[imgFile];
|
||||
if(GFX[imgFile].Load("GFX_Prefix"_S+imgFile)!=rcode::OK){
|
||||
if(GFX[imgFile].Load("GFX_Prefix"_S+imgFile,nullptr,false,false)!=rcode::OK){
|
||||
std::cout<<" WARNING! Failed to load "+imgFile+"!";
|
||||
throw;
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
#include "Crawler.h"
|
||||
#include "Menu.h"
|
||||
#include "DEFINES.h"
|
||||
#include "safemap.h"
|
||||
|
||||
bool Menu::MOUSE_NAVIGATION=true;
|
||||
std::vector<Menu*>Menu::stack;
|
||||
std::map<MenuType,Menu>Menu::menus;
|
||||
|
||||
INCLUDE_GFX
|
||||
|
||||
Menu::Menu(){}
|
||||
|
||||
Menu::Menu(vf2d size)
|
||||
@ -60,40 +64,7 @@ void Menu::Update(Crawler*game){
|
||||
}
|
||||
}
|
||||
|
||||
KeyboardButtonNavigation(game);
|
||||
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);
|
||||
//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...
|
||||
int firstInd=-1;
|
||||
for(auto&key:buttons){
|
||||
if(buttons[key.first].size()>0){
|
||||
firstInd=key.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(firstInd!=-1){ //This means we found a valid menu item. If we didn't find one don't highlight any menu item...
|
||||
selection={0,firstInd};
|
||||
}
|
||||
}
|
||||
}else{//Mouse click.
|
||||
selection={-1,-1};
|
||||
for(auto&key:buttons){
|
||||
int index=0;
|
||||
for(auto&button:key.second){
|
||||
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+upperLeftPos,button->rect.size},game->GetMousePos())){
|
||||
selection={index,key.first};
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
MenuSelect(game);
|
||||
}
|
||||
}
|
||||
KeyboardButtonNavigation(game,upperLeftPos);
|
||||
for(auto&key:buttons){
|
||||
for(auto&button:key.second){
|
||||
button->Update(game);
|
||||
@ -103,7 +74,28 @@ void Menu::Update(Crawler*game){
|
||||
|
||||
void Menu::Draw(Crawler*game){
|
||||
vf2d upperLeftPos=game->GetScreenSize()/2-size/2;
|
||||
game->FillRectDecal(upperLeftPos,size,VERY_DARK_BLUE);
|
||||
|
||||
vf2d patchSize=vf2d{float("Interface.9PatchSize"_i[0]),float("Interface.9PatchSize"_i[1])};
|
||||
|
||||
//Upper-Left
|
||||
game->DrawPartialDecal(upperLeftPos-patchSize,patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*0},patchSize);
|
||||
//Upper-Right
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{size.x,-patchSize.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*0},patchSize);
|
||||
//Bottom-Left
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{-patchSize.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*2},patchSize);
|
||||
//Bottom-Right
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{size.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*2},patchSize);
|
||||
//Top
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{0,-patchSize.y},patchSize+vf2d{size.x,0},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*0},patchSize);
|
||||
//Left
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{-patchSize.x,0},patchSize+vf2d{0,size.y},GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*1},patchSize);
|
||||
//Right
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{size.x,0},patchSize+vf2d{0,size.y},GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*1},patchSize);
|
||||
//Bottom
|
||||
game->DrawPartialDecal(upperLeftPos+vf2d{0,size.y},patchSize+vf2d{size.x,0},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*2},patchSize);
|
||||
//Center
|
||||
game->DrawPartialDecal(upperLeftPos,patchSize+size,GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*1},patchSize);
|
||||
|
||||
for(auto&key:buttons){
|
||||
for(auto&button:key.second){
|
||||
button->Draw(game,upperLeftPos);
|
||||
@ -116,7 +108,7 @@ void Menu::OpenMenu(MenuType menu){
|
||||
stack.push_back(&(menus[menu]));
|
||||
}
|
||||
|
||||
void Menu::KeyboardButtonNavigation(Crawler*game){
|
||||
void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
||||
if(game->GetKey(RIGHT).bPressed){
|
||||
if(selection==vi2d{-1,-1})return;
|
||||
MOUSE_NAVIGATION=false;
|
||||
@ -209,4 +201,37 @@ void Menu::KeyboardButtonNavigation(Crawler*game){
|
||||
selection.x=-1;
|
||||
}
|
||||
}
|
||||
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);
|
||||
//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...
|
||||
int firstInd=-1;
|
||||
for(auto&key:buttons){
|
||||
if(buttons[key.first].size()>0){
|
||||
firstInd=key.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(firstInd!=-1){ //This means we found a valid menu item. If we didn't find one don't highlight any menu item...
|
||||
selection={0,firstInd};
|
||||
}
|
||||
}
|
||||
}else{//Mouse click.
|
||||
selection={-1,-1};
|
||||
for(auto&key:buttons){
|
||||
int index=0;
|
||||
for(auto&button:key.second){
|
||||
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){
|
||||
selection={index,key.first};
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
MenuSelect(game);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,6 @@ private:
|
||||
static const Menu InitializeTestMenu();
|
||||
static const Menu InitializeTestSubMenu();
|
||||
|
||||
void KeyboardButtonNavigation(Crawler*game);
|
||||
void KeyboardButtonNavigation(Crawler*game,vf2d menuPos);
|
||||
};
|
||||
|
||||
|
BIN
Crawler/assets/9patch.png
Normal file
BIN
Crawler/assets/9patch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 618 B |
@ -6,6 +6,12 @@ WINDOW_SIZE = 360,240
|
||||
# Graphics Loading Config
|
||||
gfx_config = gfx/gfx.txt
|
||||
|
||||
Interface
|
||||
{
|
||||
# The size of each side of the 9-patch menu sprite.
|
||||
9PatchSize = 24,24
|
||||
}
|
||||
|
||||
# Map Files Loading Config
|
||||
map_config = levels.txt
|
||||
|
||||
|
@ -39,6 +39,8 @@ Images
|
||||
GFX_SkillOverlayIcon = skill_overlay_icon.png
|
||||
GFX_SkillOverlayIconOverlay = skill_overlay_icon_overlay.png
|
||||
|
||||
GFX_9Patch = 9patch.png
|
||||
|
||||
# Ability Icons
|
||||
GFX_Warrior_BattleCry_Icon = Ability Icons/battlecry.png
|
||||
GFX_Warrior_Block_Icon = Ability Icons/block.png
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Generated with GIMP Palette Export */
|
||||
.Untitled { color: rgb(55, 7, 15) }
|
||||
.Untitled { color: #37070f }
|
||||
.Untitled { color: rgb(95, 23, 31) }
|
||||
.Untitled { color: rgb(143, 39, 23) }
|
||||
.Untitled { color: rgb(199, 48, 55) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user