Skip to content

Commit

Permalink
Clone some stuff related to reading map and scripts files (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwil authored Nov 30, 2023
1 parent cebd1ae commit f865b75
Show file tree
Hide file tree
Showing 21 changed files with 1,765 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ set(GAMEENGINE_SRC
game/common/rts/specialpower.cpp
game/common/rts/team.cpp
game/common/rts/teamsinfo.cpp
game/common/skirmishbattlehonors.cpp
game/common/statemachine.cpp
game/common/staticnamekey.cpp
game/common/statscollector.cpp
Expand All @@ -266,6 +267,7 @@ set(GAMEENGINE_SRC
game/common/system/memdynalloc.cpp
game/common/system/mempool.cpp
game/common/system/mempoolfact.cpp
game/common/system/quotedprintable.cpp
game/common/system/radar.cpp
game/common/system/ramfile.cpp
game/common/system/registryget.cpp
Expand Down
277 changes: 277 additions & 0 deletions src/game/client/gui/gadget/gadgetlistbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "gadgetpushbutton.h"
#include "gadgetslider.h"
#include "gamewindow.h"
#include "gamewindowmanager.h"

void Gadget_List_Box_Set_Font(GameWindow *list_box, GameFont *font)
{
Expand Down Expand Up @@ -182,3 +183,279 @@ void Gadget_List_Box_Set_Audio_Feedback(GameWindow *list_box, bool audio_feedbac
}
}
}

int Get_List_Box_Top_Entry(_ListboxData *list)
{
for (int i = 0;; i++) {
if (list->m_listData[i].m_listHeight > list->m_displayPos) {
return i;
}

if (i >= list->m_endPos) {
break;
}
}

return 0;
}

void Adjust_Display(GameWindow *list_box, int adjustment, bool update_slider)
{
_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());
int index = adjustment + Get_List_Box_Top_Entry(data);

if (index >= 0) {
if (index >= data->m_endPos) {
index = data->m_endPos - 1;
}
} else {
index = 0;
}

if (update_slider) {
if (index <= 0) {
data->m_displayPos = 0;
} else {
data->m_displayPos = data->m_listData[index - 1].m_listHeight + 1;
}
}

if (data->m_slider != nullptr) {
_SliderData *silder_data = static_cast<_SliderData *>(data->m_slider->Win_Get_User_Data());
int slider_width;
int slider_height;
data->m_slider->Win_Get_Size(&slider_width, &slider_height);
silder_data->m_maxVal = data->m_totalHeight - (data->m_displayHeight - 2) + 1;

if (silder_data->m_maxVal < 0) {
silder_data->m_maxVal = 0;
}

GameWindow *child = data->m_slider->Win_Get_Child();
int child_width;
int child_height;
child->Win_Get_Size(&child_width, &child_height);
silder_data->m_numTicks = (float)(slider_height - child_height) / (float)silder_data->m_maxVal;

if (update_slider) {
g_theWindowManager->Win_Send_System_Msg(
data->m_slider, GSM_SET_SLIDER, silder_data->m_maxVal - data->m_displayPos, 0);
}
}
}

void Gadget_List_Box_Set_Top_Visible_Entry(GameWindow *list_box, int row)
{
if (list_box != nullptr) {
if (list_box->Win_Get_User_Data() != nullptr) {
Adjust_Display(list_box, row - Gadget_List_Box_Get_Top_Visible_Entry(list_box), true);
}
}
}

void Gadget_List_Box_Set_Selected(GameWindow *list_box, int select_count, int *select_list)
{
#ifdef GAME_DLL // temporary since we can't change the definition of Win_Send_System_Msg at this point and we can't cast a
// pointer to an unsigned int on 64 bit
if (list_box != nullptr) {
g_theWindowManager->Win_Send_System_Msg(
list_box, GLM_SET_SELECTION, select_count, reinterpret_cast<unsigned int>(select_list));
}
#endif
}

void Gadget_List_Box_Set_Item_Data(GameWindow *list_box, void *data, int row, int column)
{
#ifdef GAME_DLL // temporary since we can't change the definition of Win_Send_System_Msg at this point and we can't cast a
// pointer to an unsigned int on 64 bit
ICoord2D pos;
pos.x = column;
pos.y = row;

if (list_box != nullptr) {
g_theWindowManager->Win_Send_System_Msg(
list_box, GLM_SET_ITEM_DATA, reinterpret_cast<unsigned int>(&pos), reinterpret_cast<unsigned int>(data));
}
#endif
}

void Gadget_List_Box_Reset(GameWindow *list_box)
{
if (list_box != nullptr) {
g_theWindowManager->Win_Send_System_Msg(list_box, GLM_DEL_ALL, 0, 0);
}
}

int Gadget_List_Box_Get_Top_Visible_Entry(GameWindow *list_box)
{
if (list_box == nullptr) {
return false;
}

_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());

if (data != nullptr) {
return Get_List_Box_Top_Entry(data);
} else {
return 0;
}
}

