diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 68f0b3e..35c5bb5 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -631,7 +631,7 @@ set(src_redalert ./redalert/mapscript.cpp ./redalert/txtprnt.cpp ./redalert/tilesetxml.cpp -) + "redalert/sidebareditor.cpp") set(src_external #glew diff --git a/code/redalert/conquer.cpp b/code/redalert/conquer.cpp index f14908c..bf3c4ce 100644 --- a/code/redalert/conquer.cpp +++ b/code/redalert/conquer.cpp @@ -346,6 +346,8 @@ void Main_Game(int argc, char * argv[]) if (Map_Edit_Loop()) { break; } + + Imgui_Dialog_Function = NULL; } } #else diff --git a/code/redalert/image.h b/code/redalert/image.h index 4b1caed..f7e4e93 100644 --- a/code/redalert/image.h +++ b/code/redalert/image.h @@ -15,6 +15,10 @@ struct Image_t { Image_t(); ~Image_t(); + unsigned int GetImageForHouse(int houseId, int shapeId, int frame = 0) { + return HouseImages[houseId].image[shapeId][frame]; + } + char name[512]; int64_t namehash; HouseImage_t HouseImages[MAX_HOUSE_COLORS]; diff --git a/code/redalert/init.cpp b/code/redalert/init.cpp index 803ca6a..203c383 100644 --- a/code/redalert/init.cpp +++ b/code/redalert/init.cpp @@ -3065,6 +3065,10 @@ static void Init_Bootstrap_Mixfiles(void) bool ok = MFCD::Cache("LOCAL.MIX"); assert(ok); + new MFCD("edhi.mix", &FastKey); + ok = MFCD::Cache("edhi.mix"); + assert(ok); + #if 1 new MFCD("HIRES.MIX", &FastKey); ok = MFCD::Cache("HIRES.MIX"); diff --git a/code/redalert/mapedit.cpp b/code/redalert/mapedit.cpp index c74fb02..8bc356c 100644 --- a/code/redalert/mapedit.cpp +++ b/code/redalert/mapedit.cpp @@ -137,6 +137,8 @@ void MapEditClass::One_Time(void) { MouseClass::One_Time(); + editorSidebar.init(); + /* ** The map: a single large "button" */ @@ -567,45 +569,43 @@ void MapEditClass::AI(KeyNumType & input, int x, int y) } } + if (editorSidebar.mainmenu_selection != -1) { + /* + ** Turn off placement mode + */ + if (PendingObject) { + if (BaseBuilding) { + Cancel_Base_Building(); + } + else { + Cancel_Placement(); + } + } + + /* + ** Turn off trigger placement mode + */ + if (CurTrigger) { + Stop_Trigger_Placement(); + } + + /* + ** Unselect object & hide popup controls + */ + if (CurrentObject.Count()) { + CurrentObject[0]->Unselect(); + Popup_Controls(); + } + Main_Menu(); + input = KN_NONE; + editorSidebar.mainmenu_selection = -1; + } + /* ** Trap special editing keys; if one is detected, set 'input' to 0 to ** prevent a conflict with parent's AI(). */ switch (input) { - /* - ** F2/RMOUSE = pop up main menu - */ - case KN_RMOUSE: - - /* - ** Turn off placement mode - */ - if (PendingObject) { - if (BaseBuilding) { - Cancel_Base_Building(); - } else { - Cancel_Placement(); - } - } - - /* - ** Turn off trigger placement mode - */ - if (CurTrigger) { - Stop_Trigger_Placement(); - } - - /* - ** Unselect object & hide popup controls - */ - if (CurrentObject.Count()) { - CurrentObject[0]->Unselect(); - Popup_Controls(); - } - Main_Menu(); - input = KN_NONE; - break; - /* ** F6 = toggle passable/impassable display */ @@ -1391,6 +1391,9 @@ void MapEditClass::Draw_It(bool forced) return; } + editorSidebar.draw_it(); + + /* ** Display the total value of all Tiberium on the map. */ @@ -1508,46 +1511,6 @@ bool MapEditClass::Mouse_Moved(void) return(retcode); } -int mainmenu_selection = -1; -int mainmenu_x = -1; -int mainmenu_y = -1; - -void Imgui_MapEdit_MainMenu(void) { - bool toolActive = false; - - ImGuiStyle& style = ImGui::GetStyle(); - style.FramePadding = ImVec2(0, 0); - ImGui::SetNextWindowSize(ImVec2(150, 200)); - ImGui::SetNextWindowPos(ImVec2(mainmenu_x, mainmenu_y)); - ImGui::Begin("MainMenu", &toolActive, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar); - if (ImGui::Button("New Scenario")) { - mainmenu_selection = 0; - } - if(ImGui::Button("Load Scenario")) { - mainmenu_selection = 1; - } - if (ImGui::Button("Save Scenario")) { - mainmenu_selection = 2; - } - if (ImGui::Button("Size Map")) { - mainmenu_selection = 3; - } - if (ImGui::Button("Add Game Object")) { - mainmenu_selection = 4; - } - if (ImGui::Button("Scenario Options")) { - mainmenu_selection = 5; - } - if (ImGui::Button("AI Options")) { - mainmenu_selection = 6; - } - if (ImGui::Button("Play Scenario")) { - mainmenu_selection = 7; - } - ImGui::End(); -} - - /*************************************************************************** * MapEditClass::Main_Menu -- main menu processor for map editor * * * @@ -1569,17 +1532,12 @@ void MapEditClass::Main_Menu(void) bool process; // menu stays up while true int rc; - Imgui_Dialog_Function = Imgui_MapEdit_MainMenu; - mainmenu_selection = -1; - mainmenu_x = UserInput.Mouse.X; - mainmenu_y = UserInput.Mouse.Y; - /* ** Main Menu loop */ Override_Mouse_Shape(MOUSE_NORMAL); // display default mouse cursor process = true; - while (process) { + { /* ** Invoke game callback, to update music @@ -1590,7 +1548,7 @@ void MapEditClass::Main_Menu(void) ** Invoke menu */ Hide_Mouse(); // Do_Menu assumes the mouse is already hidden - selection = mainmenu_selection; + selection = editorSidebar.mainmenu_selection; g_globalKeyNumType = KN_NONE; g_globalKeyFlags = 0; @@ -1600,16 +1558,6 @@ void MapEditClass::Main_Menu(void) Show_Mouse(); - if (UnknownKey==KN_ESC || g_globalKeyNumType == KN_RMOUSE) { -// jmarshall - consume the RMOUSE DOWN so it doesn't bring up the context menu again. - Buttons->Input(); -// jmarshall end - break; - } - - if (selection == -1) - continue; - /* ** Process selection */ @@ -1739,13 +1687,8 @@ void MapEditClass::Main_Menu(void) Start_Scenario(Scen.ScenarioName); return; } - - mainmenu_selection = selection = -1; - break; } - Imgui_Dialog_Function = nullptr; - /* ** Restore the display: ** - Clear HIDPAGE to erase any spurious drawing done by the menu system diff --git a/code/redalert/mapedit.h b/code/redalert/mapedit.h index caa2715..d506f43 100644 --- a/code/redalert/mapedit.h +++ b/code/redalert/mapedit.h @@ -47,6 +47,7 @@ #include "function.h" #include +#include "sidebareditor.h" /* ** This is the maximum # of ObjectTypeClasses the editor has to deal with. @@ -312,6 +313,8 @@ class MapEditClass : public MouseClass static char HealthBuf[20]; GaugeClass *BaseGauge; TextLabelClass *BaseLabel; + + SidebarEditor editorSidebar; public: static MissionType MapEditMissions[]; }; diff --git a/code/redalert/sidebareditor.cpp b/code/redalert/sidebareditor.cpp new file mode 100644 index 0000000..ede4c6d --- /dev/null +++ b/code/redalert/sidebareditor.cpp @@ -0,0 +1,81 @@ +// sidebareditor.cpp +// +#include "imgui.h" +#include "function.h" +#include "image.h" + +void SidebarEditor::init() { + metalplt = LoadEditorImage("metalplt.shp"); + + mainmenu_selection = -1; +} + +Image_t* SidebarEditor::LoadEditorImage(const char* name) { + const void* shapefile = MFCD::Retrieve(name); + if(shapefile == NULL) { + return NULL; + } + + int width = Get_Build_Frame_Width(shapefile); + int height = Get_Build_Frame_Height(shapefile); + unsigned char *shape_pointer = (unsigned char*)Build_Frame(shapefile, 0, _ShapeBuffer); + short frameCount = Get_Build_Frame_Count(shapefile); + + Image_t* shape_image = Image_CreateImageFrom8Bit(name, width, height, shape_pointer); + for(int i = 1; i < frameCount; i++) { + shape_pointer = (unsigned char*)Build_Frame(shapefile, i, _ShapeBuffer); + Image_Add8BitImage(shape_image, 0, i, width, height, shape_pointer, NULL); + } + + return shape_image; +} + +void SidebarEditor::draw_it(void) { + bool toolActive; + + ImGuiStyle& style = ImGui::GetStyle(); + style.FramePadding = ImVec2(0, 0); + + if (ImGui::BeginMainMenuBar()) + { + if (ImGui::BeginMenu("File")) + { + if (ImGui::MenuItem("New Scenario")) { mainmenu_selection = 0; } + if (ImGui::MenuItem("Load Scenario")) { mainmenu_selection = 1; } + if (ImGui::MenuItem("Save Scenario")) { mainmenu_selection = 2; } + + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Map")) + { + if (ImGui::MenuItem("Size Map")) { mainmenu_selection = 3; } + if (ImGui::MenuItem("Scenario Options")) { mainmenu_selection = 5; } + if (ImGui::MenuItem("AI Options")) { mainmenu_selection = 6; } + ImGui::EndMenu(); + } + if (ImGui::BeginMenu("Objects")) + { + if (ImGui::MenuItem("Add Game Object")) { mainmenu_selection = 4; } + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Run")) + { + if (ImGui::MenuItem("Play Scenario")) { mainmenu_selection = 7; } + ImGui::EndMenu(); + } + + ImGui::EndMainMenuBar(); + } + + + //ImGui::SetNextWindowSize(ImVec2(160, ScreenHeight)); + //ImGui::SetNextWindowPos(ImVec2(ScreenWidth-160, 0)); + //ImGui::Begin("EditorSidebar", &toolActive, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar); + // // Map Preview + // //ImGui::Image((ImTextureID)metalplt->GetImageForHouse(0, 2), ImVec2(160, 192)); + // + // + // + //ImGui::End(); +} \ No newline at end of file diff --git a/code/redalert/sidebareditor.h b/code/redalert/sidebareditor.h new file mode 100644 index 0000000..856727b --- /dev/null +++ b/code/redalert/sidebareditor.h @@ -0,0 +1,16 @@ +// sidebareditor.h +// + +struct Image_t; + +class SidebarEditor { +public: + void init(void); + void draw_it(void); + + int mainmenu_selection; +private: + Image_t* LoadEditorImage(const char* name); +private: + Image_t* metalplt; +}; \ No newline at end of file diff --git a/edhi.mix b/edhi.mix new file mode 100644 index 0000000..d5cdc00 Binary files /dev/null and b/edhi.mix differ