You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FiestaOnlineEditor/FiestaOnlineEditor/FiestaOnlineEditor.cpp

203 lines
4.7 KiB

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#define OLC_PGEX_POPUPMENU
#include "olcPGEX_PopupMenu.h"
#define OLC_PGEX_SHNFile
#include "SHNFileDecryptor.h"
#define OLC_PGEX_TRANSFORMEDVIEW
#include "olcPGEX_TransformedView.h"
#include "FiestaOnlineEditor.h"
#include "ActionIDs.h"
FiestaOnlineEditor::FiestaOnlineEditor()
{
// Name your application
sAppName = "Fiesta Online Editor";
}
bool FiestaOnlineEditor::OnUserCreate(){
CreateLayer();
EnableLayer(1,true);
menu.SetTable(1,6);
menu["Save"];
menu["Items"].SetTable(1,4);
menu["Items"]["Item Editor"].SetID(LOAD_ITEM_EDITOR);
menu["Items"]["Drop Groups"];
menu["Items"]["Icons"];
menu["Mobs"];
menu["Abilities"];
menu["Buffs"];
menu["Reload"].SetID(RELOAD_FILE_DIALOG);
menu.Build();
sprMenu = new Sprite("assets/RetroMenu.png");
selectedPath.push_back("");
utils::datafile::Read(config,"assets/program.txt");
if(config.HasProperty("DefaultPath")){
manager.Open(&menu);
} else {
manager.Open(&dialog.GetMenu());
}
return true;
}
bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){
lastPressedTime=std::max(0.f,lastPressedTime-fElapsedTime);
if (GetKey(UP).bHeld&&lastPressedTime==0){
if(GetKey(UP).bPressed){
lastPressedTime=0.2;
} else {
lastPressedTime=0.03;
}
manager.OnUp();
}
if (GetKey(DOWN).bHeld&&lastPressedTime==0){
if(GetKey(DOWN).bPressed){
lastPressedTime=0.2;
} else {
lastPressedTime=0.03;
}
manager.OnDown();
}
if (GetKey(LEFT).bHeld&&lastPressedTime==0){
if(GetKey(LEFT).bPressed){
lastPressedTime=0.2;
} else {
lastPressedTime=0.03;
}
manager.OnLeft();
}
if (GetKey(RIGHT).bHeld&&lastPressedTime==0){
if(GetKey(RIGHT).bPressed){
lastPressedTime=0.2;
} else {
lastPressedTime=0.03;
}
manager.OnRight();
}
if (GetKey(X).bPressed){
if(appState!=LOADFOLDER){
manager.OnBack();
}
}
if (GetKey(Z).bPressed){
popup::Menu*selected;
if((selected=manager.OnConfirm())!=nullptr){
std::string sLastAction =
"Selected: " + selected->GetName() +
" ID: " + std::to_string(selected->GetID());
std::cout<<sLastAction<<std::endl;
switch(selected->GetID()){
case RELOAD_FILE_DIALOG:{
}break;
case CHANGE_LOAD_PATH:{
selectedPath.push_back(selectedPath.back()+"/"+selected->GetName());
dialog.ChangePath(selectedPath.back());
manager.Open(&dialog.GetMenu());
}break;
case GO_BACK:{
selectedPath.pop_back();
dialog.ChangePath(selectedPath.back());
manager.Open(&dialog.GetMenu());
}break;
case SELECTED_FOLDER:{
std::cout<<selectedPath.back()<<std::endl;
config["DefaultPath"].SetString(selectedPath.back());
utils::datafile::Write(config,"assets/program.txt");
ItemEditor*itemEditor=new ItemEditor(this,"Item Editor: "+selectedPath.back(),{32,32},GetScreenSize()-vi2d{64,64});
CreateWindow(itemEditor);
itemEditor->Load(selectedPath.back());
manager.Close();
}break;
case LOAD_ITEM_EDITOR:{
ItemEditor*itemEditor=new ItemEditor(this,"Item Editor: "+config["DefaultPath"].GetString(),{32,32},GetScreenSize()-vi2d{64,64});
CreateWindow(itemEditor);
itemEditor->Load(config["DefaultPath"].GetString());
manager.Close();
menuOpened=false;
}break;
}
}
}
if(GetKey(ESCAPE).bPressed&&!menuOpened){
menuOpened=true;
manager.Open(&menu);
}else
if(GetKey(ESCAPE).bPressed&&menuOpened){
menuOpened=false;
manager.Close();
}
SetDrawTarget(1);
Clear(olc::VERY_DARK_CYAN);
SetDrawTarget(nullptr);
Clear(olc::BLANK);
SetDrawTarget(1);
//BACKGROUND DRAWING
bool internalMouseFocus=false;
for(Window*w:windows){
if(!w->IsFocusedWindow()){
if(!menuOpened){
w->InternalUpdate(this,fElapsedTime);
}
w->Draw(this);
}
}
for(Window*w:windows){
if(w->IsFocusedWindow()){
if(!menuOpened){
if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this);
w->MouseFocus(this);
internalMouseFocus=true;
}
}
if(!menuOpened){
w->InternalUpdate(this,fElapsedTime);
}
w->Draw(this);
}
}
if(!menuOpened){
if(!internalMouseFocus){
for(Window*w:windows){ //A second iteration through the windows because windows without focus should only have priority after a window with focus.
if(!w->IsFocusedWindow()){
if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this);
w->MouseFocus(this);
}
}
}
}
}
SetDrawTarget(nullptr);
//FOREGROUND DRAWING
manager.Draw(sprMenu,{64,64});
return true;
}
void FiestaOnlineEditor::CreateWindow(Window*window){
for(Window*w:windows){
w->InternalRefresh(this);
}
window->InternalRefresh(this);
windows.push_back(window);
}
int main()
{
FiestaOnlineEditor demo;
if (demo.Construct(960, 360, 2, 2))
demo.Start();
return 0;
}