fix: redrawing admin company buttons; hang windows to parent window; code reworked

This commit is contained in:
chucky-n-ice
2024-06-03 21:02:07 +02:00
parent a52c2f1413
commit 349322cad0
6 changed files with 61 additions and 22 deletions

View File

@@ -28,9 +28,15 @@
namespace citymania {
bool _novahost = true;
bool _admin = false;
IniFile *_inilogin = NULL;
/* admin company buttons */
bool _admin = false;
int ACB_left = 0;
int ACB_top = 0;
int ACB_width = 0;
int ACB_Location[3][15];
static const int HTTPBUFLEN = 1024;
static const int MAX_COMMUNITY_STRING_LEN = 128;
@@ -1200,9 +1206,9 @@ static const NWidgetPart _nested_admin_window_widgets[] = {
static const NWidgetPart _nested_admin_company_window_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_RED, ACB_COMPANY_CAPTION), SetDataTip(CM_STR_ACB_COMPANY_ADMIN_CAPTION, 0),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
NWidget(WWT_CAPTION,COLOUR_END, ACB_COMPANY_CAPTION),
SetDataTip(CM_STR_ACB_COMPANY_ADMIN_CAPTION, 0),
SetMinimalSize(10,17),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY), SetFill(0, 1),
NWidget(NWID_HORIZONTAL),
@@ -1242,7 +1248,7 @@ static const NWidgetPart _nested_last_server_widgets[] = {
// NWidget(WWT_CAPTION, COLOUR_BROWN, LSW_CAPTION), SetMinimalSize(322, 20), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_SERVER_LIST_LAST_JOINED_SERVER, 0), SetFill(1, 1),
//EndContainer(),
NWidget(NWID_HORIZONTAL), SetPadding(4),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, LSW_BUTTON), SetMinimalSize(322, 20), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST, 0), SetFill(1, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, LSW_BUTTON), SetMinimalSize(322, 20), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST, CM_STR_SCS_COMPANY_NEW_JOIN_TOOLTIP), SetFill(1, 1),
EndContainer(),
EndContainer(),
};
@@ -1317,18 +1323,39 @@ void ShowLoginWindow() {
else AllocateWindowDescFront<LoginWindow>(&_admin_window_desc, 0);
};
void ShowAdminCompanyButtons(int left, int top, int width, int company2) {
IniInitiate();
CheckCommunity();
void ShowAdminCompanyButtons(int left, int top, int width, int company2, bool draw, bool redraw) {
//IniInitiate();
//CheckCommunity();
if (!draw) {
CloseWindowById(CM_WC_ADMIN_COMPANY_BUTTONS, company2);
/* clear for company */
ACB_Location[company2 - 1][0]=0;
ACB_Location[company2 - 1][1]=0;
ACB_Location[company2 - 1][2]=0;
return;
}
if (!Company::IsValidID((CompanyID)(company2-1))) return;
if ((left == ACB_Location[company2 - 1][0]) &&
(top == ACB_Location[company2 - 1][1]) &&
(width == ACB_Location[company2 - 1][2]) &&
(!redraw))
return;
/* set for company */
ACB_Location[company2 - 1][0] = left;
ACB_Location[company2 - 1][1] = top;
ACB_Location[company2 - 1][2] = width;
CloseWindowById(CM_WC_ADMIN_COMPANY_BUTTONS, company2);
Window *w;
CloseWindowById(CM_WC_ADMIN_COMPANY_BUTTONS, company2);
w = new AdminCompanyButtonsWindow(&_admin_company_buttons_desc, company2);
w->top = top;
w->left = left + width;
w->SetDirty();
};
/* last server widget */
void JoinLastServer(int left, int top, int height) {
CloseWindowByClass(CM_LAST_SERVER);
Window *d;

View File

@@ -6,7 +6,7 @@ namespace citymania {
void ShowCommandsToolbar();
void ShowLoginWindow();
void CheckAdmin();
void ShowAdminCompanyButtons(int left, int top, int width, int company2);
void ShowAdminCompanyButtons(int left, int top, int width, int company2, bool draw, bool redraw);
void JoinLastServer(int left, int top, int height);
bool GetAdmin();

View File

@@ -53,6 +53,8 @@
#include "safeguards.h"
/* Admin company buttons */
bool Show_ACB[15];
/** Company GUI constants. */
static void DoSelectCompanyManagerFace(Window *parent);
@@ -2199,7 +2201,7 @@ static constexpr NWidgetPart _nested_company_widgets[] = {
EndContainer(),
/* Admin company buttons */
NWidget(NWID_SELECTION, INVALID_COLOUR, CM_WID_C_SELECT_ADMINBUTTONS),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, CM_WID_C_ADMINBUTTONS), SetDataTip(CM_STR_ACB_COMPANY_ADMIN_BUTTON, CM_STR_ACB_COMPANY_ADMIN_BUTTON),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, CM_WID_C_ADMINBUTTONS), SetDataTip(CM_STR_ACB_COMPANY_ADMIN_BUTTON, CM_STR_ACB_COMPANY_ADMIN_BUTTON_TOOLTIP),
EndContainer(),
EndContainer(),
EndContainer(),
@@ -2291,7 +2293,7 @@ struct CompanyWindow : Window
/* Button bar selection. */
reinit |= this->GetWidget<NWidgetStacked>(WID_C_SELECT_BUTTONS)->SetDisplayedPlane(local ? 0 : SZSP_NONE);
/* Admin company buttons */
/* Admin company buttons: show/hide admin menue button from param of citymania.cfg */
citymania::CheckAdmin();
reinit |= this->GetWidget<NWidgetStacked>(CM_WID_C_SELECT_ADMINBUTTONS)->SetDisplayedPlane(citymania::GetAdmin() ? 0 : SZSP_NONE);
@@ -2314,10 +2316,13 @@ struct CompanyWindow : Window
if (reinit) {
this->ReInit();
/* Admin company buttons: recall buttons while join/leave company */
if (Show_ACB[this->window_number]) citymania::ShowAdminCompanyButtons(this->left, this->top, this->width, this->window_number + 1, Show_ACB[this->window_number], true);
return;
}
}
/* Admin company buttons: recall buttons while moving company window */
if (Show_ACB[this->window_number]) citymania::ShowAdminCompanyButtons(this->left, this->top, this->width, this->window_number + 1, Show_ACB[this->window_number], false);
this->DrawWidgets();
}
@@ -2605,11 +2610,12 @@ struct CompanyWindow : Window
MarkWholeScreenDirty();
break;
}
/* Admin company buttons */
case CM_WID_C_ADMINBUTTONS:
{
CompanyID company2 = (CompanyID)this->window_number;
citymania::ShowAdminCompanyButtons(this->left, this->top, this->width, company2+1);
/* Admin company buttons: show/hide buttons */
case CM_WID_C_ADMINBUTTONS: {
CompanyID company2 = (CompanyID)this->window_number;
if (!Show_ACB[company2]) Show_ACB[company2] = true;
else Show_ACB[company2] = false;
citymania::ShowAdminCompanyButtons(this->left, this->top, this->width,company2 + 1, Show_ACB[company2], false);
break;
}
}

