Skip to content

Commit

Permalink
Display the stock amount of modules in the mod fab screen
Browse files Browse the repository at this point in the history
Also recator a bit. #44
  • Loading branch information
usox committed Aug 29, 2019
1 parent 2bb0ab7 commit afe6b7f
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function handle(GameControllerInterface $game): void
$game->getUser()->getId()
);

$game->setView('SHOW_MODULE_CANCEL');
$module_id = request::postIntFatal('module');
$function = request::postIntFatal('func');
$count = request::postInt('count');
Expand All @@ -41,6 +40,9 @@ public function handle(GameControllerInterface $game): void
* @var Modules $module
*/
$module = ResourceCache()->getObject('module', $module_id);

$game->setView('SHOW_MODULE_CANCEL', ['MODULE' => $module]);

if (count(Colfields::getFieldsByBuildingFunction($colony->getId(), $function)) == 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BuildingFunctions;
use Colfields;
use Colony;
use ModuleBuildingFunction;
use request;
use Stu\Module\Control\ActionControllerInterface;
use Stu\Module\Control\GameControllerInterface;
Expand Down Expand Up @@ -73,12 +72,6 @@ public function handle(GameControllerInterface $game): void
case MENU_MODULEFAB:
if ($colony->hasModuleFab()) {
$game->setView('SHOW_MODULEFAB');
$func = new BuildingFunctions(request::getIntFatal('func'));
$game->setTemplateVar('FUNC', $func);
$game->setTemplateVar(
'MODULE_LIST',
ModuleBuildingFunction::getByFunctionAndUser($func->getFunction(), $userId)
);
return;
}
case MENU_FIGHTER_SHIPYARD:
Expand Down
11 changes: 11 additions & 0 deletions src/Module/Colony/View/ShowModuleCancel/ShowModuleCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Stu\Module\Colony\View\ShowModuleCancel;

use ModuleQueue;
use ModulesData;
use Stu\Module\Control\GameControllerInterface;
use Stu\Module\Control\ViewControllerInterface;
use Stu\Module\Colony\Lib\ColonyLoaderInterface;
Expand Down Expand Up @@ -33,11 +35,20 @@ public function handle(GameControllerInterface $game): void
$userId
);

/**
* @var ModulesData $module
*/
$module = $game->getViewContext()['MODULE'];

$queuedAmount = ModuleQueue::getAmountByColonyAndModule($colony->getId(), $module->getId());

$game->showMacro('html/colonymacros.xhtml/queue_count');
$game->setTemplateVar(
'MODULE',
ResourceCache()->getObject('module', $this->showModuleCancelRequest->getModuleId())
);
$game->setTemplateVar('COLONY', $colony);
$game->setTemplateVar('MODULE_ID', $module->getId());
$game->setTemplateVar('QUEUED_AMOUNT', $queuedAmount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Stu\Module\Colony\View\ShowModuleFab;

use ColonyData;
use ModuleQueue;
use ModulesData;

final class ModuleFabricationListItemTal
{
private $colony;

private $module;

public function __construct(
ModulesData $module,
ColonyData $colony
) {
$this->colony = $colony;
$this->module = $module;
}

public function getModule(): ModulesData
{
return $this->module;
}

public function getModuleId(): int
{
return (int)$this->module->getId();
}

public function getGoodId(): int
{
return (int)$this->module->getGoodId();
}

public function getName(): string
{
return $this->module->getName();
}

public function getEnergyCost(): int
{
return (int)$this->module->getEcost();
}

public function getConstructionCosts(): array
{
return $this->module->getCost();
}

public function getAmountQueued(): int
{
return ModuleQueue::getAmountByColonyAndModule($this->colony->getId(), $this->module->getId());
}

public function getAmountInStock(): int
{
$result = $this->colony->getStorage()[$this->getGoodId()] ?? null;

if ($result === null) {
return 0;
}
return (int) $result->getAmount();
}
}
22 changes: 16 additions & 6 deletions src/Module/Colony/View/ShowModuleFab/ShowModuleFab.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace Stu\Module\Colony\View\ShowModuleFab;

use BuildingFunctions;
use ColonyMenu;
use ModuleBuildingFunction;
use Modules;
use request;
use Stu\Module\Control\GameControllerInterface;
use Stu\Module\Control\ViewControllerInterface;
use Stu\Module\Colony\Lib\ColonyGuiHelperInterface;
use Stu\Module\Colony\Lib\ColonyLoaderInterface;

final class ShowModuleFab implements ViewControllerInterface
Expand All @@ -16,17 +19,13 @@ final class ShowModuleFab implements ViewControllerInterface

private $colonyLoader;

private $colonyGuiHelper;

private $showModuleFabRequest;

public function __construct(
ColonyLoaderInterface $colonyLoader,
ColonyGuiHelperInterface $colonyGuiHelper,
ShowModuleFabRequestInterface $showModuleFabRequest
) {
$this->colonyLoader = $colonyLoader;
$this->colonyGuiHelper = $colonyGuiHelper;
$this->showModuleFabRequest = $showModuleFabRequest;
}

Expand All @@ -39,11 +38,22 @@ public function handle(GameControllerInterface $game): void
$userId
);