int Gadget_List_Box_Get_Num_Columns(GameWindow *list_box)
{
if (list_box == nullptr) {
return false;
}

_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());

if (data != nullptr) {
return data->m_columns;
} else {
return 0;
}
}

int Gadget_List_Box_Get_Column_Width(GameWindow *list_box, int column)
{
if (list_box == nullptr) {
return false;
}

_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());

if (data == nullptr) {
return 0;
}

if (data->m_columns > column && column >= 0) {
return data->m_columnWidth[column];
}

return 0;
}

int Get_List_Box_Bottom_Entry(_ListboxData *list)
{
for (int i = list->m_endPos - 1;; i--) {
if (list->m_listData[i].m_listHeight == list->m_displayHeight + list->m_displayPos) {
return i;
}

if (list->m_listData[i].m_listHeight < list->m_displayHeight + list->m_displayPos && i != list->m_endPos - 1) {
return i + 1;
}

if (list->m_listData[i].m_listHeight < list->m_displayHeight + list->m_displayPos) {
return i;
}

if (i < 0) {
break;
}
}

return 0;
}

int Gadget_List_Box_Get_Bottom_Visible_Entry(GameWindow *list_box)
{
if (list_box == nullptr) {
return 0;
}

_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());

if (data != nullptr) {
return Get_List_Box_Bottom_Entry(data);
} else {
return 0;
}
}

int Gadget_List_Box_Add_Entry_Text(GameWindow *list_box, Utf16String text, int color, int row, int column, bool overwrite)
{
if (list_box != nullptr) {
if (text.Is_Empty()) {
text = U_CHAR(" ");
}

_AddMessageStruct entry;
entry.row = row;
entry.column = column;
entry.type = 1;
entry.data = &text;
entry.overwrite = overwrite;
entry.width = -1;
entry.height = -1;
_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());

bool list_exceeded = data->m_listLength <= data->m_endPos;
int i = list_exceeded ? 0 : 1;
int bottom = Gadget_List_Box_Get_Bottom_Visible_Entry(list_box);
int index = 0;
#ifdef GAME_DLL // temporary since we can't change the definition of Win_Send_System_Msg at this point and we can't cast a
// pointer to an unsigned int on 64 bit
index = static_cast<int>(
g_theWindowManager->Win_Send_System_Msg(list_box, GLM_ADD_ENTRY, reinterpret_cast<unsigned int>(&entry), color));
#endif
if (data->m_scrollIfAtEnd && (index - bottom) == i && Gadget_List_Box_Is_Full(list_box)) {
Gadget_List_Box_Set_Bottom_Visible_Entry(list_box, index);
}

return index;
} else {
return -1;
}
}

int Gadget_List_Box_Add_Entry_Image(
GameWindow *list_box, const Image *image, int row, int column, int width, int height, bool overwrite, int color)
{
_AddMessageStruct entry;
entry.row = row;
entry.column = column;
entry.type = 2;
entry.data = const_cast<Image *>(image);
entry.overwrite = overwrite;
entry.width = width;
entry.height = height;
int index = 0;
#ifdef GAME_DLL // temporary since we can't change the definition of Win_Send_System_Msg at this point and we can't cast a
// pointer to an unsigned int on 64 bit
index = static_cast<int>(
g_theWindowManager->Win_Send_System_Msg(list_box, GLM_ADD_ENTRY, reinterpret_cast<unsigned int>(&entry), color));
#endif
return index;
}

void Gadget_List_Box_Set_Selected(GameWindow *list_box, int select_index)
{
#ifdef GAME_DLL // temporary since we can't change the definition of Win_Send_System_Msg at this point and we can't cast a
// pointer to an unsigned int on 64 bit
if (list_box != nullptr) {
g_theWindowManager->Win_Send_System_Msg(
list_box, GLM_SET_SELECTION, reinterpret_cast<unsigned int>(&select_index), 1);
}
#endif
}

void Gadget_List_Box_Set_Bottom_Visible_Entry(GameWindow *list_box, int row)
{
if (list_box != nullptr) {
if (list_box->Win_Get_User_Data() != nullptr) {
Adjust_Display(list_box, row - Gadget_List_Box_Get_Bottom_Visible_Entry(list_box) + 1, true);
}
}
}

bool Gadget_List_Box_Is_Full(GameWindow *list_box)
{
if (list_box == nullptr) {
return false;
}

_ListboxData *data = static_cast<_ListboxData *>(list_box->Win_Get_User_Data());
return data != nullptr
&& data->m_listData[Get_List_Box_Bottom_Entry(data)].m_listHeight >= data->m_displayPos + data->m_displayHeight - 5;
}
Loading

0 comments on commit f865b75

Please sign in to comment.