From bc55854b835a992c4109775ea81f59818a0367a8 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 5 Aug 2023 23:05:07 -0500 Subject: [PATCH] Added window header --- FiestaOnlineEditor/FiestaOnlineEditor.cpp | 6 ++--- FiestaOnlineEditor/ItemEditor.cpp | 27 ++++++++++++++++++---- FiestaOnlineEditor/ItemEditor.h | 3 ++- FiestaOnlineEditor/Window.cpp | 28 ++++++++++++++++++----- FiestaOnlineEditor/Window.h | 4 +++- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/FiestaOnlineEditor/FiestaOnlineEditor.cpp b/FiestaOnlineEditor/FiestaOnlineEditor.cpp index 5e61ff1..818da9a 100644 --- a/FiestaOnlineEditor/FiestaOnlineEditor.cpp +++ b/FiestaOnlineEditor/FiestaOnlineEditor.cpp @@ -107,16 +107,16 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){ std::cout<Load(selectedPath.back()); manager.Close(); }break; 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); 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); itemEditor->Load(config["DefaultPath"].GetString()); }break; diff --git a/FiestaOnlineEditor/ItemEditor.cpp b/FiestaOnlineEditor/ItemEditor.cpp index 228af81..8e2380e 100644 --- a/FiestaOnlineEditor/ItemEditor.cpp +++ b/FiestaOnlineEditor/ItemEditor.cpp @@ -1,16 +1,35 @@ #include "FiestaOnlineEditor.h" -ItemEditor::ItemEditor(FiestaOnlineEditor*pge,vi2d pos,vi2d size) - :Window(pge,pos,size){} +ItemEditor::ItemEditor(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size) + :Window(pge,windowTitle,pos,size){} void ItemEditor::Load(std::string basePath){ ItemInfo.Load(basePath+"/ItemInfo.shn"); } 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){ - pge->DrawRect(vi2d{32,size.y-9},{16,16},WHITE); + pge->DrawRect(pos,{16,16},WHITE); } \ No newline at end of file diff --git a/FiestaOnlineEditor/ItemEditor.h b/FiestaOnlineEditor/ItemEditor.h index 7cc58f3..2d137d4 100644 --- a/FiestaOnlineEditor/ItemEditor.h +++ b/FiestaOnlineEditor/ItemEditor.h @@ -7,8 +7,9 @@ class FiestaOnlineEditor; class ItemEditor:public Window{ SHNFile ItemInfo,ItemInfoServer,ItemViewInfo; + vf2d pos={64,64}; public: - ItemEditor(FiestaOnlineEditor*pge,vi2d pos,vi2d size); + ItemEditor(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size); void Load(std::string basePath); void Refresh(FiestaOnlineEditor*pge)override; void Update(FiestaOnlineEditor*pge,float fElapsedTime)override; diff --git a/FiestaOnlineEditor/Window.cpp b/FiestaOnlineEditor/Window.cpp index df1998d..4e2ba89 100644 --- a/FiestaOnlineEditor/Window.cpp +++ b/FiestaOnlineEditor/Window.cpp @@ -2,27 +2,43 @@ Window*Window::focusedWindow=nullptr; -Window::Window(FiestaOnlineEditor*pge,vi2d pos,vi2d size) -:pos(pos),size(size){ +Window::Window(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size) +:pos(pos),size(size),windowTitle(windowTitle){ focusedWindow=this; - sprWindow=new Sprite(size.x,size.y); + sprWindow=new Sprite(size.x,size.y+headerHeight); decWindow=new Decal(sprWindow); //InternalRefresh(pge); } void Window::InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime){ - Update(pge,fElapsedTime); + if(this==focusedWindow){ + Update(pge,fElapsedTime); + } } void Window::InternalRefresh(FiestaOnlineEditor*pge){ Sprite*prevDrawTarget=pge->GetDrawTarget(); pge->SetDrawTarget(sprWindow); + + //Window background drawing if(focusedWindow==this){ - pge->FillRect({0,0},size,VERY_DARK_BLUE); + pge->FillRect({0,headerHeight},size,VERY_DARK_BLUE); } 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); + 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(); pge->SetDrawTarget(prevDrawTarget); } diff --git a/FiestaOnlineEditor/Window.h b/FiestaOnlineEditor/Window.h index 557b2ff..abc39da 100644 --- a/FiestaOnlineEditor/Window.h +++ b/FiestaOnlineEditor/Window.h @@ -7,12 +7,14 @@ class Window{ private: vi2d pos; Decal*decWindow; + const int headerHeight=12; protected: vi2d size; Sprite*sprWindow; static Window*focusedWindow; + std::string windowTitle=""; public: - Window(FiestaOnlineEditor*pge,vi2d pos,vi2d size); + Window(FiestaOnlineEditor*pge,std::string windowTitle,vi2d pos,vi2d size); void InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime); virtual void Update(FiestaOnlineEditor*pge,float fElapsedTime)=0; virtual void Refresh(FiestaOnlineEditor*pge)=0;