$this->colonyGuiHelper->register($colony, $game);
$func = new BuildingFunctions(request::getIntFatal('func'));
$modules = ModuleBuildingFunction::getByFunctionAndUser($func->getFunction(), $userId);

$list = [];
foreach ($modules as $module) {
$list[] = new ModuleFabricationListItemTal(
new Modules($module->getModuleId()),
$colony
);
}

$game->showMacro('html/colonymacros.xhtml/cm_modulefab');

$game->setTemplateVar('COLONY', $colony);
$game->setTemplateVar('COLONY_MENU_SELECTOR', new ColonyMenu(MENU_MODULEFAB));
$game->setTemplateVar('FUNC', $func);
$game->setTemplateVar('MODULE_LIST', $list);
}
}
2 changes: 1 addition & 1 deletion src/admin/help/buildingcosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Baukosten für '.$building->getName().'<br /><b>Goodid</b> <b>Count</b><br />
<img src="../../assets/buttons/e_trans1.gif" /> <input type="text" value="'.$building->getEpsCost().'" size="4" name="eps" /><br />';
foreach ($building->getCosts() as $key => $obj) {
echo '<img src="../../assets/goods/'.$obj->getGoodId().'.gif" /> <input type="text" size="4" name="goodid[]" value="'.$obj->getGoodId().'" /> <input type="text" size="4" name="costs[]" value="'.$obj->getCount().'" /><br />';
echo '<img src="../../assets/goods/'.$obj->getGoodId().'.gif" /> <input type="text" size="4" name="goodid[]" value="'.$obj->getGoodId().'" /> <input type="text" size="4" name="costs[]" value="'.$obj->getAmount().'" /><br />';
}
$i = 0;
while($i<15) {
Expand Down
39 changes: 4 additions & 35 deletions src/class/module_queue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ static function countInstances($sql="") { #{{{
return DB()->query("SELECT COUNT(*) FROM ".self::tablename." ".$sql,1);
} # }}}

/**
*/
static function getByColonyAndModule($colony_id,$module_id) { #{{{
static function getAmountByColonyAndModule($colony_id,$module_id): int {
$result = DB()->query("SELECT * FROM ".self::tablename." WHERE colony_id=".$colony_id." AND module_id=".$module_id,4);
if ($result == 0) {
return FALSE;
return 0;
}
return new ModuleQueueData($result);
} # }}}
return (int) $result['count'];
}

/**
*/
Expand Down Expand Up @@ -148,32 +146,3 @@ static function queueModule($colony_id,$function,$module_id,$count) { #{{{
} # }}}

} #}}}

/**
* @author Daniel Jakob <[email protected]>
* @version $Revision: 1.4 $
* @access public
*/
class ModuleQueueColonyWrapper { #{{{

private $module_id = 0;

/**
*/
function __construct($module_id) { #{{{
$this->module_id = $module_id;
} # }}}

/**
*/
function __get($colony_id) { #{{{
$queue = ModuleQueue::getByColonyAndModule($colony_id,$this->module_id);
if (!$queue) {
return FALSE;
}
return $queue->getAmount();
} # }}}

} #}}}

