Added new big overlay system.

This commit is contained in:
Justin Marshall
2020-07-24 15:00:19 -07:00
parent b72170fd11
commit 908f6c9c3e
34 changed files with 663 additions and 7 deletions
+2
View File
@@ -638,6 +638,8 @@ set(src_redalert
./redalert/mapscript.cpp
./redalert/txtprnt.cpp
./redalert/tilesetxml.cpp
"redalert/bigoverlay.cpp"
"redalert/bigoverlay.h"
"redalert/sidebareditor.cpp"
"redalert/rendertexture.cpp"
"redalert/rendertexture.h"
+269
View File
@@ -0,0 +1,269 @@
// bigoverlay.cpp
//
#include "function.h"
#include "bigoverlay.h"
#include "image.h"
#include <imgui.h>
BigOverlayManager bigOverlayManager;
/*
==================
BigOverlay::BigOverlay
==================
*/
BigOverlay::BigOverlay() {
image = NULL;
enabled = false;
}
/*
======================
BigOverlay::Place
======================
*/
void BigOverlay::Place(int screenx, int screeny) {
COORDINATE lightCoord;
CellClass::ConvertIsoCoordsToScreen(screenx, screeny);
position = Map.Pixel_To_Coord(screenx, screeny);
enabled = true;
}
/*
======================
BigOverlay::GetRenderPosition
======================
*/
bool BigOverlay::GetRenderPosition(int& x, int& y) {
Map.Coord_To_Pixel(position, x, y);
CellClass::ConvertCoordsToIsometric(x, y);
return true;
}
/*
======================
BigOverlay::draw_it
======================
*/
void BigOverlay::draw_it(void) {
int screenx, screeny;
GetRenderPosition(screenx, screeny);
GL_RenderImage(image, screenx, screeny, image->width, image->height);
}
/*
====================
BigOverlayManager::BigOverlayManager
====================
*/
BigOverlayManager::BigOverlayManager() {
Reset();
}
/*
====================
BigOverlayManager::Init
====================
*/
void BigOverlayManager::Init(void) {
for(int i = 1; i <= 22; i++)
{
char temp[512];
sprintf(temp, "BIGOVERLAY_WCLIFF%d", i);
RegisterBigOverlay(THEATER_SNOW, temp);
}
}
/*
====================
BigOverlayManager::RegisterBigOverlay
====================
*/
void BigOverlayManager::RegisterBigOverlay(int theater, const char* name) {
const char* hdname = Tileset_FindHDTexture(theater, name, 0, 0);
char filename[2048];
sprintf(filename, "DATA/ART/TEXTURES/SRGB/RED_ALERT/TILESETS/%s/%s", Theaters[theater].Name, hdname);
BigOverlayType_t type;
type.image = Image_LoadImage(filename);
if (type.image == NULL)
return;
bigOverlayTypes.push_back(type);
}
/*
====================
BigOverlayManager::BigOverlayManager
====================
*/
void BigOverlayManager::Reset(void) {
memset(bigOverlays, 0, sizeof(bigOverlays));
}
/*
====================
BigOverlayManager::Render
====================
*/
void BigOverlayManager::Render(void) {
for(int i = 0; i < MAX_WORLD_BIGOVERLAYS; i++) {
if (!bigOverlays[i].IsEnabled())
continue;
bigOverlays[i].draw_it();
}
}
/*
====================
BigOverlayManager::AdjustTile
====================
*/
void BigOverlayManager::AdjustTile(BigOverlay* bigOverlay, int direction) {
int index = bigOverlay->GetIndex() + direction;
if(index < 0)
{
index = bigOverlayTypes.size() - 1;
}
else if(index > bigOverlayTypes.size() - 1) {
index = 0;
}
Image_t* image = bigOverlayTypes[index].image;
bigOverlay->SetImage(index, image);
}
/*
====================
BigOverlayManager::BigOverlayManager
====================
*/
BigOverlay* BigOverlayManager::AllocateBigOverlay(void) {
for (int i = 0; i < MAX_WORLD_BIGOVERLAYS; i++) {
if (!bigOverlays[i].IsEnabled()) {
bigOverlays[i].SetEnabled(true);
bigOverlays[i].SetOverlayNum(i);
return &bigOverlays[i];
}
}
assert(!"Too many big overlays in the scene!");
return NULL;
}
/*
====================
BigOverlayManager::Editor_PlaceNewBigOverlay
====================
*/
BigOverlay* BigOverlayManager::Editor_PlaceNewBigOverlay(void) {
BigOverlay* big = NULL;
bool processing = true;
editor_selectedbigoverlay = 0;
if(bigOverlayTypes.size() == 0) {
assert(!"bigOverlayTypes size == 0");
}
while (processing)
{
g_globalKeyNumType = KN_NONE;
g_globalKeyFlags = 0;
UserInput.Process_Input();
Map.Render();
bool toolActive;
ImGuiStyle& style = ImGui::GetStyle();
style.FramePadding = ImVec2(0, 0);
ImGui::SetNextWindowSize(ImVec2(480, 220));
ImGui::SetNextWindowPos(ImVec2((ScreenWidth / 2) - 240, (ScreenHeight / 2) - 110));
ImGui::Begin("Place Big Overlay", &toolActive, ImGuiWindowFlags_AlwaysAutoResize /*| ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground*/);
Image_t* image = bigOverlayTypes[editor_selectedbigoverlay].image;
ImVec2 overlayImageSize(image->width, image->height);
ImGui::Text("Preview");
ImGui::Image((ImTextureID)image->GetImageForHouse(0, 0, 0), overlayImageSize);
if(ImGui::Button("Prev")) {
editor_selectedbigoverlay--;
if(editor_selectedbigoverlay < 0) {
editor_selectedbigoverlay = bigOverlayTypes.size() - 1;
}
}
ImGui::SameLine();
if(ImGui::Button("Next")) {
editor_selectedbigoverlay++;
if(editor_selectedbigoverlay > bigOverlayTypes.size() - 1) {
editor_selectedbigoverlay = 0;
}
}
if(ImGui::Button("Cancel")) {
processing = false;
}
ImGui::SameLine();
if(ImGui::Button("Ok")) {
big = AllocateBigOverlay();
big->SetImage(editor_selectedbigoverlay, image);
processing = false;
}
ImGui::End();
Call_Back();
}
return big;
}
/*
====================
BigOverlayManager::Write_Scenerio_Lights
====================
*/
void BigOverlayManager::Write_Scenerio(CCINIClass* ini) {
ini->Clear("BigOverlay");
// Write out the lights.
for (int i = 0; i < MAX_WORLD_BIGOVERLAYS; i++) {
if (bigOverlays[i].IsEnabled() == false) {
continue;
}
char buffer[2048];
char name[256];
sprintf(buffer, "%d,%d", bigOverlays[i].GetPosition(), bigOverlays[i].GetIndex());
sprintf(name, "%d", i);
ini->Put_String("BigOverlay", name, buffer);
}
}
/*
====================
BigOverlayManager::Read_Scenerio
====================
*/
void BigOverlayManager::Read_Scenerio(CCINIClass* ini) {
char buf[2048];
Reset();
int len = ini->Entry_Count("BigOverlay");
for (int index = 0; index < len; index++) {
char const* entry = ini->Get_Entry("BigOverlay", index);
/*
** Get a lighting entry.
*/
ini->Get_String("BigOverlay", entry, NULL, buf, sizeof(buf));
BigOverlay* bigOverlay = AllocateBigOverlay();
bigOverlay->SetPosition(atoi(strtok(buf, ",")));
int in = atoi(strtok(NULL, ","));
Image_t* image = bigOverlayTypes[in].image;
bigOverlay->SetImage(in, image);
}
}
+74
View File
@@ -0,0 +1,74 @@
// bigoverlay.h
//
#include <vector>
#define MAX_WORLD_BIGOVERLAYS 2300 // This is just a random number, increase as you want.
struct Image_t;
//
// BigOverlayType_t
//
struct BigOverlayType_t {
Image_t* image;
};
class BigOverlay {
friend class BigOverlayManager;
public:
BigOverlay();
int GetIndex(void) { return index; }
void SetImage(int index, Image_t* image) { this->index = index; this->image = image; }
void Place(int screenx, int screeny);
bool GetRenderPosition(int& x, int& y);
void draw_it(void);
Image_t* GetImage(void) { return image; }
void SetEnabled(bool enabled) { this->enabled = enabled; }
COORDINATE GetPosition() { return position; }
protected:
void SetPosition(COORDINATE position) { this->position = position; }
void SetOverlayNum(int overlayNum) { this->overlayNum = overlayNum; }
bool IsEnabled(void) { return enabled; }
private:
int overlayNum;
COORDINATE position;
Image_t* image;
bool enabled;
int index;
};
class BigOverlayManager {
public:
BigOverlayManager();
// Init's all the big overlay types.
void Init(void);
// Resets all big overlays.
void Reset(void);
// Render's all the active big overlays.
void Render(void);
void Read_Scenerio(CCINIClass* ini);
void Write_Scenerio(CCINIClass* ini);
// Adjusts the tile image.
void AdjustTile(BigOverlay* bigOverlay, int direction);
// Allocates a big overlay
BigOverlay* AllocateBigOverlay(void);
BigOverlay *Editor_PlaceNewBigOverlay(void);
private:
void RegisterBigOverlay(int theater, const char* name);
BigOverlay bigOverlays[MAX_WORLD_BIGOVERLAYS];
std::vector<BigOverlayType_t> bigOverlayTypes;
int editor_selectedbigoverlay;
};
extern BigOverlayManager bigOverlayManager;
+2 -1
View File
@@ -1630,7 +1630,8 @@ void TemplateTypeClass::Init(TheaterType theater)
Image_t *hdImage = Load_StampHD(theater, fullname, tplate.ImageData);
if (hdImage)
{
Get_Stamp_Size(tplate.ImageData, hdImage->renderwidth, hdImage->renderheight);
//Get_Stamp_Size(tplate.ImageData, hdImage->renderwidth, hdImage->renderheight);
hdImage->isoTileInfo = (IsoTile *)tplate.ImageData;
((void const*&)tplate.HDImageData) = hdImage;
}
else
+10 -3
View File
@@ -1101,11 +1101,13 @@ void CellClass::Draw_It(int x, int y, bool objects)
int cellx = Cell_X(cell);
int celly = Cell_Y(cell);
if (cellx < Map.MapCellX || celly < Map.MapCellY) {
GL_SetColor(0.35, 0.35, 0.35);
//GL_SetColor(0.35, 0.35, 0.35);
return;
}
if (cellx >= Map.MapCellX + Map.MapCellWidth || celly >= Map.MapCellY + Map.MapCellHeight) {
GL_SetColor(0.35, 0.35, 0.35);
//GL_SetColor(0.35, 0.35, 0.35);
return;
}
CellCount++;
@@ -1326,7 +1328,12 @@ void CellClass::Draw_It(int x, int y, bool objects)
** it means nothing.
*/
case RTTI_OVERLAYTYPE:
OverlayTypeClass::As_Reference(((OverlayTypeClass *)Map.PendingObject)->Type).Draw_It(x, y, OverlayData);
{
int xx = x;
int yy = y;
ConvertCoordsToIsometric(xx, yy);
OverlayTypeClass::As_Reference(((OverlayTypeClass*)Map.PendingObject)->Type).Draw_It(xx, yy, OverlayData);
}
break;
/*
+4
View File
@@ -88,6 +88,7 @@
#include "function.h"
#include "vortex.h"
#include "image.h"
#include "bigoverlay.h"
struct AdjancentWeight_t {
AdjancentWeight_t() {
@@ -2042,6 +2043,9 @@ void DisplayClass::CacheVisibleCells(void) {
if (HidPage.Lock()) {
Redraw_Icons();
// Big Overlays come after tiles.
bigOverlayManager.Render();
/*
** Draw the infantry bodies in this special layer.
*/
+44 -3
View File
@@ -57,6 +57,8 @@
#include "imgui.h"
#include "function.h"
#include "bigoverlay.h"
#include "image.h"
#ifdef SCENARIO_EDITOR
@@ -110,6 +112,7 @@ MapEditClass::MapEditClass(void)
LastHouse = HOUSE_GOOD;
GrabbedObject = 0;
GrabbedLight = nullptr;
GrabbedBigOverlay = nullptr;
Scen.Waypoint[WAYPT_HOME] = 0;
CurrentCell = 0;
CurTeam = NULL;
@@ -546,11 +549,16 @@ void MapEditClass::AI(KeyNumType & input, int x, int y)
//CELL template_cell = (ZoneCell + ZoneOffset);
//char tmp[12];
//sprintf(tmp, "%d , %d", Cell_X(template_cell), Cell_Y(template_cell));
//GL_DrawText(6, 64, 64, tmp);
//GL_DrawText(6, 64, 64, tmp);
rc = Mouse_Moved();
if (Keyboard->Down(KN_LMOUSE) && rc) {
if (GrabbedLight)
if (GrabbedBigOverlay)
{
GrabbedBigOverlay->Place(Get_Mouse_X(), Get_Mouse_Y());
GrabbedBigOverlay = nullptr;
}
else if (GrabbedLight)
{
GrabbedLight->PlaceLight(Get_Mouse_X(), Get_Mouse_Y());
GrabbedLight = nullptr;
@@ -727,6 +735,10 @@ void MapEditClass::AI(KeyNumType & input, int x, int y)
if (PendingObject) {
Place_Prev();
}
else if (GrabbedBigOverlay)
{
bigOverlayManager.AdjustTile(GrabbedBigOverlay, -1);
}
input = KN_NONE;
break;
@@ -737,6 +749,10 @@ void MapEditClass::AI(KeyNumType & input, int x, int y)
if (PendingObject) {
Place_Next();
}
else if (GrabbedBigOverlay)
{
bigOverlayManager.AdjustTile(GrabbedBigOverlay, 1);
}
input = KN_NONE;
break;
@@ -1479,7 +1495,24 @@ bool MapEditClass::Mouse_Moved(void)
const ObjectTypeClass * objtype = NULL;
bool retcode = false;
if (GrabbedLight != NULL)
if (GrabbedBigOverlay != NULL)
{
Image_t* image = GrabbedBigOverlay->GetImage();
int screenx = Get_Mouse_X();
int screeny = Get_Mouse_Y();
CellClass::ConvertIsoCoordsToScreen(screenx, screeny);
COORDINATE position = Map.Pixel_To_Coord(screenx, screeny);
Map.Coord_To_Pixel(position, screenx, screeny);
CellClass::ConvertCoordsToIsometric(screenx, screeny);
GL_RenderImage(image, screenx, screeny, image->width, image->height);
old_mx = Get_Mouse_X();
old_my = Get_Mouse_Y();
old_zonecell = ZoneCell;
return true;
}
else if (GrabbedLight != NULL)
{
GL_RenderImage(lightManager.GetLightEditorIcon(), Get_Mouse_X(), Get_Mouse_Y(), 32, 32);
old_mx = Get_Mouse_X();
@@ -1697,6 +1730,14 @@ void MapEditClass::Main_Menu(void)
GrabbedLight->isPending = true;
break;
case 9:
GrabbedBigOverlay = bigOverlayManager.Editor_PlaceNewBigOverlay();
if (GrabbedBigOverlay)
{
GrabbedBigOverlay->SetEnabled(false);
}
break;
/*
** Test-drive this scenario
*/
+2
View File
@@ -50,6 +50,7 @@
#include "sidebareditor.h"
class Light_t;
class BigOverlay;
/*
** This is the maximum # of ObjectTypeClasses the editor has to deal with.
@@ -273,6 +274,7 @@ class MapEditClass : public MouseClass
HousesType LastHouse; // house of last item picked
Light_t *GrabbedLight;
BigOverlay* GrabbedBigOverlay;
/*
** Variables for grabbing/moving objects
+3
View File
@@ -65,6 +65,7 @@
#include "ccdde.h"
#include "audiomix.h"
#include "image.h"
#include "bigoverlay.h"
extern bool SpawnedFromWChat;
#endif
@@ -2274,6 +2275,7 @@ bool Read_Scenario_INI(char * fname, bool )
Scen.Percent = ini.Get_Int(BASIC, "Percent", Scen.Percent);
lightManager.Read_Scenerio_Lights(&ini);
bigOverlayManager.Read_Scenerio(&ini);
/*
** Read in the specific information for each of the house types. This creates
@@ -2646,6 +2648,7 @@ void Write_Scenario_INI(char * fname)
ini.Put_Int(BASIC, "Percent", Scen.Percent);
lightManager.Write_Scenerio_Lights(&ini);
bigOverlayManager.Write_Scenerio(&ini);
HouseClass::Write_INI(ini);
TeamTypeClass::Write_INI(ini);
TriggerTypeClass::Write_INI(ini);
+1
View File
@@ -69,6 +69,7 @@ void SidebarEditor::draw_it(void) {
{
Debug_LockScroll = true;
if (ImGui::MenuItem("Add Game Object")) { mainmenu_selection = 4; }
if (ImGui::MenuItem("Add Big Overlay Object")) { mainmenu_selection = 9; }
ImGui::EndMenu();
}
+2
View File
@@ -69,6 +69,7 @@
#include <vector>
#include "HOUSECOLOR.H"
#include "IMGUTIL.H"
#include "bigoverlay.h"
GLuint backbuffer_texture = -1;
//byte* backbuffer_data;
@@ -889,6 +890,7 @@ void Create_Main_Window ( HANDLE instance , int command_show , int width , int h
VQA_Init();
lightManager.Init();
bigOverlayManager.Init();
}