View File

@@ -191,8 +191,6 @@ struct SelectGameWindow : public Window {
this->cur_viewport_command_time = 0;
this->mouse_idle_time = 0;
this->mouse_idle_pos = _cursor.pos;
citymania::JoinLastServer(this->left, this->top, this->height);
}
void OnRealtimeTick(uint delta_ms) override
@@ -300,6 +298,8 @@ struct SelectGameWindow : public Window {
DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_INTRO_TRANSLATION, TC_FROMSTRING, SA_CENTER);
break;
}
/* last server widget */
citymania::JoinLastServer(this->left, this->top, this->height);
}
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override

View File

@@ -6326,6 +6326,7 @@ CM_STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT :{BLACK}Show hid
### Admin Company Buttons ###
CM_STR_ACB_COMPANY_ADMIN_CAPTION :{WHITE}Admin buttons #{NUM}
CM_STR_ACB_COMPANY_ADMIN_BUTTON :{WHITE}Admin buttons
CM_STR_ACB_COMPANY_ADMIN_BUTTON_TOOLTIP :{BLACK}Show / hide the admin buttons.
CM_STR_ACB_LOCK :{BLACK}Lock
CM_STR_ACB_LOCK_TOOLTIP :{BLACK}Lock Company. All players on it will be sent to spectators.
CM_STR_ACB_UNLOCK :{BLACK}Unlock
@@ -6369,3 +6370,6 @@ CM_STR_ACB_PLAYER_NEWSTICKET :{BLACK}Type mes
CM_STR_ACB_COMPANY_NEWSTICKET :{BLACK}Type message as newspapper ticket to this Company
CM_STR_ACB_COMPANY_JOIN2 :{BLACK}A. Join
CM_STR_ACB_COMPANY_JOIN2_TOOLTIP :{BLACK}Join as an admin
### Several command strings ###
CM_STR_SCS_COMPANY_NEW_JOIN_TOOLTIP :Hold CTRL and click for joining with new company.

View File

@@ -40,6 +40,7 @@
#include "../citymania/cm_client_list_gui.hpp"
#include "../citymania/cm_commands.hpp"
#include "../citymania/cm_newgrf_revisions.hpp"
#include "../citymania/cm_commands_gui.hpp" /* Admin company buttons */
#include "../safeguards.h"
@@ -1325,7 +1326,8 @@ void NetworkClientsToSpectators(CompanyID cid)
NetworkTextMessage(NETWORK_ACTION_COMPANY_SPECTATOR, CC_DEFAULT, false, ci->client_name);
ci->client_playas = COMPANY_SPECTATOR;
}
/* Admin company buttons: delete window */
citymania::ShowAdminCompanyButtons(0, 0, 0, cid+1, false, false);
cur_company.Restore();
}