mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r23621) -Add: allow manipulation of signs via GameScripts
This commit is contained in:
parent
afcf07ac8a
commit
e7cd301d3c
@ -253,8 +253,8 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdRenameStation, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION
|
||||
DEF_CMD(CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT
|
||||
|
||||
DEF_CMD(CmdPlaceSign, 0, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
|
||||
DEF_CMD(CmdRenameSign, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
|
||||
DEF_CMD(CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN
|
||||
DEF_CMD(CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN
|
||||
|
||||
DEF_CMD(CmdTurnRoadVeh, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_TURN_ROADVEH
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include "../script/api/game/game_rail.hpp.sq"
|
||||
#include "../script/api/game/game_railtypelist.hpp.sq"
|
||||
#include "../script/api/game/game_road.hpp.sq"
|
||||
#include "../script/api/game/game_sign.hpp.sq"
|
||||
#include "../script/api/game/game_signlist.hpp.sq"
|
||||
#include "../script/api/game/game_station.hpp.sq"
|
||||
#include "../script/api/game/game_stationlist.hpp.sq"
|
||||
@ -125,6 +126,7 @@ void GameInstance::RegisterAPI()
|
||||
SQGSRail_Register(this->engine);
|
||||
SQGSRailTypeList_Register(this->engine);
|
||||
SQGSRoad_Register(this->engine);
|
||||
SQGSSign_Register(this->engine);
|
||||
SQGSSignList_Register(this->engine);
|
||||
SQGSStation_Register(this->engine);
|
||||
SQGSStationList_Register(this->engine);
|
||||
|
39
src/script/api/game/game_sign.hpp.sq
Normal file
39
src/script/api/game/game_sign.hpp.sq
Normal file
@ -0,0 +1,39 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "../script_sign.hpp"
|
||||
#include "../template/template_sign.hpp.sq"
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptSign, ST_GS>() { return "GSSign"; }
|
||||
|
||||
void SQGSSign_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptSign, ST_GS> SQGSSign("GSSign");
|
||||
SQGSSign.PreRegister(engine);
|
||||
SQGSSign.AddConstructor<void (ScriptSign::*)(), 1>(engine, "x");
|
||||
|
||||
SQGSSign.DefSQConst(engine, ScriptSign::ERR_SIGN_BASE, "ERR_SIGN_BASE");
|
||||
SQGSSign.DefSQConst(engine, ScriptSign::ERR_SIGN_TOO_MANY_SIGNS, "ERR_SIGN_TOO_MANY_SIGNS");
|
||||
|
||||
ScriptError::RegisterErrorMap(STR_ERROR_TOO_MANY_SIGNS, ScriptSign::ERR_SIGN_TOO_MANY_SIGNS);
|
||||
|
||||
ScriptError::RegisterErrorMapString(ScriptSign::ERR_SIGN_TOO_MANY_SIGNS, "ERR_SIGN_TOO_MANY_SIGNS");
|
||||
|
||||
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::IsValidSign, "IsValidSign", 2, ".i");
|
||||
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::SetName, "SetName", 3, ".i.");
|
||||
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetName, "GetName", 2, ".i");
|
||||
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetLocation, "GetLocation", 2, ".i");
|
||||
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::BuildSign, "BuildSign", 3, ".i.");
|
||||
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::RemoveSign, "RemoveSign", 2, ".i");
|
||||
|
||||
SQGSSign.PostRegister(engine);
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
/* static */ bool ScriptSign::IsValidSign(SignID sign_id)
|
||||
{
|
||||
const Sign *si = ::Sign::GetIfValid(sign_id);
|
||||
return si != NULL && si->owner == _current_company;
|
||||
return si != NULL && (si->owner == _current_company || si->owner == OWNER_DEITY);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptSign::SetName(SignID sign_id, const char *name)
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
/**
|
||||
* Class that handles all sign related functions.
|
||||
* @api ai
|
||||
* @api ai game
|
||||
*/
|
||||
class ScriptSign : public ScriptObject {
|
||||
public:
|
||||
|
@ -78,6 +78,7 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
{
|
||||
Sign *si = Sign::GetIfValid(p1);
|
||||
if (si == NULL) return CMD_ERROR;
|
||||
if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
/* Rename the signs when empty, otherwise remove it */
|
||||
if (!StrEmpty(text)) {
|
||||
|
@ -75,6 +75,7 @@ struct SignList {
|
||||
const Sign *si;
|
||||
FOR_ALL_SIGNS(si) *this->signs.Append() = si;
|
||||
|
||||
this->signs.SetFilterState(true);
|
||||
this->FilterSignList();
|
||||
this->signs.Compact();
|
||||
this->signs.RebuildDone();
|
||||
@ -119,6 +120,13 @@ struct SignList {
|
||||
return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
|
||||
}
|
||||
|
||||
/** Filter sign list excluding OWNER_DEITY */
|
||||
static bool CDECL OwnerDeityFilter(const Sign * const *a, FilterInfo filter_info)
|
||||
{
|
||||
/* You should never be able to edit signs of owner DEITY */
|
||||
return (*a)->owner != OWNER_DEITY;
|
||||
}
|
||||
|
||||
/** Filter sign list by owner */
|
||||
static bool CDECL OwnerVisibilityFilter(const Sign * const *a, FilterInfo filter_info)
|
||||
{
|
||||
@ -132,6 +140,7 @@ struct SignList {
|
||||
{
|
||||
FilterInfo filter_info = {this->filter_string, this->match_case};
|
||||
this->signs.Filter(&SignNameFilter, filter_info);
|
||||
this->signs.Filter(&OwnerDeityFilter, filter_info);
|
||||
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
|
||||
this->signs.Filter(&OwnerVisibilityFilter, filter_info);
|
||||
}
|
||||
@ -196,14 +205,11 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
|
||||
/* Copy new filter string */
|
||||
strecpy(this->filter_string, new_filter_string, lastof(this->filter_string));
|
||||
|
||||
this->signs.SetFilterState(true);
|
||||
|
||||
this->EnableWidget(WID_SIL_FILTER_CLEAR_BTN);
|
||||
} else {
|
||||
/* There is no new string -> clear this->filter_string */
|
||||
this->filter_string[0] = '\0';
|
||||
|
||||
this->signs.SetFilterState(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); // keep sign list filtering active if competitor signs should be hidden
|
||||
this->DisableWidget(WID_SIL_FILTER_CLEAR_BTN);
|
||||
}
|
||||
|
||||
@ -378,11 +384,6 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
|
||||
*/
|
||||
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
||||
{
|
||||
if (data == -1) {
|
||||
/* The DO_SHOW_COMPETITOR_SIGNS display option has changed */
|
||||
this->signs.SetFilterState(!StrEmpty(this->filter_string) || !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
|
||||
}
|
||||
|
||||
/* When there is a filter string, we always need to rebuild the list even if
|
||||
* the amount of signs in total is unchanged, as the subset of signs that is
|
||||
* accepted by the filter might has changed. */
|
||||
|
@ -1126,7 +1126,7 @@ static void ViewportAddLandscape()
|
||||
* @param string_normal String for normal and 2x zoom level
|
||||
* @param string_small String for 4x and 8x zoom level
|
||||
* @param string_small_shadow Shadow string for 4x and 8x zoom level; or #STR_NULL if no shadow
|
||||
* @param colour colour of the sign background; or 0 if transparent
|
||||
* @param colour colour of the sign background; or INVALID_COLOUR if transparent
|
||||
*/
|
||||
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2, Colours colour)
|
||||
{
|
||||
@ -1207,12 +1207,12 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
|
||||
/* Don't draw if sign is owned by another company and competitor signs should be hidden.
|
||||
* Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt
|
||||
* companies can leave OWNER_NONE signs after them. */
|
||||
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner) continue;
|
||||
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner && si->owner != OWNER_DEITY) continue;
|
||||
|
||||
ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &si->sign,
|
||||
STR_WHITE_SIGN,
|
||||
IsTransparencySet(TO_SIGNS) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
|
||||
si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : _company_colours[si->owner]);
|
||||
(IsTransparencySet(TO_SIGNS) || si->owner == OWNER_DEITY) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
|
||||
si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : (si->owner == OWNER_DEITY ? INVALID_COLOUR : _company_colours[si->owner]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1873,6 +1873,7 @@ static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
|
||||
FOR_ALL_SIGNS(si) {
|
||||
/* If competitor signs are hidden, don't check signs that aren't owned by local company */
|
||||
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner) continue;
|
||||
if (si->owner == OWNER_DEITY) continue;
|
||||
|
||||
if (CheckClickOnViewportSign(vp, x, y, &si->sign)) {
|
||||
HandleClickOnSign(si);
|
||||
|
Loading…
Reference in New Issue
Block a user