?>
6 changes: 0 additions & 6 deletions src/class/modules.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ public function setEcost($value) { # {{{
public function getEcost() { # {{{
return $this->data['ecost'];
} # }}}

/**
*/
public function getQueueCount() { #{{{
return new ModuleQueueColonyWrapper($this->getId());
} # }}}

/**
*/
Expand Down
52 changes: 33 additions & 19 deletions src/html/colonymacros.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -729,52 +729,66 @@
<stu:hidden name="id" tal:attributes="value COLONY/getId" />
<stu:hidden name="sstr" tal:attributes="value THIS/getSessionString" />
<stu:hidden name="func" tal:attributes="value FUNC/getFunction" />
<br />
<table class="tcal">
<tr>
<th i18n:translate="">Verfügbare Module</th>
<th i18n:translate="">Anzahl</th>
<th i18n:translate="">In Bau</th>
<th i18n:translate="">Lagernd</th>
<th i18n:translate="">Anzahl</th>
</tr>
<tr tal:repeat="data MODULE_LIST" tal:attributes="class string:row${repeat/data/odd}">
<td tal:define="module data/getModule">
<td>
<div style="margin-bottom: 5px;">
<img src="${GFX}/goods/${module/getGoodId}.gif" /> <span tal:content="module/getName">NAME</span>
<img src="${GFX}/goods/${data/getGoodId}.gif" /> <span tal:content="data/getName">NAME</span>
</div>
<div style="display: table-cell;">
<img src="${GFX}/buttons/e_trans2.gif" title="Energie" i18n:attributes="title" /> <span tal:replace="module/getEcost">ECOST</span>
<img src="${GFX}/buttons/e_trans2.gif" title="Energie" i18n:attributes="title" /> <span tal:replace="data/getEnergyCost">ECOST</span>
</div>
<tal:block tal:repeat="cost module/getCost">
<tal:block tal:repeat="cost data/getConstructionCosts">
<div style="display: table-cell; padding-left: 4px;">
<img src="${GFX}/goods/${cost/getGoodId}.gif" />
</div>
<div style="display: table-cell; vertical-align: middle;" tal:content="cost/getAmount">COST</div>
</tal:block>
</td>
<td style="vertical-align: middle; text-align: center;">
<input type="text" size="2" name="module[${data/getModule/getId}]" />
</td>
<td id="module_${data/getModuleId}_action" style="vertical-align: middle; text-align: center;">
<metal:macro metal:use-macro="queue_count" tal:define="MODULE data/getModule" />
<td id="module_${data/getModuleId}_action" style="vertical-align: middle; text-align: center;" tal:define="QUEUED_AMOUNT data/getAmountQueued">
<div tal:condition="QUEUED_AMOUNT">
<div style="display: table-cell; vertical-align:middle;">
<input type="text" size="2" name="cancel_module[${data/getModuleId}]" id="module_${data/getModuleId}_count" tal:attributes="value QUEUED_AMOUNT" />
</div>
<div style="display: table-cell; vertical-align:middle; padding-left: 4px;">
<stu:imagelink href="Javascript:cancelModuleQueueEntries(${data/getModuleId});" image="x" title="Anzahl löschen" i18n:attributes="title" />
</div>
</div>
<div tal:condition="not:QUEUED_AMOUNT">-</div>
</td>
<td style="vertical-align: middle; text-align: center;" tal:content="data/getAmountInStock">
</td>
<td style="vertical-align: middle; text-align: center;">
<input type="text" size="2" name="module[${data/getModuleId}]" />
</td>
</tr>
<tr>
<td colspan="3"></td>
<td>
<stu:submit name="B_CREATE_MODULES" value="Herstellen" i18n:attributes="value" />
</td>
</tr>
</table>
<br />
<div style="width: 100%; text-align: center;">
<stu:submit name="B_CREATE_MODULES" value="Herstellen" i18n:attributes="value" />
</div>
</div>
</metal:macro>
</metal:block>
<metal:macro metal:define-macro="queue_count" tal:define="queue_count MODULE/getQueueCount/${COLONY/getId}">
<div tal:condition="queue_count">
<metal:macro metal:define-macro="queue_count">
<div tal:condition="QUEUED_AMOUNT">
<div style="display: table-cell; vertical-align:middle;">
<input type="text" size="2" name="cancel_module[${MODULE/getId}]" id="module_${MODULE/getId}_count" tal:attributes="value queue_count" />
<input type="text" size="2" name="cancel_module[${MODULE_ID}]" id="module_${MODULE_ID}_count" tal:attributes="value QUEUED_AMOUNT" />
</div>
<div style="display: table-cell; vertical-align:middle; padding-left: 4px;">
<stu:imagelink href="Javascript:cancelModuleQueueEntries(${MODULE/getId});" image="x" title="Anzahl löschen" i18n:attributes="title" />
<stu:imagelink href="Javascript:cancelModuleQueueEntries(${MODULE_ID});" image="x" title="Anzahl löschen" i18n:attributes="title" />
</div>
</div>
<div tal:condition="not:queue_count">-</div>
<div tal:condition="not:QUEUED_AMOUNT">-</div>
</metal:macro>
<metal:block metal:define-macro="cm_shipyard">
<metal:macro metal:use-macro="cm_shipyard_tabs" />
Expand Down

0 comments on commit afe6b7f

Please sign in to comment.