Added window header

master
sigonasr2 1 year ago
parent c5e40dae1b
commit bc55854b83
  1. 6
      FiestaOnlineEditor/FiestaOnlineEditor.cpp
  2. 27
      FiestaOnlineEditor/ItemEditor.cpp
  3. 3
      FiestaOnlineEditor/ItemEditor.h
  4. 26
      FiestaOnlineEditor/Window.cpp
  5. 4
      FiestaOnlineEditor/Window.h

@ -107,16 +107,16 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){
std::cout<<selectedPath.back()<<std::endl; std::cout<<selectedPath.back()<<std::endl;
config["DefaultPath"].SetString(selectedPath.back()); config["DefaultPath"].SetString(selectedPath.back());
utils::datafile::Write(config,"assets/program.txt"); utils::datafile::Write(config,"assets/program.txt");
ItemEditor*itemEditor=new ItemEditor(this,{32,32},GetScreenSize()-vi2d{64,64}); ItemEditor*itemEditor=new ItemEditor(this,"Item Editor: "+selectedPath.back(),{32,32},GetScreenSize()-vi2d{64,64});
CreateWindow(itemEditor); CreateWindow(itemEditor);
itemEditor->Load(selectedPath.back()); itemEditor->Load(selectedPath.back());
manager.Close(); manager.Close();
}break; }break;
case LOAD_ITEM_EDITOR:{ case LOAD_ITEM_EDITOR:{
ItemEditor*itemEditor=new ItemEditor(this,{32,32},GetScreenSize()-vi2d{64,64}); ItemEditor*itemEditor=new ItemEditor(this,"Item Editor: "+config["DefaultPath"].GetString(),{32,32},GetScreenSize()-vi2d{64,64});
CreateWindow(itemEditor); CreateWindow(itemEditor);
itemEditor->Load(config["DefaultPath"].GetString()); itemEditor->Load(config["DefaultPath"].GetString());
itemEditor=new ItemEditor(this,{0,0},GetScreenSize()-vi2d{64,64}); itemEditor=new ItemEditor(this,"Item Editor: "+config["DefaultPath"].GetString(),{0,0},GetScreenSize()-vi2d{64,64});
CreateWindow(itemEditor); CreateWindow(itemEditor);
itemEditor->Load(config["DefaultPath"].GetString()); itemEditor->Load(config["DefaultPath"].GetString());
}break; }break;

@ -1,16 +1,35 @@
#include "FiestaOnlineEditor.h" #include "FiestaOnlineEditor.h"
ItemEditor::ItemEditor(FiestaOnlineEditor*pge,vi2d pos,vi2d size) ItemEditor::ItemEditor(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size)
:Window(pge,pos,size){} :Window(pge,windowTitle,pos,size){}
void ItemEditor::Load(std::string basePath){ void ItemEditor::Load(std::string basePath){
ItemInfo.Load(basePath+"/ItemInfo.shn"); ItemInfo.Load(basePath+"/ItemInfo.shn");
} }
void ItemEditor::Update(FiestaOnlineEditor*pge,float fElapsedTime){ void ItemEditor::Update(FiestaOnlineEditor*pge,float fElapsedTime){
bool updateRequired=false;
if(pge->GetKey(UP).bHeld){
pos.y-=32*fElapsedTime;
updateRequired=true;
}
if(pge->GetKey(DOWN).bHeld){
pos.y+=32*fElapsedTime;
updateRequired=true;
}
if(pge->GetKey(RIGHT).bHeld){
pos.x+=32*fElapsedTime;
updateRequired=true;
}
if(pge->GetKey(LEFT).bHeld){
pos.x-=32*fElapsedTime;
updateRequired=true;
}
if(updateRequired){
InternalRefresh(pge);
}
} }
void ItemEditor::Refresh(FiestaOnlineEditor*pge){ void ItemEditor::Refresh(FiestaOnlineEditor*pge){
pge->DrawRect(vi2d{32,size.y-9},{16,16},WHITE); pge->DrawRect(pos,{16,16},WHITE);
} }

@ -7,8 +7,9 @@ class FiestaOnlineEditor;
class ItemEditor:public Window{ class ItemEditor:public Window{
SHNFile ItemInfo,ItemInfoServer,ItemViewInfo; SHNFile ItemInfo,ItemInfoServer,ItemViewInfo;
vf2d pos={64,64};
public: public:
ItemEditor(FiestaOnlineEditor*pge,vi2d pos,vi2d size); ItemEditor(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size);
void Load(std::string basePath); void Load(std::string basePath);
void Refresh(FiestaOnlineEditor*pge)override; void Refresh(FiestaOnlineEditor*pge)override;
void Update(FiestaOnlineEditor*pge,float fElapsedTime)override; void Update(FiestaOnlineEditor*pge,float fElapsedTime)override;

@ -2,27 +2,43 @@
Window*Window::focusedWindow=nullptr; Window*Window::focusedWindow=nullptr;
Window::Window(FiestaOnlineEditor*pge,vi2d pos,vi2d size) Window::Window(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size)
:pos(pos),size(size){ :pos(pos),size(size),windowTitle(windowTitle){
focusedWindow=this; focusedWindow=this;
sprWindow=new Sprite(size.x,size.y); sprWindow=new Sprite(size.x,size.y+headerHeight);
decWindow=new Decal(sprWindow); decWindow=new Decal(sprWindow);
//InternalRefresh(pge); //InternalRefresh(pge);
} }
void Window::InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime){ void Window::InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime){
if(this==focusedWindow){
Update(pge,fElapsedTime); Update(pge,fElapsedTime);
} }
}
void Window::InternalRefresh(FiestaOnlineEditor*pge){ void Window::InternalRefresh(FiestaOnlineEditor*pge){
Sprite*prevDrawTarget=pge->GetDrawTarget(); Sprite*prevDrawTarget=pge->GetDrawTarget();
pge->SetDrawTarget(sprWindow); pge->SetDrawTarget(sprWindow);
//Window background drawing
if(focusedWindow==this){ if(focusedWindow==this){
pge->FillRect({0,0},size,VERY_DARK_BLUE); pge->FillRect({0,headerHeight},size,VERY_DARK_BLUE);
} else { } else {
pge->FillRect({0,0},size,VERY_DARK_GREY); pge->FillRect({0,headerHeight},size,VERY_DARK_GREY);
} }
//All other drawing functions should go here.
pos.y+=headerHeight;
Refresh(pge); Refresh(pge);
pos.y-=headerHeight;
if(focusedWindow==this){
pge->FillRect({0,0},{size.x,headerHeight},VERY_DARK_BLUE);
} else {
pge->FillRect({0,0},{size.x,headerHeight},VERY_DARK_GREY);
}
pge->DrawString({2,2},windowTitle,CYAN);
pge->DrawLine({1,10},{size.x-2,10},DARK_CYAN,0xFFFFFF00);
decWindow->Update(); decWindow->Update();
pge->SetDrawTarget(prevDrawTarget); pge->SetDrawTarget(prevDrawTarget);
} }

@ -7,12 +7,14 @@ class Window{
private: private:
vi2d pos; vi2d pos;
Decal*decWindow; Decal*decWindow;
const int headerHeight=12;
protected: protected:
vi2d size; vi2d size;
Sprite*sprWindow; Sprite*sprWindow;
static Window*focusedWindow; static Window*focusedWindow;
std::string windowTitle="";
public: public:
Window(FiestaOnlineEditor*pge,vi2d pos,vi2d size); Window(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size);
void InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime); void InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime);
virtual void Update(FiestaOnlineEditor*pge,float fElapsedTime)=0; virtual void Update(FiestaOnlineEditor*pge,float fElapsedTime)=0;
virtual void Refresh(FiestaOnlineEditor*pge)=0; virtual void Refresh(FiestaOnlineEditor*pge)=0;

Loading…
Cancel
Save